public class RESTClient extends HTTPBuilder
HttpResponseDecorator, which allows for simple
evaluation of the response.HttpResponseDecorator.getData().By default, all request method methods will return a HttpResponseDecorator
instance, which provides convenient access to response headers and the parsed
response body. The response body is parsed based on content-type, identical
to how HTTPBuilder's default response handler functions.
Failed requests (i.e. responses which return a status code > 399) will
by default throw a HttpResponseException. This exception may be used
to retrieve additional information regarding the response as well.
HTTPBuilder.RequestConfigDelegateauth, autoAcceptHeader, contentEncodingHandler, defaultContentType, defaultRequestContentType, defaultRequestHeaders, defaultResponseHandlers, defaultURI, encoders, log, parsers| Constructor and Description |
|---|
RESTClient()
Constructor.
|
RESTClient(Object defaultURI)
|
RESTClient(Object defaultURI,
Object defaultContentType)
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
defaultFailureHandler(HttpResponseDecorator resp,
Object data)
Throws an exception for non-successful HTTP response codes.
|
protected HttpResponseDecorator |
defaultSuccessHandler(HttpResponseDecorator resp,
Object data)
Returns an
HttpResponseDecorator, which provides simplified
access to headers, response code, and parsed response body, as well as
the underlying HttpResponse instance. |
Object |
delete(Map<String,?> args)
Perform a DELETE request.
|
Object |
get(Map<String,?> args)
Convenience method to perform an HTTP GET request.
|
Object |
head(Map<String,?> args)
Perform a HEAD request, often used to check preconditions before
sending a large PUT or POST request.
|
Object |
options(Map<String,?> args)
Perform an OPTIONS request.
|
Object |
patch(Map<String,?> args)
Convenience method to perform a PATCH request.
|
Object |
post(Map<String,?> args)
Convenience method to perform a POST request.
|
Object |
put(Map<String,?> args)
Convenience method to perform a PUT request.
|
buildDefaultResponseHandlers, createClient, defaultFailureHandler, doRequest, doRequest, get, getAuth, getClient, getContentType, getEncoder, getHandler, getHeaders, getParser, getUri, ignoreSSLIssues, isAutoAcceptHeader, parseResponse, post, request, request, request, setAuthConfig, setAutoAcceptHeader, setClient, setContentEncoding, setContentEncodingRegistry, setContentType, setEncoderRegistry, setHeaders, setParserRegistry, setProxy, setUri, shutdownpublic RESTClient()
HTTPBuilder.HTTPBuilder()public RESTClient(Object defaultURI) throws URISyntaxException
defaultURI - default request URI (String, URI, URL or URIBuilder)URISyntaxExceptionpublic RESTClient(Object defaultURI, Object defaultContentType) throws URISyntaxException
defaultURI - default request URI (String, URI, URL or URIBuilder)defaultContentType - default content-type (String or ContentType)URISyntaxExceptionpublic Object get(Map<String,?> args) throws ClientProtocolException, IOException, URISyntaxException
Convenience method to perform an HTTP GET request. It will use the HTTPBuilder's
registered response handlers to handle success or
failure status codes. By default, the
defaultSuccessHandler(HttpResponseDecorator, Object)
success response handler will return a decorated response
object that can be used to read response headers and data.
A 'failed' response (i.e. any HTTP status code > 399) will be handled
by the registered 'failure' handler.
The default failure handler throws a HttpResponseException.
get in class HTTPBuilderargs - named parameters - see
HTTPBuilder.RequestConfigDelegate.setPropertiesFromMap(Map)HttpResponseDecorator, unless the default success
handler is overridden.URISyntaxExceptionIOExceptionClientProtocolExceptiondefaultSuccessHandler(HttpResponseDecorator, Object),
defaultFailureHandler(HttpResponseDecorator, Object)public Object post(Map<String,?> args) throws URISyntaxException, ClientProtocolException, IOException
Convenience method to perform a POST request.
The request body (specified by a body named parameter)
will be encoded based on the requestContentType named
parameter, or if none is given, the default
content-type for this instance.
post in class HTTPBuilderargs - named parameters - see
HTTPBuilder.RequestConfigDelegate.setPropertiesFromMap(Map)HttpResponseDecorator, unless the default success
handler is overridden.ClientProtocolExceptionIOExceptionURISyntaxExceptionHTTPBuilder.getHandler(),
HTTPBuilder.defaultSuccessHandler(HttpResponseDecorator, Object),
HTTPBuilder.defaultFailureHandler(HttpResponseDecorator)public Object put(Map<String,?> args) throws URISyntaxException, ClientProtocolException, IOException
Convenience method to perform a PUT request.
The request body (specified by a body named parameter)
will be encoded based on the requestContentType named
parameter, or if none is given, the default
content-type for this instance.
args - named parameters - see
HTTPBuilder.RequestConfigDelegate.setPropertiesFromMap(Map)HttpResponseDecorator, unless the default success
handler is overridden.ClientProtocolExceptionIOExceptionURISyntaxExceptionpublic Object patch(Map<String,?> args) throws URISyntaxException, ClientProtocolException, IOException
Convenience method to perform a PATCH request.
The request body (specified by a body named parameter)
will be encoded based on the requestContentType named
parameter, or if none is given, the default
content-type for this instance.
args - named parameters - see
HTTPBuilder.RequestConfigDelegate.setPropertiesFromMap(Map)HttpResponseDecorator, unless the default success
handler is overridden.ClientProtocolExceptionIOExceptionURISyntaxExceptionpublic Object head(Map<String,?> args) throws URISyntaxException, ClientProtocolException, IOException
Perform a HEAD request, often used to check preconditions before sending a large PUT or POST request.
args - named parameters - see
HTTPBuilder.RequestConfigDelegate.setPropertiesFromMap(Map)HttpResponseDecorator, unless the default success
handler is overridden.ClientProtocolExceptionIOExceptionURISyntaxExceptionpublic Object delete(Map<String,?> args) throws URISyntaxException, ClientProtocolException, IOException
Perform a DELETE request. This method does not accept a
body argument.
args - named parameters - see
HTTPBuilder.RequestConfigDelegate.setPropertiesFromMap(Map)HttpResponseDecorator, unless the default success
handler is overridden.ClientProtocolExceptionIOExceptionURISyntaxExceptionpublic Object options(Map<String,?> args) throws ClientProtocolException, IOException, URISyntaxException
Perform an OPTIONS request.
args - named parameters - see
HTTPBuilder.RequestConfigDelegate.setPropertiesFromMap(Map)HttpResponseDecorator, unless the default success
handler is overridden.ClientProtocolExceptionIOExceptionURISyntaxExceptionprotected HttpResponseDecorator defaultSuccessHandler(HttpResponseDecorator resp, Object data) throws ResponseParseException
HttpResponseDecorator, which provides simplified
access to headers, response code, and parsed response body, as well as
the underlying HttpResponse instance.defaultSuccessHandler in class HTTPBuilderresp - HTTP responsedata - parsed data as resolved from this instance's ParserRegistryResponseParseException - if there is an error buffering a streaming
response.protected void defaultFailureHandler(HttpResponseDecorator resp, Object data) throws HttpResponseException
catch
block.resp - response objectdata - parsed response dataHttpResponseException - exception which can access the response
object.Copyright © 2008-2014. All Rights Reserved.