Class RestRequest

org.elasticsearch.rest.RestRequest
All Implemented Interfaces:
org.elasticsearch.common.xcontent.ToXContent.Params

public class RestRequest extends implements org.elasticsearch.common.xcontent.ToXContent.Params
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static class 
     
    static class 
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    RestRequest​(org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, <,​> params,  path, <,​<>> headers, HttpRequest httpRequest, HttpChannel httpChannel)
     
    protected
    RestRequest​(RestRequest restRequest)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    > applyParser)
    If there is any content then call applyParser with the parser, otherwise do nothing.
     
    int
     
    org.elasticsearch.core.Tuple<org.elasticsearch.common.xcontent.XContentType,​BytesReference>
    Get the content of the request or the contents of the source param or throw an exception if both are missing.
    org.elasticsearch.common.xcontent.XContentParser
    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.
    org.elasticsearch.common.xcontent.XContentParser
    A parser for the contents of this request if there is a body, otherwise throws an ElasticsearchParseException.
    <>
     name)
    Get all values for the header or null if the header was not found
    <,​<>>
    Get all of the headers and values associated with the headers.
     
     
    long
     
    org.elasticsearch.common.xcontent.NamedXContentRegistry
    Get the NamedXContentRegistry that should be used to create parsers from this request.
    org.elasticsearch.common.xcontent.XContentType
    The XContentType that was parsed from the Content-Type header.
    boolean
     
    boolean
    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
     key)
     
     name)
    Get the value of the header or null if not found.
    boolean
     
    Returns the HTTP method used in the REST request.
     key)
     
     key,  defaultValue)
     
    boolean
     key, boolean defaultValue)
     
     key,  defaultValue)
     
    double
     key, double defaultValue)
     
    float
     key, float defaultValue)
     
    int
     key, int defaultValue)
     
    long
     key, long defaultValue)
     
     key, ByteSizeValue defaultValue)
     
    []
     key, [] defaultValue)
     
    []
     key)
     
    org.elasticsearch.core.TimeValue
     key, org.elasticsearch.core.TimeValue defaultValue)
     
    <,​>
     
    static org.elasticsearch.common.xcontent.XContentType
    <> header)
    Parses the given content type string for the media type.
    The path part of the URI (without the query string), decoded.
    The non decoded, raw path provided.
    request​(org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel)
    Creates a new REST request.
    requestWithoutParameters​(org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel)
    Creates a new REST request.
     
    uri()
    The uri of the rest request, with the query string.
    void
    > 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.

    Methods inherited from class java.lang.

    , , , , , , , , , ,
  • Constructor Details

    • RestRequest

      protected RestRequest(org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry, <,​> params,  path, <,​<>> headers, HttpRequest httpRequest, HttpChannel httpChannel)
    • RestRequest

      protected RestRequest(RestRequest 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 throw RestRequest.BadParameterException if the path cannot be decoded
      Parameters:
      xContentRegistry - the content registry
      httpRequest - the http request
      httpChannel - the http channel
      Throws:
      RestRequest.BadParameterException - if the parameters can not be decoded
      RestRequest.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 a RestRequest.BadParameterException.
      Parameters:
      xContentRegistry - the content registry
      httpRequest - the http request
      httpChannel - the http channel
      Throws:
      RestRequest.ContentTypeHeaderException - if the Content-Type header can not be parsed
    • method

      public RestRequest.Method method()
      Returns the HTTP method used in the REST request.
      Returns:
      the RestRequest.Method used in the REST request
      Throws:
      - if the HTTP method is invalid
    • uri

      public  uri()
      The uri of the rest request, with the query string.
    • rawPath

      public  rawPath()
      The non decoded, raw path provided.
    • path

      public final  path()
      The path part of the URI (without the query string), decoded.
    • hasContent

      public boolean hasContent()
    • contentLength

      public int contentLength()
    • content

      public BytesReference content()
    • requiredContent

      public final BytesReference requiredContent()
      Returns:
      content of the request body or throw an exception if the body or content type is missing
    • header

      public final  header( name)
      Get the value of the header or null if not found. This method only retrieves the first header value if multiple values are sent. Use of getAllHeaderValues(String) should be preferred
    • getAllHeaderValues

      public final <> getAllHeaderValues( name)
      Get all values for the header or null if the header was not found
    • getHeaders

      public final <,​<>> 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()
      The 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
    • getHttpChannel

      public HttpChannel getHttpChannel()
    • getHttpRequest

      public HttpRequest getHttpRequest()
    • hasParam

      public final boolean hasParam( key)
    • param

      public final  param( key)
      Specified by:
      param in interface org.elasticsearch.common.xcontent.ToXContent.Params
    • param

      public final  param( key,  defaultValue)
      Specified by:
      param in interface org.elasticsearch.common.xcontent.ToXContent.Params
    • params

      public <,​> params()
    • paramAsFloat

      public float paramAsFloat( key, float defaultValue)
    • paramAsDouble

      public double paramAsDouble( key, double defaultValue)
    • paramAsInt

      public int paramAsInt( key, int defaultValue)
    • paramAsLong

      public long paramAsLong( key, long defaultValue)
    • paramAsBoolean

      public boolean paramAsBoolean( key, boolean defaultValue)
      Specified by:
      paramAsBoolean in interface org.elasticsearch.common.xcontent.ToXContent.Params
    • paramAsBoolean

      public  paramAsBoolean( key,  defaultValue)
      Specified by:
      paramAsBoolean in interface org.elasticsearch.common.xcontent.ToXContent.Params
    • paramAsTime

      public org.elasticsearch.core.TimeValue paramAsTime( key, org.elasticsearch.core.TimeValue defaultValue)
    • paramAsSize

      public  key, ByteSizeValue defaultValue)
    • paramAsStringArray

      public [] paramAsStringArray( key, [] defaultValue)
    • paramAsStringArrayOrEmptyIfAll

      public [] paramAsStringArrayOrEmptyIfAll( key)
    • getXContentRegistry

      public org.elasticsearch.common.xcontent.NamedXContentRegistry getXContentRegistry()
      Get the NamedXContentRegistry that should be used to create parsers from this request.
    • contentParser

      public final org.elasticsearch.common.xcontent.XContentParser contentParser() throws
      A parser for the contents of this request if there is a body, otherwise throws an 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.
      Throws:
    • applyContentParser

      public final void applyContentParser(org.elasticsearch.core.CheckedConsumer<org.elasticsearch.common.xcontent.XContentParser,​> applyParser) throws
      If there is any content then call applyParser with the parser, otherwise do nothing.
      Throws:
    • hasContentOrSourceParam

      public final 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.
    • contentOrSourceParamParser

      public final org.elasticsearch.common.xcontent.XContentParser contentOrSourceParamParser() throws
      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. Use withContentOrSourceParamParserOrNull(CheckedConsumer) instead if you need to handle the absence request content gracefully.
      Throws:
    • withContentOrSourceParamParserOrNull

      public final void withContentOrSourceParamParserOrNull(org.elasticsearch.core.CheckedConsumer<org.elasticsearch.common.xcontent.XContentParser,​> withParser) throws
      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. Use contentOrSourceParamParser() if you should throw an exception back to the user when there isn't request content.
      Throws:
    • contentOrSourceParam

      public final org.elasticsearch.core.Tuple<org.elasticsearch.common.xcontent.XContentType,​BytesReference> contentOrSourceParam()
      Get the content of the request or the contents of the source param or throw an exception if both are missing. Prefer contentOrSourceParamParser() or withContentOrSourceParamParserOrNull(CheckedConsumer) if you need a parser.
    • parseContentType

      public static org.elasticsearch.common.xcontent.XContentType parseContentType(<> header)
      Parses the given content type string for the media type. This method currently ignores parameters.