Package org.restlet.engine.application
Class StatusFilter
- java.lang.Object
-
- org.restlet.Restlet
-
- org.restlet.routing.Filter
-
- org.restlet.engine.application.StatusFilter
-
- All Implemented Interfaces:
Uniform
public class StatusFilter extends Filter
Filter associating a response entity based on the status. In order to customize the default representation, just subclass this class and override the "getRepresentation" method.
If any exception occurs during the call handling, a "server internal error" status is automatically associated to the call. Of course, you can personalize the representation of this error. Also, if no status is set (null), then the "success OK" status is assumed. Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanoverwritingIndicates if existing representations should be overwritten.private StatusServicestatusServiceThe helped status service.
-
Constructor Summary
Constructors Constructor Description StatusFilter(Context context, boolean overwriting, java.lang.String email, Reference homeRef)Constructor.StatusFilter(Context context, StatusService statusService)Constructor from a status service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterHandle(Request request, Response response)Allows filtering after its handling by the target Restlet.protected intdoHandle(Request request, Response response)Handles the call by distributing it to the next Restlet.StatusServicegetStatusService()Returns the helped status service.booleanisOverwriting()Indicates if existing representations should be overwritten.voidsetOverwriting(boolean overwriting)Indicates if existing representations should be overwritten.voidsetStatusService(StatusService statusService)Sets the helped status service.-
Methods inherited from class org.restlet.routing.Filter
beforeHandle, getNext, handle, hasNext, setNext, setNext, start, stop
-
Methods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner
-
-
-
-
Field Detail
-
overwriting
private volatile boolean overwriting
Indicates if existing representations should be overwritten.
-
statusService
private volatile StatusService statusService
The helped status service.
-
-
Constructor Detail
-
StatusFilter
public StatusFilter(Context context, boolean overwriting, java.lang.String email, Reference homeRef)
Constructor.- Parameters:
context- The context.overwriting- Indicates whether an existing representation should be overwritten.
-
StatusFilter
public StatusFilter(Context context, StatusService statusService)
Constructor from a status service.- Parameters:
context- The context.statusService- The helped status service.
-
-
Method Detail
-
afterHandle
public void afterHandle(Request request, Response response)
Allows filtering after its handling by the target Restlet. If the status is not set, setStatus.SUCCESS_OKby default. If this is an error status, try to get a representation of it withStatusService.toRepresentation(Status, Request, Response).- Overrides:
afterHandlein classFilter- Parameters:
request- The request to handle.response- The response to update.
-
doHandle
protected int doHandle(Request request, Response response)
Handles the call by distributing it to the next Restlet. If a throwable is caught, theStatusService.toStatus(Throwable, Request, Response)method is invoked.
-
getStatusService
public StatusService getStatusService()
Returns the helped status service.- Returns:
- The helped status service.
-
isOverwriting
public boolean isOverwriting()
Indicates if existing representations should be overwritten.- Returns:
- True if existing representations should be overwritten.
-
setOverwriting
public void setOverwriting(boolean overwriting)
Indicates if existing representations should be overwritten.- Parameters:
overwriting- True if existing representations should be overwritten.
-
setStatusService
public void setStatusService(StatusService statusService)
Sets the helped status service.- Parameters:
statusService- The helped status service.
-
-