public class Request
extends java.lang.Object
implements java.lang.AutoCloseable
Request class is used to set up and send HTTP Post, Get and Delete requests to a given URI.
It also manages received Cookies and it includes them in sent requests. It uses
HttpClient and HttpClientContext classes.
| Constructor and Description |
|---|
Request(java.lang.String base,
ChannelAuth auth,
java.lang.String verifyCertBundle,
boolean isHttps,
HttpProxySettings httpProxySettings) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the request object and its supporting HttpConnection.
|
java.lang.String |
delete(java.lang.String uri,
java.util.Map<java.lang.Integer,ErrorType> httpStatusMapping)
Send a DELETE request
|
java.lang.String |
get(java.lang.String uri,
java.util.Map<java.lang.Integer,ErrorType> httpStatusMapping)
Send a GET request
|
java.lang.String |
post(java.lang.String uri,
byte[] body,
java.util.Map<java.lang.Integer,ErrorType> httpStatusMapping)
Send a POST request
|
void |
resetAuthorization()
Clean up authorization data which is sent in all requests, e.g.: delete authorization token
|
void |
resetCookies()
Clean up session data which are sent in all requests, e.g.: delete cookies from HttpClientContext CookieStore
|
public Request(java.lang.String base,
ChannelAuth auth,
java.lang.String verifyCertBundle,
boolean isHttps,
HttpProxySettings httpProxySettings)
throws TemporaryError
base - scheme (http or https) and host parts of target URLs. It will be prepended to uri parameter of
post(String, byte[], Map), get(String, Map) and
delete(String, Map) methods.auth - provider of the Authorization token header to be included in the HttpRequestverifyCertBundle - CA Bundle chain certificates. This string shall be either the certificates themselves or
a path to a CA bundle file containing those certificates. The CA bundle is used to
validate that the certificate of the authentication server being connected to was signed
by a valid authority. If set to an empty string, the server certificate will not be
validated.isHttps - set to true if the connection requires SSL, false otherwisehttpProxySettings - contains http proxy url, port, username and passwordTemporaryError - if attempt to create and configure the HttpClient instance failspublic java.lang.String post(java.lang.String uri,
byte[] body,
java.util.Map<java.lang.Integer,ErrorType> httpStatusMapping)
throws ConsumerError,
TemporaryError,
PermanentError
uri - path plus query string components of the destination URLbody - to include in the request. If body is null, then no entity body is added to the request.httpStatusMapping - map HTTP Status Code to ErrorTypeConsumerError - if consumer was not foundTemporaryError - if request was not successful and httpStatusMapping maps the response http status code to
a TemporaryErrorPermanentError - if request was not successful and httpStatusMapping maps the response http status code to
a PermanentErrorpublic java.lang.String get(java.lang.String uri,
java.util.Map<java.lang.Integer,ErrorType> httpStatusMapping)
throws ConsumerError,
TemporaryError,
PermanentError
uri - path plus query string components of the destination URLhttpStatusMapping - map HTTP Status Code to ErrorTypeConsumerError - if consumer was not foundTemporaryError - if request was not successful and httpStatusMapping maps the response http status code to
a TemporaryErrorPermanentError - if request was not successful and httpStatusMapping maps the response http status code to
a PermanentErrorpublic java.lang.String delete(java.lang.String uri,
java.util.Map<java.lang.Integer,ErrorType> httpStatusMapping)
throws ConsumerError,
TemporaryError,
PermanentError
uri - path plus query string components of the destination URLhttpStatusMapping - map HTTP Status Code to ErrorTypeConsumerError - if consumer was not foundTemporaryError - if request was not successful and httpStatusMapping maps the response http status code to
a TemporaryErrorPermanentError - if request was not successful and httpStatusMapping maps the response http status code to
a PermanentErrorpublic void resetCookies()
public void resetAuthorization()
public void close()
throws TemporaryError
close in interface java.lang.AutoCloseableTemporaryError - if an error occurs when closing the request object.