Class WebComponent

java.lang.Object
org.glassfish.jersey.servlet.WebComponent

public class WebComponent extends 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 Details

    • LOGGER

      private static final Logger LOGGER
    • REQUEST_TYPE

      private static final Type REQUEST_TYPE
    • RESPONSE_TYPE

      private static final Type RESPONSE_TYPE
    • DEFAULT_ASYNC_DELEGATE

      private static final AsyncContextDelegate DEFAULT_ASYNC_DELEGATE
    • requestScopedInitializer

      private final RequestScopedInitializerProvider requestScopedInitializer
    • requestResponseBindingExternalized

      private final boolean requestResponseBindingExternalized
    • DEFAULT_REQUEST_SCOPE_INITIALIZER_PROVIDER

      private static final RequestScopedInitializerProvider DEFAULT_REQUEST_SCOPE_INITIALIZER_PROVIDER
    • appHandler

      final ApplicationHandler appHandler
      Jersey application handler.
    • backgroundTaskScheduler

      final 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).
    • asyncExtensionDelegate

      private final AsyncContextDelegateProvider asyncExtensionDelegate
      Asynchronous context delegate provider.
    • 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 Details

    • 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 Details

    • getAsyncExtensionDelegate

      private AsyncContextDelegateProvider getAsyncExtensionDelegate()
      Return the first found AsyncContextDelegateProvider (via Providers.getAllProviders(InjectionManager, Class)) or #DEFAULT_ASYNC_DELEGATE if other delegate cannot be found.
      Returns:
      a non-null AsyncContextDelegateProvider.
    • service

      public Value<Integer> service(URI baseUri, URI requestUri, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse) throws javax.servlet.ServletException, 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:
      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(URI baseUri, URI requestUri, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse) throws javax.servlet.ServletException, 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:
      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 IOException
      Initialize ContainerRequest instance to used used to handle servletRequest.
      Throws:
      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 Map<String,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 List<String> getDecodedQueryParamList(String queryString)
    • filterQueryParams

      private List<String> filterQueryParams(String name, List<String> values, Collection<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.
    • getAppHandler

      public ApplicationHandler getAppHandler()
      Get ApplicationHandler used by this web component.
      Returns:
      The application handler