public class RestResponseHeader extends Object implements Header
An extension of an HttpClient Header
that provides various support for converting the header to POJOs and
other convenience methods.
Constructor and Description |
---|
RestResponseHeader(RestRequest request,
RestResponse response,
Header header)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
as(Class<T> type)
Converts this header to the specified type.
|
<T> T |
as(ClassMeta<T> type)
Converts this header to the specified type.
|
<T> RestResponse |
as(Mutable<T> m,
Class<T> type)
Same as
as(Class) but sets the value in a mutable for fluent calls. |
<T> RestResponse |
as(Mutable<T> m,
ClassMeta<T> type)
Same as
as(ClassMeta) but sets the value in a mutable for fluent calls. |
<T> RestResponse |
as(Mutable<T> m,
Type type,
Type... args)
Same as
as(Type,Type...) but sets the value in a mutable for fluent calls. |
<T> T |
as(Type type,
Type... args)
Converts this header to the specified type.
|
BasicCsvArrayHeader |
asCsvArrayHeader()
Returns the value of this header as a CSV array header.
|
BasicDateHeader |
asDateHeader()
Returns the value of this header as a date header.
|
BasicEntityTagArrayHeader |
asEntityTagArrayHeader()
Returns the value of this header as an entity validator array header.
|
BasicEntityTagHeader |
asEntityTagHeader()
Returns the value of this header as an entity validator header.
|
<T extends BasicHeader> |
asHeader(Class<T> c)
Returns the value of this header as a
BasicHeader . |
BasicIntegerHeader |
asIntegerHeader()
Returns the value of this header as an integer header.
|
BasicLongHeader |
asLongHeader()
Returns the value of this header as a long header.
|
RestResponse |
asMatcher(Mutable<Matcher> m,
Pattern pattern)
Same as
asMatcher(Pattern) but sets the value in a mutable for fluent calls. |
RestResponse |
asMatcher(Mutable<Matcher> m,
String regex)
Same as
asMatcher(String) but sets the value in a mutable for fluent calls. |
RestResponse |
asMatcher(Mutable<Matcher> m,
String regex,
int flags)
Same as
asMatcher(String,int) but sets the value in a mutable for fluent calls. |
Matcher |
asMatcher(Pattern pattern)
Matches the specified pattern against this header value.
|
Matcher |
asMatcher(String regex)
Matches the specified pattern against this header value.
|
Matcher |
asMatcher(String regex,
int flags)
Matches the specified pattern against this header value.
|
<T> Optional<T> |
asOptional(Class<T> type)
|
<T> Optional<T> |
asOptional(ClassMeta<T> type)
Same as
as(ClassMeta) but returns the value as an Optional . |
<T> RestResponse |
asOptional(Mutable<Optional<T>> m,
Class<T> type)
Same as
asOptional(Class) but sets the value in a mutable for fluent calls. |
<T> RestResponse |
asOptional(Mutable<Optional<T>> m,
ClassMeta<T> type)
Same as
asOptional(ClassMeta) but sets the value in a mutable for fluent calls. |
<T> RestResponse |
asOptional(Mutable<Optional<T>> m,
Type type,
Type... args)
Same as
asOptional(Type,Type...) but sets the value in a mutable for fluent calls. |
<T> Optional<T> |
asOptional(Type type,
Type... args)
Same as
as(Type,Type...) but returns the value as an Optional . |
Optional<String> |
asOptionalString()
Returns the value of this header as an
Optional . |
FluentListAssertion<RestResponse> |
assertCsvArray()
Provides the ability to perform fluent-style assertions on comma-separated string headers.
|
FluentZonedDateTimeAssertion<RestResponse> |
assertDate()
Provides the ability to perform fluent-style assertions on a date response header.
|
FluentIntegerAssertion<RestResponse> |
assertInteger()
Provides the ability to perform fluent-style assertions on an integer response header.
|
FluentLongAssertion<RestResponse> |
assertLong()
Provides the ability to perform fluent-style assertions on a long response header.
|
FluentStringAssertion<RestResponse> |
assertString()
Provides the ability to perform fluent-style assertions on this response header.
|
String |
asString()
Returns the value of this header as a string.
|
RestResponse |
asString(Mutable<String> m)
Same as
asString() but sets the value in a mutable for fluent calls. |
BasicStringHeader |
asStringHeader()
Returns the value of this header as a string header.
|
RestResponse |
asStringOrElse(Mutable<String> m,
String def)
Same as
asStringOrElse(String) but sets the value in a mutable for fluent calls. |
String |
asStringOrElse(String def)
Returns the value of this header as a string with a default value.
|
BasicStringRangeArrayHeader |
asStringRangeArrayHeader()
Returns the value of this header as a range array header.
|
BasicUriHeader |
asUriHeader()
Returns the value of this header as a URI header.
|
boolean |
exists()
Returns
|
HeaderElement[] |
getElements()
Parses the value.
|
String |
getName()
Gets the name of this pair.
|
String |
getValue()
Gets the value of this pair.
|
RestResponseHeader |
parser(HttpPartParserSession value)
Specifies the part parser to use for this header.
|
RestResponseHeader |
schema(HttpPartSchema value)
Specifies the part schema for this header.
|
RestResponse |
toResponse()
Returns the response that created this object.
|
String |
toString() |
public RestResponseHeader(RestRequest request, RestResponse response, Header header)
request
- The request object.response
- The response object.header
- The wrapped header. Can be public RestResponseHeader schema(HttpPartSchema value)
Used by schema-based part parsers such as OpenApiParser
.
value
- The part schema.public RestResponseHeader parser(HttpPartParserSession value)
If not specified, uses the part parser defined on the client by calling RestClientBuilder.partParser(Class)
.
value
- The new part parser to use for this header.
SimplePartParser.DEFAULT
will be used.public boolean exists()
public String asString()
public <T extends BasicHeader> T asHeader(Class<T> c)
BasicHeader
.T
- The subclass of BasicHeader
to instantiate.c
- The subclass of BasicHeader
to instantiate.public BasicCsvArrayHeader asCsvArrayHeader()
public BasicDateHeader asDateHeader()
public BasicEntityTagArrayHeader asEntityTagArrayHeader()
public BasicEntityTagHeader asEntityTagHeader()
public BasicIntegerHeader asIntegerHeader()
public BasicLongHeader asLongHeader()
public BasicStringRangeArrayHeader asStringRangeArrayHeader()
public BasicStringHeader asStringHeader()
public BasicUriHeader asUriHeader()
public RestResponse asString(Mutable<String> m)
asString()
but sets the value in a mutable for fluent calls.m
- The mutable to set the header value in.public Optional<String> asOptionalString()
Optional
.Optional
, or an empty optional if header was not present.public String asStringOrElse(String def)
def
- The default value.public RestResponse asStringOrElse(Mutable<String> m, String def)
asStringOrElse(String)
but sets the value in a mutable for fluent calls.m
- The mutable to set the header value in.def
- The default value.public <T> T as(Type type, Type... args) throws RestCallException
T
- The type to convert to.type
- The type to convert to.args
- The type parameters.RestCallException
- If value could not be parsed.public <T> RestResponse as(Mutable<T> m, Type type, Type... args) throws RestCallException
as(Type,Type...)
but sets the value in a mutable for fluent calls.T
- The type to convert to.m
- The mutable to set the parsed header value in.type
- The type to convert to.args
- The type parameters.RestCallException
- If value could not be parsed.public <T> T as(Class<T> type) throws RestCallException
T
- The type to convert to.type
- The type to convert to.RestCallException
- If value could not be parsed.public <T> RestResponse as(Mutable<T> m, Class<T> type) throws RestCallException
as(Class)
but sets the value in a mutable for fluent calls.T
- The type to convert to.m
- The mutable to set the parsed header value in.type
- The type to convert to.RestCallException
- If value could not be parsed.public <T> T as(ClassMeta<T> type) throws RestCallException
T
- The type to convert to.type
- The type to convert to.RestCallException
- If value could not be parsed.public <T> RestResponse as(Mutable<T> m, ClassMeta<T> type) throws RestCallException
as(ClassMeta)
but sets the value in a mutable for fluent calls.T
- The type to convert to.m
- The mutable to set the parsed header value in.type
- The type to convert to.RestCallException
- If value could not be parsed.public <T> Optional<T> asOptional(Type type, Type... args) throws RestCallException
as(Type,Type...)
but returns the value as an Optional
.T
- The type to convert to.type
- The type to convert to.args
- The type parameters.Optional
, or an empty optional if header was not present.RestCallException
- If value could not be parsed.public <T> RestResponse asOptional(Mutable<Optional<T>> m, Type type, Type... args) throws RestCallException
asOptional(Type,Type...)
but sets the value in a mutable for fluent calls.T
- The type to convert to.m
- The mutable to set the parsed header value in.type
- The type to convert to.args
- The type parameters.RestCallException
- If value could not be parsed.public <T> Optional<T> asOptional(Class<T> type) throws RestCallException
T
- The type to convert to.type
- The type to convert to.Optional
, or an empty optional if header was not present.RestCallException
- If value could not be parsed.public <T> RestResponse asOptional(Mutable<Optional<T>> m, Class<T> type) throws RestCallException
asOptional(Class)
but sets the value in a mutable for fluent calls.T
- The type to convert to.m
- The mutable to set the parsed header value in.type
- The type to convert to.RestCallException
- If value could not be parsed.public <T> Optional<T> asOptional(ClassMeta<T> type) throws RestCallException
as(ClassMeta)
but returns the value as an Optional
.T
- The type to convert to.type
- The type to convert to.Optional
, or an empty optional if header was not present.RestCallException
- If value could not be parsed.public <T> RestResponse asOptional(Mutable<Optional<T>> m, ClassMeta<T> type) throws RestCallException
asOptional(ClassMeta)
but sets the value in a mutable for fluent calls.T
- The type to convert to.m
- The mutable to set the parsed header value in.type
- The type to convert to.RestCallException
- If value could not be parsed.public Matcher asMatcher(Pattern pattern) throws RestCallException
pattern
- The regular expression pattern to match.RestCallException
- If a connection error occurred.public RestResponse asMatcher(Mutable<Matcher> m, Pattern pattern) throws RestCallException
asMatcher(Pattern)
but sets the value in a mutable for fluent calls.
m
- The mutable to set the value in.pattern
- The regular expression pattern to match.RestCallException
- If a connection error occurred.public Matcher asMatcher(String regex) throws RestCallException
regex
- The regular expression pattern to match.RestCallException
- If a connection error occurred.public RestResponse asMatcher(Mutable<Matcher> m, String regex) throws RestCallException
asMatcher(String)
but sets the value in a mutable for fluent calls.
m
- The mutable to set the value in.regex
- The regular expression pattern to match.RestCallException
- If a connection error occurred.public Matcher asMatcher(String regex, int flags) throws RestCallException
regex
- The regular expression pattern to match.flags
- Pattern match flags. See Pattern.compile(String, int)
.RestCallException
- If a connection error occurred.public RestResponse asMatcher(Mutable<Matcher> m, String regex, int flags) throws RestCallException
asMatcher(String,int)
but sets the value in a mutable for fluent calls.
m
- The mutable to set the value in.regex
- The regular expression pattern to match.flags
- Pattern match flags. See Pattern.compile(String, int)
.RestCallException
- If a connection error occurred.public RestResponse toResponse()
public FluentStringAssertion<RestResponse> assertString()
This method is called directly from the RestResponse.assertStringHeader(String)
method to instantiate a fluent assertions object.
The assertion test returns the original response object allowing you to chain multiple requests like so:
public FluentIntegerAssertion<RestResponse> assertInteger()
This method is called directly from the RestResponse.assertIntegerHeader(String)
method to instantiate a fluent assertions object.
public FluentLongAssertion<RestResponse> assertLong()
This method is called directly from the RestResponse.assertLongHeader(String)
method to instantiate a fluent assertions object.
public FluentZonedDateTimeAssertion<RestResponse> assertDate()
This method is called directly from the RestResponse.assertDateHeader(String)
method to instantiate a fluent assertions object.
public FluentListAssertion<RestResponse> assertCsvArray()
This method is called directly from the RestResponse.assertCsvArrayHeader(String)
method to instantiate a fluent assertions object.
public String getName()
getName
in interface NameValuePair
public String getValue()
asString()
is an equivalent method and the preferred method for fluent-style coding.
getValue
in interface NameValuePair
public HeaderElement[] getElements() throws ParseException
getElements
in interface Header
HeaderElement
entries, may be empty, but is never ParseException
- In case of a parsing error.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.