com.sun.jersey.spi.container.servlet
Class ServletContainer

java.lang.Object
  extended by com.sun.jersey.spi.container.servlet.WebComponent
      extended by com.sun.jersey.spi.container.servlet.ServletContainer
All Implemented Interfaces:
ContainerListener, java.io.Serializable, javax.servlet.Filter, javax.servlet.Servlet, javax.servlet.ServletConfig

public class ServletContainer
extends WebComponent
implements javax.servlet.Servlet, javax.servlet.ServletConfig, javax.servlet.Filter, java.io.Serializable

A Servlet or Filter for deploying root resource classes.

If this class is declared as a filter then it must be declared at the last position in the filter chain as it will not forward any request to a next filter (if any) in the chain.

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 "com.sun.jersey.config.property.resourceConfigClass" or "javax.ws.rs.Application" and whose value is a fully qualified name of a class that implements ResourceConfig or Application. If the concrete class has a constructor that takes a single parameter of the type Map then the class is instantiated with that constructor and an instance of Map that contains all the initialization parameters is passed as the parameter. Otherwise the default contructor is used to instantate the class.

If the initialization parameter "com.sun.jersey.config.property.resourceConfigClass" or "javax.ws.rs.Application" is not present and a initialization parameter "com.sun.jersey.config.property.packages" is present (see PackagesResourceConfig.PROPERTY_PACKAGES) a new instance of PackagesResourceConfig is created. The initialization parameter "com.sun.jersey.config.property.packages" MUST be set to provide one or more package names. Each package name MUST be separated by ';'. The package names are added as a property value to a Map instance using the property name (@link PackagesResourceConfig#PROPERTY_PACKAGES}. Any additional initialization parameters are then added to the Map instance. Then that Map instance is passed to the constructor of PackagesResourceConfig.

If none of the above initialization parameters are present a new instance of ClasspathResourceConfig is created. The initialization parameter "com.sun.jersey.config.property.classpath" MAY be set to provide one or more paths. Each path MUST be separated by ';'. Each path MUST be a virtual path as specified by the ServletContext.getRealPath(java.lang.String) method, and each path is transformed by that method. The transformed paths are added as a property value to a Map instance using the property name (@link ClasspathResourceConfig.PROPERTY_CLASSPATH}. Any additional initialization parameters are then added to the Map instance. Then that Map instance is passed to the constructor of ClasspathResourceConfig. If this parameter is not set then the default value is set to the following virtual paths: "/WEB-INF/lib;/WEB-INF/classes".

All initialization parameters are added as properties of the created ResourceConfig.

A new WebApplication instance will be created and configured such that the following classes may be injected onto the field of a root resource class or a parameter of a method of root resource class that is annotated with Context: HttpServletRequest, HttpServletResponse, ServletContext, and ServletConfig. If this class is used as a Servlet then the ServletConfig class may be injected. If this class is used as a Filter then the FilterConfig class may be injected.

A IoCComponentProviderFactory instance may be registered by extending this class and overriding the method WebComponent.initiate(ResourceConfig, WebApplication) to initiate the WebApplication with the IoCComponentProviderFactory instance.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.jersey.spi.container.servlet.WebComponent
WebComponent.ContextInjectableProvider<T>
 
Field Summary
 
Fields inherited from class com.sun.jersey.spi.container.servlet.WebComponent
APPLICATION_CONFIG_CLASS, JSP_TEMPLATES_BASE_PATH, RESOURCE_CONFIG_CLASS
 
Constructor Summary
ServletContainer()
           
 
Method Summary
protected  void configure(javax.servlet.FilterConfig fc, ResourceConfig rc, WebApplication wa)
          Configure the ResourceConfig for a Filter.
protected  void configure(javax.servlet.ServletConfig sc, ResourceConfig rc, WebApplication wa)
          Configure the ResourceConfig for a Servlet.
protected  void configure(WebConfig wc, ResourceConfig rc, WebApplication wa)
          Configure the ResourceConfig.
 void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
          Dispatches client requests to the WebComponent.service(java.net.URI, java.net.URI, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          Dispatches client requests to the doFilter(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain) method.
protected  ResourceConfig getDefaultResourceConfig(java.util.Map<java.lang.String,java.lang.Object> props, javax.servlet.ServletConfig servletConfig)
          Deprecated. methods should implement WebComponent.getDefaultResourceConfig(java.util.Map, com.sun.jersey.spi.container.servlet.WebConfig).
 java.lang.String getInitParameter(java.lang.String name)
           
 java.util.Enumeration getInitParameterNames()
           
 javax.servlet.ServletConfig getServletConfig()
           
 javax.servlet.ServletContext getServletContext()
           
 java.lang.String getServletInfo()
          Returns information about the servlet, such as author, version, and copyright.
 java.lang.String getServletName()
           
 void init(javax.servlet.FilterConfig filterConfig)
           
 void init(javax.servlet.ServletConfig servletConfig)
           
 void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Dispatches client requests to the WebComponent.service(java.net.URI, java.net.URI, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.
 void service(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          Dispatches client requests to the service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.
 
Methods inherited from class com.sun.jersey.spi.container.servlet.WebComponent
create, destroy, getDefaultResourceConfig, getWebConfig, init, initiate, load, onReload, reload, service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.Servlet
destroy
 
Methods inherited from interface javax.servlet.Filter
destroy
 

Constructor Detail

ServletContainer

public ServletContainer()
Method Detail

getServletName

public java.lang.String getServletName()
Specified by:
getServletName in interface javax.servlet.ServletConfig

getServletContext

public javax.servlet.ServletContext getServletContext()
Specified by:
getServletContext in interface javax.servlet.ServletConfig

getInitParameter

public java.lang.String getInitParameter(java.lang.String name)
Specified by:
getInitParameter in interface javax.servlet.ServletConfig

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Specified by:
getInitParameterNames in interface javax.servlet.ServletConfig

getServletConfig

public javax.servlet.ServletConfig getServletConfig()
Specified by:
getServletConfig in interface javax.servlet.Servlet

getServletInfo

public java.lang.String getServletInfo()
Returns information about the servlet, such as author, version, and copyright. By default, this method returns an empty string. Override this method to have it return a meaningful value. See Servlet.getServletInfo().

Specified by:
getServletInfo in interface javax.servlet.Servlet
Returns:
String information about this servlet, by default an empty string

init

public final void init(javax.servlet.ServletConfig servletConfig)
                throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Servlet
Throws:
javax.servlet.ServletException

service

public void service(javax.servlet.ServletRequest request,
                    javax.servlet.ServletResponse response)
             throws javax.servlet.ServletException,
                    java.io.IOException
Dispatches client requests to the service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.

Specified by:
service in interface javax.servlet.Servlet
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.
Throws:
java.io.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.

service

public void service(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
             throws javax.servlet.ServletException,
                    java.io.IOException
Dispatches client requests to the WebComponent.service(java.net.URI, java.net.URI, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) method.

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.
Throws:
java.io.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.

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 request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Dispatches client requests to the doFilter(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain) method.

Specified by:
doFilter in interface javax.servlet.Filter
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:
java.io.IOException
javax.servlet.ServletException

doFilter

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

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:
java.io.IOException
javax.servlet.ServletException

configure

protected void configure(javax.servlet.ServletConfig sc,
                         ResourceConfig rc,
                         WebApplication wa)
Configure the ResourceConfig for a Servlet.

The ResourceConfig is configured such that the following classes may be injected onto the field of a root resource class or a parameter of a method of root resource class that is annotated with Context: ServletConfig.

An inheriting class may override this method to configure the ResourceConfig to provide alternative or additional instances that are resource or provider classes or instances, and may modify the features and properties of the ResourceConfig. For an inheriting class to extend configuration behaviour the overriding method MUST call super.configure(servletConfig, rc, wa) as the first statement of that method.

This method will be called only once at servlet initiation. Subsequent reloads of the Web application will not result in subsequence calls to this method.

Parameters:
sc - the Servlet configuration
rc - the Resource configuration
wa - the Web application

configure

protected void configure(javax.servlet.FilterConfig fc,
                         ResourceConfig rc,
                         WebApplication wa)
Configure the ResourceConfig for a Filter.

The ResourceConfig is configured such that the following classes may be injected onto the field of a root resource class or a parameter of a method of root resource class that is annotated with Context: FilterConfig.

An inheriting class may override this method to configure the ResourceConfig to provide alternative or additional instances that are resource or provider classes or instances, and may modify the features and properties of the ResourceConfig. For an inheriting class to extend configuration behaviour the overriding method MUST call super.configure(servletConfig, rc, wa) as the first statement of that method.

This method will be called only once at servlet initiation. Subsequent reloads of the Web application will not result in subsequence calls to this method.

Parameters:
fc - the Filter configuration
rc - the Resource configuration
wa - the Web application

configure

protected void configure(WebConfig wc,
                         ResourceConfig rc,
                         WebApplication wa)
Description copied from class: WebComponent
Configure the ResourceConfig.

The ResourceConfig is configured such that the following classes may be injected onto the field of a root resource class or a parameter of a method of root resource class that is annotated with Context: HttpServletRequest, HttpServletResponse , ServletContext and WebConfig.

Any root resource class in registered in the resource configuration that is an interface is processed as follows. If the class is an interface and there exists a JNDI named object with the fully qualified class name as the JNDI name then that named object is added as a singleton root resource and the class is removed from the set of root resource classes.

An inheriting class may override this method to configure the ResourceConfig to provide alternative or additional instances that are resource or provider classes or instances, and may modify the features and properties of the ResourceConfig. For an inheriting class to extend configuration behaviour the overriding method MUST call super.configure(servletConfig, rc, wa) as the first statement of that method.

This method will be called only once at initiation. Subsequent reloads of the Web application will not result in subsequence calls to this method.

Overrides:
configure in class WebComponent
Parameters:
wc - the Web configuration
rc - the Resource configuration
wa - the Web application

getDefaultResourceConfig

@Deprecated
protected ResourceConfig getDefaultResourceConfig(java.util.Map<java.lang.String,java.lang.Object> props,
                                                             javax.servlet.ServletConfig servletConfig)
                                           throws javax.servlet.ServletException
Deprecated. methods should implement WebComponent.getDefaultResourceConfig(java.util.Map, com.sun.jersey.spi.container.servlet.WebConfig).

Get the default resource configuration if one is not declared in the web.xml.

This implementaton returns an instance of ClasspathResourceConfig that scans in files and directories as declared by the ClasspathResourceConfig.PROPERTY_CLASSPATH if present, otherwise in the "WEB-INF/lib" and "WEB-INF/classes" directories.

An inheriting class may override this method to supply a different default resource configuraton implementaton.

Parameters:
props - the properties to pass to the resource configuraton.
servletConfig - the servlet configuration.
Returns:
the default resource configuraton.
Throws:
javax.servlet.ServletException


Copyright © 2009 Sun Microsystems, Inc. All Rights Reserved.