Class ThreadLocalCapturingInterceptor
- java.lang.Object
-
- ca.uhn.fhir.rest.client.interceptor.ThreadLocalCapturingInterceptor
-
- All Implemented Interfaces:
ca.uhn.fhir.rest.client.api.IClientInterceptor
public class ThreadLocalCapturingInterceptor extends Object implements ca.uhn.fhir.rest.client.api.IClientInterceptor
This is a client interceptor that captures the current request and response in a ThreadLocal variable, meaning that it can work in multithreaded environments without mixing up requests.Use this with caution, since this interceptor does not automatically clean up the ThreadLocal after setting it. You must make sure to call
clearThreadLocals()after a given request has been completed, or you will end up leaving stale request/response objects associated with threads that no longer need them.- Since:
- 3.5.0
- See Also:
for an equivalent interceptor that does not use a ThreadLocal
-
-
Constructor Summary
Constructors Constructor Description ThreadLocalCapturingInterceptor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearThreadLocals()This method should be called at the end of any request process, in order to clear the last request and response from the current thread.ca.uhn.fhir.rest.client.api.IHttpRequestgetRequestForCurrentThread()ca.uhn.fhir.rest.client.api.IHttpResponsegetResponseForCurrentThread()voidinterceptRequest(ca.uhn.fhir.rest.client.api.IHttpRequest theRequest)voidinterceptResponse(ca.uhn.fhir.rest.client.api.IHttpResponse theResponse)booleanisBufferResponse()Should we buffer (capture) the response body? This defaults tofalse.ThreadLocalCapturingInterceptorsetBufferResponse(boolean theBufferResponse)Should we buffer (capture) the response body? This defaults tofalse.
-
-
-
Constructor Detail
-
ThreadLocalCapturingInterceptor
public ThreadLocalCapturingInterceptor()
-
-
Method Detail
-
clearThreadLocals
public void clearThreadLocals()
This method should be called at the end of any request process, in order to clear the last request and response from the current thread.
-
getRequestForCurrentThread
public ca.uhn.fhir.rest.client.api.IHttpRequest getRequestForCurrentThread()
-
getResponseForCurrentThread
public ca.uhn.fhir.rest.client.api.IHttpResponse getResponseForCurrentThread()
-
interceptRequest
public void interceptRequest(ca.uhn.fhir.rest.client.api.IHttpRequest theRequest)
- Specified by:
interceptRequestin interfaceca.uhn.fhir.rest.client.api.IClientInterceptor
-
interceptResponse
public void interceptResponse(ca.uhn.fhir.rest.client.api.IHttpResponse theResponse)
- Specified by:
interceptResponsein interfaceca.uhn.fhir.rest.client.api.IClientInterceptor
-
isBufferResponse
public boolean isBufferResponse()
Should we buffer (capture) the response body? This defaults tofalse. Set totrueif you are planning on examining response bodies after the response processing is complete.
-
setBufferResponse
public ThreadLocalCapturingInterceptor setBufferResponse(boolean theBufferResponse)
Should we buffer (capture) the response body? This defaults tofalse. Set totrueif you are planning on examining response bodies after the response processing is complete.
-
-