public class HttpOp extends Object
For HTTP GET, the application supplies a URL, the accept header string, and a list of handlers to deal with different content type responses.
For HTTP POST, the application supplies a URL, content, the accept header string, and a list of handlers to deal with different content type responses, or no response is expected.
For HTTP PUT, the application supplies a URL, content, the accept header string
Modifier and Type | Class and Description |
---|---|
static class |
HttpOp.CaptureInput
TypedInputStream from an HTTP response.
|
static class |
HttpOp.CaptureString
Capture response as a string (UTF-8 assumed)
|
Modifier and Type | Field and Description |
---|---|
static String |
ARQ_USER_AGENT
Constant for the default User-Agent header that ARQ will use
|
static org.apache.http.client.HttpClient |
initialDefaultHttpClient
Used to reset
defaultHttpClient when needed |
Constructor and Description |
---|
HttpOp() |
Modifier and Type | Method and Description |
---|---|
static void |
applyUserAgent(org.apache.http.HttpMessage message)
Applies the configured User-Agent string to the HTTP request
|
static org.apache.http.impl.client.CloseableHttpClient |
createCachingHttpClient()
Create an HttpClient that performs client-side caching and connection pooling.
|
static org.apache.http.client.HttpClient |
createDefaultHttpClient() |
static org.apache.http.impl.client.CloseableHttpClient |
createPoolingHttpClient()
Create an HttpClient that performs connection pooling.
|
static org.apache.http.impl.client.HttpClientBuilder |
createPoolingHttpClientBuilder()
Create an HttpClientBuilder that performs connection pooling.
|
static void |
execHttpDelete(String url)
Executes a HTTP DELETE operation
|
static void |
execHttpDelete(String url,
HttpResponseHandler handler)
Executes a HTTP DELETE operation
|
static void |
execHttpDelete(String url,
HttpResponseHandler handler,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP DELETE operation
|
static TypedInputStream |
execHttpGet(String url)
Executes a HTTP GET and return a TypedInputStream.
|
static TypedInputStream |
execHttpGet(String url,
String acceptHeader)
Executes a HTTP GET and return a TypedInputStream.
|
static TypedInputStream |
execHttpGet(String url,
String acceptHeader,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP GET and returns a TypedInputStream
|
static void |
execHttpGet(String url,
String acceptHeader,
HttpResponseHandler handler)
Executes a HTTP Get request, handling the response with given handler.
|
static void |
execHttpGet(String url,
String acceptHeader,
HttpResponseHandler handler,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP Get request handling the response with one of the given
handlers
|
static String |
execHttpGetString(String url)
Convenience operation to execute a GET with no content negotiation and
return the response as a string.
|
static String |
execHttpGetString(String url,
String acceptHeader)
Convenience operation to execute a GET and return the response as a
string
|
static void |
execHttpHead(String url)
Executes a HTTP HEAD operation
|
static void |
execHttpHead(String url,
String acceptString,
HttpResponseHandler handler)
Executes a HTTP HEAD operation
|
static void |
execHttpHead(String url,
String acceptString,
HttpResponseHandler handler,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP HEAD operation
|
static void |
execHttpPost(String url,
org.apache.http.HttpEntity entity)
Executes a HTTP POST of the given entity
|
static void |
execHttpPost(String url,
org.apache.http.HttpEntity entity,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
POST with response body.
|
static void |
execHttpPost(String url,
org.apache.http.HttpEntity entity,
String acceptString,
HttpResponseHandler handler)
Executes a HTTP Post
|
static void |
execHttpPost(String url,
org.apache.http.HttpEntity entity,
String acceptHeader,
HttpResponseHandler handler,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
POST with response body.
|
static void |
execHttpPost(String url,
String contentType,
InputStream input,
long length)
Executes a HTTP POST with a request body from an input stream without
response body with no response handling
|
static void |
execHttpPost(String url,
String contentType,
InputStream input,
long length,
String acceptType,
HttpResponseHandler handler)
Executes a HTTP POST with request body from an input stream and response
handling.
|
static void |
execHttpPost(String url,
String contentType,
InputStream input,
long length,
String acceptType,
HttpResponseHandler handler,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP POST with request body from an input stream and response
handling.
|
static void |
execHttpPost(String url,
String contentType,
String content)
Executes a HTTP POST with the given contentype/string as the request body
and throws away success responses, failure responses will throw an error.
|
static void |
execHttpPost(String url,
String contentType,
String content,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP POST with a string as the request body and response
handling
|
static void |
execHttpPost(String url,
String contentType,
String content,
String acceptType,
HttpResponseHandler handler,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP POST with a string as the request body and response
handling
|
static void |
execHttpPostForm(String url,
Params params)
Executes a HTTP POST.
|
static void |
execHttpPostForm(String url,
Params params,
String acceptString,
HttpResponseHandler handler)
Executes a HTTP POST form operation
|
static void |
execHttpPostForm(String url,
Params params,
String acceptHeader,
HttpResponseHandler handler,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP POST form operation
|
static TypedInputStream |
execHttpPostFormStream(String url,
Params params,
String acceptHeader)
Executes a HTTP POST and returns a TypedInputStream, The TypedInputStream
must be closed.
|
static TypedInputStream |
execHttpPostFormStream(String url,
Params params,
String acceptHeader,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP POST Form and returns a TypedInputStream
|
static TypedInputStream |
execHttpPostStream(String url,
org.apache.http.HttpEntity entity,
String acceptHeader)
Execute a HTTP POST and return the typed return stream.
|
static TypedInputStream |
execHttpPostStream(String url,
org.apache.http.HttpEntity entity,
String acceptHeader,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
POST with response body.
|
static TypedInputStream |
execHttpPostStream(String url,
String contentType,
String content,
String acceptType)
Execute a HTTP POST and return the typed return stream.
|
static TypedInputStream |
execHttpPostStream(String url,
String contentType,
String content,
String acceptType,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext) |
static void |
execHttpPut(String url,
org.apache.http.HttpEntity entity)
Executes a HTTP PUT operation
|
static void |
execHttpPut(String url,
org.apache.http.HttpEntity entity,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP PUT operation
|
static void |
execHttpPut(String url,
String contentType,
InputStream input,
long length)
Executes a HTTP PUT operation
|
static void |
execHttpPut(String url,
String contentType,
InputStream input,
long length,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP PUT operation
|
static void |
execHttpPut(String url,
String contentType,
String content)
Executes a HTTP PUT operation
|
static void |
execHttpPut(String url,
String contentType,
String content,
org.apache.http.client.HttpClient httpClient,
org.apache.http.protocol.HttpContext httpContext)
Executes a HTTP PUT operation
|
static org.apache.http.client.HttpClient |
getDefaultHttpClient()
Return the current default
HttpClient . |
static String |
getUserAgent()
Gets the User-Agent string that ARQ is applying to all HTTP requests
|
static String |
readPayload(org.apache.http.HttpEntity entity) |
static void |
setDefaultHttpClient(org.apache.http.client.HttpClient client)
Performance can be improved by using a shared HttpClient that uses connection pooling.
|
static HttpRequestTransformer |
setRequestTransformer(HttpRequestTransformer tform)
Setting an
HttpRequestTransformer allows manipulation or enhancement of HTTP requests. |
static void |
setUserAgent(String userAgent)
Sets the User-Agent string that ARQ will apply to all HTTP requests
|
public static final org.apache.http.client.HttpClient initialDefaultHttpClient
defaultHttpClient
when neededpublic static final String ARQ_USER_AGENT
public static org.apache.http.client.HttpClient createDefaultHttpClient()
public static org.apache.http.client.HttpClient getDefaultHttpClient()
HttpClient
. This may be null, meaning
a new HttpClient
is created each time, if none is provided
in the HttpOp function call.public static void setDefaultHttpClient(org.apache.http.client.HttpClient client)
client
- HTTP client to use, if this is null, reset to original default insteadpublic static HttpRequestTransformer setRequestTransformer(HttpRequestTransformer tform)
HttpRequestTransformer
allows manipulation or enhancement of HTTP requests.tform
- HttpRequestTransformer to use, null
for none (the default)public static org.apache.http.impl.client.CloseableHttpClient createPoolingHttpClient()
setDefaultHttpClient(org.apache.http.client.HttpClient)
or provided in the HttpOp calls.public static org.apache.http.impl.client.HttpClientBuilder createPoolingHttpClientBuilder()
public static org.apache.http.impl.client.CloseableHttpClient createCachingHttpClient()
setDefaultHttpClient(org.apache.http.client.HttpClient)
or provided in the HttpOp calls.
Beware that content is cached in this process, including across remote server restart.public static String getUserAgent()
public static void setUserAgent(String userAgent)
userAgent
- User-Agent stringpublic static void execHttpGet(String url, String acceptHeader, HttpResponseHandler handler)
HTTP responses 400 and 500 become exceptions.
url
- URLacceptHeader
- Accept Headerhandler
- Response Handlerpublic static void execHttpGet(String url, String acceptHeader, HttpResponseHandler handler, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
The acceptHeader string is any legal value for HTTP Accept: field.
The handlers are the set of content types (without charset), used to dispatch the response body for handling.
HTTP responses 400 and 500 become exceptions.
url
- URLacceptHeader
- Accept Headerhandler
- Response handler called to process the responsehttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static TypedInputStream execHttpGet(String url)
The acceptHeader string is any legal value for HTTP Accept: field.
url
- URLpublic static TypedInputStream execHttpGet(String url, String acceptHeader)
The acceptHeader string is any legal value for HTTP Accept: field.
url
- URLacceptHeader
- Accept Headerpublic static TypedInputStream execHttpGet(String url, String acceptHeader, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
A 404 will result in a null stream being returned, any other error code results in an exception.
url
- URLacceptHeader
- Accept HeaderhttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static String execHttpGetString(String url)
url
- URLpublic static String execHttpGetString(String url, String acceptHeader)
url
- URLacceptHeader
- Accept header.public static void execHttpPost(String url, String contentType, String content)
url
- URLcontentType
- Content Type to POSTcontent
- Content to POSTpublic static TypedInputStream execHttpPostStream(String url, String contentType, String content, String acceptType)
url
- URLcontentType
- Content Type to POSTcontent
- Content to POSTacceptType
- Accept Typepublic static void execHttpPost(String url, String contentType, String content, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
url
- URLcontentType
- Content Type to POSTcontent
- Content to POSThttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static TypedInputStream execHttpPostStream(String url, String contentType, String content, String acceptType, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
public static void execHttpPost(String url, String contentType, String content, String acceptType, HttpResponseHandler handler, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
url
- URLcontentType
- Content Type to POSTcontent
- Content to POSTacceptType
- Accept Typehandler
- Response handler called to process the responsehttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpPost(String url, String contentType, InputStream input, long length)
url
- URLcontentType
- Content Type to POSTinput
- Input Stream to POST fromlength
- Amount of content to POSTpublic static void execHttpPost(String url, String contentType, InputStream input, long length, String acceptType, HttpResponseHandler handler)
The input stream is assumed to be UTF-8.
url
- URLcontentType
- Content Type to POSTinput
- Input Stream to POST content fromlength
- Length of content to POSTacceptType
- Accept Typehandler
- Response handler called to process the responsepublic static void execHttpPost(String url, String contentType, InputStream input, long length, String acceptType, HttpResponseHandler handler, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
The input stream is assumed to be UTF-8.
url
- URLcontentType
- Content Type to POSTinput
- Input Stream to POST content fromlength
- Length of content to POSTacceptType
- Accept Typehandler
- Response handler called to process the responsehttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpPost(String url, org.apache.http.HttpEntity entity)
url
- URLentity
- Entity to POSTpublic static TypedInputStream execHttpPostStream(String url, org.apache.http.HttpEntity entity, String acceptHeader)
url
- URLentity
- Entity to POSTpublic static void execHttpPost(String url, org.apache.http.HttpEntity entity, String acceptString, HttpResponseHandler handler)
url
- URLentity
- Entity to POSTacceptString
- Accept Headerhandler
- Response Handlerpublic static void execHttpPost(String url, org.apache.http.HttpEntity entity, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
The content for the POST body comes from the HttpEntity.
Additional headers e.g. for authentication can be injected through an
HttpContext
url
- URLentity
- Entity to POSThttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static TypedInputStream execHttpPostStream(String url, org.apache.http.HttpEntity entity, String acceptHeader, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
The content for the POST body comes from the HttpEntity.
Additional headers e.g. for authentication can be injected through an
HttpContext
url
- URLentity
- Entity to POSTacceptHeader
- Accept HeaderhttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpPost(String url, org.apache.http.HttpEntity entity, String acceptHeader, HttpResponseHandler handler, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
The content for the POST body comes from the HttpEntity.
Additional headers e.g. for authentication can be injected through an
HttpContext
url
- URLentity
- Entity to POSTacceptHeader
- Accept Headerhandler
- Response handler called to process the responsehttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpPostForm(String url, Params params)
url
- URLparams
- Parameters to POSTpublic static TypedInputStream execHttpPostFormStream(String url, Params params, String acceptHeader)
url
- URLparams
- Parameters to POSTacceptHeader
- public static TypedInputStream execHttpPostFormStream(String url, Params params, String acceptHeader, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
The acceptHeader string is any legal value for HTTP Accept: field.
A 404 will result in a null stream being returned, any other error code results in an exception.
url
- URLacceptHeader
- Accept Headerparams
- Parameters to POSThttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpPostForm(String url, Params params, String acceptString, HttpResponseHandler handler)
url
- URLparams
- Form parameters to POSTacceptString
- Accept Headerhandler
- Response handler called to process the responsepublic static void execHttpPostForm(String url, Params params, String acceptHeader, HttpResponseHandler handler, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
url
- URLparams
- Form parameters to POSTacceptHeader
- Accept Headerhandler
- Response handler called to process the responsehttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpPut(String url, String contentType, String content)
url
- URLcontentType
- Content Type for the PUTcontent
- Content for the PUTpublic static void execHttpPut(String url, String contentType, String content, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
url
- URLcontentType
- Content Type for the PUTcontent
- Content for the PUThttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpPut(String url, String contentType, InputStream input, long length)
url
- URLcontentType
- Content Type for the PUTinput
- Input Stream to read PUT content fromlength
- Amount of content to PUTpublic static void execHttpPut(String url, String contentType, InputStream input, long length, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
url
- URLcontentType
- Content Type for the PUTinput
- Input Stream to read PUT content fromlength
- Amount of content to PUThttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpPut(String url, org.apache.http.HttpEntity entity)
url
- URLentity
- HTTP Entity to PUTpublic static void execHttpPut(String url, org.apache.http.HttpEntity entity, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
url
- URLentity
- HTTP Entity to PUThttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpHead(String url)
url
- URLpublic static void execHttpHead(String url, String acceptString, HttpResponseHandler handler)
url
- URLacceptString
- Accept Headerhandler
- Response Handlerpublic static void execHttpHead(String url, String acceptString, HttpResponseHandler handler, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
url
- URLacceptString
- Accept Headerhandler
- Response HandlerhttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static void execHttpDelete(String url)
url
- URLpublic static void execHttpDelete(String url, HttpResponseHandler handler)
url
- URLhandler
- Response Handlerpublic static void execHttpDelete(String url, HttpResponseHandler handler, org.apache.http.client.HttpClient httpClient, org.apache.http.protocol.HttpContext httpContext)
url
- URLhandler
- Response HandlerhttpClient
- HTTP ClienthttpContext
- HTTP Contextpublic static String readPayload(org.apache.http.HttpEntity entity) throws IOException
IOException
public static void applyUserAgent(org.apache.http.HttpMessage message)
message
- HTTP requestLicenced under the Apache License, Version 2.0