public class RequestUtil extends Object
Copyright (c) 2008
Boomi Software
Modifier and Type | Field and Description |
---|---|
static org.restlet.data.Parameter |
FOLLOW_REDIRECTS_ENABLED |
static String |
HEADER_CONTENT_MD5 |
static String |
HEADER_CONTENT_TYPE |
static String |
HEADER_DATE |
static String |
HEADER_DATE_FORMAT |
static String |
HEADER_IF_MATCH |
static String |
HEADER_IF_NONE_MATCH |
static Long |
NO_TIMEOUT |
static String |
NUM_ATTEMPTS_PARAM |
static List<org.restlet.data.Protocol> |
PROTOCOLS |
Constructor and Description |
---|
RequestUtil() |
Modifier and Type | Method and Description |
---|---|
static RequestFactory |
buildDownloadRequestFactory(org.restlet.data.Method method,
String url)
Returns a RequestFactory for use with
ClientUtil.handle(Client,RequestFactory,com.boomi.util.retry.RetryStrategy) which will generate a Request
with the given info for each request call. |
static RequestFactory |
buildRequestFactoryWithCustomHeaders(org.restlet.data.Method method,
String url,
org.restlet.resource.Representation representation,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider,
Map<String,Object> customHeaders)
Returns a RequestFactory for use with
ClientUtil.handle(Client,RequestFactory,com.boomi.util.retry.RetryStrategy) which will generate a Request
by calling #formatRequestWithHeaders(Method,String,Representation,AuthorizationProvider,Map
with the given info for each request call. |
static RequestFactory |
buildSimpleRequestFactory(org.restlet.data.Method method,
String url)
Returns a RequestFactory for a simple request w/ no Representation, no authentication.
|
static RequestFactory |
buildSimpleRequestFactory(org.restlet.data.Method method,
String url,
org.restlet.resource.Representation rep,
com.boomi.util.retry.RetryStrategy retry)
Returns a RequestFactory for a simple request w/ no authentication.
|
static RequestFactory |
buildStandardRequestFactory(org.restlet.data.Method method,
String url,
org.restlet.resource.Representation representation,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider)
Returns a RequestFactory for use with
ClientUtil.handle(Client,RequestFactory,com.boomi.util.retry.RetryStrategy) which will generate a Request
by calling formatRequest(Method,String,Representation,AuthorizationProvider) with the given info for
each request call. |
static org.restlet.data.Response |
doDelete(String urlString,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doDelete(String urlString,
org.restlet.resource.Representation rep,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doDelete(String urlString,
org.restlet.resource.Representation rep,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doGet(org.restlet.Client client,
String urlString,
AuthorizationProvider authProvider)
This method creates a new
Method.GET Request using the provided url and authorization provider
and then executes that request using the provided client. |
static org.restlet.data.Response |
doGet(String urlString,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doGet(String urlString,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doGet(String urlString,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider,
boolean isDownload) |
static org.restlet.data.Response |
doPost(org.restlet.Client client,
String urlString,
org.restlet.resource.Representation rep,
AuthorizationProvider authProvider)
This method creates a new
Method.POST Request using the provided url, representation, and
authorization provider and then executes that request using the provided client and the NeverRetry
strategy. |
static org.restlet.data.Response |
doPost(String urlString,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doPost(String urlString,
org.restlet.resource.Representation rep,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doPost(String urlString,
org.restlet.resource.Representation rep,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doPut(String urlString,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doPut(String urlString,
org.restlet.resource.Representation rep,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doPut(String urlString,
org.restlet.resource.Representation rep,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider) |
static org.restlet.data.Response |
doRequest(org.restlet.Client client,
org.restlet.data.Method method,
String urlString,
org.restlet.resource.Representation rep,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider,
boolean isDownload)
Run a request with the following settings.
|
static org.restlet.data.Response |
doRequest(org.restlet.data.Method method,
String urlString,
org.restlet.resource.Representation rep,
com.boomi.util.retry.RetryStrategy retry,
AuthorizationProvider authProvider,
boolean isDownload)
Run a request with the following settings.
|
static <T> T |
executeRequest(org.restlet.Client client,
org.restlet.data.Request request,
com.boomi.util.StreamUtil.Parser<T> parser)
This method executes a
Request and parses the underlying InputStream present in the
Response to return T. |
static <T> T |
executeRequest(org.restlet.data.Request request,
com.boomi.util.StreamUtil.Parser<T> parser)
This method executes a
Request and parses the underlying InputStream present in the
Response to return T. |
static org.restlet.data.Request |
formatRequest(org.restlet.data.Method method,
String url,
org.restlet.resource.Representation representation,
AuthorizationProvider authProvider)
Generates a Request including authorization headers using the given info.
|
static org.restlet.data.Request |
formatRequestWithHeaders(org.restlet.data.Method method,
String url,
org.restlet.resource.Representation representation,
AuthorizationProvider authProvider,
Map<String,Object> customHeaders)
Generates a Request including authorization and custom headers using the given info
|
static org.restlet.Client |
newClient()
Returns a new Client initialized with
PROTOCOLS . |
static org.restlet.Client |
newClient(Long timeout)
Returns a new Client initialized with
PROTOCOLS and the given timeout if non-null . |
static org.restlet.Client |
newClient(Long timeout,
Logger log)
Returns a new Client initialized with
PROTOCOLS and the given timeout if non-null . |
static org.restlet.Client |
newClient(org.restlet.data.Parameter... parameters)
Returns a new Client initialized with
PROTOCOLS , the default network timeouts (if configured for the
JVM), and the specified parameters. |
static org.restlet.Client |
newClient(String... parameters)
Returns a new Client initialized with
PROTOCOLS , the default network timeouts (if configured for the
JVM), and the specified parameters. |
static org.restlet.Client |
setClientReadTimeout(org.restlet.Client client,
long timeout)
Modifies the read timeout parameter for a given
Client . |
static void |
validateRetryableRepresentation(org.restlet.resource.Representation representation,
com.boomi.util.retry.RetryStrategy retry)
Verifies that the given Representation is valid for use in a retry loop.
|
public static final List<org.restlet.data.Protocol> PROTOCOLS
public static final String HEADER_CONTENT_TYPE
public static final String HEADER_CONTENT_MD5
public static final String HEADER_IF_MATCH
public static final String HEADER_IF_NONE_MATCH
public static final String HEADER_DATE
public static final String HEADER_DATE_FORMAT
public static final String NUM_ATTEMPTS_PARAM
public static final Long NO_TIMEOUT
public static final org.restlet.data.Parameter FOLLOW_REDIRECTS_ENABLED
public static org.restlet.Client newClient(String... parameters)
PROTOCOLS
, the default network timeouts (if configured for the
JVM), and the specified parameters. If the specified parameters contain a timeout setting, it will override the
JVM defaults.parameters
- the parameter names and values in the form "name1, value1, name2, value2". This is required to
contain an even number of values.Client
instance with the default protocols and the specified parameterpublic static org.restlet.Client newClient(org.restlet.data.Parameter... parameters)
PROTOCOLS
, the default network timeouts (if configured for the
JVM), and the specified parameters. If the specified parameters contain timeout settings, they will override the
JVM defaults.parameters
- the parameters to add to the clientClient
instance with the default protocols and any specified parameterspublic static org.restlet.Client newClient()
PROTOCOLS
.
NOTE: This utility does NOT include an actual implementation. Restlet API by itself is set so that if it can't
find an appropriate implementation, constructed through "magical classloader stuff," it will tell you
everything's OK (200) and not actually run your request. Projects that want to use RequestUtil must contain a
concrete restlet implementation, i.e. noelios or some such.Client
object with HTTP / HTTPS protocols.public static org.restlet.Client newClient(Long timeout)
PROTOCOLS
and the given timeout if non-null
. If no timeout
is specified, but default network timeouts have been configured for the jvm, apply those (to disable this default
timeout, pass an explicit timeout of 0, e.g. NO_TIMEOUT
).public static org.restlet.Client newClient(Long timeout, Logger log)
PROTOCOLS
and the given timeout if non-null
. If no timeout
is specified, but default network timeouts have been configured for the jvm, apply those (to disable this default
timeout, pass an explicit timeout of 0, e.g. NO_TIMEOUT
).public static org.restlet.Client setClientReadTimeout(org.restlet.Client client, long timeout)
Client
.client
- the Client objecttimeout
- the read timeout value (in milliseconds)public static <T> T executeRequest(org.restlet.data.Request request, com.boomi.util.StreamUtil.Parser<T> parser) throws IOException
Request
and parses the underlying InputStream
present in the
Response
to return T. The StreamUtil.Parser
implementation will parse the
InputStream
by executing StreamUtil.Parser.parse(InputStream)
. The
InputStream
will be closed once it has been parsed.
This method will throw an IOException
if ResponseUtil.validateResponse(Response)
is false or the
Response
is null orMessage.isEntityAvailable()
is false.
A new client will be created to Uniform.handle(Request)
the request using newClient()
.T
- request
- The request to handleparser
- The parser implementation that will parse the underlying input streamIOException
public static <T> T executeRequest(org.restlet.Client client, org.restlet.data.Request request, com.boomi.util.StreamUtil.Parser<T> parser) throws IOException
Request
and parses the underlying InputStream
present in the
Response
to return T. The StreamUtil.Parser
implementation will parse the
InputStream
by executing StreamUtil.Parser.parse(InputStream)
. The
InputStream
will be closed once it has been parsed.
This method will throw an IOException
if ResponseUtil.validateResponse(Response)
is false or the
Response
is null orMessage.isEntityAvailable()
is false.T
- client
- the client to Uniform.handle(Request)
the requestrequest
- The request to handleparser
- The parser implementation that will parse the underlying input streamIOException
public static org.restlet.data.Response doGet(org.restlet.Client client, String urlString, AuthorizationProvider authProvider) throws GeneralSecurityException
Method.GET
Request
using the provided url and authorization provider
and then executes that request using the provided client. The request will not include a Representation
and will use the NeverRetry
strategy.client
- the client to execute the requesturlString
- the url for the requestauthProvider
- the authorization provider for the requestGeneralSecurityException
public static org.restlet.data.Response doGet(String urlString, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doGet(String urlString, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doGet(String urlString, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider, boolean isDownload) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doPost(org.restlet.Client client, String urlString, org.restlet.resource.Representation rep, AuthorizationProvider authProvider) throws GeneralSecurityException
Method.POST
Request
using the provided url, representation, and
authorization provider and then executes that request using the provided client and the NeverRetry
strategy.client
- the client to execute the requesturlString
- the url for the requestrep
- payload representation for the requestauthProvider
- the authorization provider for the requestGeneralSecurityException
public static org.restlet.data.Response doPost(String urlString, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doPost(String urlString, org.restlet.resource.Representation rep, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doPost(String urlString, org.restlet.resource.Representation rep, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doPut(String urlString, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doPut(String urlString, org.restlet.resource.Representation rep, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doPut(String urlString, org.restlet.resource.Representation rep, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doDelete(String urlString, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doDelete(String urlString, org.restlet.resource.Representation rep, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doDelete(String urlString, org.restlet.resource.Representation rep, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider) throws GeneralSecurityException
GeneralSecurityException
public static org.restlet.data.Response doRequest(org.restlet.data.Method method, String urlString, org.restlet.resource.Representation rep, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider, boolean isDownload) throws GeneralSecurityException
method
- the request methodurlString
- the URL stringrep
- Representation
to include in the requestretry
- the RetryStrategy
authProvider
- the AuthorizationProvider
for the connectionisDownload
- is this a download request?Response
GeneralSecurityException
- if there's a security error while creating the request.public static org.restlet.data.Response doRequest(org.restlet.Client client, org.restlet.data.Method method, String urlString, org.restlet.resource.Representation rep, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider, boolean isDownload) throws GeneralSecurityException
client
- client to use. If there's no need to specify this, use the method call without client parm, which
will make one.method
- the request methodurlString
- the URL stringrep
- Representation
to include in the requestretry
- the RetryStrategy
authProvider
- the AuthorizationProvider
for the connectionisDownload
- is this a download request?Response
GeneralSecurityException
- if there's a security error while creating the request.public static RequestFactory buildSimpleRequestFactory(org.restlet.data.Method method, String url)
public static RequestFactory buildSimpleRequestFactory(org.restlet.data.Method method, String url, org.restlet.resource.Representation rep, com.boomi.util.retry.RetryStrategy retry)
public static RequestFactory buildStandardRequestFactory(org.restlet.data.Method method, String url, org.restlet.resource.Representation representation, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider)
ClientUtil.handle(Client,RequestFactory,com.boomi.util.retry.RetryStrategy)
which will generate a Request
by calling formatRequest(Method,String,Representation,AuthorizationProvider)
with the given info for
each request call.method
- the request methodurl
- the request urlrepresentation
- optional request representation, must not be transientretry
- the RetryStrategy
to implementauthProvider
- the AuthorizationProvider
to implement if the request needs to be authorizedpublic static RequestFactory buildRequestFactoryWithCustomHeaders(org.restlet.data.Method method, String url, org.restlet.resource.Representation representation, com.boomi.util.retry.RetryStrategy retry, AuthorizationProvider authProvider, Map<String,Object> customHeaders)
ClientUtil.handle(Client,RequestFactory,com.boomi.util.retry.RetryStrategy)
which will generate a Request
by calling #formatRequestWithHeaders(Method,String,Representation,AuthorizationProvider,Map)
with the given info for each request call.method
- the request methodurl
- the request urlrepresentation
- optional request representation, must not be transientretry
- the RetryStrategy
to implementauthProvider
- the AuthorizationProvider
to implement if the request needs to be authorizedpublic static RequestFactory buildDownloadRequestFactory(org.restlet.data.Method method, String url)
ClientUtil.handle(Client,RequestFactory,com.boomi.util.retry.RetryStrategy)
which will generate a Request
with the given info for each request call.
A "download" request differs from a normal request in the following ways:
NUM_ATTEMPTS_PARAM
parameter will be added to the url which indicates the number of attempts made
for this call, starting at 0method
- the request methodurl
- the request url (will be appended to on reattempts)public static void validateRetryableRepresentation(org.restlet.resource.Representation representation, com.boomi.util.retry.RetryStrategy retry)
representation
- The representation to checkretry
- The RetryStrategy
to implementpublic static org.restlet.data.Request formatRequest(org.restlet.data.Method method, String url, org.restlet.resource.Representation representation, AuthorizationProvider authProvider) throws GeneralSecurityException
method
- the request methodurl
- the request urlrepresentation
- optional request representationauthProvider
- the AuthorizationProvider
to implementGeneralSecurityException
- if an error occurred creating the requestpublic static org.restlet.data.Request formatRequestWithHeaders(org.restlet.data.Method method, String url, org.restlet.resource.Representation representation, AuthorizationProvider authProvider, Map<String,Object> customHeaders) throws GeneralSecurityException
method
- the request methodurl
- the request urlrepresentation
- optional request representationauthProvider
- the AuthorizationProvider
to implementcustomHeaders
- the custom headers to send with this requestGeneralSecurityException
- if an error occurred creating the request