public class ApacheHttpClient4Executor extends java.lang.Object implements ClientExecutor
Modifier and Type | Class and Description |
---|---|
private static class |
ApacheHttpClient4Executor.FileExposingFileEntity
We use
FileEntity as the HttpEntity implementation when the request OutputStream has been
saved to a File on disk (because it was too large to fit into memory see
RestCFHttpClientExecutor#writeRequestBodyToOutputStream(ClientRequest) ); however, we have to delete
the File supporting the 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 class |
ApacheHttpClient4Executor.MemoryUnit
Enumeration to represent memory units.
|
(package private) static class |
ApacheHttpClient4Executor.ResponseStream |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BYTE_MEMORY_UNIT |
protected boolean |
closed |
protected boolean |
createdHttpClient |
private int |
fileUploadInMemoryThresholdLimit
For uploading File's over JAX-RS framework, this property, together with
fileUploadMemoryUnit ,
defines the maximum File size allowed in memory. |
private ApacheHttpClient4Executor.MemoryUnit |
fileUploadMemoryUnit
The unit for
fileUploadInMemoryThresholdLimit . |
private java.io.File |
fileUploadTempFileDir
Temp directory to write output request stream to.
|
static java.lang.String |
GIGABYTE_MEMORY_UNIT |
protected org.apache.http.client.HttpClient |
httpClient |
protected org.apache.http.protocol.HttpContext |
httpContext |
static java.lang.String |
KILOBYTE_MEMORY_UNIT |
static java.lang.String |
MEGABYTE_MEMORY_UNIT |
private static java.lang.String |
processId
Used to build temp file prefix.
|
protected int |
responseBufferSize |
Constructor and Description |
---|
ApacheHttpClient4Executor() |
ApacheHttpClient4Executor(org.apache.http.client.HttpClient httpClient) |
ApacheHttpClient4Executor(org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext) |
Modifier and Type | Method and Description |
---|---|
protected org.apache.http.HttpEntity |
buildEntity(ClientRequest request)
Build the HttpEntity to be sent to the Service as part of (POST) request.
|
private static void |
checkClientExceptionMapper() |
protected void |
cleanUpAfterExecute(org.apache.http.client.methods.HttpRequestBase httpMethod)
If passed httpMethod is of type HttpPost then obtain its entity.
|
void |
close() |
void |
commitHeaders(ClientRequest request,
org.apache.http.client.methods.HttpRequestBase httpMethod) |
protected java.io.InputStream |
createBufferedStream(java.io.InputStream is) |
private org.apache.http.client.methods.HttpRequestBase |
createHttpMethod(java.lang.String url,
java.lang.String restVerb) |
ClientRequest |
createRequest(java.lang.String uriTemplate) |
ClientRequest |
createRequest(javax.ws.rs.core.UriBuilder uriBuilder) |
ClientResponse |
execute(ClientRequest request) |
static CaseInsensitiveMap<java.lang.String> |
extractHeaders(org.apache.http.HttpResponse response) |
void |
finalize() |
org.apache.http.client.HttpClient |
getHttpClient() |
org.apache.http.protocol.HttpContext |
getHttpContext() |
private int |
getMemoryUnitMultiplier() |
int |
getResponseBufferSize()
Response stream is wrapped in a BufferedInputStream.
|
protected java.lang.String |
getTempfilePrefix()
Use context information, which will include node name, to avoid conflicts in case of multiple VMS using same
temp directory location.
|
private void |
handleFileNotDeletedError(java.io.File tempRequestFile,
java.lang.Exception ex)
Log that the file did not get deleted but prevent the request from failing by eating the exception.
|
boolean |
isClosed() |
void |
loadHttpMethod(ClientRequest request,
org.apache.http.client.methods.HttpRequestBase httpMethod) |
void |
setFileUploadInMemoryThresholdLimit(int pInMemoryThresholdLimit)
Setter for
fileUploadInMemoryThresholdLimit |
void |
setFileUploadMemoryUnit(java.lang.String pMemoryUnit)
Setter for
fileUploadMemoryUnit |
void |
setFileUploadTempFileDir(java.io.File pTempFileDir)
Setter for
fileUploadTempFileDir |
(package private) void |
setHttpClient(org.apache.http.client.HttpClient pHttpClient)
Setter for the
HttpClient to which this class delegates the actual HTTP call. |
void |
setHttpContext(org.apache.http.protocol.HttpContext httpContext) |
void |
setResponseBufferSize(int responseBufferSize)
Response stream is wrapped in a BufferedInputStream.
|
private org.apache.commons.io.output.DeferredFileOutputStream |
writeRequestBodyToOutputStream(ClientRequest request)
Creates the request OutputStream, to be sent to the end Service invoked, as a
DeferredFileOutputStream.
|
public static final java.lang.String BYTE_MEMORY_UNIT
public static final java.lang.String KILOBYTE_MEMORY_UNIT
public static final java.lang.String MEGABYTE_MEMORY_UNIT
public static final java.lang.String GIGABYTE_MEMORY_UNIT
private static java.lang.String processId
protected org.apache.http.client.HttpClient httpClient
protected boolean createdHttpClient
protected org.apache.http.protocol.HttpContext httpContext
protected boolean closed
private int fileUploadInMemoryThresholdLimit
fileUploadMemoryUnit
,
defines the maximum File size allowed in memory. If fileSize exceeds this size, it will be stored to
fileUploadTempFileDir
. private ApacheHttpClient4Executor.MemoryUnit fileUploadMemoryUnit
ApacheHttpClient4Executor.MemoryUnit
private java.io.File fileUploadTempFileDir
protected int responseBufferSize
public ApacheHttpClient4Executor()
public ApacheHttpClient4Executor(org.apache.http.client.HttpClient httpClient)
public ApacheHttpClient4Executor(org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
private static void checkClientExceptionMapper()
public int getResponseBufferSize()
public void setResponseBufferSize(int responseBufferSize)
responseBufferSize
- public org.apache.http.client.HttpClient getHttpClient()
public org.apache.http.protocol.HttpContext getHttpContext()
public void setHttpContext(org.apache.http.protocol.HttpContext httpContext)
public static CaseInsensitiveMap<java.lang.String> extractHeaders(org.apache.http.HttpResponse response)
public ClientRequest createRequest(java.lang.String uriTemplate)
createRequest
in interface ClientExecutor
public ClientRequest createRequest(javax.ws.rs.core.UriBuilder uriBuilder)
createRequest
in interface ClientExecutor
protected java.io.InputStream createBufferedStream(java.io.InputStream is)
public ClientResponse execute(ClientRequest request) throws java.lang.Exception
execute
in interface ClientExecutor
java.lang.Exception
protected void cleanUpAfterExecute(org.apache.http.client.methods.HttpRequestBase httpMethod)
httpMethod
- - the httpMethod to clean up.writeRequestBodyToOutputStream(ClientRequest)
private org.apache.http.client.methods.HttpRequestBase createHttpMethod(java.lang.String url, java.lang.String restVerb)
public void loadHttpMethod(ClientRequest request, org.apache.http.client.methods.HttpRequestBase httpMethod) throws java.lang.Exception
java.lang.Exception
protected org.apache.http.HttpEntity buildEntity(ClientRequest request) throws java.io.IOException
ApacheHttpClient4Executor.FileExposingFileEntity
or a regular in-memory ByteArrayEntity
depending on if the request
OutputStream fit into memory when built by calling writeRequestBodyToOutputStream(ClientRequest)
.request
- -java.io.IOException
- -private org.apache.commons.io.output.DeferredFileOutputStream writeRequestBodyToOutputStream(ClientRequest request) throws java.io.IOException
request
- -java.io.IOException
- -private int getMemoryUnitMultiplier()
fileUploadInMemoryThresholdLimit
with based on
fileUploadMemoryUnit
enumeration value.protected java.lang.String getTempfilePrefix()
private void handleFileNotDeletedError(java.io.File tempRequestFile, java.lang.Exception ex)
tempRequestFile
- -ex
- - a null may be passed in which case this param gets ignored.void setHttpClient(org.apache.http.client.HttpClient pHttpClient)
HttpClient
to which this class delegates the actual HTTP call. Note that this class
acts as the adapter between RestEasy and Apache HTTP Component library.pHttpClient
- -public void setFileUploadInMemoryThresholdLimit(int pInMemoryThresholdLimit)
fileUploadInMemoryThresholdLimit
pInMemoryThresholdLimit
- - the inMemoryThresholdLimitMB to setpublic void setFileUploadTempFileDir(java.io.File pTempFileDir)
fileUploadTempFileDir
pTempFileDir
- the tempFileDir to setpublic void setFileUploadMemoryUnit(java.lang.String pMemoryUnit)
fileUploadMemoryUnit
pMemoryUnit
- the memoryUnit to setpublic void commitHeaders(ClientRequest request, org.apache.http.client.methods.HttpRequestBase httpMethod)
public void close()
close
in interface ClientExecutor
public boolean isClosed()
public void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable