public class WebComponent extends java.lang.Object implements ContainerListener
Modifier and Type | Class and Description |
---|---|
protected static class |
WebComponent.ContextInjectableProvider<T>
A helper class for creating an injectable provider that supports
Context with a type and constant value. |
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
WebComponent() |
WebComponent(Application app) |
Modifier and Type | Method and Description |
---|---|
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.
|
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
public WebComponent()
public WebComponent(Application app)
public WebConfig getWebConfig()
public ResourceConfig getResourceConfig()
public void init(WebConfig webConfig) throws javax.servlet.ServletException
webConfig
- the Web configuration.javax.servlet.ServletException
- in case of any initialization errorpublic void destroy()
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
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.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.protected ContainerRequest createRequest(WebApplication app, javax.servlet.http.HttpServletRequest request, java.net.URI baseUri, java.net.URI requestUri) throws java.io.IOException
app
- the web apprequest
- the current servlet api requestbaseUri
- the base urirequestUri
- the request urijava.io.IOException
- if any error occurs when getting the input streamprotected WebApplication create()
WebApplication
.WebApplication
instance.protected void configure(WebConfig wc, 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 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.wc
- the Web configurationrc
- the Resource configurationwa
- the Web applicationprotected void initiate(ResourceConfig rc, WebApplication wa)
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.rc
- the Resource configurationwa
- the Web applicationpublic void load()
protected ResourceConfig getDefaultResourceConfig(java.util.Map<java.lang.String,java.lang.Object> props, WebConfig wc) throws javax.servlet.ServletException
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.props
- the properties to pass to the resource configuration.wc
- the web configuration.javax.servlet.ServletException
- in case of any issues with providing \
the default resource configurationpublic void onReload()
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.onReload
in interface ContainerListener
onReload
in interface ReloadListener
Copyright © 2016 Oracle Corporation. All Rights Reserved.