Class ContainerRequest

    • Method Detail

      • getRequestScopedInitializer

        public RequestScopedInitializer getRequestScopedInitializer()
        Get a custom container extensions initializer for the current request.

        The initializer is guaranteed to be run from within the request scope of the current request.

        Returns:
        custom container extensions initializer or null if not available.
      • setRequestScopedInitializer

        public void setRequestScopedInitializer​(RequestScopedInitializer requestScopedInitializer)
        Set a custom container extensions initializer for the current request.

        The initializer is guaranteed to be run from within the request scope of the current request.

        Parameters:
        requestScopedInitializer - custom container extensions initializer.
      • getResponseWriter

        public ContainerResponseWriter getResponseWriter()
        Get the container response writer for the current request.
        Returns:
        container response writer.
      • setWriter

        public void setWriter​(ContainerResponseWriter responseWriter)
        Set the container response writer for the current request.
        Parameters:
        responseWriter - container response writer. Must not be null.
      • readEntity

        public <T> T readEntity​(Class<T> rawType)
        Read entity from a context entity input stream.
        Type Parameters:
        T - entity Java object type.
        Parameters:
        rawType - raw Java entity type.
        Returns:
        entity read from a context entity input stream.
      • readEntity

        public <T> T readEntity​(Class<T> rawType,
                                Annotation[] annotations)
        Read entity from a context entity input stream.
        Type Parameters:
        T - entity Java object type.
        Parameters:
        rawType - raw Java entity type.
        annotations - entity annotations.
        Returns:
        entity read from a context entity input stream.
      • readEntity

        public <T> T readEntity​(Class<T> rawType,
                                Type type)
        Read entity from a context entity input stream.
        Type Parameters:
        T - entity Java object type.
        Parameters:
        rawType - raw Java entity type.
        type - generic Java entity type.
        Returns:
        entity read from a context entity input stream.
      • readEntity

        public <T> T readEntity​(Class<T> rawType,
                                Type type,
                                Annotation[] annotations)
        Read entity from a context entity input stream.
        Type Parameters:
        T - entity Java object type.
        Parameters:
        rawType - raw Java entity type.
        type - generic Java entity type.
        annotations - entity annotations.
        Returns:
        entity read from a context entity input stream.
      • resolveProperty

        public <T> T resolveProperty​(String name,
                                     Class<T> type)
        Description copied from interface: PropertiesResolver
        Resolve a property value for the specified property name.

        The method returns the value of the property registered in the request-specific property bag, if available. If no property for the given property name is found in the request-specific property bag, the method looks at the properties stored in the global runtime configuration this request belongs to. If there is a value defined in the runtime configuration, it is returned, otherwise the method returns null if no such property is registered neither in the runtime nor in the request-specific property bag.

        Specified by:
        resolveProperty in interface PropertiesResolver
        Type Parameters:
        T - property Java type.
        Parameters:
        name - property name.
        type - expected property class type.
        Returns:
        resolved property value or null if no such property is registered.
      • resolveProperty

        public <T> T resolveProperty​(String name,
                                     T defaultValue)
        Description copied from interface: PropertiesResolver
        Resolve a property value for the specified property name.

        The method returns the value of the property registered in the request-specific property bag, if available. If no property for the given property name is found in the request-specific property bag, the method looks at the properties stored in the global runtime configuration this request belongs to. If there is a value defined in the runtime configuration, it is returned, otherwise the method returns defaultValue if no such property is registered neither in the runtime nor in the request-specific property bag.

        Specified by:
        resolveProperty in interface PropertiesResolver
        Type Parameters:
        T - property Java type.
        Parameters:
        name - property name.
        defaultValue - default value to return if the property is not registered.
        Returns:
        resolved property value or defaultValue if no such property is registered.
      • getProperty

        public Object getProperty​(String name)
        Description copied from interface: ContainerRequestContext
        Returns the property with the given name registered in the current request/response exchange context, or null if there is no property by that name.

        A property allows a JAX-RS filters and interceptors to exchange additional custom information not already provided by this interface.

        A list of supported properties can be retrieved using ContainerRequestContext.getPropertyNames(). Custom property names should follow the same convention as package names.

        In a Servlet container, the properties are synchronized with the ServletRequest and expose all the attributes available in the ServletRequest. Any modifications of the properties are also reflected in the set of properties of the associated ServletRequest.

        Specified by:
        getProperty in interface ContainerRequestContext
        Specified by:
        getProperty in interface PropertiesDelegate
        Parameters:
        name - a String specifying the name of the property.
        Returns:
        an Object containing the value of the property, or null if no property exists matching the given name.
        See Also:
        ContainerRequestContext.getPropertyNames()
      • setProperty

        public void setProperty​(String name,
                                Object object)
        Description copied from interface: ContainerRequestContext
        Binds an object to a given property name in the current request/response exchange context. If the name specified is already used for a property, this method will replace the value of the property with the new value.

        A property allows a JAX-RS filters and interceptors to exchange additional custom information not already provided by this interface.

        A list of supported properties can be retrieved using ContainerRequestContext.getPropertyNames(). Custom property names should follow the same convention as package names.

        If a null value is passed, the effect is the same as calling the ContainerRequestContext.removeProperty(String) method.

        In a Servlet container, the properties are synchronized with the ServletRequest and expose all the attributes available in the ServletRequest. Any modifications of the properties are also reflected in the set of properties of the associated ServletRequest.

        Specified by:
        setProperty in interface ContainerRequestContext
        Specified by:
        setProperty in interface PropertiesDelegate
        Parameters:
        name - a String specifying the name of the property.
        object - an Object representing the property to be bound.
      • removeProperty

        public void removeProperty​(String name)
        Description copied from interface: ContainerRequestContext
        Removes a property with the given name from the current request/response exchange context. After removal, subsequent calls to ContainerRequestContext.getProperty(java.lang.String) to retrieve the property value will return null.

        In a Servlet container, the properties are synchronized with the ServletRequest and expose all the attributes available in the ServletRequest. Any modifications of the properties are also reflected in the set of properties of the associated ServletRequest.

        Specified by:
        removeProperty in interface ContainerRequestContext
        Specified by:
        removeProperty in interface PropertiesDelegate
        Parameters:
        name - a String specifying the name of the property to be removed.
      • getPropertiesDelegate

        public PropertiesDelegate getPropertiesDelegate()
        Get the underlying properties delegate.
        Returns:
        underlying properties delegate.
      • getUriInfo

        public ExtendedUriInfo getUriInfo()
        Description copied from interface: ContainerRequestContext
        Get request URI information. The returned object contains "live" view of the request URI information in a sense that any changes made to the request URI using one of the setRequestUri(...) methods will be reflected in the previously returned UriInfo instance.
        Specified by:
        getUriInfo in interface ContainerRequestContext
        Returns:
        request URI information.
      • getReaderInterceptors

        protected Iterable<ReaderInterceptor> getReaderInterceptors()
        Get all reader interceptors applicable to this request. This is populated once the right resource method is matched.
        Specified by:
        getReaderInterceptors in class InboundMessageContext
        Returns:
        All reader interceptors applicable to the matched inflector (or an empty collection if no inflector matched yet).
      • getBaseUri

        public URI getBaseUri()
        Get base request URI.
        Returns:
        base request URI.
      • getRequestUri

        public URI getRequestUri()
        Get request URI.
        Returns:
        request URI.
      • getAbsolutePath

        public URI getAbsolutePath()
        Get the absolute path of the request. This includes everything preceding the path (host, port etc), but excludes query parameters or fragment.
        Returns:
        the absolute path of the request.
      • getPath

        public String getPath​(boolean decode)
        Get the path of the current request relative to the application root (base) URI as a string.
        Parameters:
        decode - controls whether sequences of escaped octets are decoded (true) or not (false).
        Returns:
        relative request path.
      • setMethodWithoutException

        public void setMethodWithoutException​(String method)
        Like setMethod(String) but does not throw IllegalStateException if the method is invoked in other than pre-matching phase.
        Parameters:
        method - HTTP method.
      • abortWith

        public void abortWith​(Response response)
        Description copied from interface: ContainerRequestContext
        Abort the filter chain with a response. This method breaks the filter chain processing and returns the provided response back to the client. The provided response goes through the chain of applicable response filters.
        Specified by:
        abortWith in interface ContainerRequestContext
        Parameters:
        response - response to be sent back to the client.
      • inResponseProcessing

        public void inResponseProcessing()
        Notify this request that the response created from this request is already being processed. This means that the request processing phase has finished and this request can be used only in the request processing phase (for example in ContainerResponseFilter).

        The request can be used for processing of more than one response (in async cases). Then this method should be called when the first response is created from this request. Multiple calls to this method has the same effect as calling the method only once.

      • getAbortResponse

        public Response getAbortResponse()
        Get the request filter chain aborting response if set, or null otherwise.
        Returns:
        request filter chain aborting response if set, or null otherwise.
      • selectVariant

        public Variant selectVariant​(List<Variant> variants)
                              throws IllegalArgumentException
        Description copied from interface: Request
        Select the representation variant that best matches the request. Returns null in case there is no matching variant in the list.

        More explicit variants are chosen ahead of less explicit ones. A vary header is computed from the supplied list and automatically added to the response.

        Specified by:
        selectVariant in interface Request
        Parameters:
        variants - a list of Variant that describe all of the available representation variants.
        Returns:
        the variant that best matches the request or null if there's no match.
        Throws:
        IllegalArgumentException - if variants is empty or null.
        See Also:
        Variant.VariantListBuilder
      • getVaryValue

        public String getVaryValue()
        Get the value of HTTP Vary response header to be set in the response, or null if no value is to be set.
        Returns:
        value of HTTP Vary response header to be set in the response if available, null otherwise.
      • evaluatePreconditions

        public Response.ResponseBuilder evaluatePreconditions​(EntityTag eTag)
        Description copied from interface: Request
        Evaluate request preconditions based on the passed in value.
        Specified by:
        evaluatePreconditions in interface Request
        Parameters:
        eTag - an ETag for the current state of the resource
        Returns:
        null if the preconditions are met or a ResponseBuilder set with the appropriate status if the preconditions are not met. A returned ResponseBuilder will include an ETag header set with the value of eTag, provided none of the precondition evaluation has failed, in which case the ETag header would not be included and the status code of the returned ResponseBuilder would be set to Response.Status.PRECONDITION_FAILED.
      • evaluatePreconditions

        public Response.ResponseBuilder evaluatePreconditions​(Date lastModified)
        Description copied from interface: Request
        Evaluate request preconditions based on the passed in value.
        Specified by:
        evaluatePreconditions in interface Request
        Parameters:
        lastModified - a date that specifies the modification date of the resource
        Returns:
        null if the preconditions are met or a ResponseBuilder set with the appropriate status if the preconditions are not met.
      • evaluatePreconditions

        public Response.ResponseBuilder evaluatePreconditions​(Date lastModified,
                                                              EntityTag eTag)
        Description copied from interface: Request
        Evaluate request preconditions based on the passed in value.
        Specified by:
        evaluatePreconditions in interface Request
        Parameters:
        lastModified - a date that specifies the modification date of the resource
        eTag - an ETag for the current state of the resource
        Returns:
        null if the preconditions are met or a ResponseBuilder set with the appropriate status if the preconditions are not met. A returned ResponseBuilder will include an ETag header set with the value of eTag, provided none of the precondition evaluation has failed, in which case the ETag header would not be included and the status code of the returned ResponseBuilder would be set to Response.Status.PRECONDITION_FAILED.
      • evaluatePreconditions

        public Response.ResponseBuilder evaluatePreconditions()
        Description copied from interface: Request
        Evaluate request preconditions for a resource that does not currently exist. The primary use of this method is to support the If-Match: * and If-None-Match: * preconditions.

        Note that precondition If-None-Match: something will never be considered to have been met, and it is the application's responsibility to enforce any additional method-specific semantics. E.g. a PUT on a resource that does not exist might succeed whereas a GET on a resource that does not exist would likely result in a 404 response. It would be the responsibility of the application to generate the 404 response.

        Specified by:
        evaluatePreconditions in interface Request
        Returns:
        null if the preconditions are met or a ResponseBuilder set with the appropriate status if the preconditions are not met.
      • getRequestHeader

        public List<String> getRequestHeader​(String name)
        Get the values of an HTTP request header if the header exists on the current request. The returned value will be a read-only List if the specified header exists or null if it does not. This is a shortcut for getRequestHeaders().get(name).
        Specified by:
        getRequestHeader in interface HttpHeaders
        Parameters:
        name - the header name, case insensitive.
        Returns:
        a read-only list of header values if the specified header exists, otherwise null.
        Throws:
        IllegalStateException - if called outside the scope of a request.
      • getRequestHeaders

        public MultivaluedMap<String,​String> getRequestHeaders()
        Get the values of HTTP request headers. The returned Map is case-insensitive wrt. keys and is read-only. The method never returns null.
        Specified by:
        getRequestHeaders in interface HttpHeaders
        Returns:
        a read-only map of header names and values.
        Throws:
        IllegalStateException - if called outside the scope of a request.