|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.tomcat.core.BaseInterceptor
Implement "Chain of Responsiblity" pattern ( == hooks ). You can extend this class and implement a number of hooks. The interceptor is added to a Container ( that represents a group of URLs where the interceptor will operate ) and the methods that are re-defined in the subclass are detected ( using introspection ) and used to select the chains where the intercepptor is interested to participate. It is possible to define new chains by adding a new method to this class. The caller ( "chain user" ) will determine the behavior in case of error and "call all" or "call until [condition]" rules. Interceptors are the main extension mechanism for tomcat. They have full access and control all aspects in tomcat operation.
Sandboxing. Tomcat may be run in a java2 sandboxed environment. All request processing callbacks can be initiated as a result of user ( untrusted ) code ( for example - a servlet creating a new session ). The module is responsible for using doPriviledged() blocks for all actions that require special priviledges. "Base" modules ( included in the distribution ) that perform essential functionality must also ensure JDK1.1 compatibility. The priviledged block must be as small as possible and do only a clearly defined action.
Field Summary | |
protected ContextManager |
cm
|
protected Container |
ct
|
protected Context |
ctx
|
protected int |
debug
|
static int |
DECLINED
|
protected Log |
loghelper
|
static int |
OK
|
Constructor Summary | |
BaseInterceptor()
|
Method Summary | |
void |
addContainer(Container container)
Notify that certain properties are defined for a URL pattern. |
void |
addContext(ContextManager cm,
Context ctx)
Called when a context is added to a CM. |
void |
addHandler(Handler h)
Notification of a new content handler added to a context |
void |
addInterceptor(ContextManager cm,
Context ctx,
BaseInterceptor i)
Hook called when a new interceptor is added. |
void |
addSecurityConstraint(Context ctx,
java.lang.String path,
Container ct)
|
int |
afterBody(Request request,
Response response)
Called after the output stream is closed ( either by servlet or automatically at end of service ). |
int |
authenticate(Request request,
Response response)
This callback is used to extract and verify the user identity and credentials. |
int |
authorize(Request request,
Response response,
java.lang.String[] reqRoles)
Will check if the current ( authenticated ) user is authorized to access a resource, by checking if it have one of the required roles. |
int |
beforeBody(Request rrequest,
Response response)
Called before the first body write, and before sending the headers. |
int |
beforeCommit(Request request,
Response response)
Called before the output buffer is commited. |
void |
contextInit(Context ctx)
Notify when a context is initialized. |
int |
contextMap(Request rrequest)
Will detect the context path for a request. |
void |
contextShutdown(Context ctx)
Called when a context is stoped, before removeContext. |
void |
contextState(Context ctx,
int newState)
Notify that the context state changed |
void |
copyContext(Request req,
Context oldC,
Context newC)
Reload notification - called whenever a full reload is done. |
void |
engineInit(ContextManager cm)
Initialize the module. |
void |
engineShutdown(ContextManager cm)
Shut down the module. |
void |
engineStart(ContextManager cm)
Notify that the server is ready and able to process requests |
void |
engineState(ContextManager cm,
int state)
Notifies the module that the server changed it's state. |
void |
engineStop(ContextManager cm)
Notify that the server is disabled and shoulnd't process more requests |
ServerSession |
findSession(Request req,
java.lang.String reqSessionId,
boolean create)
The hook for session managers. |
Context |
getContext()
|
ContextManager |
getContextManager()
|
int |
getDebug()
|
java.lang.Object |
getInfo(Context ctx,
Request request,
int id,
java.lang.String key)
Hook for lazy evaluation of request info. |
Log |
getLog()
|
java.lang.Object |
getNote(int pos)
|
java.lang.Object |
getNote(java.lang.String name)
|
int |
handleError(Request request,
Response response,
java.lang.Throwable t)
This callback is called whenever an exception happen. |
void |
log(java.lang.String s)
|
void |
log(java.lang.String s,
int level)
|
void |
log(java.lang.String s,
java.lang.Throwable t)
|
void |
log(java.lang.String s,
java.lang.Throwable t,
int level)
|
int |
postInitCheck(Request req,
Handler sw)
|
int |
postReadRequest(Request request)
Called immediately after the request has been received, before any mapping. |
int |
postRequest(Request request,
Response response)
Experimental hook: called after the request is finished, before returning to the caller. |
int |
postService(Request request,
Response response)
Called after service method ends. |
void |
postServletDestroy(Context ctx,
Handler sw)
|
void |
postServletInit(Context ctx,
Handler sw)
|
int |
preInitCheck(Request req,
Handler sw)
Setup before calling init. |
int |
preService(Request request,
Response response)
Called before service method is invoked. |
void |
preServletDestroy(Context ctx,
Handler sw)
Servlet Destroy notification |
void |
preServletInit(Context ctx,
Handler sw)
Servlet Init notification |
int |
registerHooks(Hooks h,
ContextManager cm,
Context ctx)
Special method for self-registered hooks, intended to support a mechanism similar with Apache2.0 and further extensibility without interface changes. |
void |
reload(Request req,
Context ctx)
Reload notification - called whenever a reload is done. |
void |
removeContainer(Container container)
A rule was removed, update the internal strucures. |
void |
removeContext(ContextManager cm,
Context ctx)
Called when a context is removed from a CM. |
void |
removeHandler(Handler h)
Notification of a content handler removal |
void |
removeInterceptor(ContextManager cm,
Context ctx,
BaseInterceptor i)
Hook called when interceptors are removed. |
int |
requestMap(Request request)
Handle mappings inside a context. |
int |
sessionState(Request req,
ServerSession sess,
int newState)
Hook for session state changes. |
void |
setContext(Context ctx)
Called for context-level interceptors |
void |
setContextManager(ContextManager cm)
|
void |
setDebug(int d)
|
int |
setInfo(Context ctx,
Request request,
int id,
java.lang.String key,
java.lang.Object obj)
|
void |
setNote(int pos,
java.lang.Object value)
|
void |
setNote(java.lang.String name,
java.lang.Object value)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DECLINED
public static final int OK
protected ContextManager cm
protected Container ct
protected Context ctx
protected int debug
protected Log loghelper
Constructor Detail |
public BaseInterceptor()
Method Detail |
public int postReadRequest(Request request)
public int requestMap(Request request)
public int contextMap(Request rrequest)
public int authenticate(Request request, Response response)
public int authorize(Request request, Response response, java.lang.String[] reqRoles)
public int preService(Request request, Response response)
public int beforeBody(Request rrequest, Response response)
public ServerSession findSession(Request req, java.lang.String reqSessionId, boolean create)
reqSessionId
- if null the manager will generate the idpublic int sessionState(Request req, ServerSession sess, int newState)
public int beforeCommit(Request request, Response response)
public int afterBody(Request request, Response response)
public int postService(Request request, Response response)
public int postRequest(Request request, Response response)
public java.lang.Object getInfo(Context ctx, Request request, int id, java.lang.String key)
public int setInfo(Context ctx, Request request, int id, java.lang.String key, java.lang.Object obj)
public int handleError(Request request, Response response, java.lang.Throwable t)
public void addInterceptor(ContextManager cm, Context ctx, BaseInterceptor i) throws TomcatException
cm
- the serverctx
- not null if this is a local interceptori
- the new added interceptor
TomcatException
- The module will not be added if any
module throws an exception.public void removeInterceptor(ContextManager cm, Context ctx, BaseInterceptor i) throws TomcatException
cm
- the serverctx
- not null if this is a local interceptori
- the removed interceptor
TomcatException
- is logged, but will not have any effectpublic void engineInit(ContextManager cm) throws TomcatException
TomcatException
- The module will not be added if any
exception is thrown by engineInit.public void engineShutdown(ContextManager cm) throws TomcatException
If
- any exception is reported, the module will be removed.
XXX (?)
TomcatException
public void engineStart(ContextManager cm) throws TomcatException
TomcatException
public void engineStop(ContextManager cm) throws TomcatException
TomcatException
public void engineState(ContextManager cm, int state) throws TomcatException
TomcatException
public void addContext(ContextManager cm, Context ctx) throws TomcatException
TomcatException
public void removeContext(ContextManager cm, Context ctx) throws TomcatException
TomcatException
public void contextInit(Context ctx) throws TomcatException
If
- the interceptor throws exception the context will
not be initialized ( state==NEW or ADDED or DISABLED ).
TomcatException
public void contextShutdown(Context ctx) throws TomcatException
TomcatException
public void contextState(Context ctx, int newState) throws TomcatException
TomcatException
public void reload(Request req, Context ctx) throws TomcatException
TomcatException
public void copyContext(Request req, Context oldC, Context newC) throws TomcatException
TomcatException
public void addContainer(Container container) throws TomcatException
TomcatException
public void removeContainer(Container container) throws TomcatException
TomcatException
public void addSecurityConstraint(Context ctx, java.lang.String path, Container ct) throws TomcatException
TomcatException
public void addHandler(Handler h) throws TomcatException
TomcatException
public void removeHandler(Handler h) throws TomcatException
TomcatException
public void preServletInit(Context ctx, Handler sw) throws TomcatException
TomcatException
public void postServletInit(Context ctx, Handler sw) throws TomcatException
TomcatException
public int preInitCheck(Request req, Handler sw) throws TomcatException
TomcatException
public int postInitCheck(Request req, Handler sw) throws TomcatException
TomcatException
public void preServletDestroy(Context ctx, Handler sw) throws TomcatException
TomcatException
public void postServletDestroy(Context ctx, Handler sw) throws TomcatException
TomcatException
public final void setDebug(int d)
public void setContextManager(ContextManager cm)
public final ContextManager getContextManager()
public void setContext(Context ctx)
public Context getContext()
public final void log(java.lang.String s)
public final void log(java.lang.String s, java.lang.Throwable t)
public final void log(java.lang.String s, int level)
public final void log(java.lang.String s, java.lang.Throwable t, int level)
public Log getLog()
public final int getDebug()
public int registerHooks(Hooks h, ContextManager cm, Context ctx)
public final void setNote(int pos, java.lang.Object value)
public final java.lang.Object getNote(int pos)
public java.lang.Object getNote(java.lang.String name) throws TomcatException
TomcatException
public void setNote(java.lang.String name, java.lang.Object value) throws TomcatException
TomcatException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |