public class ApacheHttpClient4Engine extends java.lang.Object implements ClientHttpEngine
Modifier and Type | Class and Description |
---|---|
private static class |
ApacheHttpClient4Engine.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 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. |
static class |
ApacheHttpClient4Engine.MemoryUnit
Enumeration to represent memory units.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
chunked |
protected boolean |
closed |
protected boolean |
createdHttpClient |
protected org.apache.http.HttpHost |
defaultProxy |
protected int |
fileUploadInMemoryThresholdLimit
For uploading File's over JAX-RS framework, this property, together with
fileUploadMemoryUnit ,
defines the maximum File size allowed in memory. |
protected ApacheHttpClient4Engine.MemoryUnit |
fileUploadMemoryUnit
The unit for
fileUploadInMemoryThresholdLimit . |
protected java.io.File |
fileUploadTempFileDir
Temp directory to write output request stream to.
|
protected javax.net.ssl.HostnameVerifier |
hostnameVerifier |
protected org.apache.http.client.HttpClient |
httpClient |
protected org.apache.http.protocol.HttpContext |
httpContext |
protected HttpContextProvider |
httpContextProvider |
private static java.lang.String |
processId
Used to build temp file prefix.
|
protected int |
responseBufferSize |
protected javax.net.ssl.SSLContext |
sslContext |
Constructor and Description |
---|
ApacheHttpClient4Engine() |
ApacheHttpClient4Engine(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) |
Modifier and Type | Method and Description |
---|---|
protected org.apache.http.HttpEntity |
buildEntity(ClientInvocation request)
Build the HttpEntity to be sent to the Service as part of (POST) request.
|
protected void |
cleanUpAfterExecute(org.apache.http.client.methods.HttpRequestBase httpMethod)
If passed httpMethod is of type HttpPost then obtain its entity.
|
void |
close() |
protected void |
commitHeaders(ClientInvocation request,
org.apache.http.client.methods.HttpRequestBase httpMethod) |
protected java.io.InputStream |
createBufferedStream(java.io.InputStream is) |
protected org.apache.http.client.HttpClient |
createDefaultHttpClient() |
protected org.apache.http.client.methods.HttpRequestBase |
createHttpMethod(java.lang.String url,
java.lang.String restVerb) |
static CaseInsensitiveMap<java.lang.String> |
extractHeaders(org.apache.http.HttpResponse response) |
void |
finalize() |
org.apache.http.HttpHost |
getDefaultProxy() |
int |
getFileUploadInMemoryThresholdLimit()
Based on memory unit
|
ApacheHttpClient4Engine.MemoryUnit |
getFileUploadMemoryUnit() |
java.io.File |
getFileUploadTempFileDir() |
javax.net.ssl.HostnameVerifier |
getHostnameVerifier()
Needed for Client.getHostnameVerifier()
|
org.apache.http.client.HttpClient |
getHttpClient() |
org.apache.http.protocol.HttpContext |
getHttpContext()
Deprecated.
|
private int |
getMemoryUnitMultiplier() |
int |
getResponseBufferSize()
Response stream is wrapped in a BufferedInputStream.
|
javax.net.ssl.SSLContext |
getSslContext()
Needed for Client.getSslContext();
|
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.
|
ClientResponse |
invoke(ClientInvocation request) |
boolean |
isChunked() |
boolean |
isClosed() |
protected boolean |
isRedirectRequired(ClientInvocation request,
org.apache.http.client.methods.HttpRequestBase httpMethod) |
protected void |
loadHttpMethod(ClientInvocation request,
org.apache.http.client.methods.HttpRequestBase httpMethod) |
void |
setChunked(boolean chunked) |
void |
setFileUploadInMemoryThresholdLimit(int fileUploadInMemoryThresholdLimit) |
void |
setFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit fileUploadMemoryUnit) |
void |
setFileUploadTempFileDir(java.io.File fileUploadTempFileDir) |
void |
setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier) |
void |
setHttpContext(org.apache.http.protocol.HttpContext httpContext)
Deprecated.
|
protected void |
setRedirectNotRequired(ClientInvocation request,
org.apache.http.client.methods.HttpRequestBase httpMethod) |
protected void |
setRedirectRequired(ClientInvocation request,
org.apache.http.client.methods.HttpRequestBase httpMethod) |
void |
setResponseBufferSize(int responseBufferSize)
Response stream is wrapped in a BufferedInputStream.
|
void |
setSslContext(javax.net.ssl.SSLContext sslContext) |
private org.apache.commons.io.output.DeferredFileOutputStream |
writeRequestBodyToOutputStream(ClientInvocation request)
Creates the request OutputStream, to be sent to the end Service invoked, as a
DeferredFileOutputStream.
|
private static java.lang.String processId
protected org.apache.http.client.HttpClient httpClient
protected boolean createdHttpClient
protected org.apache.http.protocol.HttpContext httpContext
protected HttpContextProvider httpContextProvider
protected boolean closed
protected javax.net.ssl.SSLContext sslContext
protected javax.net.ssl.HostnameVerifier hostnameVerifier
protected int responseBufferSize
protected org.apache.http.HttpHost defaultProxy
protected boolean chunked
protected int fileUploadInMemoryThresholdLimit
fileUploadMemoryUnit
,
defines the maximum File size allowed in memory. If fileSize exceeds this size, it will be stored to
fileUploadTempFileDir
. protected ApacheHttpClient4Engine.MemoryUnit fileUploadMemoryUnit
ApacheHttpClient4Engine.MemoryUnit
protected java.io.File fileUploadTempFileDir
public ApacheHttpClient4Engine()
public ApacheHttpClient4Engine(org.apache.http.HttpHost defaultProxy)
public ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient)
public ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, boolean closeHttpClient)
@Deprecated public ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
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.
httpClient
- The http clienthttpContext
- The context to be used for executing requestspublic ApacheHttpClient4Engine(org.apache.http.client.HttpClient httpClient, HttpContextProvider httpContextProvider)
public int getResponseBufferSize()
public void setResponseBufferSize(int responseBufferSize)
responseBufferSize
- public int getFileUploadInMemoryThresholdLimit()
public void setFileUploadInMemoryThresholdLimit(int fileUploadInMemoryThresholdLimit)
public ApacheHttpClient4Engine.MemoryUnit getFileUploadMemoryUnit()
public void setFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit fileUploadMemoryUnit)
public java.io.File getFileUploadTempFileDir()
public void setFileUploadTempFileDir(java.io.File fileUploadTempFileDir)
public org.apache.http.client.HttpClient getHttpClient()
@Deprecated public org.apache.http.protocol.HttpContext getHttpContext()
@Deprecated public void setHttpContext(org.apache.http.protocol.HttpContext httpContext)
public javax.net.ssl.SSLContext getSslContext()
ClientHttpEngine
getSslContext
in interface ClientHttpEngine
public void setSslContext(javax.net.ssl.SSLContext sslContext)
public javax.net.ssl.HostnameVerifier getHostnameVerifier()
ClientHttpEngine
getHostnameVerifier
in interface ClientHttpEngine
public void setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
public org.apache.http.HttpHost getDefaultProxy()
public static CaseInsensitiveMap<java.lang.String> extractHeaders(org.apache.http.HttpResponse response)
protected java.io.InputStream createBufferedStream(java.io.InputStream is)
public ClientResponse invoke(ClientInvocation request)
invoke
in interface ClientHttpEngine
protected org.apache.http.client.methods.HttpRequestBase createHttpMethod(java.lang.String url, java.lang.String restVerb)
protected boolean isRedirectRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod)
protected org.apache.http.client.HttpClient createDefaultHttpClient()
protected void setRedirectRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod)
protected void setRedirectNotRequired(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod)
protected void loadHttpMethod(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod) throws java.lang.Exception
java.lang.Exception
protected void commitHeaders(ClientInvocation request, org.apache.http.client.methods.HttpRequestBase httpMethod)
public void close()
close
in interface ClientHttpEngine
public boolean isClosed()
public void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public boolean isChunked()
public void setChunked(boolean chunked)
protected void cleanUpAfterExecute(org.apache.http.client.methods.HttpRequestBase httpMethod)
httpMethod
- - the httpMethod to clean up.protected org.apache.http.HttpEntity buildEntity(ClientInvocation request) throws java.io.IOException
ApacheHttpClient4Engine.FileExposingFileEntity
or a regular in-memory ByteArrayEntity
depending on if the request
OutputStream fit into memory when built by calling.request
- -java.io.IOException
- -private org.apache.commons.io.output.DeferredFileOutputStream writeRequestBodyToOutputStream(ClientInvocation request) throws java.io.IOException
request
- -java.io.IOException
- -protected java.lang.String getTempfilePrefix()
private int getMemoryUnitMultiplier()
fileUploadInMemoryThresholdLimit
with based on
fileUploadMemoryUnit
enumeration value.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.