|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.sun.jersey.spi.container.servlet.ServletContainer
public class ServletContainer
A servlet container for deploying root resource classes.
The web.xml MAY configure the servlet 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 servlet 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
.
A IoCComponentProviderFactory
instance may be registered by extending this class
and overriding the method initiate(ResourceConfig, WebApplication)
to initiate the WebApplication
with the IoCComponentProviderFactory
instance.
Field Summary | |
---|---|
static java.lang.String |
APPLICATION_CONFIG_CLASS
The servlet initializaton property whose value is a fully qualified class name of a class that implements ResourceConfig or
Application . |
static java.lang.String |
JSP_TEMPLATES_BASE_PATH
The base path in the Web Pages where JSP templates, associated with viewables of resource classes, are located. |
static java.lang.String |
RESOURCE_CONFIG_CLASS
The servlet initializaton property whose value is a fully qualified class name of a class that implements ResourceConfig or
Application . |
Constructor Summary | |
---|---|
ServletContainer()
|
Method Summary | |
---|---|
protected void |
configure(javax.servlet.ServletConfig sc,
ResourceConfig rc,
WebApplication wa)
Configure the ResourceConfig . |
protected WebApplication |
create()
Create a new instance of a WebApplication . |
void |
destroy()
|
protected ResourceConfig |
getDefaultResourceConfig(java.util.Map<java.lang.String,java.lang.Object> props,
javax.servlet.ServletConfig servletConfig)
Get the default resource configuration if one is not declared in the web.xml. |
void |
init(javax.servlet.ServletConfig servletConfig)
|
protected void |
initiate(ResourceConfig rc,
WebApplication wa)
Initiate the WebApplication . |
void |
load()
Load the Web application. |
void |
onReload()
Called when reloading of the container is requested. |
void |
reload()
Reload the Web application. |
void |
service(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
|
Methods inherited from class javax.servlet.http.HttpServlet |
---|
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service |
Methods inherited from class javax.servlet.GenericServlet |
---|
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String APPLICATION_CONFIG_CLASS
ResourceConfig
or
Application
.
public static final java.lang.String RESOURCE_CONFIG_CLASS
ResourceConfig
or
Application
.
public static final java.lang.String JSP_TEMPLATES_BASE_PATH
If this property is not set then the base path will be the root path of the Web Pages.
Constructor Detail |
---|
public ServletContainer()
Method Detail |
---|
public final void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
public void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
service
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
public final void load()
public final void reload()
ResourceConfig
implementation
that was used to load the Web application.
This method may be called at runtime, more than once, to reload the
Web application. For example, if a ResourceConfig
implementation
is capable of detecting changes to resource classes (addition or removal)
or providers then this method may be invoked to reload the web
application for such changes to take effect.
If this method is called when there are pending requests then such requests will be processed using the previously loaded web application.
protected WebApplication create()
WebApplication
.
WebApplication
instance.protected void configure(javax.servlet.ServletConfig sc, ResourceConfig rc, WebApplication wa)
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 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.
sc
- the Servlet configurationrc
- the Resource configurationwa
- the Web applicationprotected void initiate(ResourceConfig rc, WebApplication wa)
WebApplication
.
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.
This method will be called once at servlet initiation and for each reload of the Web application.
rc
- the Resource configurationwa
- the Web applicationprotected ResourceConfig getDefaultResourceConfig(java.util.Map<java.lang.String,java.lang.Object> props, javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
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.
props
- the properties to pass to the resource configuraton.servletConfig
- the servlet configuration.
javax.servlet.ServletException
public void onReload()
ContainerListener
onReload
in interface ContainerListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |