Package org.restlet.routing
Class Filter
java.lang.Object
org.restlet.Restlet
org.restlet.routing.Filter
- All Implemented Interfaces:
Uniform
- Direct Known Subclasses:
Authenticator,Authorizer,CorsFilter,Decoder,Encoder,Extractor,LogFilter,RangeFilter,Route,StatusFilter,TemplateDispatcher,TunnelFilter,Validator
Restlet filtering calls before passing them to an attached Restlet. The
purpose is to do some pre-processing or post-processing on the calls going
through it before or after they are actually handled by an attached Restlet.
Also note that you can attach and detach targets while handling incoming
calls as the filter is ensured to be thread-safe.
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.
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.
- Author:
- Jerome Louvel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates that the request processing should continue normally.static final intIndicates that after thebeforeHandle(Request, Response)method, the request processing should skip thedoHandle(Request, Response)method to continue with theafterHandle(Request, Response)method.static final intIndicates that the request processing should stop and return the current response from the filter. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterHandle(Request request, Response response) Allows filtering after processing by the next Restlet.protected intbeforeHandle(Request request, Response response) Allows filtering before processing by the next Restlet.protected intHandles the call by distributing it to the next Restlet.getNext()Returns the next Restlet.final voidHandles a call by first invoking the beforeHandle() method for pre-filtering, then distributing the call to the next Restlet via the doHandle() method.booleanhasNext()Indicates if there is a next Restlet.voidsetNext(Class<? extends ServerResource> targetClass) voidSets the next Restlet.voidstart()Starts the filter and the next Restlet if attached.voidstop()Stops the filter and the next Restlet if attached.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 Details
-
CONTINUE
public static final int CONTINUEIndicates that the request processing should continue normally. If returned from thebeforeHandle(Request, Response)method, the filter then invokes thedoHandle(Request, Response)method. If returned from thedoHandle(Request, Response)method, the filter then invokes theafterHandle(Request, Response)method.- See Also:
-
SKIP
public static final int SKIPIndicates that after thebeforeHandle(Request, Response)method, the request processing should skip thedoHandle(Request, Response)method to continue with theafterHandle(Request, Response)method.- See Also:
-
STOP
public static final int STOPIndicates that the request processing should stop and return the current response from the filter.- See Also:
-
-
Constructor Details
-
Filter
public Filter()Constructor. -
Filter
Constructor.- Parameters:
context- The context.
-
Filter
Constructor.- Parameters:
context- The context.next- The next Restlet.
-
-
Method Details
-
afterHandle
Allows filtering after processing by the next Restlet. Does nothing by default.- Parameters:
request- The request to handle.response- The response to update.
-
beforeHandle
Allows filtering before processing by the next Restlet. ReturnsCONTINUEby default. -
doHandle
Handles the call by distributing it to the next Restlet. If no Restlet is attached, then aStatus.SERVER_ERROR_INTERNALstatus is returned. ReturnsCONTINUEby default. -
getNext
Returns the next Restlet.- Returns:
- The next Restlet or null.
-
handle
Handles a call by first invoking the beforeHandle() method for pre-filtering, then distributing the call to the next Restlet via the doHandle() method. When the handling is completed, it finally invokes the afterHandle() method for post-filtering. -
hasNext
public boolean hasNext()Indicates if there is a next Restlet.- Returns:
- True if there is a next Restlet.
-
setNext
Sets the nextRestletas aFinderfor a givenServerResourceclass. When the call is delegated to theFinderinstance, a new instance of the resource class will be created and will actually handle the request.- Parameters:
targetClass- The target resource class to attach.
-
setNext
Sets the next Restlet. In addition, this method will set the context of the next Restlet if it is null by passing a reference to its own context.- Parameters:
next- The next Restlet.
-
start
Starts the filter and the next Restlet if attached. -
stop
Stops the filter and the next Restlet if attached.
-