Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whenever I get a 405 response from a server, a null pointer exception is thrown because the connection wasn't found #620

Closed
FrankApiyo opened this issue Sep 1, 2022 · 1 comment

Comments

@FrankApiyo
Copy link

Here is my code

        _ (println "do we get here??")
        {:keys [status body] :as response}
        (client/post
         (if edit?
           (get-enketo-instance-endpoint)
           (get-enketo-survey-endpoint))
         {:form-params form-params
          :basic-auth (str enketo-api-key
                           ":")
          :as :application/json})
        _ (println "how about here??")

Here are my logs

zebra_1  | 11:15:50.103 [XNIO-1 task-2] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Starting handshake
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Secure session established
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  negotiated protocol: TLSv1.3
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  negotiated cipher suite: TLS_AES_256_GCM_SHA384
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  peer principal: CN=enketo-stage.ona.io
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  peer alternative names: [enketo-stage.ona.io]
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  issuer principal: CN=R3, O=Let's Encrypt, C=US
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 172.20.0.2:60500<->18.170.246.107:443
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request POST /api_v2/instance HTTP/1.1
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 >> POST /api_v2/instance HTTP/1.1
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 >> Connection: close
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 >> content-type: application/x-www-form-urlencoded
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 >> accept-encoding: gzip, deflate
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 >> authorization: Basic MG5hZDFzcnVwdHM6
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 >> Content-Length: 641
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 >> Host: enketo-stage.ona.io
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 >> User-Agent: Apache-HttpClient/4.5.13 (Java/17.0.2)
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "POST /api_v2/instance HTTP/1.1[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "Connection: close[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "content-type: application/x-www-form-urlencoded[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "accept-encoding: gzip, deflate[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "authorization: Basic MG5hZDFzcnVwdHM6[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "Content-Length: 641[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "Host: enketo-stage.ona.io[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "User-Agent: Apache-HttpClient/4.5.13 (Java/17.0.2)[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "[\r][\n]"
zebra_1  | 11:15:50.384 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 >> "form_id=locs200_1&server_url=https%3A%2F%2Fstage-api.ona.io%2Fenketo%2F3039&instance=%3C%3Fxml+version%3D%221.0%22+%3F%3E%3Cdata+id%3D%22locs200_1%22+instanceID%3D%22uuid%3Auuid%3Ac939805f-f7b0-46b0-a97f-dfcf87f5532c%22+submissionDate%3D%222022-05-12T13%3A46%3A21.230024%22%3E%3Ccity%3ENairobi%3C%2Fcity%3E%3Ccounty%3ENairobi%3C%2Fcounty%3E%3Cformhub%3E++%3Cuuid%3Ec3e5987987bc407ca55d9a5f95eb24d4%3C%2Fuuid%3E%3C%2Fformhub%3E%3Cid%3E1.0%3C%2Fid%3E%3Cmeta%3E++%3CinstanceID%3Euuid%3Ac939805f-f7b0-46b0-a97f-dfcf87f5532c%3C%2FinstanceID%3E%3C%2Fmeta%3E%3C%2Fdata%3E&instance_id=c939805f-f7b0-46b0-a97f-dfcf87f5532c&instance_attachments=%7B%7D"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "HTTP/1.1 405 Method Not Allowed[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "Date: Thu, 01 Sep 2022 11:15:50 GMT[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "Content-Type: application/json; charset=utf-8[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "Content-Length: 81[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "Connection: close[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "X-Powered-By: Express[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "Content-Language: en[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "ETag: W/"51-sQRJVKH3s9LtqKAukgv2ckzuNvw"[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "Vary: Accept-Encoding[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "Strict-Transport-Security: max-age=15724800; includeSubDomains[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "[\r][\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "{[\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "    "code": 405,[\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "    "message": "Not allowed. Record is already being edited"[\n]"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.wire - http-outgoing-19 << "}"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << HTTP/1.1 405 Method Not Allowed
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << Date: Thu, 01 Sep 2022 11:15:50 GMT
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << Content-Type: application/json; charset=utf-8
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << Content-Length: 81
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << Connection: close
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << X-Powered-By: Express
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << Content-Language: en
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << ETag: W/"51-sQRJVKH3s9LtqKAukgv2ckzuNvw"
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << Vary: Accept-Encoding
zebra_1  | 11:15:50.718 [XNIO-1 task-2] DEBUG org.apache.http.headers - http-outgoing-19 << Strict-Transport-Security: max-age=15724800; includeSubDomains
zebra_1  | 11:15:50.719 [XNIO-1 task-2] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-19: Close connection
zebra_1  | 11:15:50.722 [XNIO-1 task-2] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
zebra_1  | 11:15:50.722 [XNIO-1 task-2] DEBUG org.apache.http.impl.conn.BasicHttpClientConnectionManager - Releasing connection [Not bound]
zebra_1  | java.lang.NullPointerException: null
zebra_1  | 11:15:50.729 [XNIO-1 task-2] ERROR ring.logger - {:request-method :get, :uri "/frankapiyo/559/3039/webform", :server-name "localhost", :ring.logger/type :finish, :status 500, :ring.logger/ms 7325}
zebra_1  | 11:15:50.730 [XNIO-1 task-2] DEBUG io.undertow.request.error-response - Setting error code 500 for exchange HttpServerExchange{ GET /frankapiyo/559/3039/webform}
zebra_1  | java.lang.RuntimeException: null
zebra_1  | 	at io.undertow.server.HttpServerExchange.setStatusCode(HttpServerExchange.java:1491)
zebra_1  | 	at ring.adapter.undertow.response$set_exchange_response.invokeStatic(response.clj:57)
zebra_1  | 	at ring.adapter.undertow.response$set_exchange_response.invoke(response.clj:52)
zebra_1  | 	at ring.adapter.undertow$handle_request.invokeStatic(undertow.clj:23)
zebra_1  | 	at ring.adapter.undertow$handle_request.invoke(undertow.clj:19)
zebra_1  | 	at ring.adapter.undertow$undertow_handler$fn$reify__46898.handleRequest(undertow.clj:41)
zebra_1  | 	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
zebra_1  | 	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:859)
zebra_1  | 	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
zebra_1  | 	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2019)
zebra_1  | 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1558)
zebra_1  | 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1449)
zebra_1  | 	at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
zebra_1  | 	at java.base/java.lang.Thread.run(Thread.java:833)



@FrankApiyo
Copy link
Author

It seems client/post throws an error when response is a 4xx that I needed to handle by calling this in a try/catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant