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

java.lang.Object
  extended by com.sun.jersey.spi.container.servlet.WebComponent
All Implemented Interfaces:
ContainerListener, ReloadListener

public class WebComponent
extends java.lang.Object
implements ContainerListener

An abstract Web component that may be extended a Servlet and/or Filter implementation, or encapsulated by a Servlet or Filter implementation.

Author:
[email protected]

Nested Class Summary
protected static class WebComponent.ContextInjectableProvider<T>
          A helper class for creating an injectable provider that supports Context with a type and constant value.
 
Field Summary
static java.lang.String APPLICATION_CONFIG_CLASS
          The servlet initialization 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 initialization property whose value is a fully qualified class name of a class that implements ResourceConfig or Application.
 
Constructor Summary
WebComponent()
           
WebComponent(Application app)
           
 
Method Summary
protected  void configure(WebConfig wc, ResourceConfig rc, WebApplication wa)
          Configure the ResourceConfig.
protected  WebApplication create()
          Create a new instance of a WebApplication.
protected  ContainerRequest createRequest(WebApplication app, javax.servlet.http.HttpServletRequest request, java.net.URI baseUri, java.net.URI requestUri)
          Extension point for creating your custom container request.
 void destroy()
          Destroy this Web component.
protected  ResourceConfig getDefaultResourceConfig(java.util.Map<java.lang.String,java.lang.Object> props, WebConfig wc)
          Get the default resource configuration if one is not declared in the web.xml.
 ResourceConfig getResourceConfig()
          Get the resource configuration.
 WebConfig getWebConfig()
          Get the Web configuration.
 void init(WebConfig webConfig)
          Initiate the Web component.
protected  void initiate(ResourceConfig rc, WebApplication wa)
          Initiate the WebApplication.
 void load()
          Load the Web application.
 void onReload()
          Reload the Web application.
 int service(java.net.URI baseUri, java.net.URI requestUri, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Dispatch client requests to a resource class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPLICATION_CONFIG_CLASS

public static final java.lang.String APPLICATION_CONFIG_CLASS
The servlet initialization property whose value is a fully qualified class name of a class that implements ResourceConfig or Application.

See Also:
Constant Field Values

RESOURCE_CONFIG_CLASS

public static final java.lang.String RESOURCE_CONFIG_CLASS
The servlet initialization property whose value is a fully qualified class name of a class that implements ResourceConfig or Application.

See Also:
Constant Field Values

JSP_TEMPLATES_BASE_PATH

public static final 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.

If this property is not set then the base path will be the root path of the Web Pages.

See Also:
Constant Field Values
Constructor Detail

WebComponent

public WebComponent()

WebComponent

public WebComponent(Application app)
Method Detail

getWebConfig

public WebConfig getWebConfig()
Get the Web configuration.

Returns:
the Web configuration.

getResourceConfig

public ResourceConfig getResourceConfig()
Get the resource configuration.

Returns:
the resource configuration.

init

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

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

destroy

public void destroy()
Destroy this Web component.

This will destroy the Web application created by this this Web component.


service

public int service(java.net.URI baseUri,
                   java.net.URI requestUri,
                   javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException,
                   java.io.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:
java.io.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.

createRequest

protected ContainerRequest createRequest(WebApplication app,
                                         javax.servlet.http.HttpServletRequest request,
                                         java.net.URI baseUri,
                                         java.net.URI requestUri)
                                  throws java.io.IOException
Extension point for creating your custom container request.

Parameters:
app - the web app
request - the current servlet api request
baseUri - the base uri
requestUri - the request uri
Returns:
the request container
Throws:
java.io.IOException - if any error occurs when getting the input stream

create

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

Returns:
the WebApplication instance.

configure

protected void configure(WebConfig wc,
                         ResourceConfig rc,
                         WebApplication wa)
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.

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

initiate

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

This method will be called once at initiation and for each reload of the Web application.

An inheriting class may override this method to initiate the Web application with different parameters.

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

load

public void load()
Load the Web application. This will create, configure and initiate the web application.


getDefaultResourceConfig

protected ResourceConfig getDefaultResourceConfig(java.util.Map<java.lang.String,java.lang.Object> props,
                                                  WebConfig wc)
                                           throws javax.servlet.ServletException
Get the default resource configuration if one is not declared in the web.xml.

This implementation returns an instance of WebAppResourceConfig 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 configuration implementation.

Parameters:
props - the properties to pass to the resource configuration.
wc - the web configuration.
Returns:
the default resource configuration.
Throws:
javax.servlet.ServletException - in case of any issues with providing \ the default resource configuration

onReload

public void onReload()
Reload the Web application. This will create and initiate the web application using the same 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.

Specified by:
onReload in interface ContainerListener
Specified by:
onReload in interface ReloadListener


Copyright © 2011 Oracle Corporation. All Rights Reserved.