org.glassfish.jersey.servlet
Class ServletContainer

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.glassfish.jersey.servlet.ServletContainer
All Implemented Interfaces:
Serializable, javax.servlet.Filter, javax.servlet.Servlet, javax.servlet.ServletConfig

public class ServletContainer
extends javax.servlet.http.HttpServlet
implements javax.servlet.Filter

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 "javax.ws.rs.Application" (see ServerProperties.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 "javax.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 Application 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.

Author:
Paul Sandoz, Pavel Bucek (pavel.bucek at oracle.com)
See Also:
Serialized Form

Constructor Summary
ServletContainer()
           
ServletContainer(ResourceConfig resourceConfig)
           
 
Method Summary
 void destroy()
           
 void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
          Dispatches client requests to the service(URI, URI, HttpServletRequest, HttpServletResponse) method.
 void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)
           
 javax.servlet.ServletContext getServletContext()
          Get the servlet context for the servlet or filter, depending on how this class is registered.
protected  Pattern getStaticContentPattern()
          Get the static content path pattern.
 void init()
           
 void init(javax.servlet.FilterConfig filterConfig)
           
protected  void init(WebConfig webConfig)
          Initiate the Web component.
protected  void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class.
 void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res)
          Dispatches client requests to the protected service method.
 int service(URI baseUri, URI requestUri, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Dispatch client requests to a resource class.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletContainer

public ServletContainer()

ServletContainer

public ServletContainer(ResourceConfig resourceConfig)
                 throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException
Method Detail

init

protected void init(WebConfig webConfig)
             throws javax.servlet.ServletException
Initiate the Web component.

Parameters:
webConfig - the Web configuration.
Throws:
javax.servlet.ServletException - in case of an initialization failure

service

public void service(javax.servlet.ServletRequest req,
                    javax.servlet.ServletResponse res)
             throws javax.servlet.ServletException,
                    IOException
Dispatches client requests to the protected service method. There's no need to override this method.

Specified by:
service in interface javax.servlet.Servlet
Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
req - the HttpServletRequest object that contains the request the client made of the servlet
res - the HttpServletResponse object 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
javax.servlet.ServletException - if the HTTP request cannot be handled
See Also:
Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)

service

protected void service(javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response)
                throws javax.servlet.ServletException,
                       IOException
Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. This method is an HTTP-specific version of the Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) method. There's no need to override this method.

Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
request - the HttpServletRequest object that contains the request the client made of the servlet
response - the HttpServletResponse object 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
javax.servlet.ServletException - if the HTTP request cannot be handled
See Also:
Servlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter
Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

service

public int service(URI baseUri,
                   URI requestUri,
                   javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            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.
request - the HttpServletRequest object that contains the request the client made to the Web component.
response - the HttpServletResponse object that contains the response the Web component returns to the client.
Returns:
the status code of the response.
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.

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

doFilter

public void doFilter(javax.servlet.ServletRequest servletRequest,
                     javax.servlet.ServletResponse servletResponse,
                     javax.servlet.FilterChain filterChain)
              throws IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException

getServletContext

public javax.servlet.ServletContext getServletContext()
Get the servlet context for the servlet or filter, depending on how this class is registered.

Specified by:
getServletContext in interface javax.servlet.ServletConfig
Overrides:
getServletContext in class javax.servlet.GenericServlet
Returns:
the servlet context for the servlet or filter.

doFilter

public void doFilter(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response,
                     javax.servlet.FilterChain chain)
              throws IOException,
                     javax.servlet.ServletException
Dispatches client requests to the service(URI, URI, HttpServletRequest, HttpServletResponse) method.

If the servlet path matches the regular expression declared by the property ServletProperties.FILTER_STATIC_CONTENT_REGEXP then 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 HttpServletRequest object that contains the request the client made to the servlet.
response - the HttpServletResponse object 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
javax.servlet.ServletException

getStaticContentPattern

protected Pattern getStaticContentPattern()
Get the static content path pattern.

Returns:
the Pattern compiled from a regular expression that is the property value of ServletProperties.FILTER_STATIC_CONTENT_REGEXP. A null value will be returned if the property is not set or is an empty String.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.