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 classprivate static classprivate final class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ApplicationHandlerJersey application handler.private final AsyncContextDelegateProviderAsynchronous context delegate provider.(package private) final ScheduledExecutorServiceJersey background task scheduler - used for scheduling request timeout event handling tasks.(package private) final booleanCached value of configuration propertyServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR.private static final AsyncContextDelegateprivate static final RequestScopedInitializerProvider(package private) final booleanIftrueand deployed as filter, the unmatched requests will be forwarded.private static final Loggerprivate final booleanFlag 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 Typeprivate final booleanprivate final RequestScopedInitializerProviderprivate static final Type(package private) final WebConfigWeb component configuration. -
Constructor Summary
ConstructorsConstructorDescriptionWebComponent(WebConfig webConfig, ResourceConfig resourceConfig) Create and initialize new web component instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddRequestHeaders(javax.servlet.http.HttpServletRequest request, ContainerRequest requestContext) Copy request headers present inrequestintorequestContextignoringnullvalues.private voidconfigure(ResourceConfig resourceConfig, ServletContainerProvider[] allServletContainerProviders) SPI/extension hook to configure ResourceConfig.private static ResourceConfigcreateResourceConfig(WebConfig config) Create aResourceConfiginstance from givenWebConfig.private voidfilterFormParameters(javax.servlet.http.HttpServletRequest servletRequest, ContainerRequest containerRequest) Extract parameters contained inservlet requestand put them intocontainer requestunder "jersey.config.server.representation.decoded.form" property (asForminstance).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.GetApplicationHandlerused by this web component.private AsyncContextDelegateProviderReturn the first foundAsyncContextDelegateProvider(viaProviders.getAllProviders(InjectionManager, Class)) or#DEFAULT_ASYNC_DELEGATEif other delegate cannot be found.getDecodedQueryParamList(String queryString) getInitParams(WebConfig webConfig) Extract init params fromWebConfig.private static javax.ws.rs.core.SecurityContextgetSecurityContext(javax.servlet.http.HttpServletRequest request) Get defaultSecurityContextfor givenrequest.private voidinitContainerRequest(ContainerRequest requestContext, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, ResponseWriter responseWriter) InitializeContainerRequestinstance 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) ResponseWriterserviceImpl(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 forwardOn404Iftrueand deployed as filter, the unmatched requests will be forwarded. -
configSetStatusOverSendError
final boolean configSetStatusOverSendErrorCached value of configuration propertyServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR. IftruemethodHttpServletResponse.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_DELEGATEif 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- theHttpServletRequestobject that contains the request the client made to the Web component.servletResponse- theHttpServletResponseobject 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(),-1is 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- theHttpServletRequestobject that contains the request the client made to the Web component.servletResponse- theHttpServletResponseobject that contains the response the Web component returns to the client.- Returns:
- returns
ResponseWriter, Servlet'sContainerResponseWriterimplementation, 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 InitializeContainerRequestinstance to used used to handleservletRequest.- Throws:
IOException
-
getSecurityContext
private static javax.ws.rs.core.SecurityContext getSecurityContext(javax.servlet.http.HttpServletRequest request) Get defaultSecurityContextfor 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 aResourceConfiginstance 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 inrequestintorequestContextignoringnullvalues.- 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 requestand put them intocontainer requestunder "jersey.config.server.representation.decoded.form" property (asForminstance).- Parameters:
servletRequest- http servlet request to extract params from.containerRequest- container request to putFormproperty 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
GetApplicationHandlerused by this web component.- Returns:
- The application handler
-