Class ApacheHttpClient4Engine
java.lang.Object
org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine
- All Implemented Interfaces:
ClientHttpEngine
- Direct Known Subclasses:
ApacheHttpClient43Engine
- Version:
- $Revision: 1 $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classWe useFileEntityas theHttpEntityimplementation when the request OutputStream has been saved to a File on disk (because it was too large to fit into memory see however, we have to delete the File supporting theFileEntity, otherwise the disk will soon run out of space - remember that there can be very huge files, in GB range, processed on a regular basis - and FileEntity exposes its content File as a protected field.static enumEnumeration to represent memory units. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected booleanprotected org.apache.http.HttpHostprotected intFor uploading File's over JAX-RS framework, this property, together withfileUploadMemoryUnit, defines the maximum File size allowed in memory.protected ApacheHttpClient4Engine.MemoryUnitThe unit forfileUploadInMemoryThresholdLimit.protected FileTemp directory to write output request stream to.protected HostnameVerifierprotected org.apache.http.client.HttpClientprotected org.apache.http.protocol.HttpContextprotected HttpContextProviderprivate static StringUsed to build temp file prefix.protected intprotected SSLContext -
Constructor Summary
ConstructorsConstructorDescriptionApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient) ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, boolean closeHttpClient) ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext) Deprecated.ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, HttpContextProvider httpContextProvider) ApacheHttpClient4Engine(org.apache.http.HttpHost defaultProxy) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.http.HttpEntitybuildEntity(ClientInvocation request) Build the HttpEntity to be sent to the Service as part of (POST) request.protected voidcleanUpAfterExecute(org.apache.http.client.methods.HttpRequestBase httpMethod) If passed httpMethod is of type HttpPost then obtain its entity.voidclose()protected voidcommitHeaders(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod) protected InputStreamprotected org.apache.http.client.HttpClientprotected org.apache.http.client.methods.HttpRequestBasecreateHttpMethod(String url, String restVerb) static CaseInsensitiveMap<String> extractHeaders(org.apache.http.HttpResponse response) voidfinalize()org.apache.http.HttpHostintBased on memory unitNeeded for Client.getHostnameVerifier()org.apache.http.client.HttpClientorg.apache.http.protocol.HttpContextDeprecated.private intintResponse stream is wrapped in a BufferedInputStream.Needed for Client.getSslContext();protected StringUse context information, which will include node name, to avoid conflicts in case of multiple VMS using same temp directory location.private voidhandleFileNotDeletedError(File tempRequestFile, Exception ex) Log that the file did not get deleted but prevent the request from failing by eating the exception.invoke(ClientInvocation request) booleanbooleanisClosed()protected booleanisRedirectRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod) protected voidloadHttpMethod(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod) voidsetChunked(boolean chunked) voidsetFileUploadInMemoryThresholdLimit(int fileUploadInMemoryThresholdLimit) voidsetFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit fileUploadMemoryUnit) voidsetFileUploadTempFileDir(File fileUploadTempFileDir) voidsetHostnameVerifier(HostnameVerifier hostnameVerifier) voidsetHttpContext(org.apache.http.protocol.HttpContext httpContext) Deprecated.protected voidsetRedirectNotRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod) protected voidsetRedirectRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod) voidsetResponseBufferSize(int responseBufferSize) Response stream is wrapped in a BufferedInputStream.voidsetSslContext(SSLContext sslContext) private org.apache.commons.io.output.DeferredFileOutputStreamCreates the request OutputStream, to be sent to the end Service invoked, as a DeferredFileOutputStream.
-
Field Details
-
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
-
closed
protected boolean closed -
sslContext
-
hostnameVerifier
-
responseBufferSize
protected int responseBufferSize -
defaultProxy
protected org.apache.http.HttpHost defaultProxy -
chunked
protected boolean chunked -
fileUploadInMemoryThresholdLimit
protected int fileUploadInMemoryThresholdLimitFor uploading File's over JAX-RS framework, this property, together withfileUploadMemoryUnit, defines the maximum File size allowed in memory. If fileSize exceeds this size, it will be stored tofileUploadTempFileDir.
Defaults to 1 MB -
fileUploadMemoryUnit
- See Also:
-
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 specifiedHttpClientandHttpContextinstances. 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 HttpClientexecute(HttpUriRequest request, HttpContext context)
method to perform a deep copy of the context before executing the request.- Parameters:
httpClient- The http clienthttpContext- 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
-
setFileUploadMemoryUnit
-
getFileUploadTempFileDir
-
setFileUploadTempFileDir
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient() -
getHttpContext
Deprecated. -
setHttpContext
Deprecated. -
getSslContext
Description copied from interface:ClientHttpEngineNeeded for Client.getSslContext();- Specified by:
getSslContextin interfaceClientHttpEngine- Returns:
-
setSslContext
-
getHostnameVerifier
Description copied from interface:ClientHttpEngineNeeded for Client.getHostnameVerifier()- Specified by:
getHostnameVerifierin interfaceClientHttpEngine- Returns:
-
setHostnameVerifier
-
getDefaultProxy
public org.apache.http.HttpHost getDefaultProxy() -
extractHeaders
-
createBufferedStream
-
invoke
- Specified by:
invokein interfaceClientHttpEngine
-
createHttpMethod
-
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:
closein interfaceClientHttpEngine
-
isClosed
public boolean isClosed() -
finalize
-
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
Build the HttpEntity to be sent to the Service as part of (POST) request. Creates a off-memoryApacheHttpClient4Engine.FileExposingFileEntityor a regular in-memoryByteArrayEntitydepending 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
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
fileUploadInMemoryThresholdLimitwith based onfileUploadMemoryUnitenumeration value.
-
handleFileNotDeletedError
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.
-