Package org.elasticsearch.rest
Class RestRequest
java.lang.Object
org.elasticsearch.rest.RestRequest
- All Implemented Interfaces:
org.elasticsearch.xcontent.ToXContent.Params
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic enum -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRestRequest(RestRequest other) protectedRestRequest(org.elasticsearch.xcontent.XContentParserConfiguration parserConfig, Map<String, String> params, String path, Map<String, List<String>> headers, HttpRequest httpRequest, HttpChannel httpChannel) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidapplyContentParser(org.elasticsearch.core.CheckedConsumer<org.elasticsearch.xcontent.XContentParser, IOException> applyParser) If there is any content then callapplyParserwith the parser, otherwise do nothing.content()intfinal org.elasticsearch.core.Tuple<org.elasticsearch.xcontent.XContentType,BytesReference> Get the content of the request or the contents of thesourceparam or throw an exception if both are missing.final org.elasticsearch.xcontent.XContentParserA parser for the contents of this request if it has contents, otherwise a parser for thesourceparameter if there is one, otherwise throws anElasticsearchParseException.final org.elasticsearch.xcontent.XContentParserA parser for the contents of this request if there is a body, otherwise throws anElasticsearchParseException.org.elasticsearch.xcontent.XContentParserConfigurationGet the configuration that should be used to createXContentParserfrom this request.getAllHeaderValues(String name) Get all values for the header ornullif the header was not foundGet all of the headers and values associated with the headers.org.elasticsearch.xcontent.ParsedMediaTypeorg.elasticsearch.xcontent.ParsedMediaTypefinal longorg.elasticsearch.core.RestApiVersionThe requested version of the REST API.final org.elasticsearch.xcontent.XContentTypeTheXContentTypethat was parsed from theContent-Typeheader.booleanfinal booleanDoes this request have content or asourceparameter? Use this instead ofhasContent()if this RestHandler treats thesourceparameter like the body content.final booleanfinal StringGet the value of the header ornullif not found.booleanmethod()Returns the HTTP method used in the REST request.final Stringfinal StringbooleanparamAsBoolean(String key, boolean defaultValue) paramAsBoolean(String key, Boolean defaultValue) doubleparamAsDouble(String key, double defaultValue) floatparamAsFloat(String key, float defaultValue) intparamAsInt(String key, int defaultValue) longparamAsLong(String key, long defaultValue) paramAsSize(String key, ByteSizeValue defaultValue) String[]paramAsStringArray(String key, String[] defaultValue) String[]org.elasticsearch.core.TimeValueparamAsTime(String key, org.elasticsearch.core.TimeValue defaultValue) params()static org.elasticsearch.xcontent.XContentTypeparseContentType(List<String> header) Parses the given content type string for the media type.final Stringpath()The path part of the URI (without the query string), decoded.rawPath()The non decoded, raw path provided.static RestRequestrequest(org.elasticsearch.xcontent.XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request.static RestRequestrequestWithoutParameters(org.elasticsearch.xcontent.XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request.final BytesReferenceuri()The uri of the rest request, with the query string.final voidwithContentOrSourceParamParserOrNull(org.elasticsearch.core.CheckedConsumer<org.elasticsearch.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 thesourceparameter if there is one, otherwise withnull.
-
Constructor Details
-
RestRequest
protected RestRequest(org.elasticsearch.xcontent.XContentParserConfiguration parserConfig, 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.elasticsearch.xcontent.XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request.- Throws:
RestRequest.BadParameterException- if the parameters can not be decodedRestRequest.MediaTypeHeaderException- if the Content-Type or Accept header can not be parsed
-
requestWithoutParameters
public static RestRequest requestWithoutParameters(org.elasticsearch.xcontent.XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request. The path is not decoded so this constructor will not throw aRestRequest.BadParameterException.- Throws:
RestRequest.MediaTypeHeaderException- if the Content-Type or Accept header can not be parsed
-
method
Returns the HTTP method used in the REST request.- Returns:
- the
RestRequest.Methodused 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() -
contentLength
public int contentLength() -
content
-
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 ornullif 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 ornullif 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() -
getXContentType
@Nullable public final org.elasticsearch.xcontent.XContentType getXContentType()TheXContentTypethat was parsed from theContent-Typeheader. This value will benullin the case of a request without a validContent-Typeheader, a request without content (hasContent(), or a plain text request -
getHttpChannel
-
getHttpRequest
-
hasParam
-
param
- Specified by:
paramin interfaceorg.elasticsearch.xcontent.ToXContent.Params
-
param
- Specified by:
paramin interfaceorg.elasticsearch.xcontent.ToXContent.Params
-
params
-
paramAsFloat
-
paramAsDouble
-
paramAsInt
-
paramAsLong
-
paramAsBoolean
- Specified by:
paramAsBooleanin interfaceorg.elasticsearch.xcontent.ToXContent.Params
-
paramAsBoolean
- Specified by:
paramAsBooleanin interfaceorg.elasticsearch.xcontent.ToXContent.Params
-
paramAsTime
public org.elasticsearch.core.TimeValue paramAsTime(String key, org.elasticsearch.core.TimeValue defaultValue) -
paramAsSize
-
paramAsStringArray
-
paramAsStringArrayOrEmptyIfAll
-
contentParserConfig
public org.elasticsearch.xcontent.XContentParserConfiguration contentParserConfig()Get the configuration that should be used to createXContentParserfrom this request. -
contentParser
A parser for the contents of this request if there is a body, otherwise throws anElasticsearchParseException. 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 thesourceparam.- Throws:
IOException
-
applyContentParser
public final void applyContentParser(org.elasticsearch.core.CheckedConsumer<org.elasticsearch.xcontent.XContentParser, IOException> applyParser) throws IOExceptionIf there is any content then callapplyParserwith the parser, otherwise do nothing.- Throws:
IOException
-
hasContentOrSourceParam
public final boolean hasContentOrSourceParam()Does this request have content or asourceparameter? Use this instead ofhasContent()if this RestHandler treats thesourceparameter like the body content. -
contentOrSourceParamParser
public final org.elasticsearch.xcontent.XContentParser contentOrSourceParamParser() throws IOExceptionA parser for the contents of this request if it has contents, otherwise a parser for thesourceparameter if there is one, otherwise throws anElasticsearchParseException. UsewithContentOrSourceParamParserOrNull(CheckedConsumer)instead if you need to handle the absence request content gracefully.- Throws:
IOException
-
withContentOrSourceParamParserOrNull
public final void withContentOrSourceParamParserOrNull(org.elasticsearch.core.CheckedConsumer<org.elasticsearch.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 thesourceparameter 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.elasticsearch.core.Tuple<org.elasticsearch.xcontent.XContentType,BytesReference> contentOrSourceParam()Get the content of the request or the contents of thesourceparam or throw an exception if both are missing. PrefercontentOrSourceParamParser()orwithContentOrSourceParamParserOrNull(CheckedConsumer)if you need a parser. -
getParsedAccept
public org.elasticsearch.xcontent.ParsedMediaType getParsedAccept() -
getParsedContentType
public org.elasticsearch.xcontent.ParsedMediaType getParsedContentType() -
parseContentType
Parses the given content type string for the media type. This method currently ignores parameters. -
getRestApiVersion
public org.elasticsearch.core.RestApiVersion getRestApiVersion()The requested version of the REST API.
-