You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When sending a request to an API which returns a 204 on success.
If you need to have the responseBodyOnError = true
and the API sends back a 204 on success the Jpos server just hangs. The issue is around the following code within the HttpQuery class
The actual problem is in this line
ctx.put (responseName, EntityUtils.toString(result.getEntity()));
It is because the EntityUtils is attempting to convert the result.getEntity into an entity to assign as the value for the response name in the context map, in this case the result is actually null so instead of the EntityUtils throwing an exception, it just causes the server to hang.
This causes a hang because the response does not have a body given the 204.
There should be null safety checks here and if the result.getEntity is null then assign the status value (sc) to the context instead.
The text was updated successfully, but these errors were encountered:
mpp-jamesl
pushed a commit
to mpp-jamesl/jPOS-EE
that referenced
this issue
Mar 23, 2021
Jpos hangs when a server response is 204 no content. in the case where
the responseBodyOnError is set true and the response status is 204 jpos
hangs becuase there is no response body to process. This causes the
EntityUtils to attempt to process the response, calling the
result.getEntity() which does nothing. This change allows for the
situation where 204 is the response staus, and the responseBodyOnError
to be true but not call the EntityUtils when there is no response body
to process, by adding the status to the context using the mapping value
of HTTP_RESPONSE_STATUS
ar
added a commit
that referenced
this issue
Mar 24, 2021
Jpos server hangs on HttpResponse 204
When sending a request to an API which returns a 204 on success.
If you need to have the responseBodyOnError = true
and the API sends back a 204 on success the Jpos server just hangs. The issue is around the following code within the HttpQuery class
boolean includeResponse= (sc == HttpStatus.SC_CREATED) || (sc == HttpStatus.SC_OK) || responseOnError; if (includeResponse) { try { ctx.put (responseName, EntityUtils.toString(result.getEntity())); } catch (IOException e) { ctx.log (e); } }
The actual problem is in this line
ctx.put (responseName, EntityUtils.toString(result.getEntity()));
It is because the EntityUtils is attempting to convert the result.getEntity into an entity to assign as the value for the response name in the context map, in this case the result is actually null so instead of the EntityUtils throwing an exception, it just causes the server to hang.
This causes a hang because the response does not have a body given the 204.
There should be null safety checks here and if the result.getEntity is null then assign the status value (sc) to the context instead.
The text was updated successfully, but these errors were encountered: