Package org.opensearch.rest
Class RestRequest
java.lang.Object
org.opensearch.rest.RestRequest
- All Implemented Interfaces:
org.opensearch.core.xcontent.ToXContent.Params
@PublicApi(since="1.0.0")
public class RestRequest
extends Object
implements org.opensearch.core.xcontent.ToXContent.Params
REST Request
- Opensearch.api:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Thrown if there is a bad parameter.static class
Thrown if there is an error in the content type header.static enum
The method used. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
RestRequest
(org.opensearch.core.xcontent.NamedXContentRegistry xContentRegistry, Map<String, String> params, String path, Map<String, List<String>> headers, HttpRequest httpRequest, HttpChannel httpChannel) protected
RestRequest
(RestRequest restRequest) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
applyContentParser
(org.opensearch.common.CheckedConsumer<org.opensearch.core.xcontent.XContentParser, IOException> applyParser) If there is any content then callapplyParser
with the parser, otherwise do nothing.Returns a list of parameters that have been consumed.org.opensearch.core.common.bytes.BytesReference
content()
protected org.opensearch.core.common.bytes.BytesReference
content
(boolean contentConsumed) final org.opensearch.common.collect.Tuple
<org.opensearch.core.xcontent.MediaType, org.opensearch.core.common.bytes.BytesReference> Get the content of the request or the contents of thesource
param or throw an exception if both are missing.final org.opensearch.core.xcontent.XContentParser
A parser for the contents of this request if it has contents, otherwise a parser for thesource
parameter if there is one, otherwise throws anOpenSearchParseException
.final org.opensearch.core.xcontent.XContentParser
A parser for the contents of this request if there is a body, otherwise throws anOpenSearchParseException
.getAllHeaderValues
(String name) Get all values for the header ornull
if the header was not foundGet all of the headers and values associated with the headers.final org.opensearch.core.xcontent.MediaType
TheMediaType
that was parsed from theContent-Type
header.final long
org.opensearch.core.xcontent.NamedXContentRegistry
Get theNamedXContentRegistry
that should be used to create parsers from this request.boolean
final boolean
Does this request have content or asource
parameter? Use this instead ofhasContent()
if this RestHandler treats thesource
parameter like the body content.final boolean
final String
Get the value of the header ornull
if not found.boolean
method()
Returns the HTTP method used in the REST request.final String
final String
boolean
paramAsBoolean
(String key, boolean defaultValue) paramAsBoolean
(String key, Boolean defaultValue) float
paramAsFloat
(String key, float defaultValue) int
paramAsInt
(String key, int defaultValue) long
paramAsLong
(String key, long defaultValue) org.opensearch.core.common.unit.ByteSizeValue
paramAsSize
(String key, org.opensearch.core.common.unit.ByteSizeValue defaultValue) String[]
paramAsStringArray
(String key, String[] defaultValue) String[]
org.opensearch.common.unit.TimeValue
paramAsTime
(String key, org.opensearch.common.unit.TimeValue defaultValue) params()
static org.opensearch.core.xcontent.MediaType
parseContentType
(List<String> header) Parses the given content type string for the media type.parsePaginatedQueryParams
(String defaultSortOrder, int defaultPageSize) final String
path()
The path part of the URI (without the query string), decoded.rawPath()
The non decoded, raw path provided.static RestRequest
request
(org.opensearch.core.xcontent.NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request.static RestRequest
requestWithoutParameters
(org.opensearch.core.xcontent.NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request.final org.opensearch.core.common.bytes.BytesReference
uri()
The uri of the rest request, with the query string.final void
withContentOrSourceParamParserOrNull
(org.opensearch.common.CheckedConsumer<org.opensearch.core.xcontent.XContentParser, IOException> withParser) Call a consumer with the parser for the contents of this request if it has contents, otherwise with a parser for thesource
parameter if there is one, otherwise withnull
.
-
Constructor Details
-
RestRequest
protected RestRequest(org.opensearch.core.xcontent.NamedXContentRegistry xContentRegistry, Map<String, String> params, String path, Map<String, List<String>> headers, HttpRequest httpRequest, HttpChannel httpChannel) -
RestRequest
-
-
Method Details
-
isContentConsumed
public boolean isContentConsumed() -
request
public static RestRequest request(org.opensearch.core.xcontent.NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request. This method will throwRestRequest.BadParameterException
if the path cannot be decoded- Parameters:
xContentRegistry
- the content registryhttpRequest
- the http requesthttpChannel
- the http channel- Throws:
RestRequest.BadParameterException
- if the parameters can not be decodedRestRequest.ContentTypeHeaderException
- if the Content-Type header can not be parsed
-
requestWithoutParameters
public static RestRequest requestWithoutParameters(org.opensearch.core.xcontent.NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request. The path is not decoded so this constructor will not throw aRestRequest.BadParameterException
.- Parameters:
xContentRegistry
- the content registryhttpRequest
- the http requesthttpChannel
- the http channel- Throws:
RestRequest.ContentTypeHeaderException
- if the Content-Type header can not be parsed
-
method
Returns the HTTP method used in the REST request.- Returns:
- the
RestRequest.Method
used in the REST request - Throws:
IllegalArgumentException
- if the HTTP method is invalid
-
uri
The uri of the rest request, with the query string. -
rawPath
The non decoded, raw path provided. -
path
The path part of the URI (without the query string), decoded. -
hasContent
public boolean hasContent() -
content
public org.opensearch.core.common.bytes.BytesReference content() -
content
protected org.opensearch.core.common.bytes.BytesReference content(boolean contentConsumed) -
requiredContent
public final org.opensearch.core.common.bytes.BytesReference requiredContent()- Returns:
- content of the request body or throw an exception if the body or content type is missing
-
header
Get the value of the header ornull
if not found. This method only retrieves the first header value if multiple values are sent. Use ofgetAllHeaderValues(String)
should be preferred -
getAllHeaderValues
Get all values for the header ornull
if the header was not found -
getHeaders
Get all of the headers and values associated with the headers. Modifications of this map are not supported. -
getRequestId
public final long getRequestId() -
getMediaType
@Nullable public final org.opensearch.core.xcontent.MediaType getMediaType()TheMediaType
that was parsed from theContent-Type
header. This value will benull
in the case of a request without a validContent-Type
header, a request without content (hasContent()
, or a plain text request -
getHttpChannel
-
getHttpRequest
-
hasParam
-
param
- Specified by:
param
in interfaceorg.opensearch.core.xcontent.ToXContent.Params
-
param
- Specified by:
param
in interfaceorg.opensearch.core.xcontent.ToXContent.Params
-
params
-
consumedParams
Returns a list of parameters that have been consumed. This method returns a copy, callers are free to modify the returned list.- Returns:
- the list of currently consumed parameters.
-
paramAsFloat
-
paramAsInt
-
paramAsLong
-
paramAsBoolean
- Specified by:
paramAsBoolean
in interfaceorg.opensearch.core.xcontent.ToXContent.Params
-
paramAsBoolean
- Specified by:
paramAsBoolean
in interfaceorg.opensearch.core.xcontent.ToXContent.Params
-
paramAsTime
public org.opensearch.common.unit.TimeValue paramAsTime(String key, org.opensearch.common.unit.TimeValue defaultValue) -
paramAsSize
public org.opensearch.core.common.unit.ByteSizeValue paramAsSize(String key, org.opensearch.core.common.unit.ByteSizeValue defaultValue) -
paramAsStringArray
-
paramAsStringArrayOrEmptyIfAll
-
getXContentRegistry
public org.opensearch.core.xcontent.NamedXContentRegistry getXContentRegistry()Get theNamedXContentRegistry
that should be used to create parsers from this request. -
contentParser
A parser for the contents of this request if there is a body, otherwise throws anOpenSearchParseException
. UseapplyContentParser(CheckedConsumer)
if you want to gracefully handle when the request doesn't have any contents. UsecontentOrSourceParamParser()
for requests that support specifying the request body in thesource
param.- Throws:
IOException
-
applyContentParser
public final void applyContentParser(org.opensearch.common.CheckedConsumer<org.opensearch.core.xcontent.XContentParser, IOException> applyParser) throws IOExceptionIf there is any content then callapplyParser
with the parser, otherwise do nothing.- Throws:
IOException
-
hasContentOrSourceParam
public final boolean hasContentOrSourceParam()Does this request have content or asource
parameter? Use this instead ofhasContent()
if this RestHandler treats thesource
parameter like the body content. -
contentOrSourceParamParser
public final org.opensearch.core.xcontent.XContentParser contentOrSourceParamParser() throws IOExceptionA parser for the contents of this request if it has contents, otherwise a parser for thesource
parameter if there is one, otherwise throws anOpenSearchParseException
. UsewithContentOrSourceParamParserOrNull(CheckedConsumer)
instead if you need to handle the absence request content gracefully.- Throws:
IOException
-
withContentOrSourceParamParserOrNull
public final void withContentOrSourceParamParserOrNull(org.opensearch.common.CheckedConsumer<org.opensearch.core.xcontent.XContentParser, IOException> withParser) throws IOExceptionCall a consumer with the parser for the contents of this request if it has contents, otherwise with a parser for thesource
parameter if there is one, otherwise withnull
. UsecontentOrSourceParamParser()
if you should throw an exception back to the user when there isn't request content.- Throws:
IOException
-
contentOrSourceParam
public final org.opensearch.common.collect.Tuple<org.opensearch.core.xcontent.MediaType,org.opensearch.core.common.bytes.BytesReference> contentOrSourceParam()Get the content of the request or the contents of thesource
param or throw an exception if both are missing. PrefercontentOrSourceParamParser()
orwithContentOrSourceParamParserOrNull(CheckedConsumer)
if you need a parser. -
parseContentType
Parses the given content type string for the media type. This method currently ignores parameters. -
parsePaginatedQueryParams
-