Class RestRequest

    • Constructor Detail

      • RestRequest

        public RestRequest​(NamedXContentRegistry xContentRegistry,
                           java.lang.String uri,
                           java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers)
        Creates a new REST request.
        Parameters:
        xContentRegistry - the content registry
        uri - the raw URI that will be parsed into the path and the parameters
        headers - a map of the header; this map should implement a case-insensitive lookup
        Throws:
        RestRequest.BadParameterException - if the parameters can not be decoded
        RestRequest.ContentTypeHeaderException - if the Content-Type header can not be parsed
      • RestRequest

        public 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 REST request. In contrast to RestRequest(NamedXContentRegistry, Map, String, Map), the path is not decoded so this constructor will not throw a RestRequest.BadParameterException.
        Parameters:
        xContentRegistry - the content registry
        params - the request parameters
        path - the raw path (which is not parsed)
        headers - a map of the header; this map should implement a case-insensitive lookup
        Throws:
        RestRequest.ContentTypeHeaderException - if the Content-Type header can not be parsed
    • Method Detail

      • uri

        public abstract 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 abstract boolean hasContent()
      • 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 java.lang.String header​(java.lang.String 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 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
      • 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.
      • getXContentType

        @Nullable
        public final 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
      • getRemoteAddress

        @Nullable
        public java.net.SocketAddress getRemoteAddress()
      • getLocalAddress

        @Nullable
        public java.net.SocketAddress getLocalAddress()
      • hasParam

        public final boolean hasParam​(java.lang.String key)
      • param

        public final java.lang.String param​(java.lang.String key)
        Specified by:
        param in interface ToXContent.Params
      • param

        public final java.lang.String param​(java.lang.String key,
                                            java.lang.String defaultValue)
        Specified by:
        param in interface ToXContent.Params
      • params

        public java.util.Map<java.lang.String,​java.lang.String> params()
      • paramAsFloat

        public float paramAsFloat​(java.lang.String key,
                                  float 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 interface ToXContent.Params
      • paramAsBoolean

        public java.lang.Boolean paramAsBoolean​(java.lang.String key,
                                                java.lang.Boolean defaultValue)
        Specified by:
        paramAsBoolean in interface ToXContent.Params
      • paramAsTime

        public TimeValue paramAsTime​(java.lang.String key,
                                     TimeValue defaultValue)
      • paramAsStringArray

        public java.lang.String[] paramAsStringArray​(java.lang.String key,
                                                     java.lang.String[] defaultValue)
      • paramAsStringArrayOrEmptyIfAll

        public java.lang.String[] paramAsStringArrayOrEmptyIfAll​(java.lang.String key)
      • applyContentParser

        public final void applyContentParser​(CheckedConsumer<XContentParser,​java.io.IOException> applyParser)
                                      throws java.io.IOException
        If there is any content then call applyParser with the parser, otherwise do nothing.
        Throws:
        java.io.IOException
      • 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.
      • withContentOrSourceParamParserOrNull

        public final void withContentOrSourceParamParserOrNull​(CheckedConsumer<XContentParser,​java.io.IOException> withParser)
                                                        throws java.io.IOException
        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:
        java.io.IOException
      • parseContentType

        public static XContentType parseContentType​(java.util.List<java.lang.String> header)
        Parses the given content type string for the media type. This method currently ignores parameters.