public class RequestHeader extends Object implements Header
Constructor and Description |
---|
RequestHeader(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.
|
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 . |
RestResponse |
assertContains(String... values)
Asserts that the header contains all the specified substrings.
|
RestResponse |
assertExists()
Asserts that the header equals the specified value.
|
RestResponse |
assertMatches(Pattern pattern)
Asserts that the header matches the specified pattern.
|
RestResponse |
assertMatches(String regex)
Asserts that the header matches the specified regular expression.
|
RestResponse |
assertMatches(String regex,
int flags)
Asserts that the header matches the specified regular expression.
|
RestResponse |
assertValue(Predicate<String> test)
Asserts that the header passes the specified predicate test.
|
RestResponse |
assertValue(String value)
Asserts that the header equals the specified value.
|
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. |
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.
|
boolean |
exists()
Returns
|
HeaderElement[] |
getElements()
Parses the value.
|
String |
getName()
Gets the name of this pair.
|
String |
getValue()
Gets the value of this pair.
|
RequestHeader |
parser(HttpPartParserSession value)
Specifies the part parser to use for this header.
|
RequestHeader |
schema(HttpPartSchema value)
Specifies the part schema for this header.
|
RestResponse |
toResponse()
Returns the response that created this object.
|
String |
toString() |
public RequestHeader(RestRequest request, RestResponse response, Header header)
request
- The request object.response
- The response object.header
- The wrapped header. Can be public RequestHeader schema(HttpPartSchema value)
Used by schema-based part parsers such as OpenApiParser
.
value
- The part schema.public RequestHeader parser(HttpPartParserSession value)
If not specified, uses the part parser defined on the client by calling RestContextBuilder.partParser(Class)
.
value
- The new part parser to use for this header.
SimplePartParser.DEFAULT
will be used.public boolean exists()
public String asString()
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 ParseException
T
- The type to convert to.type
- The type to convert to.args
- The type parameters.ParseException
- If value could not be parsed.public <T> RestResponse as(Mutable<T> m, Type type, Type... args) throws ParseException
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.ParseException
- If value could not be parsed.public <T> T as(Class<T> type) throws ParseException
T
- The type to convert to.type
- The type to convert to.ParseException
- If value could not be parsed.public <T> RestResponse as(Mutable<T> m, Class<T> type) throws ParseException
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.ParseException
- If value could not be parsed.public <T> T as(ClassMeta<T> type) throws ParseException
T
- The type to convert to.type
- The type to convert to.ParseException
- If value could not be parsed.public <T> RestResponse as(Mutable<T> m, ClassMeta<T> type) throws ParseException
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.ParseException
- If value could not be parsed.public <T> Optional<T> asOptional(Type type, Type... args) throws ParseException
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.ParseException
- If value could not be parsed.public <T> RestResponse asOptional(Mutable<Optional<T>> m, Type type, Type... args) throws ParseException
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.ParseException
- If value could not be parsed.public <T> Optional<T> asOptional(Class<T> type) throws ParseException
T
- The type to convert to.type
- The type to convert to.Optional
, or an empty optional if header was not present.ParseException
- If value could not be parsed.public <T> RestResponse asOptional(Mutable<Optional<T>> m, Class<T> type) throws ParseException
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.ParseException
- If value could not be parsed.public <T> Optional<T> asOptional(ClassMeta<T> type) throws ParseException
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.ParseException
- If value could not be parsed.public <T> RestResponse asOptional(Mutable<Optional<T>> m, ClassMeta<T> type) throws ParseException
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.ParseException
- If value could not be parsed.public Matcher asMatcher(Pattern pattern)
pattern
- The regular expression pattern to match.public RestResponse asMatcher(Mutable<Matcher> m, Pattern pattern)
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.public Matcher asMatcher(String regex)
regex
- The regular expression pattern to match.public RestResponse asMatcher(Mutable<Matcher> m, String regex)
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.public Matcher asMatcher(String regex, int flags)
regex
- The regular expression pattern to match.flags
- Pattern match flags. See Pattern.compile(String, int)
.public RestResponse asMatcher(Mutable<Matcher> m, String regex, int flags)
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)
.public RestResponse toResponse()
public RestResponse assertExists() throws AssertionError
AssertionError
- If assertion failed.public RestResponse assertValue(String value) throws AssertionError
value
- The value to test for.AssertionError
- If assertion failed.public RestResponse assertValue(Predicate<String> test) throws AssertionError
test
- The predicate to test for.AssertionError
- If assertion failed.public RestResponse assertContains(String... values) throws AssertionError
values
- The substrings to test for.AssertionError
- If assertion failed.public RestResponse assertMatches(String regex) throws AssertionError
regex
- The pattern to test for.AssertionError
- If assertion failed.public RestResponse assertMatches(String regex, int flags) throws AssertionError
regex
- The pattern to test for.flags
- Pattern match flags. See Pattern.compile(String, int)
.AssertionError
- If assertion failed.public RestResponse assertMatches(Pattern pattern) throws AssertionError
The pattern can contain
pattern
- The pattern to test for.AssertionError
- If assertion failed.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.