Class WebComponent


  • public class WebComponent
    extends java.lang.Object
    An common Jersey web component that may be extended by a Servlet and/or Filter implementation, or encapsulated by a Servlet or Filter implementation.
    • Field Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • REQUEST_TYPE

        private static final java.lang.reflect.Type REQUEST_TYPE
      • RESPONSE_TYPE

        private static final java.lang.reflect.Type RESPONSE_TYPE
      • requestResponseBindingExternalized

        private final boolean requestResponseBindingExternalized
      • backgroundTaskScheduler

        final java.util.concurrent.ScheduledExecutorService backgroundTaskScheduler
        Jersey background task scheduler - used for scheduling request timeout event handling tasks.
      • webConfig

        final WebConfig webConfig
        Web component configuration.
      • forwardOn404

        final boolean forwardOn404
        If true and deployed as filter, the unmatched requests will be forwarded.
      • configSetStatusOverSendError

        final boolean configSetStatusOverSendError
        Cached value of configuration property ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR. If true method HttpServletResponse.setStatus(int) is used over HttpServletResponse.sendError(int, java.lang.String).
      • queryParamsAsFormParams

        private final boolean queryParamsAsFormParams
        Flag whether query parameters should be kept as entity form params if a servlet filter consumes entity and Jersey has to retrieve form params from servlet request parameters.
    • Constructor Detail

      • WebComponent

        public WebComponent​(WebConfig webConfig,
                            ResourceConfig resourceConfig)
                     throws javax.servlet.ServletException
        Create and initialize new web component instance.
        Parameters:
        webConfig - we component configuration.
        resourceConfig - Jersey application configuration.
        Throws:
        javax.servlet.ServletException - in case the Jersey application cannot be created from the supplied resource configuration.
    • Method Detail

      • service

        public Value<java.lang.Integer> service​(java.net.URI baseUri,
                                                java.net.URI requestUri,
                                                javax.servlet.http.HttpServletRequest servletRequest,
                                                javax.servlet.http.HttpServletResponse servletResponse)
                                         throws javax.servlet.ServletException,
                                                java.io.IOException
        Dispatch client requests to a resource class.
        Parameters:
        baseUri - the base URI of the request.
        requestUri - the URI of the request.
        servletRequest - the HttpServletRequest object that contains the request the client made to the Web component.
        servletResponse - the HttpServletResponse object that contains the response the Web component returns to the client.
        Returns:
        lazily initialized response status code value provider. If not resolved in the moment of call to Value.get(), -1 is returned.
        Throws:
        java.io.IOException - if an input or output error occurs while the Web component is handling the HTTP request.
        javax.servlet.ServletException - if the HTTP request cannot be handled.
      • serviceImpl

        ResponseWriter serviceImpl​(java.net.URI baseUri,
                                   java.net.URI requestUri,
                                   javax.servlet.http.HttpServletRequest servletRequest,
                                   javax.servlet.http.HttpServletResponse servletResponse)
                            throws javax.servlet.ServletException,
                                   java.io.IOException
        Dispatch client requests to a resource class.
        Parameters:
        baseUri - the base URI of the request.
        requestUri - the URI of the request.
        servletRequest - the HttpServletRequest object that contains the request the client made to the Web component.
        servletResponse - the HttpServletResponse object that contains the response the Web component returns to the client.
        Returns:
        returns ResponseWriter, Servlet's ContainerResponseWriter implementation, into which processed request response was written to.
        Throws:
        java.io.IOException - if an input or output error occurs while the Web component is handling the HTTP request.
        javax.servlet.ServletException - if the HTTP request cannot be handled.
      • initContainerRequest

        private void initContainerRequest​(ContainerRequest requestContext,
                                          javax.servlet.http.HttpServletRequest servletRequest,
                                          javax.servlet.http.HttpServletResponse servletResponse,
                                          ResponseWriter responseWriter)
                                   throws java.io.IOException
        Initialize ContainerRequest instance to used used to handle servletRequest.
        Throws:
        java.io.IOException
      • getSecurityContext

        private static javax.ws.rs.core.SecurityContext getSecurityContext​(javax.servlet.http.HttpServletRequest request)
        Get default SecurityContext for given request.
        Parameters:
        request - http servlet request to create a security context for.
        Returns:
        a non-null security context instance.
      • createResourceConfig

        private static ResourceConfig createResourceConfig​(WebConfig config)
                                                    throws javax.servlet.ServletException
        Create a ResourceConfig instance from given WebConfig.
        Parameters:
        config - web config to create resource config from.
        Returns:
        resource config instance.
        Throws:
        javax.servlet.ServletException - if an error has occurred.
      • configure

        private void configure​(ResourceConfig resourceConfig,
                               ServletContainerProvider[] allServletContainerProviders)
                        throws javax.servlet.ServletException
        SPI/extension hook to configure ResourceConfig.
        Parameters:
        resourceConfig - Jersey application configuration.
        Throws:
        javax.servlet.ServletException - if an error has occurred.
      • addRequestHeaders

        private void addRequestHeaders​(javax.servlet.http.HttpServletRequest request,
                                       ContainerRequest requestContext)
        Copy request headers present in request into requestContext ignoring null values.
        Parameters:
        request - http servlet request to copy headers from.
        requestContext - container request to copy headers to.
      • getInitParams

        private static java.util.Map<java.lang.String,​java.lang.Object> getInitParams​(WebConfig webConfig)
        Extract init params from WebConfig.
        Parameters:
        webConfig - actual servlet context.
        Returns:
        map representing current init parameters.
      • filterFormParameters

        private void filterFormParameters​(javax.servlet.http.HttpServletRequest servletRequest,
                                          ContainerRequest containerRequest)
        Extract parameters contained in servlet request and put them into container request under "jersey.config.server.representation.decoded.form" property (as Form instance).
        Parameters:
        servletRequest - http servlet request to extract params from.
        containerRequest - container request to put Form property to.
      • getDecodedQueryParamList

        private java.util.List<java.lang.String> getDecodedQueryParamList​(java.lang.String queryString)
      • filterQueryParams

        private java.util.List<java.lang.String> filterQueryParams​(java.lang.String name,
                                                                   java.util.List<java.lang.String> values,
                                                                   java.util.Collection<java.lang.String> params)
        From given list of values remove values that represents values of query params of the same name as the processed form parameter.
        Parameters:
        name - name of form/query parameter.
        values - values of form/query parameter.
        params - collection of unprocessed query parameters.
        Returns:
        list of form param values for given name without values of query param of the same name.