Package org.elasticsearch.rest
Class RestRequest
java.lang.Object
org.elasticsearch.rest.RestRequest
- All Implemented Interfaces:
org.elasticsearch.common.xcontent.ToXContent.Params
public class RestRequest
extends java.lang.Object
implements org.elasticsearch.common.xcontent.ToXContent.Params
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RestRequest.BadParameterException
static class
RestRequest.ContentTypeHeaderException
static class
RestRequest.Method
-
Constructor Summary
Constructors Modifier Constructor Description protected
RestRequest(org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, java.util.Map<java.lang.String,java.lang.String> params, java.lang.String path, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, HttpRequest httpRequest, HttpChannel httpChannel)
protected
RestRequest(RestRequest restRequest)
-
Method Summary
Modifier and Type Method Description void
applyContentParser(org.elasticsearch.common.CheckedConsumer<org.elasticsearch.common.xcontent.XContentParser,java.io.IOException> applyParser)
If there is any content then callapplyParser
with the parser, otherwise do nothing.BytesReference
content()
int
contentLength()
org.elasticsearch.common.collect.Tuple<org.elasticsearch.common.xcontent.XContentType,BytesReference>
contentOrSourceParam()
Get the content of the request or the contents of thesource
param or throw an exception if both are missing.org.elasticsearch.common.xcontent.XContentParser
contentOrSourceParamParser()
A parser for the contents of this request if it has contents, otherwise a parser for thesource
parameter if there is one, otherwise throws anElasticsearchParseException
.org.elasticsearch.common.xcontent.XContentParser
contentParser()
A parser for the contents of this request if there is a body, otherwise throws anElasticsearchParseException
.java.util.List<java.lang.String>
getAllHeaderValues(java.lang.String name)
Get all values for the header ornull
if the header was not foundjava.util.Map<java.lang.String,java.util.List<java.lang.String>>
getHeaders()
Get all of the headers and values associated with the headers.HttpChannel
getHttpChannel()
HttpRequest
getHttpRequest()
long
getRequestId()
org.elasticsearch.common.xcontent.NamedXContentRegistry
getXContentRegistry()
Get theNamedXContentRegistry
that should be used to create parsers from this request.org.elasticsearch.common.xcontent.XContentType
getXContentType()
TheXContentType
that was parsed from theContent-Type
header.boolean
hasContent()
boolean
hasContentOrSourceParam()
Does this request have content or asource
parameter? Use this instead ofhasContent()
if this RestHandler treats thesource
parameter like the body content.boolean
hasParam(java.lang.String key)
java.lang.String
header(java.lang.String name)
Get the value of the header ornull
if not found.boolean
isContentConsumed()
RestRequest.Method
method()
Returns the HTTP method used in the REST request.java.lang.String
param(java.lang.String key)
java.lang.String
param(java.lang.String key, java.lang.String defaultValue)
boolean
paramAsBoolean(java.lang.String key, boolean defaultValue)
java.lang.Boolean
paramAsBoolean(java.lang.String key, java.lang.Boolean defaultValue)
double
paramAsDouble(java.lang.String key, double defaultValue)
float
paramAsFloat(java.lang.String key, float defaultValue)
int
paramAsInt(java.lang.String key, int defaultValue)
long
paramAsLong(java.lang.String key, long defaultValue)
ByteSizeValue
paramAsSize(java.lang.String key, ByteSizeValue defaultValue)
java.lang.String[]
paramAsStringArray(java.lang.String key, java.lang.String[] defaultValue)
java.lang.String[]
paramAsStringArrayOrEmptyIfAll(java.lang.String key)
org.elasticsearch.common.unit.TimeValue
paramAsTime(java.lang.String key, org.elasticsearch.common.unit.TimeValue defaultValue)
java.util.Map<java.lang.String,java.lang.String>
params()
static org.elasticsearch.common.xcontent.XContentType
parseContentType(java.util.List<java.lang.String> header)
Parses the given content type string for the media type.java.lang.String
path()
The path part of the URI (without the query string), decoded.java.lang.String
rawPath()
The non decoded, raw path provided.static RestRequest
request(org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel)
Creates a new REST request.static RestRequest
requestWithoutParameters(org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel)
Creates a new REST request.BytesReference
requiredContent()
java.lang.String
uri()
The uri of the rest request, with the query string.void
withContentOrSourceParamParserOrNull(org.elasticsearch.common.CheckedConsumer<org.elasticsearch.common.xcontent.XContentParser,java.io.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
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
RestRequest
protected RestRequest(org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, java.util.Map<java.lang.String,java.lang.String> params, java.lang.String path, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, HttpRequest httpRequest, HttpChannel httpChannel) -
RestRequest
-
-
Method Details
-
isContentConsumed
public boolean isContentConsumed() -
request
public static RestRequest request(org.elasticsearch.common.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.elasticsearch.common.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:
java.lang.IllegalArgumentException
- if the HTTP method is invalid
-
uri
public java.lang.String uri()The uri of the rest request, with the query string. -
rawPath
public java.lang.String rawPath()The non decoded, raw path provided. -
path
public final java.lang.String 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
public final java.lang.String header(java.lang.String name)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
public final java.util.List<java.lang.String> getAllHeaderValues(java.lang.String name)Get all values for the header ornull
if the header was not found -
getHeaders
public final java.util.Map<java.lang.String,java.util.List<java.lang.String>> 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.common.xcontent.XContentType getXContentType()TheXContentType
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
public final boolean hasParam(java.lang.String key) -
param
public final java.lang.String param(java.lang.String key)- Specified by:
param
in interfaceorg.elasticsearch.common.xcontent.ToXContent.Params
-
param
public final java.lang.String param(java.lang.String key, java.lang.String defaultValue)- Specified by:
param
in interfaceorg.elasticsearch.common.xcontent.ToXContent.Params
-
params
public java.util.Map<java.lang.String,java.lang.String> params() -
paramAsFloat
public float paramAsFloat(java.lang.String key, float defaultValue) -
paramAsDouble
public double paramAsDouble(java.lang.String key, double defaultValue) -
paramAsInt
public int paramAsInt(java.lang.String key, int defaultValue) -
paramAsLong
public long paramAsLong(java.lang.String key, long defaultValue) -
paramAsBoolean
public boolean paramAsBoolean(java.lang.String key, boolean defaultValue)- Specified by:
paramAsBoolean
in interfaceorg.elasticsearch.common.xcontent.ToXContent.Params
-
paramAsBoolean
public java.lang.Boolean paramAsBoolean(java.lang.String key, java.lang.Boolean defaultValue)- Specified by:
paramAsBoolean
in interfaceorg.elasticsearch.common.xcontent.ToXContent.Params
-
paramAsTime
public org.elasticsearch.common.unit.TimeValue paramAsTime(java.lang.String key, org.elasticsearch.common.unit.TimeValue defaultValue) -
paramAsSize
-
paramAsStringArray
public java.lang.String[] paramAsStringArray(java.lang.String key, java.lang.String[] defaultValue) -
paramAsStringArrayOrEmptyIfAll
public java.lang.String[] paramAsStringArrayOrEmptyIfAll(java.lang.String key) -
getXContentRegistry
public org.elasticsearch.common.xcontent.NamedXContentRegistry getXContentRegistry()Get theNamedXContentRegistry
that should be used to create parsers from this request. -
contentParser
public final org.elasticsearch.common.xcontent.XContentParser contentParser() throws java.io.IOExceptionA 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 thesource
param.- Throws:
java.io.IOException
-
applyContentParser
public final void applyContentParser(org.elasticsearch.common.CheckedConsumer<org.elasticsearch.common.xcontent.XContentParser,java.io.IOException> applyParser) throws java.io.IOExceptionIf there is any content then callapplyParser
with the parser, otherwise do nothing.- Throws:
java.io.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.elasticsearch.common.xcontent.XContentParser contentOrSourceParamParser() throws java.io.IOExceptionA parser for the contents of this request if it has contents, otherwise a parser for thesource
parameter if there is one, otherwise throws anElasticsearchParseException
. UsewithContentOrSourceParamParserOrNull(CheckedConsumer)
instead if you need to handle the absence request content gracefully.- Throws:
java.io.IOException
-
withContentOrSourceParamParserOrNull
public final void withContentOrSourceParamParserOrNull(org.elasticsearch.common.CheckedConsumer<org.elasticsearch.common.xcontent.XContentParser,java.io.IOException> withParser) throws java.io.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:
java.io.IOException
-
contentOrSourceParam
public final org.elasticsearch.common.collect.Tuple<org.elasticsearch.common.xcontent.XContentType,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
public static org.elasticsearch.common.xcontent.XContentType parseContentType(java.util.List<java.lang.String> header)Parses the given content type string for the media type. This method currently ignores parameters.
-