FHIR Chat · CapturingInterceptor · hapi

Stream: hapi

Topic: CapturingInterceptor


view this post on Zulip 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.

view this post on Zulip 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

view this post on Zulip 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?

view this post on Zulip Jenni Syed (Dec 16 2016 at 18:59):

HAPI 2.1, if it makes a difference

view this post on Zulip 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 :)

view this post on Zulip 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.

view this post on Zulip 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.

view this post on Zulip 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...

view this post on Zulip 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.

view this post on Zulip James Agnew (Dec 19 2016 at 16:13):

That'd be awesome, yeah


Last updated: Apr 12 2022 at 19:14 UTC