|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.grizzly.tcp.StaticResourcesAdapter
com.sun.grizzly.tcp.http11.GrizzlyAdapter
com.sun.grizzly.http.servlet.ServletAdapter
public class ServletAdapter
Adapter class that can initiate a FilterChain and execute its
Filter and its Servlet
Configuring a SelectorThread to use this GrizzlyAdapter implementation add
the ability of servicing Servlet as well as static resource to the Grizzly http extension.
This class can be used to programatically configure a Servlet, Filters, paths,
init parameters, etc. a deployer usually do based on the web.xml content.
As an example:
final SelectorThread selectorThread = new SelectorThread(){
public void listen() throws IOException, InstantiationException{
super.listen();
System.out.println("Server started in " + (System.currentTimeMillis() - t1)
+ " milliseconds.");
}
};
selectorThread.setAlgorithmClassName(StaticStreamAlgorithm.class.getName());
selectorThread.setPort(port);
SelectorThread.setWebAppRootPath(folder);
ServletAdapter adapter = new ServletAdapter();
adapter.setRootFolder(SelectorThread.getWebAppRootPath());
st.setAdapter(adapter);
adapter.setHandleStaticResources(true);
Servlet servlet = new MyOwnServlet();
// programatically configure the servlet (like web.xml usually doing)
adapter.setServletInstance(servlet);
adapter.addInitParameter("Grizzly","is Really Cool!");
adapter.setServletPath("/myPath");
selectorThread.setAdapter(adapter);
selectorThread.setDisplayConfiguration(true);
selectorThread.listen();
| Field Summary | |
|---|---|
protected HashMap<String,Object> |
properties
Holder for our configured properties. |
static int |
REQUEST_RESPONSE_NOTES
|
static int |
SERVLETCONFIG_NOTES
|
| Fields inherited from class com.sun.grizzly.tcp.http11.GrizzlyAdapter |
|---|
ADAPTER_NOTES, ALLOW_BACKSLASH |
| Fields inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter |
|---|
commitErrorResponse, logger |
| Fields inherited from interface com.sun.grizzly.tcp.Adapter |
|---|
CONNECTION_PROCESSING_COMPLETED, CONNECTION_PROCESSING_STARTED, REQUEST_PROCESSING_COMPLETED, REQUEST_PROCESSING_STARTED |
| Constructor Summary | |
|---|---|
ServletAdapter()
|
|
ServletAdapter(String publicDirectory)
Create a new instance which will look for static pages located under publicDirectory folder. |
|
| Method Summary | |
|---|---|
void |
addFilter(Filter filter,
String filterName,
Map initParameters)
Add a Filter to the FilterChain |
void |
addInitParameter(String name,
String value)
Add a new servlet initialization parameter for this servlet. |
void |
afterService(GrizzlyRequest request,
GrizzlyResponse response)
|
void |
customizeErrorPage(GrizzlyResponse response,
String message,
int errorCode)
Customize the error page returned to the client. |
protected String |
getBasePath()
Return the current based path. |
String |
getContextPath()
Returns the portion of the request URI that indicates the context of the request. |
Object |
getProperty(String name)
Return a configured property. |
Servlet |
getServletInstance()
Return the Servlet instance used by this Adapter |
String |
getServletPath()
Returns the part of this request's URL that calls the servlet. |
void |
removeProperty(String name)
remove a configured property. |
void |
service(GrizzlyRequest request,
GrizzlyResponse response)
|
protected void |
setBasePath(String basePath)
Set the basePath used by the ServletContext#getRealPath. |
void |
setContextPath(String contextPath)
Programmatically set the context path of the Servlet. |
void |
setProperty(String name,
Object value)
Set a configured property. |
void |
setServletInstance(Servlet servletInstance)
Set the Servlet instance used by this Adapter |
void |
setServletPath(String servletPath)
Programmatically set the servlet path of the Servlet. |
| Methods inherited from class com.sun.grizzly.tcp.http11.GrizzlyAdapter |
|---|
afterService, convertMB, convertURI, copyBytes, isHandleStaticResources, log, log, normalize, service, setHandleStaticResources |
| Methods inherited from class com.sun.grizzly.tcp.StaticResourcesAdapter |
|---|
customizedErrorPage, fireAdapterEvent, getLogger, getRootFolder, service, setLogger, setRootFolder |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int REQUEST_RESPONSE_NOTES
public static final int SERVLETCONFIG_NOTES
protected HashMap<String,Object> properties
| Constructor Detail |
|---|
public ServletAdapter()
public ServletAdapter(String publicDirectory)
publicDirectory - the folder where the static resource are located.| Method Detail |
|---|
public void service(GrizzlyRequest request,
GrizzlyResponse response)
service in class GrizzlyAdapter
public void customizeErrorPage(GrizzlyResponse response,
String message,
int errorCode)
response - the GrizzlyResponsemessage - the Http error messageerroCode - the error code.
public void afterService(GrizzlyRequest request,
GrizzlyResponse response)
throws Exception
afterService in class GrizzlyAdapterException
public void addInitParameter(String name,
String value)
name - Name of this initialization parameter to addvalue - Value of this initialization parameter to add
public void addFilter(Filter filter,
String filterName,
Map initParameters)
Filter to the FilterChain
filter - an instance of FilterfilterName - the Filter's nameinitParameters - the Filter init parameters.public Servlet getServletInstance()
Servlet instance used by this Adapter
public void setServletInstance(Servlet servletInstance)
Servlet instance used by this Adapter
servletInstance - an instance of Servlet.public String getServletPath()
This method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.
String containing
the name or path of the servlet being
called, as specified in the request URL,
decoded, or an empty string if the servlet
used to process the request is matched
using the "/*" pattern.public void setServletPath(String servletPath)
servletPath - public String getContextPath()
It is possible that a servlet container may match a context by
more than one context path. In such cases this method will return the
actual context path used by the request and it may differ from the
path returned by the
ServletContext.getContextPath() method.
The context path returned by
ServletContext.getContextPath()
should be considered as the prime or preferred context path of the
application.
String specifying the
portion of the request URI that indicates the context
of the requestServletContext.getContextPath()public void setContextPath(String contextPath)
contextPath - protected String getBasePath()
protected void setBasePath(String basePath)
ServletContext#getRealPath.
basePath - public Object getProperty(String name)
public void setProperty(String name,
Object value)
public void removeProperty(String name)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||