Class RequestHttpPart
- Direct Known Subclasses:
RequestFormParam
,RequestHeader
,RequestPathParam
,RequestQueryParam
See Also:
-
Constructor Summary
ConstructorDescriptionRequestHttpPart
(HttpPartType partType, RestRequest request, String name, String value) Constructor. -
Method Summary
Modifier and TypeMethodDescription<T> Optional<T>
Converts this part to the specified POJO type using the requestHttpPartParser
and optional schema.<T> Optional<T>
Converts this part to the specified POJO type using the requestHttpPartParser
and optional schema.<T> Optional<T>
Converts this part to the specified POJO type using the requestHttpPartParser
and optional schema.Returns the value of this parameter as a boolean.Returns the value of this parameter as aBasicBooleanPart
.Returns the value of this parameter as a list from a comma-delimited string.Returns the value of this parameter as aBasicCsvArrayPart
.asDate()
Returns the value of this parameter as a date.Returns the value of this parameter as aBasicDatePart
.Returns the value of this parameter as an integer.Returns the value of this parameter as aBasicIntegerPart
.asLong()
Returns the value of this parameter as a long.Returns the value of this parameter as aBasicLongPart
.Matches the specified pattern against this part value.Matches the specified pattern against this part value.Matches the specified pattern against this part value.Provides the ability to perform fluent-style assertions on comma-separated string parameters.Provides the ability to perform fluent-style assertions on a date parameter.Provides the ability to perform fluent-style assertions on an integer parameter.Provides the ability to perform fluent-style assertions on a long parameter.Provides the ability to perform fluent-style assertions on this parameter.asString()
Returns the value of this part as a string.Returns the value of this parameter as aBasicStringPart
.Returns the value of this parameter as aBasicUriPart
.Sets a default value for this part.get()
If a value is present, returns the value, otherwise throwsNoSuchElementException
.getName()
Gets the name of this part.protected RestRequest
Returns the request that created this part.getValue()
Returns the value of this part.boolean
Returnstrue if this part exists on the request.Return the value if present, otherwise return other.parser
(HttpPartParserSession value) Specifies the part parser to use for this part.schema
(HttpPartSchema value) Specifies the part schema for this part.toString()
-
Constructor Details
-
RequestHttpPart
Constructor.- Parameters:
partType
- The HTTP part type.request
- The request object.name
- The part name.value
- The part value.
-
-
Method Details
-
schema
Specifies the part schema for this part.Used by schema-based part parsers such as
OpenApiParser
.- Parameters:
value
- The part schema.- Returns:
- This object.
-
parser
Specifies the part parser to use for this part.If not specified, uses the part parser defined on the client by calling
RestContext.Builder.partParser()
.- Parameters:
value
- The new part parser to use for this part.
Ifnull ,SimplePartParser.DEFAULT
will be used.- Returns:
- This object.
-
def
Sets a default value for this part.- Parameters:
def
- The default value.- Returns:
- This object.
-
getValue
Returns the value of this part.- Returns:
- The value of this part.
-
isPresent
Returnstrue if this part exists on the request.This is a shortened form for calling
asString().isPresent() .- Returns:
true if this part exists on the request.
-
get
If a value is present, returns the value, otherwise throwsNoSuchElementException
.This is a shortened form for calling
asString().get() .- Returns:
- The value if present.
-
orElse
Return the value if present, otherwise return other.This is a shortened form for calling
asString().orElse( .other )- Parameters:
other
- The value to be returned if there is no value present, may benull .- Returns:
- The value, if present, otherwise other.
-
asString
Returns the value of this part as a string.- Returns:
- The value of this part as a string, or
Optional.empty()
if the part was not present.
-
as
Converts this part to the specified POJO type using the requestHttpPartParser
and optional schema.See Complex Data Types for information on defining complex generic types of
Maps
andCollections
.- Type Parameters:
T
- The type to convert to.- Parameters:
type
- The type to convert to.args
- The type parameters.- Returns:
- The converted type, or
Optional.empty()
if the part is not present. - Throws:
BasicHttpException
- If value could not be parsed.
-
as
Converts this part to the specified POJO type using the requestHttpPartParser
and optional schema.If the specified type is an HTTP part type (extends from
Header
/NameValuePair
), then looks for one of the following constructors:public T(Stringname , Stringvalue );
If it doesn't find one of those constructors, then it parses it into the specified type using the part parser.
- Type Parameters:
T
- The type to convert to.- Parameters:
type
- The type to convert to.- Returns:
- The converted type, or
Optional.empty()
if the part is not present. - Throws:
BasicHttpException
- If value could not be parsed.
-
as
Converts this part to the specified POJO type using the requestHttpPartParser
and optional schema.If the specified type is an HTTP part type (extends from
Header
/NameValuePair
), then looks for one of the following constructors:public T(Stringname , Stringvalue );
If it doesn't find one of those constructors, then it parses it into the specified type using the part parser.
- Type Parameters:
T
- The type to convert to.- Parameters:
type
- The type to convert to.- Returns:
- The converted type, or
Optional.empty()
if the part is not present. - Throws:
BasicHttpException
- If value could not be parsed.
-
asMatcher
Matches the specified pattern against this part value.Example:
Matcher
matcher =request .getHeader("Content-Type" ) .asMatcher(Pattern.compile ("application/(.*)" ));if (matcher .matches()) { StringmediaType =matcher .group(1); }- Parameters:
pattern
- The regular expression pattern to match.- Returns:
- The matcher.
- Throws:
BasicHttpException
- If a connection error occurred.
-
asMatcher
Matches the specified pattern against this part value.Example:
Matcher
matcher =request .getHeader("Content-Type" ) .asMatcher("application/(.*)" );if (matcher .matches()) { StringmediaType =matcher .group(1); }- Parameters:
regex
- The regular expression pattern to match.- Returns:
- The matcher.
- Throws:
BasicHttpException
- If a connection error occurred.
-
asMatcher
Matches the specified pattern against this part value.Example:
Matcher
matcher =request .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.
- Throws:
BasicHttpException
- If a connection error occurred.
-
asInteger
Returns the value of this parameter as an integer.- Returns:
- The value of this parameter as an integer, or
Optional.empty()
if the parameter was not present.
-
asBoolean
Returns the value of this parameter as a boolean.- Returns:
- The value of this parameter as a boolean, or
Optional.empty()
if the parameter was not present.
-
asLong
Returns the value of this parameter as a long.- Returns:
- The value of this parameter as a long, or
Optional.empty()
if the parameter was not present.
-
asDate
Returns the value of this parameter as a date.- Returns:
- The value of this parameter as a date, or
Optional.empty()
if the parameter was not present.
-
asCsvArray
Returns the value of this parameter as a list from a comma-delimited string.- Returns:
- The value of this parameter as a list from a comma-delimited string, or
Optional.empty()
if the parameter was not present.
-
asCsvArrayPart
Returns the value of this parameter as aBasicCsvArrayPart
.- Returns:
- The value of this parameter as a
BasicCsvArrayPart
, nevernull .
-
asDatePart
Returns the value of this parameter as aBasicDatePart
.- Returns:
- The value of this parameter as a
BasicDatePart
, nevernull .
-
asIntegerPart
Returns the value of this parameter as aBasicIntegerPart
.- Returns:
- The value of this parameter as a
BasicIntegerPart
, nevernull .
-
asBooleanPart
Returns the value of this parameter as aBasicBooleanPart
.- Returns:
- The value of this parameter as a
BasicBooleanPart
, nevernull .
-
asLongPart
Returns the value of this parameter as aBasicLongPart
.- Returns:
- The value of this parameter as a
BasicLongPart
, nevernull .
-
asStringPart
Returns the value of this parameter as aBasicStringPart
.- Returns:
- The value of this parameter as a
BasicStringPart
, nevernull .
-
asUriPart
Returns the value of this parameter as aBasicUriPart
.- Returns:
- The value of this parameter as a
BasicUriPart
, nevernull .
-
assertString
Provides the ability to perform fluent-style assertions on this parameter.Examples:
request .getQueryParam("foo" ) .assertString().contains("bar" );The assertion test returns the original object allowing you to chain multiple requests like so:
String
foo =request .getQueryParam("foo" ) .assertString().contains("bar" ) .asString().get();- Returns:
- A new fluent assertion object.
-
assertInteger
Provides the ability to perform fluent-style assertions on an integer parameter.Examples:
request .getQueryParam("age" ) .assertInteger().isGreaterThan(1);- Returns:
- A new fluent assertion object.
-
assertLong
Provides the ability to perform fluent-style assertions on a long parameter.Examples:
request .getQueryParam("length" ) .assertLong().isLessThan(100000);- Returns:
- A new fluent assertion object.
-
assertDate
Provides the ability to perform fluent-style assertions on a date parameter.Examples:
request .getQueryParam("time" ) .assertDate().isAfterNow();- Returns:
- A new fluent assertion object.
-
assertCsvArray
Provides the ability to perform fluent-style assertions on comma-separated string parameters.Examples:
request .getQueryParam("allow" ) .assertCsvArray().contains("GET" );- Returns:
- A new fluent assertion object.
-
getRequest
Returns the request that created this part.- Returns:
- The request that created this part.
-
getName
Gets the name of this part.- Returns:
- The name of this part, never
null .
-
toString
-