Interface IRequestCycleListener
-
- All Known Implementing Classes:
CsrfPreventionRequestCycleListener,PageRequestHandlerTracker,RequestCycleListenerCollection,RequestLoggerRequestCycleListener
public interface IRequestCycleListenerA callback interface for various methods in the request cycle. If you are creating a framework that needs to do something in this methods, rather than extending RequestCycle or one of its subclasses, you should implement this callback and allow users to add your listener to their custom request cycle.These listeners can be added directly to the request cycle when it is created or to the
Application.NOTE: a listener implementation is a singleton and hence needs to ensure proper handling of multi-threading issues.
Call order
The interface methods are ordered in the execution order as Wicket goes through the request cycle:
The previous call sequence is valid for any Wicket request passing through the Wicket filter. Additionally when a request handler was resolved, a new handler scheduled, or an unhandled exception occurred during the request processing, any of the following can be called:
onRequestHandlerResolved(RequestCycle, org.apache.wicket.request.IRequestHandler)onRequestHandlerScheduled(RequestCycle, org.apache.wicket.request.IRequestHandler)onException(RequestCycle, Exception), followed byonExceptionRequestHandlerResolved(RequestCycle, org.apache.wicket.request.IRequestHandler, Exception)
Implementing your own
Use
AbstractRequestCycleListenerfor a default, empty implementation as a base class.Example
A short example of a request counter.
public class RequestCounter extends AbstractRequestCycleListener { private AtomicLong counter = new AtomicLong(0); public void onBeginRequest(RequestCycle cycle) { counter.incrementAndGet(); } public long getRequestCount() { return counter.longValue(); } } public class MyApplication extends WebApplication { public void init() { super.init(); getRequestCycleListeners().add(new RequestCounter()); } }- Author:
- Jeremy Thomerson, Martijn Dashorst
- See Also:
AbstractRequestCycleListener,Application.getRequestCycleListeners()
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidonBeginRequest(RequestCycle cycle)Called when the request cycle object is beginning its responsedefault voidonDetach(RequestCycle cycle)Called after the request cycle has been detacheddefault voidonEndRequest(RequestCycle cycle)Called when the request cycle object has finished its responsedefault org.apache.wicket.request.IRequestHandleronException(RequestCycle cycle, java.lang.Exception ex)Called when there is an exception in the request cycle that would normally be handled byRequestCycle.handleException(Exception)Note that in the event of an exception,onEndRequest(RequestCycle)will still be called after these listeners haveonException(RequestCycle, Exception)calleddefault voidonExceptionRequestHandlerResolved(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler, java.lang.Exception exception)Called when anIRequestHandleris resolved for an exception and will be executed.default voidonRequestHandlerExecuted(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler)Called after anIRequestHandlerhas been executed.default voidonRequestHandlerResolved(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler)Called when anIRequestHandleris resolved and will be executed.default voidonRequestHandlerScheduled(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler)Called when aIRequestHandlerhas been scheduled.default voidonUrlMapped(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler, org.apache.wicket.request.Url url)Called after a Url is generated for aIRequestHandler.
-
-
-
Method Detail
-
onBeginRequest
default void onBeginRequest(RequestCycle cycle)
Called when the request cycle object is beginning its response- Parameters:
cycle-
-
onEndRequest
default void onEndRequest(RequestCycle cycle)
Called when the request cycle object has finished its response- Parameters:
cycle-
-
onDetach
default void onDetach(RequestCycle cycle)
Called after the request cycle has been detached- Parameters:
cycle-
-
onRequestHandlerResolved
default void onRequestHandlerResolved(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler)
Called when anIRequestHandleris resolved and will be executed.- Parameters:
cycle-handler-
-
onRequestHandlerScheduled
default void onRequestHandlerScheduled(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler)
Called when aIRequestHandlerhas been scheduled. Can be called multiple times during a request when new handlers get scheduled for processing.- Parameters:
cycle-handler-- See Also:
RequestCycle.scheduleRequestHandlerAfterCurrent(IRequestHandler)
-
onException
default org.apache.wicket.request.IRequestHandler onException(RequestCycle cycle, java.lang.Exception ex)
Called when there is an exception in the request cycle that would normally be handled byRequestCycle.handleException(Exception)Note that in the event of an exception,onEndRequest(RequestCycle)will still be called after these listeners haveonException(RequestCycle, Exception)calledImportant: Custom implementations are recommended to not try to handle exceptions implementing
IWicketInternalExceptioninterface. Usually such kind of exceptions should be handled by the framework.- Parameters:
cycle- The currentrequest cycleex- the exception that was passed in toRequestCycle.handleException(Exception)- Returns:
- request handler that will be executed or
nullif none. If a request handler is returned, it will override any configuredexception mapper.
-
onExceptionRequestHandlerResolved
default void onExceptionRequestHandlerResolved(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler, java.lang.Exception exception)
Called when anIRequestHandleris resolved for an exception and will be executed.- Parameters:
cycle-handler-exception-
-
onRequestHandlerExecuted
default void onRequestHandlerExecuted(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler)
Called after anIRequestHandlerhas been executed. If the execution resulted in an exception this method will not be called for that particularIRequestHandler.- Parameters:
cycle-handler-
-
onUrlMapped
default void onUrlMapped(RequestCycle cycle, org.apache.wicket.request.IRequestHandler handler, org.apache.wicket.request.Url url)
Called after a Url is generated for aIRequestHandler. This method can be used to modify generated urls, for example query parameters can be added.- Parameters:
cycle-handler-url-
-
-