Package org.glassfish.jersey.servlet
Class ServletContainer
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.glassfish.jersey.servlet.ServletContainer
- All Implemented Interfaces:
- jakarta.servlet.Filter,- jakarta.servlet.Servlet,- jakarta.servlet.ServletConfig,- Serializable,- Container
public class ServletContainer
extends jakarta.servlet.http.HttpServlet
implements jakarta.servlet.Filter, Container
A 
Servlet or Filter for deploying root resource classes.
 
 The following sections make reference to initialization parameters. Unless
 otherwise specified the initialization parameters apply to both server
 and filter initialization parameters.
 
 The servlet or filter may be configured to have an initialization
 parameter "jakarta.ws.rs.Application"
 (see ServletProperties.JAXRS_APPLICATION_CLASS) and whose value is a
 fully qualified name of a class that implements Application.
 The class is instantiated as a singleton component
 managed by the runtime, and injection may be performed (the artifacts that
 may be injected are limited to injectable providers registered when
 the servlet or filter is configured).
 
 If the initialization parameter "jakarta.ws.rs.Application"
 is not present and a initialization parameter "jersey.config.server.provider.packages"
 is present (see ServerProperties.PROVIDER_PACKAGES) a new instance of
 ResourceConfig with this configuration is created. The initialization parameter
 "jersey.config.server.provider.packages" MUST be set to provide one or
 more package names. Each package name MUST be separated by ';'.
 
 If none of the above resource configuration related initialization parameters
 are present a new instance of ResourceConfig with WebAppResourcesScanner
 is created. The initialization parameter "jersey.config.server.provider.classpath"
 is present (see ServerProperties.PROVIDER_CLASSPATH) MAY be
 set to provide one or more resource paths. Each path MUST be separated by ';'.
 If the initialization parameter is not present then the following resource
 paths are utilized: "/WEB-INF/lib" and "/WEB-INF/classes".
 
 All initialization parameters are added as properties of the created
 ResourceConfig.
 
 A new ApplicationHandler instance will be created and configured such
 that the following classes may be injected onto a root resource, provider
 and Application classes using @Context annotation:
 HttpServletRequest, HttpServletResponse,
 ServletContext, ServletConfig and WebConfig.
 If this class is used as a Servlet then the ServletConfig class may
 be injected. If this class is used as a servlet filter then the FilterConfig
 class may be injected. WebConfig may be injected to abstract
 servlet or filter deployment.
 
 Persistence units that may be injected must be configured in web.xml
 in the normal way plus an additional servlet parameter to enable the
 Jersey servlet to locate them in JNDI. E.g. with the following
 persistence unit configuration:
 
 <persistence-unit-ref>
     <persistence-unit-ref-name>persistence/widget</persistence-unit-ref-name>
     <persistence-unit-name>WidgetPU</persistence-unit-name>
 </persistence-unit-ref>
 
 <init-param>
     <param-name>unit:WidgetPU</param-name>
     <param-value>persistence/widget</param-value>
 </init-param>
 EntityManagerFactory found
 at java:comp/env/persistence/widget in JNDI when encountering a
 field or parameter annotated with @PersistenceUnit(unitName="WidgetPU").- Author:
- Paul Sandoz, Pavel Bucek, Michal Gajdos, Libor Kramolis
- See Also:
- 
Field SummaryFields inherited from class jakarta.servlet.http.HttpServletLEGACY_DO_HEADFields inherited from interface org.glassfish.jersey.server.spi.ContainerDEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT
- 
Constructor SummaryConstructorsConstructorDescriptionCreate Jersey Servlet container.ServletContainer(ResourceConfig resourceConfig) Create Jersey Servlet container.
- 
Method SummaryModifier and TypeMethodDescriptionvoiddestroy()voiddoFilter(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) Dispatches client requests to theservice(URI, URI, HttpServletRequest, HttpServletResponse)method.voiddoFilter(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse, jakarta.servlet.FilterChain filterChain) Get the Jersey server-side application handler associated with the container.Return an immutable representation of the currentconfiguration.jakarta.servlet.ServletContextGet the servlet context for the servlet or filter, depending on how this class is registered.protected PatternGet the static content path pattern.GetWebComponentused by this servlet container.voidinit()voidinit(jakarta.servlet.FilterConfig filterConfig) protected voidInitiate the Web component.voidreload()Reload the hosted Jersey application using the currentconfiguration.voidreload(ResourceConfig configuration) Reload the hosted Jersey application using a newconfiguration.protected voidservice(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Receives standard HTTP requests from the publicservicemethod and dispatches them to thedoXXX methods defined in this class.voidservice(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res) Dispatches client requests to the protectedservicemethod.org.glassfish.jersey.internal.util.collection.Value<Integer>service(URI baseUri, URI requestUri, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Dispatch client requests to a resource class.Methods inherited from class jakarta.servlet.http.HttpServletdoDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, initMethods inherited from class jakarta.servlet.GenericServletgetInitParameter, getInitParameterNames, getServletConfig, getServletInfo, getServletName, log, log
- 
Constructor Details- 
ServletContainerpublic ServletContainer()Create Jersey Servlet container.
- 
ServletContainerCreate Jersey Servlet container.- Parameters:
- resourceConfig- container configuration.
 
 
- 
- 
Method Details- 
initInitiate the Web component.- Parameters:
- webConfig- the Web configuration.
- Throws:
- jakarta.servlet.ServletException- in case of an initialization failure
 
- 
servicepublic void service(jakarta.servlet.ServletRequest req, jakarta.servlet.ServletResponse res) throws jakarta.servlet.ServletException, IOException Dispatches client requests to the protectedservicemethod. There's no need to override this method.- Specified by:
- servicein interface- jakarta.servlet.Servlet
- Overrides:
- servicein class- jakarta.servlet.http.HttpServlet
- Parameters:
- req- the- HttpServletRequestobject that contains the request the client made of the servlet
- res- the- HttpServletResponseobject that contains the response the servlet returns to the client
- Throws:
- IOException- if an input or output error occurs while the servlet is handling the HTTP request
- jakarta.servlet.ServletException- if the HTTP request cannot be handled
- See Also:
- 
- Servlet.service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
 
 
- 
serviceprotected void service(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException Receives standard HTTP requests from the publicservicemethod and dispatches them to thedoXXX methods defined in this class. This method is an HTTP-specific version of theServlet.service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)method. There's no need to override this method.- Overrides:
- servicein class- jakarta.servlet.http.HttpServlet
- Parameters:
- request- the- HttpServletRequestobject that contains the request the client made of the servlet
- response- the- HttpServletResponseobject that contains the response the servlet returns to the client
- Throws:
- IOException- if an input or output error occurs while the servlet is handling the HTTP request
- jakarta.servlet.ServletException- if the HTTP request cannot be handled
- See Also:
- 
- Servlet.service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
 
 
- 
destroypublic void destroy()- Specified by:
- destroyin interface- jakarta.servlet.Filter
- Specified by:
- destroyin interface- jakarta.servlet.Servlet
- Overrides:
- destroyin class- jakarta.servlet.GenericServlet
 
- 
initpublic void init() throws jakarta.servlet.ServletException- Overrides:
- initin class- jakarta.servlet.GenericServlet
- Throws:
- jakarta.servlet.ServletException
 
- 
servicepublic org.glassfish.jersey.internal.util.collection.Value<Integer> service(URI baseUri, URI requestUri, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException Dispatch client requests to a resource class.- Parameters:
- baseUri- the base URI of the request.
- requestUri- the URI of the request.
- request- the- HttpServletRequestobject that contains the request the client made to the Web component.
- response- the- HttpServletResponseobject 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.
- jakarta.servlet.ServletException- if the HTTP request cannot be handled.
 
- 
initpublic void init(jakarta.servlet.FilterConfig filterConfig) throws jakarta.servlet.ServletException - Specified by:
- initin interface- jakarta.servlet.Filter
- Throws:
- jakarta.servlet.ServletException
 
- 
doFilterpublic void doFilter(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse, jakarta.servlet.FilterChain filterChain) throws IOException, jakarta.servlet.ServletException - Specified by:
- doFilterin interface- jakarta.servlet.Filter
- Throws:
- IOException
- jakarta.servlet.ServletException
 
- 
getServletContextpublic jakarta.servlet.ServletContext getServletContext()Get the servlet context for the servlet or filter, depending on how this class is registered.- Specified by:
- getServletContextin interface- jakarta.servlet.ServletConfig
- Overrides:
- getServletContextin class- jakarta.servlet.GenericServlet
- Returns:
- the servlet context for the servlet or filter.
 
- 
doFilterpublic void doFilter(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException Dispatches client requests to theservice(URI, URI, HttpServletRequest, HttpServletResponse)method. If the servlet path matches the regular expression declared by the propertyServletProperties.FILTER_STATIC_CONTENT_REGEXthen the request is forwarded to the next filter in the filter chain so that the underlying servlet engine can process the request otherwise Jersey will process the request.- Parameters:
- request- the- HttpServletRequestobject that contains the request the client made to the servlet.
- response- the- HttpServletResponseobject that contains the response the servlet returns to the client.
- chain- the chain of filters from which the next filter can be invoked.
- Throws:
- IOException- in case of an I/O error.
- jakarta.servlet.ServletException- in case of an error while executing the filter chain.
 
- 
getStaticContentPatternGet the static content path pattern.- Returns:
- the Patterncompiled from a regular expression that is the property value ofServletProperties.FILTER_STATIC_CONTENT_REGEX. Anullvalue will be returned if the property is not set or is an empty String.
 
- 
getConfigurationDescription copied from interface:ContainerReturn an immutable representation of the currentconfiguration.- Specified by:
- getConfigurationin interface- Container
- Returns:
- current configuration of the hosted Jersey application.
 
- 
reloadpublic void reload()Description copied from interface:ContainerReload the hosted Jersey application using the currentconfiguration.
- 
reloadDescription copied from interface:ContainerReload the hosted Jersey application using a newconfiguration.
- 
getApplicationHandlerDescription copied from interface:ContainerGet the Jersey server-side application handler associated with the container.- Specified by:
- getApplicationHandlerin interface- Container
- Returns:
- Jersey server-side application handler associated with the container.
 
- 
getWebComponentGetWebComponentused by this servlet container.- Returns:
- The web component.
 
 
-