Interface IRequestCycleListener

All Known Implementing Classes:
CrossOriginEmbedderPolicyRequestCycleListener, CrossOriginOpenerPolicyRequestCycleListener, CSPRequestCycleListener, PageRequestHandlerTracker, RequestCycleListenerCollection, RequestLoggerRequestCycleListener, ResourceIsolationRequestCycleListener

public interface IRequestCycleListener
A 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:

  1. onBeginRequest(RequestCycle)
  2. onEndRequest(RequestCycle)
  3. onDetach(RequestCycle)

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:

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: