public abstract class RestRequest extends java.lang.Object implements ToXContent.Params
Modifier and Type | Class and Description |
---|---|
static class |
RestRequest.Method |
Constructor and Description |
---|
RestRequest(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)
Creates a new RestRequest
|
RestRequest(NamedXContentRegistry xContentRegistry,
java.lang.String uri,
java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
Creates a new RestRequest
|
Modifier and Type | Method and Description |
---|---|
void |
applyContentParser(CheckedConsumer<XContentParser,java.io.IOException> applyParser)
If there is any content then call
applyParser with the parser, otherwise do nothing. |
abstract BytesReference |
content() |
Tuple<XContentType,BytesReference> |
contentOrSourceParam()
Get the content of the request or the contents of the
source param or throw an exception if both are missing. |
XContentParser |
contentOrSourceParamParser()
A parser for the contents of this request if it has contents, otherwise a parser for the
source parameter if there is one,
otherwise throws an ElasticsearchParseException . |
XContentParser |
contentParser()
A parser for the contents of this request if there is a body, otherwise throws an
ElasticsearchParseException . |
java.util.List<java.lang.String> |
getAllHeaderValues(java.lang.String name)
Get all values for the header or
null if the header was not found |
BytesReference |
getContentOrSourceParamOnly()
Deprecated.
we should only take xcontent
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getHeaders()
Get all of the headers and values associated with the headers.
|
java.net.SocketAddress |
getLocalAddress() |
java.net.SocketAddress |
getRemoteAddress() |
NamedXContentRegistry |
getXContentRegistry()
Get the
NamedXContentRegistry that should be used to create parsers from this request. |
XContentType |
getXContentType()
The
XContentType that was parsed from the Content-Type header. |
abstract boolean |
hasContent() |
boolean |
hasContentOrSourceParam()
Does this request have content or a
source parameter? Use this instead of hasContent() if this
RestHandler treats the source 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 or
null if not found. |
abstract RestRequest.Method |
method() |
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) |
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) |
TimeValue |
paramAsTime(java.lang.String key,
TimeValue defaultValue) |
java.util.Map<java.lang.String,java.lang.String> |
params() |
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.
|
BytesReference |
requiredContent() |
abstract java.lang.String |
uri()
The uri of the rest request, with the query string.
|
void |
withContentOrSourceParamParserOrNull(CheckedConsumer<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 the
source
parameter if there is one, otherwise with null . |
void |
withContentOrSourceParamParserOrNullLenient(CheckedConsumer<XContentParser,java.io.IOException> withParser)
Deprecated.
|
public RestRequest(NamedXContentRegistry xContentRegistry, java.lang.String uri, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
xContentRegistry
- the xContentRegistry to use when parsing XContenturi
- the URI of the request that potentially contains request parametersheaders
- a map of the headers. This map should implement a Case-Insensitive hashing for keys as HTTP header names are case
insensitivepublic RestRequest(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)
xContentRegistry
- the xContentRegistry to use when parsing XContentparams
- the parameters of the requestpath
- the path of the request. This should not contain request parametersheaders
- a map of the headers. This map should implement a Case-Insensitive hashing for keys as HTTP header names are case
insensitivepublic abstract RestRequest.Method method()
public abstract java.lang.String uri()
public java.lang.String rawPath()
public final java.lang.String path()
public abstract boolean hasContent()
public abstract BytesReference content()
public final BytesReference requiredContent()
public final java.lang.String header(java.lang.String name)
null
if not found. This method only retrieves the first header value if multiple values are
sent. Use of getAllHeaderValues(String)
should be preferredpublic final java.util.List<java.lang.String> getAllHeaderValues(java.lang.String name)
null
if the header was not foundpublic final java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
@Nullable public final XContentType getXContentType()
XContentType
that was parsed from the Content-Type
header. This value will be null
in the case of
a request without a valid Content-Type
header, a request without content (hasContent()
, or a plain text request@Nullable public java.net.SocketAddress getRemoteAddress()
@Nullable public java.net.SocketAddress getLocalAddress()
public final boolean hasParam(java.lang.String key)
public final java.lang.String param(java.lang.String key)
param
in interface ToXContent.Params
public final java.lang.String param(java.lang.String key, java.lang.String defaultValue)
param
in interface ToXContent.Params
public java.util.Map<java.lang.String,java.lang.String> params()
public float paramAsFloat(java.lang.String key, float defaultValue)
public int paramAsInt(java.lang.String key, int defaultValue)
public long paramAsLong(java.lang.String key, long defaultValue)
public boolean paramAsBoolean(java.lang.String key, boolean defaultValue)
paramAsBoolean
in interface ToXContent.Params
public java.lang.Boolean paramAsBoolean(java.lang.String key, java.lang.Boolean defaultValue)
paramAsBoolean
in interface ToXContent.Params
public ByteSizeValue paramAsSize(java.lang.String key, ByteSizeValue defaultValue)
public java.lang.String[] paramAsStringArray(java.lang.String key, java.lang.String[] defaultValue)
public java.lang.String[] paramAsStringArrayOrEmptyIfAll(java.lang.String key)
public NamedXContentRegistry getXContentRegistry()
NamedXContentRegistry
that should be used to create parsers from this request.public final XContentParser contentParser() throws java.io.IOException
ElasticsearchParseException
. Use
applyContentParser(CheckedConsumer)
if you want to gracefully handle when the request doesn't have any contents. Use
contentOrSourceParamParser()
for requests that support specifying the request body in the source
param.java.io.IOException
public final void applyContentParser(CheckedConsumer<XContentParser,java.io.IOException> applyParser) throws java.io.IOException
applyParser
with the parser, otherwise do nothing.java.io.IOException
public final boolean hasContentOrSourceParam()
source
parameter? Use this instead of hasContent()
if this
RestHandler treats the source
parameter like the body content.public final XContentParser contentOrSourceParamParser() throws java.io.IOException
source
parameter if there is one,
otherwise throws an ElasticsearchParseException
. Use withContentOrSourceParamParserOrNull(CheckedConsumer)
instead
if you need to handle the absence request content gracefully.java.io.IOException
public final void withContentOrSourceParamParserOrNull(CheckedConsumer<XContentParser,java.io.IOException> withParser) throws java.io.IOException
source
parameter if there is one, otherwise with null
. Use contentOrSourceParamParser()
if you should throw an exception
back to the user when there isn't request content.java.io.IOException
public final Tuple<XContentType,BytesReference> contentOrSourceParam()
source
param or throw an exception if both are missing.
Prefer contentOrSourceParamParser()
or withContentOrSourceParamParserOrNull(CheckedConsumer)
if you need a parser.@Deprecated public final void withContentOrSourceParamParserOrNullLenient(CheckedConsumer<XContentParser,java.io.IOException> withParser) throws java.io.IOException
source
parameter if there is one, otherwise with null
. Use contentOrSourceParamParser()
if you should throw an exception
back to the user when there isn't request content. This version allows for plain text contentjava.io.IOException
@Deprecated public final BytesReference getContentOrSourceParamOnly()
source
param without the xcontent type. This is useful the request can
accept non xcontent values.