Class ApacheHttpClient4Engine

java.lang.Object
org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine
All Implemented Interfaces:
ClientHttpEngine
Direct Known Subclasses:
ApacheHttpClient43Engine

public class ApacheHttpClient4Engine extends Object implements ClientHttpEngine
Version:
$Revision: 1 $
  • Field Details

    • processId

      private static String processId
      Used to build temp file prefix.
    • httpClient

      protected org.apache.http.client.HttpClient httpClient
    • createdHttpClient

      protected boolean createdHttpClient
    • httpContext

      protected org.apache.http.protocol.HttpContext httpContext
    • httpContextProvider

      protected HttpContextProvider httpContextProvider
    • closed

      protected boolean closed
    • sslContext

      protected SSLContext sslContext
    • hostnameVerifier

      protected HostnameVerifier hostnameVerifier
    • responseBufferSize

      protected int responseBufferSize
    • defaultProxy

      protected org.apache.http.HttpHost defaultProxy
    • chunked

      protected boolean chunked
    • fileUploadInMemoryThresholdLimit

      protected int fileUploadInMemoryThresholdLimit
      For uploading File's over JAX-RS framework, this property, together with fileUploadMemoryUnit, defines the maximum File size allowed in memory. If fileSize exceeds this size, it will be stored to fileUploadTempFileDir.

      Defaults to 1 MB
    • fileUploadMemoryUnit

      protected ApacheHttpClient4Engine.MemoryUnit fileUploadMemoryUnit
      The unit for fileUploadInMemoryThresholdLimit.

      Defaults to MB.
      See Also:
    • fileUploadTempFileDir

      protected File fileUploadTempFileDir
      Temp directory to write output request stream to. Any file to be uploaded has to be written out to the output request stream to be sent to the service and when the File is too huge the output request stream is written out to the disk rather than to memory.

      Defaults to JVM temp directory.
  • Constructor Details

    • ApacheHttpClient4Engine

      public ApacheHttpClient4Engine()
    • ApacheHttpClient4Engine

      public ApacheHttpClient4Engine(org.apache.http.HttpHost defaultProxy)
    • ApacheHttpClient4Engine

      public ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient)
    • ApacheHttpClient4Engine

      public ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, boolean closeHttpClient)
    • ApacheHttpClient4Engine

      @Deprecated public ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
      Deprecated.
      Creates a client engine instance using the specified HttpClient and HttpContext instances. Note that the same instance of httpContext is passed to the engine, which may store thread unsafe attributes in it. It is hence recommended to override the HttpClient
      execute(HttpUriRequest request, HttpContext context)
      method to perform a deep copy of the context before executing the request.
      Parameters:
      httpClient - The http client
      httpContext - The context to be used for executing requests
    • ApacheHttpClient4Engine

      public ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, HttpContextProvider httpContextProvider)
  • Method Details

    • getResponseBufferSize

      public int getResponseBufferSize()
      Response stream is wrapped in a BufferedInputStream. Default is 8192. Value of 0 will not wrap it. Value of -1 will use a SelfExpandingBufferedInputStream
      Returns:
    • setResponseBufferSize

      public void setResponseBufferSize(int responseBufferSize)
      Response stream is wrapped in a BufferedInputStream. Default is 8192. Value of 0 will not wrap it. Value of -1 will use a SelfExpandingBufferedInputStream
      Parameters:
      responseBufferSize -
    • getFileUploadInMemoryThresholdLimit

      public int getFileUploadInMemoryThresholdLimit()
      Based on memory unit
      Returns:
    • setFileUploadInMemoryThresholdLimit

      public void setFileUploadInMemoryThresholdLimit(int fileUploadInMemoryThresholdLimit)
    • getFileUploadMemoryUnit

      public ApacheHttpClient4Engine.MemoryUnit getFileUploadMemoryUnit()
    • setFileUploadMemoryUnit

      public void setFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit fileUploadMemoryUnit)
    • getFileUploadTempFileDir

      public File getFileUploadTempFileDir()
    • setFileUploadTempFileDir

      public void setFileUploadTempFileDir(File fileUploadTempFileDir)
    • getHttpClient

      public org.apache.http.client.HttpClient getHttpClient()
    • getHttpContext

      @Deprecated public org.apache.http.protocol.HttpContext getHttpContext()
      Deprecated.
    • setHttpContext

      @Deprecated public void setHttpContext(org.apache.http.protocol.HttpContext httpContext)
      Deprecated.
    • getSslContext

      public SSLContext getSslContext()
      Description copied from interface: ClientHttpEngine
      Needed for Client.getSslContext();
      Specified by:
      getSslContext in interface ClientHttpEngine
      Returns:
    • setSslContext

      public void setSslContext(SSLContext sslContext)
    • getHostnameVerifier

      public HostnameVerifier getHostnameVerifier()
      Description copied from interface: ClientHttpEngine
      Needed for Client.getHostnameVerifier()
      Specified by:
      getHostnameVerifier in interface ClientHttpEngine
      Returns:
    • setHostnameVerifier

      public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
    • getDefaultProxy

      public org.apache.http.HttpHost getDefaultProxy()
    • extractHeaders

      public static CaseInsensitiveMap<String> extractHeaders(org.apache.http.HttpResponse response)
    • createBufferedStream

      protected InputStream createBufferedStream(InputStream is)
    • invoke

      public ClientResponse invoke(ClientInvocation request)
      Specified by:
      invoke in interface ClientHttpEngine
    • createHttpMethod

      protected org.apache.http.client.methods.HttpRequestBase createHttpMethod(String url, String restVerb)
    • isRedirectRequired

      protected boolean isRedirectRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod)
    • createDefaultHttpClient

      protected org.apache.http.client.HttpClient createDefaultHttpClient()
    • setRedirectRequired

      protected void setRedirectRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod)
    • setRedirectNotRequired

      protected void setRedirectNotRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod)
    • loadHttpMethod

      protected void loadHttpMethod(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod) throws Exception
      Throws:
      Exception
    • commitHeaders

      protected void commitHeaders(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod)
    • close

      public void close()
      Specified by:
      close in interface ClientHttpEngine
    • isClosed

      public boolean isClosed()
    • finalize

      public void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • isChunked

      public boolean isChunked()
    • setChunked

      public void setChunked(boolean chunked)
    • cleanUpAfterExecute

      protected void cleanUpAfterExecute(org.apache.http.client.methods.HttpRequestBase httpMethod)
      If passed httpMethod is of type HttpPost then obtain its entity. If the entity has an enclosing File then delete it by invoking this method after the request has completed. The entity will have an enclosing File only if it was too huge to fit into memory.
      Parameters:
      httpMethod - - the httpMethod to clean up.
    • buildEntity

      protected org.apache.http.HttpEntity buildEntity(ClientInvocation request) throws IOException
      Build the HttpEntity to be sent to the Service as part of (POST) request. Creates a off-memory ApacheHttpClient4Engine.FileExposingFileEntity or a regular in-memory ByteArrayEntity depending on if the request OutputStream fit into memory when built by calling.
      Parameters:
      request - -
      Returns:
      - the built HttpEntity
      Throws:
      IOException - -
    • writeRequestBodyToOutputStream

      private org.apache.commons.io.output.DeferredFileOutputStream writeRequestBodyToOutputStream(ClientInvocation request) throws IOException
      Creates the request OutputStream, to be sent to the end Service invoked, as a DeferredFileOutputStream.
      Parameters:
      request - -
      Returns:
      - DeferredFileOutputStream with the ClientRequest written out per HTTP specification.
      Throws:
      IOException - -
    • getTempfilePrefix

      protected String getTempfilePrefix()
      Use context information, which will include node name, to avoid conflicts in case of multiple VMS using same temp directory location.
      Returns:
      -
    • getMemoryUnitMultiplier

      private int getMemoryUnitMultiplier()
      Returns:
      - the constant to multiply fileUploadInMemoryThresholdLimit with based on fileUploadMemoryUnit enumeration value.
    • handleFileNotDeletedError

      private void handleFileNotDeletedError(File tempRequestFile, Exception ex)
      Log that the file did not get deleted but prevent the request from failing by eating the exception. Register the file to be deleted on exit, so it will get deleted eventually.
      Parameters:
      tempRequestFile - -
      ex - - a null may be passed in which case this param gets ignored.