Interface IRequestCycleListener
- All Known Subinterfaces:
ICdiAwareRequestCycleListener
- All Known Implementing Classes:
ConversationPropagator
,CrossOriginEmbedderPolicyRequestCycleListener
,CrossOriginOpenerPolicyRequestCycleListener
,CSPRequestCycleListener
,DetachEventEmitter
,PageRequestHandlerTracker
,RequestCycleListenerCollection
,RequestLoggerRequestCycleListener
,ResourceIsolationRequestCycleListener
,WebSocketAwareResourceIsolationRequestCycleListener
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)
A short example of a request counter.
public class RequestCounter implements IRequestCycleListener { 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:
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
onBeginRequest
(RequestCycle cycle) Called when the request cycle object is beginning its responsedefault void
onDetach
(RequestCycle cycle) Called after the request cycle has been detacheddefault void
onEndRequest
(RequestCycle cycle) Called when the request cycle object has finished its responsedefault IRequestHandler
onException
(RequestCycle cycle, 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 void
onExceptionRequestHandlerResolved
(RequestCycle cycle, IRequestHandler handler, Exception exception) Called when anIRequestHandler
is resolved for an exception and will be executed.default void
onRequestHandlerExecuted
(RequestCycle cycle, IRequestHandler handler) Called after anIRequestHandler
has been executed.default void
onRequestHandlerResolved
(RequestCycle cycle, IRequestHandler handler) Called when anIRequestHandler
is resolved and will be executed.default void
onRequestHandlerScheduled
(RequestCycle cycle, IRequestHandler handler) Called when aIRequestHandler
has been scheduled.default void
onUrlMapped
(RequestCycle cycle, IRequestHandler handler, Url url) Called after a Url is generated for aIRequestHandler
.
-
Method Details
-
onBeginRequest
Called when the request cycle object is beginning its response- Parameters:
cycle
-
-
onEndRequest
Called when the request cycle object has finished its response- Parameters:
cycle
-
-
onDetach
Called after the request cycle has been detached- Parameters:
cycle
-
-
onRequestHandlerResolved
Called when anIRequestHandler
is resolved and will be executed.- Parameters:
cycle
-handler
-
-
onRequestHandlerScheduled
Called when aIRequestHandler
has been scheduled. Can be called multiple times during a request when new handlers get scheduled for processing.- Parameters:
cycle
-handler
-- See Also:
-
onException
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
IWicketInternalException
interface. Usually such kind of exceptions should be handled by the framework.- Parameters:
cycle
- The currentrequest cycle
ex
- the exception that was passed in toRequestCycle.handleException(Exception)
- Returns:
- request handler that will be executed or
null
if none. If a request handler is returned, it will override any configuredexception mapper
.
-
onExceptionRequestHandlerResolved
default void onExceptionRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler, Exception exception) Called when anIRequestHandler
is resolved for an exception and will be executed.- Parameters:
cycle
-handler
-exception
-
-
onRequestHandlerExecuted
Called after anIRequestHandler
has been executed. If the execution resulted in an exception this method will not be called for that particularIRequestHandler
.- Parameters:
cycle
-handler
-
-
onUrlMapped
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
-
-