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 Details

  • Method Details

    • 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:
      interceptRequest in interface ca.uhn.fhir.rest.client.api.IClientInterceptor
    • interceptResponse

      public void interceptResponse(ca.uhn.fhir.rest.client.api.IHttpResponse theResponse)
      Specified by:
      interceptResponse in interface ca.uhn.fhir.rest.client.api.IClientInterceptor
    • isBufferResponse

      public boolean isBufferResponse()
      Should we buffer (capture) the response body? This defaults to false. Set to true if 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 to false. Set to true if you are planning on examining response bodies after the response processing is complete.