|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||

java.lang.Objectorg.xlightweb.RequestHandlerChain
public class RequestHandlerChain
Implements a handler chain. The next handler of the chain will be called (in the registering order) by forwarding
the request. See IHttpExchange. Example:
@Execution(Execution.NONTHREADED)
class HeaderLogInterceptor implements IHttpRequestHandler {
public void onRequest(final IHttpExchange exchange) throws IOException {
IHttpResponseHandler respHdl = new IHttpResponseHandler() {
public void onResponse(IHttpResponse response) throws IOException {
System.out.println(response.getResponseHeader());
exchange.send(response);
}
public void onException(IOException ioe) {
System.out.println(ioe.toString());
exchange.sendError(500);
}
};
System.out.println(exchange.getRequest().getRequestHeader());
exchange.forward(exchange.getRequest(), respHdl);
}
}
RequestHandlerChain chain = new RequestHandlerChain();
chain.addLast(new HeaderLogInterceptor());
chain.addLast(new MySeviceHandler());
IServer server = new HttpServer(8080, chain);
server.start();
| Field Summary |
|---|
| Fields inherited from interface org.xlightweb.IHttpRequestHandler |
|---|
DEFAULT_EXECUTION_MODE, DEFAULT_INVOKE_ON_MODE, DEFAULT_SYNCHRONIZED_ON_MODE |
| Fields inherited from interface org.xlightweb.IHttpRequestTimeoutHandler |
|---|
DEFAULT_EXECUTION_MODE |
| Constructor Summary | |
|---|---|
RequestHandlerChain()
constructor |
|
RequestHandlerChain(List<IHttpRequestHandler> handlers)
constructor |
|
| Method Summary | |
|---|---|
void |
addFirst(IHttpRequestHandler handler)
add a handler to the top of the chain |
void |
addLast(IHttpRequestHandler handler)
add a handler to the end of the chain |
void |
clear()
removes all handler |
List<IHttpRequestHandler> |
getHandlers()
returns all handler |
void |
onDestroy()
|
void |
onInit()
|
void |
onRequest(IHttpExchange exchange)
call back method, which will be called if a request message (header) is received |
boolean |
onRequestTimeout(IHttpConnection connection)
see IConnectionTimeoutHandler |
void |
remove(IHttpRequestHandler handler)
removes the handler |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public RequestHandlerChain()
public RequestHandlerChain(List<IHttpRequestHandler> handlers)
handlers - the initial handlers| Method Detail |
|---|
public void addFirst(IHttpRequestHandler handler)
handler - the handler to addpublic void addLast(IHttpRequestHandler handler)
handler - the handler to addpublic void remove(IHttpRequestHandler handler)
handler - the handler to removepublic void clear()
public List<IHttpRequestHandler> getHandlers()
public void onInit()
onInit in interface ILifeCycle
public void onDestroy()
throws IOException
onDestroy in interface ILifeCycleIOException
public void onRequest(IHttpExchange exchange)
throws IOException
onRequest in interface IHttpRequestHandlerexchange - the exchange contains the request from the client is used to send the response
IOException - if an exception occurred. By throwing this exception an error http response message
will be sent by xSocket, if one or more requests are unanswered. The underlying
connection will be closed
BadMessageException - By throwing this exception an error http response message will be sent by xSocket,
which contains the exception message. The underlying connection will be closed
public boolean onRequestTimeout(IHttpConnection connection)
throws IOException
IHttpRequestTimeoutHandlerIConnectionTimeoutHandler
onRequestTimeout in interface IHttpRequestTimeoutHandlerIOExceptionpublic String toString()
toString in class Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||