Package org.glassfish.jersey.servlet
Class WebComponent
- java.lang.Object
-
- org.glassfish.jersey.servlet.WebComponent
-
public class WebComponent extends java.lang.ObjectAn 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 Classes Modifier and Type Class Description private static classWebComponent.HttpServletRequestReferencingFactoryprivate static classWebComponent.HttpServletResponseReferencingFactoryprivate classWebComponent.WebComponentBinder
-
Field Summary
Fields Modifier and Type Field Description (package private) ApplicationHandlerappHandlerJersey application handler.private AsyncContextDelegateProviderasyncExtensionDelegateAsynchronous context delegate provider.(package private) java.util.concurrent.ScheduledExecutorServicebackgroundTaskSchedulerJersey background task scheduler - used for scheduling request timeout event handling tasks.(package private) booleanconfigSetStatusOverSendErrorCached value of configuration propertyServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR.private static AsyncContextDelegateDEFAULT_ASYNC_DELEGATEprivate static RequestScopedInitializerProviderDEFAULT_REQUEST_SCOPE_INITIALIZER_PROVIDER(package private) booleanforwardOn404Iftrueand deployed as filter, the unmatched requests will be forwarded.private static java.util.logging.LoggerLOGGERprivate booleanqueryParamsAsFormParamsFlag 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 java.lang.reflect.TypeREQUEST_TYPEprivate booleanrequestResponseBindingExternalizedprivate RequestScopedInitializerProviderrequestScopedInitializerprivate static java.lang.reflect.TypeRESPONSE_TYPE(package private) WebConfigwebConfigWeb component configuration.
-
Constructor Summary
Constructors Constructor Description WebComponent(WebConfig webConfig, ResourceConfig resourceConfig)Create and initialize new web component instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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).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.ApplicationHandlergetAppHandler()GetApplicationHandlerused by this web component.private AsyncContextDelegateProvidergetAsyncExtensionDelegate()Return the first foundAsyncContextDelegateProvider(viaProviders.getAllProviders(InjectionManager, Class)) or#DEFAULT_ASYNC_DELEGATEif other delegate cannot be found.private java.util.List<java.lang.String>getDecodedQueryParamList(java.lang.String queryString)private static java.util.Map<java.lang.String,java.lang.Object>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.Value<java.lang.Integer>service(java.net.URI baseUri, java.net.URI requestUri, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse)Dispatch client requests to a resource class.(package private) ResponseWriterserviceImpl(java.net.URI baseUri, java.net.URI requestUri, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse)Dispatch client requests to a resource class.
-
-
-
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
-
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 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
Iftrueand deployed as filter, the unmatched requests will be forwarded.
-
configSetStatusOverSendError
final boolean configSetStatusOverSendError
Cached value of configuration propertyServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR. IftruemethodHttpServletResponse.setStatus(int)is used overHttpServletResponse.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 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
-
getAsyncExtensionDelegate
private AsyncContextDelegateProvider 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<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- 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:
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- 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:
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
InitializeContainerRequestinstance to used used to handleservletRequest.- Throws:
java.io.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
private static java.util.Map<java.lang.String,java.lang.Object> getInitParams(WebConfig webConfig)
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
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.
-
getAppHandler
public ApplicationHandler getAppHandler()
GetApplicationHandlerused by this web component.- Returns:
- The application handler
-
-