public class HttpRESTUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
HttpRESTUtils.HttpIOException
Indicates an IO failure
|
static class |
HttpRESTUtils.HttpRequestException
Indicates a general failure
|
static class |
HttpRESTUtils.Method |
| Modifier and Type | Field and Description |
|---|---|
static String |
CONTENT_TYPE_UTF8 |
static String |
ENCODING_UTF8 |
static int |
MAX_RESPONSE_SIZE_CHARS |
| Constructor and Description |
|---|
HttpRESTUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
encodeDateHttp(Date date)
Encode a date into an http date string
|
static HttpResponse |
fireRequest(HttpClientWrapper httpClientWrapper,
String URL,
HttpRESTUtils.Method method,
Map<String,String> params,
Map<String,String> headers,
Object data,
boolean guaranteeSSL)
Fire off a request to a URL using the specified method but reuse the client for efficiency,
include optional params and data in the request,
the response data will be returned in the object if the request can be carried out
|
static HttpResponse |
fireRequest(HttpClientWrapper httpClientWrapper,
String URL,
HttpRESTUtils.Method method,
Map<String,String> params,
Object data,
boolean guaranteeSSL)
Fire off a request to a URL using the specified method but reuse the client for efficiency,
include optional params and data in the request,
the response data will be returned in the object if the request can be carried out
|
static HttpResponse |
fireRequest(String URL,
HttpRESTUtils.Method method)
Fire off a request to a URL using the specified method,
include optional params and data in the request,
the response data will be returned in the object if the request can be carried out
|
static HttpResponse |
fireRequest(String URL,
HttpRESTUtils.Method method,
Map<String,String> params)
Fire off a request to a URL using the specified method,
include optional params and data in the request,
the response data will be returned in the object if the request can be carried out
|
static HttpResponse |
fireRequest(String URL,
HttpRESTUtils.Method method,
Map<String,String> params,
Map<String,String> headers,
Object data,
boolean guaranteeSSL)
Fire off a request to a URL using the specified method,
include optional params, headers, and data in the request,
the response data will be returned in the object if the request can be carried out
|
static HttpResponse |
fireRequest(String URL,
HttpRESTUtils.Method method,
Map<String,String> params,
Object data,
boolean guaranteeSSL)
Fire off a request to a URL using the specified method,
include optional params and data in the request,
the response data will be returned in the object if the request can be carried out
|
protected static void |
handleRequestData(org.apache.commons.httpclient.methods.EntityEnclosingMethod method,
Object data) |
static HttpRESTUtils.Method |
makeMethodFromString(String method)
Turns a method string ("get") into a
HttpRESTUtils.Method enum object |
static HttpClientWrapper |
makeReusableHttpClient(boolean multiThreaded,
int idleConnectionTimeout,
javax.servlet.http.Cookie[] cookies)
Generates a reusable http client wrapper which can be given to
fireRequest(HttpClientWrapper, String, Method, Map, Object, boolean)
as an efficiency mechanism |
static String |
mergeQueryStringWithParams(String queryString,
Map<String,String> params)
Merges an existing queryString with a set of params to create one queryString,
this basically just adds the params to the end of the existing query string and will not insert a "?"
|
static URLData |
parseURL(String urlString)
Parses a url string into component pieces,
unlike the java URL class, this will work with partial urls
|
static Map<String,String> |
parseURLintoParams(String urlString)
Get the query parameters out of a query string and return them as a map,
this can be
|
protected static String |
urlEncodeUTF8(String toEncode) |
public static final String CONTENT_TYPE_UTF8
public static final String ENCODING_UTF8
public static final int MAX_RESPONSE_SIZE_CHARS
public static HttpResponse fireRequest(String URL, HttpRESTUtils.Method method)
URL - the url to send the request to (absolute or relative, can include query params)method - the method to use (e.g. GET, POST, etc.)HttpRESTUtils.HttpRequestException - if the request cannot be processed for some reason (this is unrecoverable)public static HttpResponse fireRequest(String URL, HttpRESTUtils.Method method, Map<String,String> params)
URL - the url to send the request to (absolute or relative, can include query params)method - the method to use (e.g. GET, POST, etc.)params - (optional) params to send along with the request, will be encoded in the query string or in the body depending on the methodHttpRESTUtils.HttpRequestException - if the request cannot be processed for some reason (this is unrecoverable)public static HttpResponse fireRequest(String URL, HttpRESTUtils.Method method, Map<String,String> params, Object data, boolean guaranteeSSL)
URL - the url to send the request to (absolute or relative, can include query params)method - the method to use (e.g. GET, POST, etc.)params - (optional) params to send along with the request, will be encoded in the query string or in the body depending on the methoddata - (optional) data to send along in the body of the request, this only works for POST and PUT requests, ignored for the other typesguaranteeSSL - if this is true then the request is sent in a mode which will allow self signed certs to work,
otherwise https requests will fail if the certs cannot be centrally verifiedHttpRESTUtils.HttpRequestException - if the request cannot be processed for some reason (this is unrecoverable)public static HttpResponse fireRequest(String URL, HttpRESTUtils.Method method, Map<String,String> params, Map<String,String> headers, Object data, boolean guaranteeSSL)
URL - the url to send the request to (absolute or relative, can include query params)method - the method to use (e.g. GET, POST, etc.)params - (optional) params to send along with the request, will be encoded in the query string or in the body depending on the methodparams - (optional) headers to send along with the request, will be encoded in the headersdata - (optional) data to send along in the body of the request, this only works for POST and PUT requests, ignored for the other typesguaranteeSSL - if this is true then the request is sent in a mode which will allow self signed certs to work,
otherwise https requests will fail if the certs cannot be centrally verifiedHttpRESTUtils.HttpRequestException - if the request cannot be processed for some reason (this is unrecoverable)public static HttpResponse fireRequest(HttpClientWrapper httpClientWrapper, String URL, HttpRESTUtils.Method method, Map<String,String> params, Object data, boolean guaranteeSSL)
httpClientWrapper - (optional) allows the http client to be reused for efficiency,
if null a new one will be created each time, use #makeReusableHttpClient(boolean, int) to
create a reusable instanceURL - the url to send the request to (absolute or relative, can include query params)method - the method to use (e.g. GET, POST, etc.)params - (optional) params to send along with the request, will be encoded in the query string or in the body depending on the methoddata - (optional) data to send along in the body of the request, this only works for POST and PUT requests, ignored for the other typesguaranteeSSL - if this is true then the request is sent in a mode which will allow self signed certs to work,
otherwise https requests will fail if the certs cannot be centrally verifiedHttpRESTUtils.HttpRequestException - if the request cannot be processed for some reason (this is unrecoverable)public static HttpResponse fireRequest(HttpClientWrapper httpClientWrapper, String URL, HttpRESTUtils.Method method, Map<String,String> params, Map<String,String> headers, Object data, boolean guaranteeSSL)
httpClientWrapper - (optional) allows the http client to be reused for efficiency,
if null a new one will be created each time, use #makeReusableHttpClient(boolean, int) to
create a reusable instanceURL - the url to send the request to (absolute or relative, can include query params)method - the method to use (e.g. GET, POST, etc.)params - (optional) params to send along with the request, will be encoded in the query string or in the body depending on the methodparams - (optional) headers to send along with the request, will be encoded in the headersdata - (optional) data to send along in the body of the request, this only works for POST and PUT requests, ignored for the other typesguaranteeSSL - if this is true then the request is sent in a mode which will allow self signed certs to work,
otherwise https requests will fail if the certs cannot be centrally verifiedHttpRESTUtils.HttpRequestException - if the request cannot be processed for some reason (this is unrecoverable)public static String mergeQueryStringWithParams(String queryString, Map<String,String> params)
queryString - the query string in URL encoded form, without a leading '?'params - a set of key->value strings to use as params for the requestpublic static Map<String,String> parseURLintoParams(String urlString)
urlString - a complete URL with query string at the end or a partial URL
or just a query string only (e.g. /thing/stuff?blah=1&apple=fruitprotected static void handleRequestData(org.apache.commons.httpclient.methods.EntityEnclosingMethod method,
Object data)
public static URLData parseURL(String urlString)
urlString - any URL stringpublic static HttpRESTUtils.Method makeMethodFromString(String method)
HttpRESTUtils.Method enum objectmethod - a method string (case is not important) e.g. GET, Post, put, DeLeTeHttpRESTUtils.Method enumpublic static HttpClientWrapper makeReusableHttpClient(boolean multiThreaded, int idleConnectionTimeout, javax.servlet.http.Cookie[] cookies)
fireRequest(HttpClientWrapper, String, Method, Map, Object, boolean)
as an efficiency mechanismmultiThreaded - true if you want to allow the client to run in multiple threadsidleConnectionTimeout - if this is 0 then it will use the defaults, otherwise connections will be timed out after this long (ms)cookies - to send along with every request from this clientCopyright © 2007–2020 CARET, University of Cambridge. All rights reserved.