In your class that extends WebApplication
or AuthenticatedWebApplication
in the init()
function.
You need to get the request cycle listeners and add your new listener to the list.
So, if you want to output the requested URI you'd do something like this:
getRequestCycleListeners().add(
new AbstractRequestCycleListener()
{
public void onBeginRequest(RequestCycle cycle)
{
if( cycle.getRequest().getContainerRequest() instanceof HttpServletRequest )
{
HttpServletRequest containerRequest =
(HttpServletRequest)cycle.getRequest().getContainerRequest();
System.out.println("URI="+containerRequest.getRequestURI() );
}
};
}
);
Getting the browser info can be done almost anywhere, not necessarily just in the request.
String userAgent = WebSession.get().getClientInfo().getUserAgent();