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

Jpos hangs on response 204 #208

Closed
mpp-jamesl opened this issue Mar 23, 2021 · 0 comments
Closed

Jpos hangs on response 204 #208

mpp-jamesl opened this issue Mar 23, 2021 · 0 comments

Comments

@mpp-jamesl
Copy link
Contributor

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.

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
…ponse-204

fix(Issue #208): Jpos hangs on htp response 204 no content
@ar ar closed this as completed Mar 24, 2021
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

2 participants