Class ResponseHeader
- All Implemented Interfaces:
Serializable,Cloneable,Header,NameValuePair
An extension of an HttpClient Header that provides various support for converting the header to POJOs and
other convenience methods.
See Also:
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionResponseHeader(String name, RestRequest request, RestResponse response, Header header) Constructor. -
Method Summary
Modifier and TypeMethodDescription<T> Optional<T>Converts this header to the specified type.<T> Optional<T>Converts this header to the specified type.<T> Optional<T>Converts this header to the specified type.<T> RestResponseSame asas(Class)but sets the value in a mutable for fluent calls.<T> RestResponseSame asas(Type,Type...)but sets the value in a mutable for fluent calls.<T> RestResponseSame asas(ClassMeta)but sets the value in a mutable for fluent calls.Returns the value of this header as a boolean.Returns the value of this header as an boolean header.Returns the value of this header as a list from a comma-delimited string.Returns the value of this header as a CSV array header.asDate()Returns the value of this header as a date.Returns the value of this header as a date header.Returns the value of this header as an entity validator header.Returns the value of this header as an entity validator array header.<T extends BasicHeader>
TReturns the value of this header as aBasicHeader.Returns the value of this header as an integer.Returns the value of this header as an integer header.asLong()Returns the value of this header as a long.Returns the value of this header as a long header.Matches the specified pattern against this header value.Matches the specified pattern against this header value.Matches the specified pattern against this header value.Shortcut for callingassertValue().asInteger() .Shortcut for callingassertValue().asLong() .Shortcut for callingassertValue().asString() .Provides the ability to perform fluent-style assertions on this response header.Shortcut for callingassertValue().asZonedDateTime() .Same asBasicHeader.asString()but sets the value in a mutable for fluent calls.Returns the value of this header as a string header.Returns the value of this header as a range array header.Returns the value of this header as a URI header.Parses the value.parser(HttpPartParserSession value) Specifies the part parser to use for this header.response()Returns the response that created this object.schema(HttpPartSchema value) Specifies the part schema for this header.Methods inherited from class org.apache.juneau.http.header.BasicHeader
assertName, assertStringValue, asString, equals, equalsIgnoreCase, get, getName, getValue, hashCode, isNotEmpty, isPresent, of, of, orElse, toString
-
Constructor Details
-
ResponseHeader
Constructor.- Parameters:
name- The header name.request- The request object.response- The response object.header- The wrapped header. Can benull .- Throws:
IllegalArgumentException- If name isnull or empty.
-
-
Method Details
-
as
Converts this header to the specified type.- Type Parameters:
T- The type to convert to.- Parameters:
type- The type to convert to.- Returns:
- The converted type, or
null if header is not present.
-
as
Converts this header to the specified type.- Type Parameters:
T- The type to convert to.- Parameters:
type- The type to convert to.- Returns:
- The converted type, or
null if header is not present.
-
as
Converts this header to the specified type.See Complex Data Types for information on defining complex generic types of
MapsandCollections.- Type Parameters:
T- The type to convert to.- Parameters:
type- The type to convert to.args- The type parameters.- Returns:
- The converted type, or
null if header is not present.
-
as
Same asas(Class)but sets the value in a mutable for fluent calls.- Type Parameters:
T- The type to convert to.- Parameters:
value- The mutable to set the parsed header value in.type- The type to convert to.- Returns:
- This object.
-
as
Same asas(ClassMeta)but sets the value in a mutable for fluent calls.- Type Parameters:
T- The type to convert to.- Parameters:
value- The mutable to set the parsed header value in.type- The type to convert to.- Returns:
- This object.
-
as
Same asas(Type,Type...)but sets the value in a mutable for fluent calls.See Complex Data Types for information on defining complex generic types of
MapsandCollections.- Type Parameters:
T- The type to convert to.- Parameters:
value- The mutable to set the parsed header value in.type- The type to convert to.args- The type parameters.- Returns:
- This object.
-
asBoolean
Returns the value of this header as a boolean.- Returns:
- The value of this header as a boolean, or
Optional.empty()if the header was not present.
-
asBooleanHeader
Returns the value of this header as an boolean header.- Returns:
- The value of this header as an boolean header, never
null .
-
asCsvArray
Returns the value of this header as a list from a comma-delimited string.- Returns:
- The value of this header as a list from a comma-delimited string, or
Optional.empty()if the header was not present.
-
asCsvHeader
Returns the value of this header as a CSV array header.- Returns:
- The value of this header as a CSV array header, never
null .
-
asDate
Returns the value of this header as a date.- Returns:
- The value of this header as a date, or
Optional.empty()if the header was not present.
-
asDateHeader
Returns the value of this header as a date header.- Returns:
- The value of this header as a date header, never
null .
-
asEntityTagHeader
Returns the value of this header as an entity validator header.- Returns:
- The value of this header as an entity validator array, never
null .
-
asEntityTagsHeader
Returns the value of this header as an entity validator array header.- Returns:
- The value of this header as an entity validator array header, never
null .
-
asHeader
Returns the value of this header as aBasicHeader.- Type Parameters:
T- The subclass ofBasicHeaderto instantiate.- Parameters:
c- The subclass ofBasicHeaderto instantiate.- Returns:
- The value of this header as a string, never
null .
-
asInteger
Returns the value of this header as an integer.- Returns:
- The value of this header as an integer, or
Optional.empty()if the header was not present.
-
asIntegerHeader
Returns the value of this header as an integer header.- Returns:
- The value of this header as an integer header, never
null .
-
asLong
Returns the value of this header as a long.- Returns:
- The value of this header as a long, or
Optional.empty()if the header was not present.
-
asLongHeader
Returns the value of this header as a long header.- Returns:
- The value of this header as a long header, never
null .
-
asMatcher
Matches the specified pattern against this header value.Example:
// Parse header using a regular expression. Matchermatcher =client .get(URI ) .run() .getResponseHeader("Content-Type" ).asMatcher(Pattern.compile ("application/(.*)" ));if (matcher .matches()) { StringmediaType =matcher .group(1); }- Parameters:
pattern- The regular expression pattern to match.- Returns:
- The matcher.
-
asMatcher
Matches the specified pattern against this header value.Example:
// Parse header using a regular expression. Matchermatcher =client .get(URI ) .run() .getHeader("Content-Type" ).asMatcher("application/(.*)" );if (matcher .matches()) { StringmediaType =matcher .group(1); }- Parameters:
regex- The regular expression pattern to match.- Returns:
- The matcher.
-
asMatcher
Matches the specified pattern against this header value.Example:
// Parse header using a regular expression. Matchermatcher =client .get(URI ) .run() .getHeader("Content-Type" ).asMatcher("application/(.*)" ,CASE_INSENSITIVE );if (matcher .matches()) { StringmediaType =matcher .group(1); }- Parameters:
regex- The regular expression pattern to match.flags- Pattern match flags. SeePattern.compile(String, int).- Returns:
- The matcher.
-
assertInteger
Shortcut for callingassertValue().asInteger() .- Returns:
- A new fluent assertion.
-
assertLong
Shortcut for callingassertValue().asLong() .- Returns:
- A new fluent assertion.
-
assertString
Shortcut for callingassertValue().asString() .- Returns:
- A new fluent assertion.
-
assertValue
Provides the ability to perform fluent-style assertions on this response header.Examples:
// Validates the content type header is provided. client .get(URI ) .run() .getHeader("Content-Type" ).assertValue().exists();// Validates the content type is JSON. client .get(URI ) .run() .getHeader("Content-Type" ).assertValue().equals("application/json" );// Validates the content type is JSON using test predicate. client .get(URI ) .run() .getHeader("Content-Type" ).assertValue().is(x ->x .equals("application/json" ));// Validates the content type is JSON by just checking for substring. client .get(URI ) .run() .getHeader("Content-Type" ).assertValue().contains("json" );// Validates the content type is JSON using regular expression. client .get(URI ) .run() .getHeader("Content-Type" ).assertValue().isPattern(".*json.*" );// Validates the content type is JSON using case-insensitive regular expression. client .get(URI ) .run() .getHeader("Content-Type" ).assertValue().isPattern(".*json.*" ,CASE_INSENSITIVE );The assertion test returns the original response object allowing you to chain multiple requests like so:
// Validates the header and converts it to a bean. MediaTypemediaType =client .get(URI ) .run() .getHeader("Content-Type" ).assertValue().isNotEmpty() .getHeader("Content-Type" ).assertValue().isPattern(".*json.*" ) .getHeader("Content-Type" ).as(MediaType.class );- Returns:
- A new fluent assertion object.
-
assertZonedDateTime
Shortcut for callingassertValue().asZonedDateTime() .- Returns:
- A new fluent assertion.
-
asString
Same asBasicHeader.asString()but sets the value in a mutable for fluent calls.- Parameters:
value- The mutable to set the header value in.- Returns:
- This object.
-
asStringHeader
Returns the value of this header as a string header.- Returns:
- The value of this header as a string header, never
null .
-
asStringRangesHeader
Returns the value of this header as a range array header.- Returns:
- The value of this header as a range array header, never
null .
-
asUriHeader
Returns the value of this header as a URI header.- Returns:
- The value of this header as a URI header, never
null .
-
getElements
Parses the value.- Specified by:
getElementsin interfaceHeader- Overrides:
getElementsin classBasicHeader- Returns:
- An array of
HeaderElemententries, may be empty, but is nevernull . - Throws:
ParseException- In case of a parsing error.
-
parser
Specifies the part parser to use for this header.If not specified, uses the part parser defined on the client by calling
RestClient.Builder.partParser(Class).- Parameters:
value- The new part parser to use for this header.
Ifnull ,SimplePartParser.DEFAULTwill be used.- Returns:
- This object.
-
response
Returns the response that created this object.- Returns:
- The response that created this object.
-
schema
Specifies the part schema for this header.Used by schema-based part parsers such as
OpenApiParser.- Parameters:
value- The part schema.- Returns:
- This object.
-