Package org.glassfish.jersey.servlet
Class WebComponent
java.lang.Object
org.glassfish.jersey.servlet.WebComponent
An common Jersey web component that may be extended by a Servlet and/or
Filter implementation, or encapsulated by a Servlet or Filter implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
private final class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ApplicationHandler
Jersey application handler.private final AsyncContextDelegateProvider
Asynchronous context delegate provider.(package private) final ScheduledExecutorService
Jersey background task scheduler - used for scheduling request timeout event handling tasks.(package private) final boolean
Cached value of configuration propertyServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR
.private static final AsyncContextDelegate
private static final RequestScopedInitializerProvider
(package private) final boolean
Iftrue
and deployed as filter, the unmatched requests will be forwarded.private static final Logger
private final boolean
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.private static final Type
private final boolean
private final RequestScopedInitializerProvider
private static final Type
(package private) final WebConfig
Web component configuration. -
Constructor Summary
ConstructorsConstructorDescriptionWebComponent
(WebConfig webConfig, ResourceConfig resourceConfig) Create and initialize new web component instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addRequestHeaders
(javax.servlet.http.HttpServletRequest request, ContainerRequest requestContext) Copy request headers present inrequest
intorequestContext
ignoringnull
values.private void
configure
(ResourceConfig resourceConfig, ServletContainerProvider[] allServletContainerProviders) SPI/extension hook to configure ResourceConfig.private static ResourceConfig
createResourceConfig
(WebConfig config) Create aResourceConfig
instance from givenWebConfig
.private void
filterFormParameters
(javax.servlet.http.HttpServletRequest servletRequest, ContainerRequest containerRequest) Extract parameters contained inservlet request
and put them intocontainer request
under "jersey.config.server.representation.decoded.form" property (asForm
instance).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.GetApplicationHandler
used by this web component.private AsyncContextDelegateProvider
Return the first foundAsyncContextDelegateProvider
(viaProviders.getAllProviders(InjectionManager, Class)
) or#DEFAULT_ASYNC_DELEGATE
if other delegate cannot be found.getDecodedQueryParamList
(String queryString) getInitParams
(WebConfig webConfig) Extract init params fromWebConfig
.private static javax.ws.rs.core.SecurityContext
getSecurityContext
(javax.servlet.http.HttpServletRequest request) Get defaultSecurityContext
for givenrequest
.private void
initContainerRequest
(ContainerRequest requestContext, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, ResponseWriter responseWriter) InitializeContainerRequest
instance to used used to handleservletRequest
.service
(URI baseUri, URI requestUri, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse) Dispatch client requests to a resource class.(package private) ResponseWriter
serviceImpl
(URI baseUri, URI requestUri, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse) Dispatch client requests to a resource class.
-
Field Details
-
LOGGER
-
REQUEST_TYPE
-
RESPONSE_TYPE
-
DEFAULT_ASYNC_DELEGATE
-
requestScopedInitializer
-
requestResponseBindingExternalized
private final boolean requestResponseBindingExternalized -
DEFAULT_REQUEST_SCOPE_INITIALIZER_PROVIDER
-
appHandler
Jersey application handler. -
backgroundTaskScheduler
Jersey background task scheduler - used for scheduling request timeout event handling tasks. -
webConfig
Web component configuration. -
forwardOn404
final boolean forwardOn404Iftrue
and deployed as filter, the unmatched requests will be forwarded. -
configSetStatusOverSendError
final boolean configSetStatusOverSendErrorCached value of configuration propertyServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR
. Iftrue
methodHttpServletResponse.setStatus(int)
is used overHttpServletResponse.sendError(int, java.lang.String)
. -
asyncExtensionDelegate
Asynchronous context delegate provider. -
queryParamsAsFormParams
private final boolean queryParamsAsFormParamsFlag 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
Return the first foundAsyncContextDelegateProvider
(viaProviders.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
- theHttpServletRequest
object that contains the request the client made to the Web component.servletResponse
- theHttpServletResponse
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 toValue.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
- theHttpServletRequest
object that contains the request the client made to the Web component.servletResponse
- theHttpServletResponse
object that contains the response the Web component returns to the client.- Returns:
- returns
ResponseWriter
, Servlet'sContainerResponseWriter
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 InitializeContainerRequest
instance to used used to handleservletRequest
.- Throws:
IOException
-
getSecurityContext
private static javax.ws.rs.core.SecurityContext getSecurityContext(javax.servlet.http.HttpServletRequest request) Get defaultSecurityContext
for givenrequest
.- 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 aResourceConfig
instance from givenWebConfig
.- 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 inrequest
intorequestContext
ignoringnull
values.- Parameters:
request
- http servlet request to copy headers from.requestContext
- container request to copy headers to.
-
getInitParams
Extract init params fromWebConfig
.- 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 inservlet request
and put them intocontainer request
under "jersey.config.server.representation.decoded.form" property (asForm
instance).- Parameters:
servletRequest
- http servlet request to extract params from.containerRequest
- container request to putForm
property to.
-
getDecodedQueryParamList
-
filterQueryParams
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
GetApplicationHandler
used by this web component.- Returns:
- The application handler
-