public class RestRequest extends BeanSession implements HttpUriRequest, Configurable
Instances of this class are created by the various creator methods on the RestClient
class.
Modifier | Constructor and Description |
---|---|
protected |
RestRequest(RestClient client,
URI uri,
String method,
boolean hasBody)
Constructs a REST call with the specified method name.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts this http request.
|
RestRequest |
accept(Object value)
Sets the value for the
|
RestRequest |
acceptCharset(Object value)
Sets the value for the
|
RestRequest |
acceptEncoding(Object value)
Sets the value for the
|
RestRequest |
acceptLanguage(Object value)
Sets the value for the
|
void |
addHeader(Header header)
Adds a header to this message.
|
void |
addHeader(String name,
String value)
Adds a header to this message.
|
RestRequest |
authorization(Object value)
Sets the value for the
|
RestRequest |
body(Object input)
Sets the body of this request.
|
RestRequest |
body(Object input,
HttpPartSchema schema)
Sets the body of this request.
|
RestRequest |
bodyString(Object input)
Sets the body of this request as straight text bypassing the serializer.
|
RestRequest |
cacheControl(Object value)
Sets the value for the
|
RestRequest |
cancellable(Cancellable cancellable)
Sets
Cancellable for the ongoing operation. |
RestRequest |
clientVersion(Object value)
Sets the client version by setting the value for the
|
RestResponse |
complete()
Same as
run() but immediately calls RestResponse.consume() to clean up the response. |
RestRequest |
completed()
Used in combination with
cancellable(Cancellable) . |
Future<RestResponse> |
completeFuture()
Same as
complete() but allows you to run the call asynchronously. |
RestRequest |
config(RequestConfig value)
Sets the actual request configuration.
|
RestRequest |
connection(Object value)
Sets the value for the
|
boolean |
containsHeader(String name)
Checks if a certain header is present in this message.
|
RestRequest |
contentEncoding(Object value)
Sets the value for the
|
RestRequest |
contentLength(Object value)
Sets the value for the
|
RestRequest |
contentType(Object value)
Sets the value for the
|
RestRequest |
context(HttpContext context)
Override the context to use for the execution.
|
protected HttpRequestBase |
createInnerRequest(String method,
URI uri,
boolean hasBody)
Constructs the
HttpRequestBase object that ends up being passed to the client execute method. |
RestRequest |
date(Object value)
Sets the value for the
|
RestRequest |
debug()
Sets
|
RestRequest |
errorCodes(Predicate<Integer> value)
Allows you to override what status codes are considered error codes that would result in a
RestCallException . |
RestRequest |
expect(Object value)
Sets the value for the
|
RestRequest |
formData(AddFlag flag,
String name,
Object value)
Adds a form-data parameter to the request body.
|
RestRequest |
formData(AddFlag flag,
String name,
Object value,
HttpPartSchema schema)
Adds a form-data parameter to the request body.
|
RestRequest |
formData(NameValuePair pair)
Adds a form-data parameter to the request body.
|
RestRequest |
formData(String name,
Object value)
Adds a form-data parameter to the request body.
|
RestRequest |
formData(String name,
Object value,
HttpPartSchema schema)
Adds a form-data parameter to the request body.
|
RestRequest |
formDataCustom(Object value)
Adds form-data parameters as the entire body of the request.
|
RestRequest |
formDataPairs(Object... pairs)
Adds form-data parameters to the request body using free-form key/value pairs.
|
RestRequest |
formDatas(AddFlag flag,
Object... params)
Adds multiple form-data parameters to the request body.
|
RestRequest |
formDatas(Object... params)
Adds a form-data parameter to the request body.
|
RestRequest |
forwarded(Object value)
Sets the value for the
|
RestRequest |
fragment(String fragment)
Sets the URI fragment.
|
RestRequest |
from(Object value)
Sets the value for the
|
Header[] |
getAllHeaders()
Returns all the headers of this message.
|
RequestConfig |
getConfig()
Returns the actual request configuration.
|
Header |
getFirstHeader(String name)
Returns the first header with a specified name of this message.
|
String |
getHeader(String name)
Convenience method for reading the current last value of the specified header.
|
String |
getHeader(String name,
String def)
Convenience method for reading the current last value of the specified header.
|
Header[] |
getHeaders(String name)
Returns all the headers with a specified name of this message.
|
HttpEntity |
getHttpEntity()
Returns the body of this request.
|
Header |
getLastHeader(String name)
Returns the last header with a specified name of this message.
|
String |
getMethod()
Returns the HTTP method this request uses, such as GET, PUT, POST, or other.
|
HttpParams |
getParams()
Deprecated.
Use constructor parameters of configuration API provided by HttpClient.
|
OMap |
getProperties()
Returns the session properties.
|
ProtocolVersion |
getProtocolVersion()
Returns the protocol version this message is compatible with.
|
RequestLine |
getRequestLine()
Returns the request line of this request.
|
String |
getUri()
Returns the original request URI as a simple string.
|
URI |
getURI()
Returns the original request URI.
|
boolean |
hasHttpEntity()
Returns
|
RestRequest |
header(AddFlag flag,
String name,
Object value)
Adds a header to the request.
|
RestRequest |
header(AddFlag flag,
String name,
Object value,
HttpPartSchema schema)
Adds a header on the request.
|
RestRequest |
header(Header header)
Appends a header on the request.
|
RestRequest |
header(String name,
Object value)
Appends a header on the request.
|
RestRequest |
header(String name,
Object value,
HttpPartSchema schema)
Appends a header on the request.
|
HeaderIterator |
headerIterator()
Returns an iterator of all the headers.
|
HeaderIterator |
headerIterator(String name)
Returns an iterator of the headers with a given name.
|
RestRequest |
headerPairs(Object... pairs)
Appends multiple headers on the request using freeform key/value pairs.
|
RestRequest |
headers(AddFlag flag,
Object... headers)
Sets multiple headers on the request.
|
RestRequest |
headers(Object... headers)
Appends multiple headers to the request.
|
RestRequest |
host(String host)
Sets the URI host.
|
RestRequest |
hostHeader(Object value)
Sets the value for the
|
RestRequest |
html()
Convenience method for specifying HTML as the marshalling transmission media type for this request only.
|
RestRequest |
htmlDoc()
Convenience method for specifying HTML DOC as the marshalling transmission media type for this request only.
|
RestRequest |
htmlStrippedDoc()
Convenience method for specifying Stripped HTML DOC as the marshalling transmission media type for this request only.
|
RestRequest |
ifMatch(Object value)
Sets the value for the
|
RestRequest |
ifModifiedSince(Object value)
Sets the value for the
|
RestRequest |
ifNoneMatch(Object value)
Sets the value for the
|
RestRequest |
ifRange(Object value)
Sets the value for the
|
RestRequest |
ifUnmodifiedSince(Object value)
Sets the value for the
|
RestRequest |
ignoreErrors()
Prevent
RestCallExceptions from being thrown when HTTP status 400+ is encountered. |
RestRequest |
interceptors(RestCallInterceptor... interceptors)
Add one or more interceptors for this call only.
|
boolean |
isAborted() |
boolean |
isDebug()
Returns
|
RestRequest |
json()
Convenience method for specifying JSON as the marshalling transmission media type for this request only.
|
RestRequest |
log(Level level,
String msg,
Object... args)
Logs a message.
|
RestRequest |
log(Level level,
Throwable t,
String msg,
Object... args)
Logs a message.
|
RestRequest |
maxForwards(Object value)
Sets the value for the
|
RestRequest |
msgPack()
Convenience method for specifying MessagePack as the marshalling transmission media type for this request only.
|
RestRequest |
noTrace()
When called,
|
RestRequest |
openApi()
Convenience method for specifying OpenAPI as the marshalling transmission media type for this request only.
|
RestRequest |
origin(Object value)
Sets the value for the
|
RestRequest |
parser(Class<? extends Parser> parser)
Specifies the parser to use on the response body.
|
RestRequest |
parser(Parser parser)
Specifies the parser to use on the response body.
|
RestRequest |
path(NameValuePair pair)
Replaces a path parameter of the form
|
RestRequest |
path(String name,
Object value)
Replaces a path parameter of the form
|
RestRequest |
path(String name,
Object value,
HttpPartSchema schema)
Replaces a path parameter of the form
|
RestRequest |
pathPairs(Object... pairs)
Replaces path parameters of the form
|
RestRequest |
paths(Object... params)
Replaces multiple path parameter of the form
|
RestRequest |
plainText()
Convenience method for specifying Plain Text as the marshalling transmission media type for this request only.
|
RestRequest |
port(int port)
Sets the URI port.
|
RestRequest |
pragma(Object value)
Sets the value for the
|
RestRequest |
protocolVersion(ProtocolVersion version)
Sets the protocol version for this request.
|
RestRequest |
proxyAuthorization(Object value)
Sets the value for the
|
RestRequest |
queries(AddFlag flag,
Object... params)
Sets multiple parameters on the query string.
|
RestRequest |
queries(Object... params)
Sets multiple parameters on the query string.
|
RestRequest |
query(AddFlag flag,
String name,
Object value)
Adds a query parameter to the URI.
|
RestRequest |
query(AddFlag flag,
String name,
Object value,
HttpPartSchema schema)
Sets a query parameter on the URI.
|
RestRequest |
query(NameValuePair pair)
Adds a query parameter to the URI.
|
RestRequest |
query(String name,
Object value)
Adds a query parameter to the URI.
|
RestRequest |
query(String name,
Object value,
HttpPartSchema schema)
Adds a query parameter to the URI.
|
RestRequest |
queryCustom(Object value)
Adds a free-form custom query.
|
RestRequest |
queryPairs(Object... pairs)
Adds query parameters to the URI query using free-form key/value pairs..
|
RestRequest |
range(Object value)
Sets the value for the
|
RestRequest |
referer(Object value)
Sets the value for the
|
void |
removeHeader(Header header)
Removes a header from this message.
|
void |
removeHeaders(String name)
Removes all headers with a certain name from this message.
|
RestResponse |
run()
Runs this request and returns the resulting response object.
|
Future<RestResponse> |
runFuture()
Same as
run() but allows you to run the call asynchronously. |
RestRequest |
scheme(String scheme)
Sets the URI scheme.
|
RestRequest |
serializer(Class<? extends Serializer> serializer)
Specifies the serializer to use on the request body.
|
RestRequest |
serializer(Serializer serializer)
Specifies the serializer to use on the request body.
|
void |
setHeader(Header header)
Overwrites the first header with the same name.
|
void |
setHeader(String name,
String value)
Overwrites the first header with the same name.
|
void |
setHeaders(Header[] headers)
Overwrites all the headers in the message.
|
void |
setParams(HttpParams params)
Deprecated.
Use constructor parameters of configuration API provided by HttpClient.
|
RestRequest |
simpleJson()
Convenience method for specifying Simplified JSON as the marshalling transmission media type for this request only.
|
RestRequest |
target(HttpHost target)
Specifies the target host for the request.
|
RestRequest |
te(Object value)
Sets the value for the
|
OMap |
toMap()
Returns the properties defined on this bean context as a simple map for debugging purposes.
|
RestRequest |
uon()
Convenience method for specifying UON as the marshalling transmission media type for this request only.
|
RestRequest |
upgrade(Object value)
Sets the value for the
|
RestRequest |
uri(Object uri)
Sets the URI for this request.
|
RestRequest |
urlEnc()
Convenience method for specifying URL-Encoding as the marshalling transmission media type for this request only.
|
RestRequest |
userAgent(Object value)
Sets the value for the
|
RestRequest |
userInfo(String userInfo)
Sets the URI user info.
|
RestRequest |
userInfo(String username,
String password)
Sets the URI user info.
|
RestRequest |
via(Object value)
Sets the value for the
|
RestRequest |
warning(Object value)
Sets the value for the
|
RestRequest |
xml()
Convenience method for specifying XML as the marshalling transmission media type for this request only.
|
_class, addWarning, checkForWarnings, convertToMemberType, convertToMemberType, convertToType, convertToType, convertToType, getArgsClassMeta, getBeanClassVisibility, getBeanConstructorVisibility, getBeanDictionaryClasses, getBeanFieldVisibility, getBeanFilters, getBeanMeta, getBeanMethodVisibility, getBeanRegistry, getBeanTypePropertyName, getBeanTypePropertyName, getClassMeta, getClassMeta, getClassMetaForObject, getClassMetaForObject, getExamples, getImplClasses, getNamePropertyName, getNotBeanClasses, getNotBeanPackagesNames, getNotBeanPackagesPrefixes, getPropertyNamer, getSchema, getStringBuilder, getSwaps, isBean, isBean, isBeanMapPutReturnsOldValue, isBeansRequireDefaultConstructor, isBeansRequireSerializable, isBeansRequireSettersForGetters, isBeansRequireSomeProperties, isFluentSetters, isIgnoreInvocationExceptionsOnGetters, isIgnoreInvocationExceptionsOnSetters, isIgnorePropertiesWithoutSetters, isIgnoreUnknownBeanProperties, isIgnoreUnknownNullBeanProperties, isSortProperties, isUseEnumNames, isUseInterfaceProxies, isUseJavaBeanIntrospector, newBean, newBean, newBeanMap, newBeanMap, object, returnStringBuilder, string, toArray, toBeanMap, toBeanMap
addToCache, addToCache, getClassProperty, getFromCache, getInstanceArrayProperty, getInstanceProperty, getLocale, getMediaType, getProperty, getProperty, getProperty, getPropertyKeys, getTimeZone, getTimeZoneId, getWarnings, hasProperty, hasWarnings, toString
protected RestRequest(RestClient client, URI uri, String method, boolean hasBody) throws RestCallException
client
- The client that created this request.uri
- The target URI.method
- The HTTP method name (uppercase).hasBody
- Whether this method has a body.RestCallException
- If an exception or non-200 response code occurred during the connection attempt.protected HttpRequestBase createInnerRequest(String method, URI uri, boolean hasBody)
HttpRequestBase
object that ends up being passed to the client execute method.
Subclasses can override this method to create their own request base objects.
method
- The HTTP method.uri
- The HTTP URI.hasBody
- Whether the HTTP request has a body.HttpRequestBase
object.public RestRequest json()
JsonSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
JsonParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest simpleJson()
Simplified JSON is typically useful for automated tests because you can do simple string comparison of results without having to escape lots of quotes.
SimpleJsonSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
JsonParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
, or per-request via header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
, or per-request via header(String,Object)
or contentType(Object)
.
Can be combined with other marshaller setters such as xml()
to provide support for multiple languages.
Identical to calling
public RestRequest xml()
XmlSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
XmlParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest html()
POJOs are converted to HTML without any sort of doc wrappers.
HtmlSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
HtmlParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest htmlDoc()
POJOs are converted to fully renderable HTML pages.
HtmlDocSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
HtmlParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest htmlStrippedDoc()
Same as htmlDoc()
but without the header and body tags and page title and description.
HtmlStrippedDocSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
HtmlParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest plainText()
Plain text marshalling typically only works on simple POJOs that can be converted to and from strings using swaps, swap methods, etc...
PlainTextSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
PlainTextParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest msgPack()
MessagePack is a binary equivalent to JSON that takes up considerably less space than JSON.
MsgPackSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
MsgPackParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest uon()
UON is Url-Encoding Object notation that is equivalent to JSON but suitable for transmission as URL-encoded query and form post values.
UonSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
UonParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest urlEnc()
UrlEncodingSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
formData(String, Object)
(and related) methods for constructing
the request body. Instead, the part serializer specified via RestClientBuilder.partSerializer(Class)
is used.
UrlEncodingParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest openApi()
OpenAPI is a language that allows serialization to formats that use HttpPartSchema
objects to describe their structure.
OpenApiSerializer
will be used to serialize POJOs to request bodies unless overridden per request via serializer(Serializer)
.
RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
body(Object, HttpPartSchema)
method will be used to specify the body of the request with the
schema describing it's structure.
OpenApiParser
will be used to parse POJOs from response bodies unless overridden per request via parser(Parser)
.
RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
RestResponseBody.schema(HttpPartSchema)
method will be used to specify the structure of the response body.
header(String,Object)
or accept(Object)
.
header(String,Object)
or contentType(Object)
.
Identical to calling
public RestRequest serializer(Serializer serializer)
Overrides the serializers specified on the RestClient
.
The serializer is not modified by an of the serializer property setters (e.g. RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
If the
serializer
- The serializer used to serialize POJOs to the body of the HTTP request.public RestRequest serializer(Class<? extends Serializer> serializer)
Overrides the serializers specified on the RestClient
.
The serializer can be configured using any of the serializer property setters (e.g. RestClientBuilder.sortCollections()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
If the
serializer
- The serializer used to serialize POJOs to the body of the HTTP request.public RestRequest parser(Parser parser)
Overrides the parsers specified on the RestClient
.
The parser is not modified by any of the parser property setters (e.g. RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
If the
parser
- The parser used to parse POJOs from the body of the HTTP response.public RestRequest parser(Class<? extends Parser> parser)
Overrides the parsers specified on the RestClient
.
The parser can be configured using any of the parser property setters (e.g. RestClientBuilder.strict()
),
bean context property setters (e.g. RestClientBuilder.swaps(Object...)
), or generic property setters (e.g. RestClientBuilder.set(String, Object)
) defined on this builder class.
If the
parser
- The parser used to parse POJOs from the body of the HTTP response.public RestRequest errorCodes(Predicate<Integer> value)
RestCallException
.
The default error code predicate is: x -> x >= 400
.
value
- The new predicate for calculating error codes.public RestRequest interceptors(RestCallInterceptor... interceptors) throws RestCallException
interceptors
- The interceptors to add to this call.RestCallException
- If init method on interceptor threw an exception.public RestRequest ignoreErrors()
RestCallExceptions
from being thrown when HTTP status 400+ is encountered.
This overrides the
public RestRequest debug() throws RestCallException
RestCallException
- Invalid input.public boolean isDebug()
isDebug
in class Session
Context.CONTEXT_debug
public RestRequest target(HttpHost target)
target
- The target host for the request.
Implementations may accept public RestRequest context(HttpContext context)
context
- The context to use for the execution, or public RestRequest uri(Object uri) throws RestCallException
Can be any of the following types:
URI
URL
URIBuilder
Object.toString()
.
Relative URI strings will be interpreted as relative to the root URI defined on the client.
uri
- The URI of the remote REST resource.
URIBuilder
URI
URL
String
Object
- Converted to RestCallException
- Invalid URI syntax detected.public RestRequest scheme(String scheme)
scheme
- The new URI host.public RestRequest host(String host)
host
- The new URI host.public RestRequest port(int port)
port
- The new URI port.public RestRequest userInfo(String userInfo)
userInfo
- The new URI user info.public RestRequest userInfo(String username, String password)
username
- The new URI username.password
- The new URI password.public RestRequest fragment(String fragment)
fragment
- The URI fragment. The value is expected to be unescaped and may contain non ASCII characters.public RestRequest path(String name, Object value) throws RestCallException
name
- The parameter name.value
- The parameter value.
Supplier
.
RestCallException
- Invalid input.public RestRequest path(NameValuePair pair) throws RestCallException
pair
- The parameter.RestCallException
- Invalid input.public RestRequest path(String name, Object value, HttpPartSchema schema) throws RestCallException
name
- The parameter name.value
- The parameter value.
Supplier
.
schema
- The part schema. Can be RestCallException
- Invalid input.public RestRequest paths(Object... params) throws RestCallException
params
- The path parameters to set.
NameValuePair
NameValuePairable
Map.Entry
NameValuePairSupplier
Map
RestCallException
- Invalid input.public RestRequest pathPairs(Object... pairs) throws RestCallException
pairs
- The path key/value pairs.
RestCallException
- Invalid input.public RestRequest query(AddFlag flag, String name, Object value, HttpPartSchema schema) throws RestCallException
flag
- How to add this parameter.
name
- The parameter name.value
- The parameter value.
Supplier
.
schema
- The schema object that defines the format of the output.
HttpPartSchema.DEFAULT
.
OpenApiSerializer
).
RestCallException
- Invalid input.public RestRequest query(String name, Object value) throws RestCallException
name
- The parameter name.value
- The parameter value.
Supplier
.
RestCallException
- Invalid input.public RestRequest query(NameValuePair pair) throws RestCallException
pair
- The parameter.RestCallException
- Invalid input.public RestRequest query(String name, Object value, HttpPartSchema schema) throws RestCallException
The optional schema allows for specifying how part should be serialized (as a pipe-delimited list for example).
name
- The parameter name.value
- The parameter value.
Supplier
.
schema
- The HTTP part schema. Can be RestCallException
- Invalid input.public RestRequest query(AddFlag flag, String name, Object value) throws RestCallException
flag
- How to add this parameter.
name
- The parameter name.value
- The parameter value.
Supplier
.
RestCallException
- Invalid input.public RestRequest queries(Object... params) throws RestCallException
params
- The parameters to set.
NameValuePair
NameValuePairable
Map.Entry
NameValuePairSupplier
Map
RestCallException
- Invalid input.public RestRequest queries(AddFlag flag, Object... params) throws RestCallException
flag
- How to add this parameter.
params
- The parameters to set.
NameValuePair
NameValuePairable
Map.Entry
NameValuePairSupplier
Map
RestCallException
- Invalid input.public RestRequest queryPairs(Object... pairs) throws RestCallException
pairs
- The query key/value pairs.
RestCallException
- Invalid input.public RestRequest queryCustom(Object value) throws RestCallException
value
- The parameter value.
CharSequence
Reader
- Raw contents of Reader
will be serialized to remote resource.
InputStream
- Raw contents of InputStream
will be serialized to remote resource.
NameValuePairSupplier
- Converted to a URL-encoded query.
RestCallException
- Invalid input.public RestRequest formData(AddFlag flag, String name, Object value, HttpPartSchema schema) throws RestCallException
flag
- How to add this parameter.
name
- The parameter name.value
- The parameter value.
Supplier
.
schema
- The schema object that defines the format of the output.
HttpPartSchema.DEFAULT
.
OpenApiSerializer
).
RestCallException
- Invalid input.public RestRequest formData(String name, Object value) throws RestCallException
name
- The parameter name.value
- The parameter value.
Supplier
.
RestCallException
- Invalid input.public RestRequest formData(NameValuePair pair) throws RestCallException
pair
- The parameter.RestCallException
- Invalid input.public RestRequest formData(String name, Object value, HttpPartSchema schema) throws RestCallException
The optional schema allows for specifying how part should be serialized (as a pipe-delimited list for example).
name
- The parameter name.value
- The parameter value.
Supplier
.
schema
- The HTTP part schema. Can be RestCallException
- Invalid input.public RestRequest formData(AddFlag flag, String name, Object value) throws RestCallException
flag
- How to add this parameter.
name
- The parameter name.value
- The parameter value.
Supplier
.
RestCallException
- Invalid input.public RestRequest formDatas(Object... params) throws RestCallException
params
- The parameters to set.
NameValuePair
NameValuePairable
Map.Entry
NameValuePairSupplier
Map
RestCallException
- Invalid input.public RestRequest formDatas(AddFlag flag, Object... params) throws RestCallException
flag
- How to add this parameter.
params
- The parameters to set.
NameValuePair
NameValuePairable
Map.Entry
NameValuePairSupplier
Map
RestCallException
- Invalid input.public RestRequest formDataPairs(Object... pairs) throws RestCallException
pairs
- The form-data key/value pairs.
RestCallException
- Invalid input.public RestRequest formDataCustom(Object value) throws RestCallException
value
- The parameter value.
CharSequence
Reader
- Raw contents of Reader
will be serialized to remote resource.
InputStream
- Raw contents of InputStream
will be serialized to remote resource.
HttpResource
/BasicHttpResource
- Raw contents will be serialized to remote resource. Additional headers and media type will be set on request.
HttpEntity
/BasicHttpEntity
- Bypass Juneau serialization and pass HttpEntity directly to HttpClient.
Object
- POJO to be converted to text using the Serializer
registered with the
RestClient
.
NameValuePairSupplier
- Converted to a URL-encoded FORM post.
RestCallException
- Invalid input.public RestRequest body(Object input) throws RestCallException
input
- The input to be sent to the REST resource (only valid for PUT/POST/PATCH) requests.
Reader
- Raw contents of Reader
will be serialized to remote resource.
InputStream
- Raw contents of InputStream
will be serialized to remote resource.
HttpResource
/BasicHttpResource
- Raw contents will be serialized to remote resource. Additional headers and media type will be set on request.
HttpEntity
/BasicHttpEntity
- Bypass Juneau serialization and pass HttpEntity directly to HttpClient.
Object
- POJO to be converted to text using the Serializer
registered with the
RestClient
.
NameValuePairSupplier
- Converted to a URL-encoded FORM post.
Supplier
of anything on this list.
RestCallException
- If a retry was attempted, but the entity was not repeatable.public RestRequest bodyString(Object input) throws RestCallException
Note that this is different than the following which will serialize
input
- The input to be sent to the REST resource (only valid for PUT/POST/PATCH) requests.RestCallException
- If a retry was attempted, but the entity was not repeatable.public RestRequest body(Object input, HttpPartSchema schema) throws RestCallException
input
- The input to be sent to the REST resource (only valid for PUT/POST/PATCH) requests.
Reader
- Raw contents of Reader
will be serialized to remote resource.
InputStream
- Raw contents of InputStream
will be serialized to remote resource.
HttpResource
/BasicHttpResource
- Raw contents will be serialized to remote resource. Additional headers and media type will be set on request.
HttpEntity
/BasicHttpEntity
- Bypass Juneau serialization and pass HttpEntity directly to HttpClient.
Object
- POJO to be converted to text using the Serializer
registered with the
RestClient
.
NameValuePairSupplier
- Converted to a URL-encoded FORM post.
Supplier
of anything on this list.
schema
- The schema object that defines the format of the output.
HttpPartSchema.DEFAULT
.
OpenApiSerializer
).
RestCallException
- If a retry was attempted, but the entity was not repeatable.public RestRequest header(AddFlag flag, String name, Object value, HttpPartSchema schema) throws RestCallException
flag
- How to add this parameter.
name
- The header name.value
- The header value.
Supplier
.
schema
- The schema object that defines the format of the output.
HttpPartSchema.DEFAULT
.
OpenApiSerializer
).
RestCallException
- Invalid input.public RestRequest header(String name, Object value) throws RestCallException
name
- The header name.value
- The header value.
Supplier
.
RestCallException
- Invalid input.public RestRequest header(String name, Object value, HttpPartSchema schema) throws RestCallException
The optional schema allows for specifying how part should be serialized (as a pipe-delimited list for example).
name
- The header name.value
- The header value.
Supplier
.
schema
- The HTTP part schema. Can be RestCallException
- Invalid input.public RestRequest header(AddFlag flag, String name, Object value) throws RestCallException
flag
- How to add this parameter.
name
- The header name.value
- The header value.
Supplier
.
RestCallException
- Invalid input.public RestRequest header(Header header) throws RestCallException
header
- The header to set.RestCallException
- Invalid input.public RestRequest headers(Object... headers) throws RestCallException
headers
- The headers to set.
Header
(including any subclasses such as Accept
)
Headerable
Map.Entry
HeaderSupplier
Map
RestCallException
- Invalid input.public RestRequest headers(AddFlag flag, Object... headers) throws RestCallException
flag
- How to add this parameter.
headers
- The headers to set.
Header
(including any subclasses such as Accept
)
Headerable
Map.Entry
HeaderSupplier
Map
RestCallException
- Invalid input.public RestRequest headerPairs(Object... pairs) throws RestCallException
pairs
- The form-data key/value pairs.
RestCallException
- Invalid input.public String getHeader(String name)
name
- The header name.public String getHeader(String name, String def)
name
- The header name.def
- The default value if the header is not set.public RestRequest accept(Object value) throws RestCallException
This overrides the media type specified on the parser, but is overridden by calling
header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest acceptCharset(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest acceptEncoding(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest acceptLanguage(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest authorization(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest cacheControl(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest connection(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest contentLength(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest contentType(Object value) throws RestCallException
This overrides the media type specified on the serializer, but is overridden by calling
header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest contentEncoding(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest date(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest expect(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest forwarded(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest from(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest hostHeader(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest ifMatch(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest ifModifiedSince(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest ifNoneMatch(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest ifRange(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest ifUnmodifiedSince(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest maxForwards(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest noTrace() throws RestCallException
This gives the opportunity for the servlet to not log errors on invalid requests. This is useful for testing purposes when you don't want your log file to show lots of errors that are simply the results of testing.
RestCallException
- Invalid input.public RestRequest origin(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest pragma(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest proxyAuthorization(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest range(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest referer(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest te(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest userAgent(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest upgrade(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest via(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest warning(Object value) throws RestCallException
This is a shortcut for calling header(
value
- The new header value.RestCallException
- Invalid input.public RestRequest clientVersion(Object value) throws RestCallException
value
- The version string (e.g. RestCallException
- Invalid input.public RestResponse run() throws RestCallException
complete()
method which will automatically
consume the response so that you don't need to call InputStream.close()
on the response body.
RestCallException
- If an exception or non-200 response code occurred during the connection attempt.public Future<RestResponse> runFuture() throws RestCallException
run()
but allows you to run the call asynchronously.
Future<RestResponse>
RestClientBuilder.executorService(ExecutorService, boolean)
method to customize the
executor service used for creating Futures
.
RestCallException
- If the executor service was not defined.public RestResponse complete() throws RestCallException
run()
but immediately calls RestResponse.consume()
to clean up the response.
Use this method if you're only interested in the status line of the response and not the response entity.
Attempts to call any of the methods on the response object that retrieve the body (e.g. RestResponseBody.asReader()
will cause a RestCallException
to be thrown.
InputStream.close()
on the response body to consume the response.
RestCallException
- If an exception or non-200 response code occurred during the connection attempt.public Future<RestResponse> completeFuture() throws RestCallException
complete()
but allows you to run the call asynchronously.
Future<RestResponse>
RestClientBuilder.executorService(ExecutorService, boolean)
method to customize the
executor service used for creating Futures
.
InputStream.close()
on the response body to consume the response.
RestCallException
- If the executor service was not defined.public boolean hasHttpEntity()
public HttpEntity getHttpEntity()
public RestRequest log(Level level, Throwable t, String msg, Object... args)
level
- The log level.t
- The throwable cause.msg
- The message with MessageFormat
-style arguments.args
- The arguments.public RestRequest log(Level level, String msg, Object... args)
level
- The log level.msg
- The message with MessageFormat
-style arguments.args
- The arguments.public RestRequest config(RequestConfig value)
value
- The new value.public RestRequest cancellable(Cancellable cancellable)
Cancellable
for the ongoing operation.cancellable
- The cancellable object.public RestRequest protocolVersion(ProtocolVersion version)
version
- The protocol version for this request.public RestRequest completed()
cancellable(Cancellable)
.public String getMethod()
getMethod
in interface HttpUriRequest
public URI getURI()
getURI
in interface HttpUriRequest
public String getUri()
public void abort() throws UnsupportedOperationException
abort
in interface HttpUriRequest
UnsupportedOperationException
public boolean isAborted()
isAborted
in interface HttpUriRequest
public RequestLine getRequestLine()
getRequestLine
in interface HttpRequest
public ProtocolVersion getProtocolVersion()
getProtocolVersion
in interface HttpMessage
public boolean containsHeader(String name)
containsHeader
in interface HttpMessage
name
- The header name to check for.public Header[] getHeaders(String name)
getHeaders
in interface HttpMessage
name
- The name of the headers to return.public Header getFirstHeader(String name)
getHeaders(String)
is returned.
getFirstHeader
in interface HttpMessage
name
- The name of the header to return.public Header getLastHeader(String name)
getHeaders(String)
is returned.
getLastHeader
in interface HttpMessage
name
- The name of the header to return.public Header[] getAllHeaders()
getAllHeaders
in interface HttpMessage
public void addHeader(Header header)
header(Header)
is an equivalent method and the preferred method for fluent-style coding.
addHeader
in interface HttpMessage
header
- The header to append.public void addHeader(String name, String value)
header(String,Object)
is an equivalent method and the preferred method for fluent-style coding.
addHeader
in interface HttpMessage
name
- The name of the header.value
- The value of the header.public void setHeader(Header header)
setHeader
in interface HttpMessage
header
- The header to set.public void setHeader(String name, String value)
setHeader
in interface HttpMessage
name
- The name of the header.value
- The value of the header.public void setHeaders(Header[] headers)
setHeaders
in interface HttpMessage
headers
- The array of headers to set.public void removeHeader(Header header)
removeHeader
in interface HttpMessage
header
- The header to remove.public void removeHeaders(String name)
removeHeaders
in interface HttpMessage
name
- The name of the headers to remove.public HeaderIterator headerIterator()
headerIterator
in interface HttpMessage
Header
objects in the sequence they are sent over a connection.public HeaderIterator headerIterator(String name)
headerIterator
in interface HttpMessage
name
- the name of the headers over which to iterate, or Header
objects with the argument name in the sequence they are sent over a connection.@Deprecated public HttpParams getParams()
setParams(HttpParams)
.getParams
in interface HttpMessage
setParams(HttpParams)
.@Deprecated public void setParams(HttpParams params)
setParams
in interface HttpMessage
params
- The parameters.public RequestConfig getConfig()
getConfig
in interface Configurable
public OMap getProperties()
Session
getProperties
in class Session
public OMap toMap()
Session
toMap
in class BeanSession
Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.