|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xlightweb.HttpRequestHandler
public class HttpRequestHandler
Provides an abstract class to be subclassed to implement a
IHttpRequestHandler
. A subclass of HttpRequestHandlerAdapter
must override at least one method, usually one of these:
doGet
, if the implementation supports HTTP GET requests
doPost
, for HTTP POST requests
doPut
, for HTTP PUT requests
doDelete
, for HTTP DELETE requests
class MyRequestHandler extends HttpRequestHandler { @Override protected void doGet(IHttpExchange exchange) throws IOException, BadMessageException { exchange.send(new HttpResponse(200, "text/plain", "GET called")); } @Override protected void doPost(IHttpExchange exchange) throws IOException, BadMessageException { exchange.send(new HttpResponse(200, "text/plain", "POST called")); } }For more examples see
IHttpRequestHandler
Field Summary |
---|
Fields inherited from interface org.xlightweb.IHttpRequestHandler |
---|
DEFAULT_EXECUTION_MODE, DEFAULT_INVOKE_ON_MODE, DEFAULT_SYNCHRONIZED_ON_MODE |
Constructor Summary | |
---|---|
HttpRequestHandler()
|
Method Summary | |
---|---|
void |
doDelete(IHttpExchange exchange)
call back which will be called, if a DELETE request is received This method does not need to be either safe or idempotent. |
void |
doGet(IHttpExchange exchange)
call back which will be called, if a GET request is received Overriding this method to support a GET request also automatically supports an HTTP HEAD request. |
void |
doHead(IHttpExchange exchange)
call back which will be called, if a HEAD request is received The client sends a HEAD request when it wants to see only the headers of a response, such as Content-Type or Content-Length. |
void |
doOptions(IHttpExchange exchange)
call back which will be called, if a OPTIONS request is received |
void |
doPost(IHttpExchange exchange)
call back which will be called, if a POST request is received This method does not need to be either safe or idempotent. |
void |
doPut(IHttpExchange exchange)
call back which will be called, if a PUT request is received This method does not need to be either safe or idempotent. |
void |
doTrace(IHttpExchange exchange)
call back which will be called, if a TRACE request is received |
void |
onRequest(IHttpExchange exchange)
call back method, which will be called if a request message (header) is received |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HttpRequestHandler()
Method Detail |
---|
public final void onRequest(IHttpExchange exchange) throws IOException
onRequest
in interface IHttpRequestHandler
exchange
- 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 closedpublic void doGet(IHttpExchange exchange) throws IOException, BadMessageException
Overriding this method to support a GET request also automatically supports an HTTP HEAD request. A HEAD request is a GET request that returns no body in the response, only the request header fields.
The GET method should also be idempotent, meaning that it can be safely repeated.
exchange
- the exchange
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 closedpublic void doPost(IHttpExchange exchange) throws IOException, BadMessageException
This method does not need to be either safe or idempotent. Operations requested through POST can have side effects
exchange
- the exchange
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 closedpublic void doPut(IHttpExchange exchange) throws IOException, BadMessageException
This method does not need to be either safe or idempotent.
Operations that doPut
performs can have side
effects
exchange
- the exchange
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 closedpublic void doDelete(IHttpExchange exchange) throws IOException, BadMessageException
This method does not need to be either safe or idempotent. Operations requested through DELETE can have side effects
exchange
- the exchange
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 closedpublic void doHead(IHttpExchange exchange) throws IOException, BadMessageException
The client sends a HEAD request when it wants to see only the headers of a response, such as Content-Type or Content-Length.
exchange
- the exchange
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 closedpublic void doOptions(IHttpExchange exchange) throws IOException, BadMessageException
exchange
- the exchange
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 closedpublic void doTrace(IHttpExchange exchange) throws IOException, BadMessageException
exchange
- the exchange
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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |