com.sun.ws.rest.spi.container.servlet
Class ServletContainer

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.sun.ws.rest.spi.container.servlet.ServletContainer
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class ServletContainer
extends javax.servlet.http.HttpServlet

A servlet container for deploying root resource classes.

The web.xml MAY configure the servlet to have an initialization parameter "com.sun.ws.rest.config.property.resourceConfigClass" and whose value is a fully qualified name of a class that implements ResourceConfig. 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.ws.rest.config.property.resourceConfigClass" is not present a new instance of ClasspathResourceConfig is created. The initialization parameter "com.sun.ws.rest.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 passe 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".

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 Resource: @{link HttpServletRequest}, HttpServletResponse and ServletConfig.

See Also:
Serialized Form

Constructor Summary
ServletContainer()
           
 
Method Summary
protected  void configure(javax.servlet.ServletConfig sc, ResourceConfig rc, WebApplication wa)
          Configure the WebApplication.
protected  WebApplication create()
          Create a new instance of a WebApplication.
 void init(javax.servlet.ServletConfig servletConfig)
           
protected  void initiate(ResourceConfig rc, WebApplication wa)
          Initiate the WebApplication.
 void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, 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
 

Constructor Detail

ServletContainer

public ServletContainer()
Method Detail

init

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

service

public final void service(javax.servlet.http.HttpServletRequest req,
                          javax.servlet.http.HttpServletResponse resp)
                   throws javax.servlet.ServletException,
                          java.io.IOException
Overrides:
service in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

create

protected WebApplication create()
Create a new instance of a WebApplication.


configure

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

The WebApplication 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 Resource: @{link HttpServletRequest}, @{link HttpServletResponse} and ServletConfig.

An inheriting class may override this method to configure the WebApplication to provide alternative or additional instance that may be injected into a root resource class, 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.

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

initiate

protected void initiate(ResourceConfig rc,
                        WebApplication wa)
Initiate the WebApplication.

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