Class ApacheHttpClient4Executor
java.lang.Object
org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor
- All Implemented Interfaces:
ClientExecutor
- 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 theinvalid reference
RestCFHttpClientExecutor#writeRequestBodyToOutputStream(ClientRequest)FileEntity, 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.private static enumEnumeration to represent memory units.(package private) static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected booleanprotected booleanprivate intFor uploading File's over JAX-RS framework, this property, together withfileUploadMemoryUnit, defines the maximum File size allowed in memory.The unit forfileUploadInMemoryThresholdLimit.private FileTemp directory to write output request stream to.static final Stringprotected org.apache.http.client.HttpClientprotected org.apache.http.protocol.HttpContextstatic final Stringstatic final Stringprivate static StringUsed to build temp file prefix.protected int -
Constructor Summary
ConstructorsConstructorDescriptionApacheHttpClient4Executor(org.apache.http.client.HttpClient httpClient) ApacheHttpClient4Executor(org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.http.HttpEntitybuildEntity(ClientRequest request) Build the HttpEntity to be sent to the Service as part of (POST) request.private static voidprotected voidcleanUpAfterExecute(org.apache.http.client.methods.HttpRequestBase httpMethod) If passed httpMethod is of type HttpPost then obtain its entity.voidclose()voidcommitHeaders(ClientRequest request, org.apache.http.client.methods.HttpRequestBase httpMethod) protected InputStreamprivate org.apache.http.client.methods.HttpRequestBasecreateHttpMethod(String url, String restVerb) createRequest(String uriTemplate) createRequest(javax.ws.rs.core.UriBuilder uriBuilder) execute(ClientRequest request) static CaseInsensitiveMap<String> extractHeaders(org.apache.http.HttpResponse response) voidfinalize()org.apache.http.client.HttpClientorg.apache.http.protocol.HttpContextprivate intintResponse stream is wrapped in a BufferedInputStream.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.booleanisClosed()voidloadHttpMethod(ClientRequest request, org.apache.http.client.methods.HttpRequestBase httpMethod) voidsetFileUploadInMemoryThresholdLimit(int pInMemoryThresholdLimit) Setter forfileUploadInMemoryThresholdLimitvoidsetFileUploadMemoryUnit(String pMemoryUnit) Setter forfileUploadMemoryUnitvoidsetFileUploadTempFileDir(File pTempFileDir) Setter forfileUploadTempFileDir(package private) voidsetHttpClient(org.apache.http.client.HttpClient pHttpClient) Setter for theHttpClientto which this class delegates the actual HTTP call.voidsetHttpContext(org.apache.http.protocol.HttpContext httpContext) voidsetResponseBufferSize(int responseBufferSize) Response stream is wrapped in a BufferedInputStream.private org.apache.commons.io.output.DeferredFileOutputStreamCreates the request OutputStream, to be sent to the end Service invoked, as a DeferredFileOutputStream.
-
Field Details
-
BYTE_MEMORY_UNIT
- See Also:
-
KILOBYTE_MEMORY_UNIT
- See Also:
-
MEGABYTE_MEMORY_UNIT
- See Also:
-
GIGABYTE_MEMORY_UNIT
- See Also:
-
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 -
closed
protected boolean closed -
fileUploadInMemoryThresholdLimit
private 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. -
responseBufferSize
protected int responseBufferSize
-
-
Constructor Details
-
ApacheHttpClient4Executor
public ApacheHttpClient4Executor() -
ApacheHttpClient4Executor
public ApacheHttpClient4Executor(org.apache.http.client.HttpClient httpClient) -
ApacheHttpClient4Executor
public ApacheHttpClient4Executor(org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
-
-
Method Details
-
checkClientExceptionMapper
private static void checkClientExceptionMapper() -
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-
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient() -
getHttpContext
public org.apache.http.protocol.HttpContext getHttpContext() -
setHttpContext
public void setHttpContext(org.apache.http.protocol.HttpContext httpContext) -
extractHeaders
-
createRequest
- Specified by:
createRequestin interfaceClientExecutor
-
createRequest
- Specified by:
createRequestin interfaceClientExecutor
-
createBufferedStream
-
execute
- Specified by:
executein interfaceClientExecutor- Throws:
Exception
-
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.- See Also:
-
createHttpMethod
-
loadHttpMethod
public void loadHttpMethod(ClientRequest request, org.apache.http.client.methods.HttpRequestBase httpMethod) throws Exception - Throws:
Exception
-
buildEntity
Build the HttpEntity to be sent to the Service as part of (POST) request. Creates a off-memoryApacheHttpClient4Executor.FileExposingFileEntityor a regular in-memoryByteArrayEntitydepending on if the request OutputStream fit into memory when built by callingwriteRequestBodyToOutputStream(ClientRequest).- Parameters:
request- -- Returns:
- - the built HttpEntity
- Throws:
IOException- -
-
writeRequestBodyToOutputStream
private org.apache.commons.io.output.DeferredFileOutputStream writeRequestBodyToOutputStream(ClientRequest 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- -
-
getMemoryUnitMultiplier
private int getMemoryUnitMultiplier()- Returns:
- - the constant to multiply
fileUploadInMemoryThresholdLimitwith based onfileUploadMemoryUnitenumeration value.
-
getTempfilePrefix
Use context information, which will include node name, to avoid conflicts in case of multiple VMS using same temp directory location.- Returns:
- -
-
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.
-
setHttpClient
void setHttpClient(org.apache.http.client.HttpClient pHttpClient) Setter for theHttpClientto which this class delegates the actual HTTP call. Note that this class acts as the adapter between RestEasy and Apache HTTP Component library.- Parameters:
pHttpClient- -
-
setFileUploadInMemoryThresholdLimit
public void setFileUploadInMemoryThresholdLimit(int pInMemoryThresholdLimit) Setter forfileUploadInMemoryThresholdLimit- Parameters:
pInMemoryThresholdLimit- - the inMemoryThresholdLimitMB to set
-
setFileUploadTempFileDir
Setter forfileUploadTempFileDir- Parameters:
pTempFileDir- the tempFileDir to set
-
setFileUploadMemoryUnit
Setter forfileUploadMemoryUnit- Parameters:
pMemoryUnit- the memoryUnit to set
-
commitHeaders
public void commitHeaders(ClientRequest request, org.apache.http.client.methods.HttpRequestBase httpMethod) -
close
public void close()- Specified by:
closein interfaceClientExecutor
-
isClosed
public boolean isClosed() -
finalize
-