|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.restlet.Handler
public abstract class Handler
Final handler of calls typically created by Finders. Handler instances allow
the processing of a call in a thread-safe context. This is different from the
Uniform subclasses like Restlet, Filter and Router which can be invoked by
multiple threads at the same time. However, as they offer a rather low-level
API and its subclass Resource
is often preferred
for concrete handlers.
This class exposes a different set of handle*() and allow*() Java methods for
each type of Uniform method supported by your handler. It has a predefined
set for common methods like GET, POST, PUT, DELETE, HEAD and OPTIONS.
Extension methods like MOVE or PATCH are automatically supported using Java
introspection. The actual dispatching of the call to those methods is
dynamically done by the Finder
class.
The HEAD method has a default implementation based on the GET method and the
OPTIONS method automatically updates the list of allowed methods in the
response, as required by the HTTP specification.
Also, you can declare which REST methods are allowed by your Handler by
overiding the matching allow*() method. By default, allowOptions() returns
true, but all other allow*() methods will return false. Therefore, if you
want to accept MOVE method calls, just override allowMove() and return true.
Again, the invoking Finder will be able to detect this method and know
whether or not your Handler should be invoked. It is also used by the
handleOptions() method to return the list of allowed methods.
Concurrency note: typically created by Finders, Handler instances are the
final handlers of requests. Unlike the other processors in the Restlet chain,
a Handler instance is not reused by several calls and is only invoked by one
thread. Therefore, it doesn't have to be thread-safe.
Finder
Constructor Summary | |
---|---|
Handler()
Special constructor used by IoC frameworks. |
|
Handler(Context context,
Request request,
Response response)
Normal constructor. |
Method Summary | |
---|---|
boolean |
allowDelete()
Indicates if DELETE calls are allowed. |
boolean |
allowGet()
Indicates if GET calls are allowed. |
boolean |
allowHead()
Indicates if HEAD calls are allowed. |
boolean |
allowOptions()
Indicates if OPTIONS calls are allowed. |
boolean |
allowPost()
Indicates if POST calls are allowed. |
boolean |
allowPut()
Indicates if PUT calls are allowed. |
Reference |
generateRef(java.lang.String uriTemplate)
Generates a reference based on a template URI. |
java.util.Set<Method> |
getAllowedMethods()
Returns the set of allowed methods. |
Application |
getApplication()
Returns the parent application if it exists, or null. |
Context |
getContext()
Returns the context. |
java.util.logging.Logger |
getLogger()
Returns the logger to use. |
Form |
getMatrix()
Returns the optional matrix of the request's target resource reference as a form (series of parameters). |
Form |
getQuery()
Returns the parsed query of the request's target resource reference as a form (series of parameters). |
Request |
getRequest()
Returns the request. |
Response |
getResponse()
Returns the response. |
void |
handleDelete()
Handles a DELETE call. |
void |
handleGet()
Handles a GET call. |
void |
handleHead()
Handles a HEAD call. |
void |
handleOptions()
Handles an OPTIONS call introspecting the target resource (as provided by the 'findTarget' method). |
void |
handlePost()
Handles a POST call. |
void |
handlePut()
Handles a PUT call. |
void |
init(Context context,
Request request,
Response response)
Initialize the resource with its context. |
void |
setContext(Context context)
Sets the parent context. |
void |
setRequest(Request request)
Sets the request to handle. |
void |
setResponse(Response response)
Sets the response to update. |
void |
updateAllowedMethods()
Updates the set of allowed methods on the response. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Handler()
public Handler(Context context, Request request, Response response)
context
- The parent context.request
- The request to handle.response
- The response to return.Method Detail |
---|
public boolean allowDelete()
public boolean allowGet()
public boolean allowHead()
public boolean allowOptions()
public boolean allowPost()
public boolean allowPut()
public Reference generateRef(java.lang.String uriTemplate)
uriTemplate
- The URI template to use for generation.
public java.util.Set<Method> getAllowedMethods()
public Application getApplication()
public Context getContext()
public java.util.logging.Logger getLogger()
public Form getMatrix()
Reference.getMatrixAsForm()
public Form getQuery()
Reference.getQueryAsForm()
public Request getRequest()
public Response getResponse()
public void handleDelete()
Status.SERVER_ERROR_INTERNAL
.
public void handleGet()
Status.SERVER_ERROR_INTERNAL
.
public void handleHead()
public void handleOptions()
public void handlePost()
Status.SERVER_ERROR_INTERNAL
.
public void handlePut()
Status.SERVER_ERROR_INTERNAL
.
public void init(Context context, Request request, Response response)
context
- The parent context.request
- The request to handle.response
- The response to return.public void setContext(Context context)
context
- The parent context.public void setRequest(Request request)
request
- The request to handle.public void setResponse(Response response)
response
- The response to update.public void updateAllowedMethods()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |