public interface IRequestCycleListener
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.
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 by
onExceptionRequestHandlerResolved(RequestCycle, org.apache.wicket.request.IRequestHandler, Exception)
Use AbstractRequestCycleListener
for a default, empty implementation as a base class.
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()); } }
AbstractRequestCycleListener
,
Application.getRequestCycleListeners()
Modifier and Type | Method and Description |
---|---|
default void |
onBeginRequest(RequestCycle cycle)
Called when the request cycle object is beginning its response
|
default void |
onDetach(RequestCycle cycle)
Called after the request cycle has been detached
|
default void |
onEndRequest(RequestCycle cycle)
Called when the request cycle object has finished before flushing the response
|
default IRequestHandler |
onException(RequestCycle cycle,
Exception ex)
Called when there is an exception in the request cycle that would normally be handled by
RequestCycle.handleException(Exception)
Note that in the event of an exception, onEndRequest(RequestCycle) will still be called after
these listeners have onException(RequestCycle, Exception) called |
default void |
onExceptionRequestHandlerResolved(RequestCycle cycle,
IRequestHandler handler,
Exception exception)
Called when an
IRequestHandler is resolved for an exception and will be executed. |
default void |
onRequestHandlerExecuted(RequestCycle cycle,
IRequestHandler handler)
Called after an
IRequestHandler has been executed. |
default void |
onRequestHandlerResolved(RequestCycle cycle,
IRequestHandler handler)
Called when an
IRequestHandler is resolved and will be executed. |
default void |
onRequestHandlerScheduled(RequestCycle cycle,
IRequestHandler handler)
Called when a
IRequestHandler has been scheduled. |
default void |
onUrlMapped(RequestCycle cycle,
IRequestHandler handler,
Url url)
Called after a Url is generated for a
IRequestHandler . |
default void onBeginRequest(RequestCycle cycle)
cycle
- default void onEndRequest(RequestCycle cycle)
cycle
- default void onDetach(RequestCycle cycle)
cycle
- default void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
IRequestHandler
is resolved and will be executed.cycle
- handler
- default void onRequestHandlerScheduled(RequestCycle cycle, IRequestHandler handler)
IRequestHandler
has been scheduled. Can be called multiple times during
a request when new handlers get scheduled for processing.cycle
- handler
- RequestCycle.scheduleRequestHandlerAfterCurrent(IRequestHandler)
default IRequestHandler onException(RequestCycle cycle, Exception ex)
RequestCycle.handleException(Exception)
Note that in the event of an exception, onEndRequest(RequestCycle)
will still be called after
these listeners have onException(RequestCycle, Exception)
called
Important: Custom implementations are recommended to not try to
handle exceptions implementing IWicketInternalException
interface.
Usually such kind of exceptions should be handled by the framework.
cycle
- The current request cycle
ex
- the exception that was passed in to
RequestCycle.handleException(Exception)
null
if none. If a request handler
is returned, it will override any configured
exception mapper
.default void onExceptionRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler, Exception exception)
IRequestHandler
is resolved for an exception and will be executed.cycle
- handler
- exception
- default void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler)
IRequestHandler
has been executed. If the execution resulted in an
exception this method will not be called for that particular IRequestHandler
.cycle
- handler
- default void onUrlMapped(RequestCycle cycle, IRequestHandler handler, Url url)
IRequestHandler
. This method can be used to
modify generated urls, for example query parameters can be added.cycle
- handler
- url
- Copyright © 2006–2022 Apache Software Foundation. All rights reserved.