Stream: hapi
Topic: CapturingInterceptor
Jenni Syed (Dec 16 2016 at 18:56):
I've been playing around with the capturingInterceptor to try to pull the raw response. However, the stream is always closed after the client execution is done.
Jenni Syed (Dec 16 2016 at 18:57):
For example:
Bundle bundle = client.search().byUrl(queryUrl).returnBundle(Bundle.class).execute();
IOUtils.toString(capturingInterceptor.myLastResponse.readEntity());
Will always throw an exception for reading from a closed stream
Jenni Syed (Dec 16 2016 at 18:58):
Is there some other path that will allow me to get to the raw entity body from the response after the execute?
Jenni Syed (Dec 16 2016 at 18:59):
HAPI 2.1, if it makes a difference
Jenni Syed (Dec 16 2016 at 19:01):
It looks like the interceptor has a direct copy of the original response, so it's not that surprising that the stream is closed once HAPI parses it. However, it was a bit surprising because I was expecting the interceptor to be used for this exact situation :)
Jenni Syed (Dec 16 2016 at 19:02):
I've also been staring at a bunch of code for a while, so I could be missing something.
Jenni Syed (Dec 16 2016 at 22:36):
Note: I got past this by creating my own interceptor, calling the bufferResponse() method when the interceptResponse(...) method was called, and copying the entity (in string form for now) to another field.
James Agnew (Dec 19 2016 at 16:03):
Hey @Jenni Syed , The right way to avoid the is to call bufferEntitity()
on the IHttpResponse
method (presumably that's what you meant by bufferResponse()
?) so you're definitely doing this the "right" way.
CaptureInterceptor should probably do exactly what you're doing.. I've only ever used it to capture the request URL which is why it hasn't led to the problem you're talking about. (Any chance you want to contribute your interceptor? Happy to include it if you think it'd be a worthwhile successor to CaptureInterceptor)
As a dumb aside, I see that bufferEntitity
has a typo. Sigh, will fix that and deprecate the old method...
Jenni Syed (Dec 19 2016 at 16:12):
@James Agnew any interest in "fixing" the existing Interceptor? The documentation seems to indicate getting the response is one of the functions that should be available there? If so, I can look at contributing a patch that fixes it.
James Agnew (Dec 19 2016 at 16:13):
That'd be awesome, yeah
Last updated: Apr 12 2022 at 19:14 UTC