01 package com.x8ing.mc.web;
02
03 import java.text.DateFormat;
04 import java.text.SimpleDateFormat;
05 import java.util.Calendar;
06 import java.util.Locale;
07
08 import javax.servlet.ServletRequestEvent;
09 import javax.servlet.ServletRequestListener;
10 import javax.servlet.http.HttpServletRequest;
11
12 public class GlobalRequestListener implements ServletRequestListener {
13
14 public void requestDestroyed(ServletRequestEvent sre) {
15 // get perflog event from request
16 }
17
18 public void requestInitialized(ServletRequestEvent sre) {
19
20 HttpServletRequest req = (HttpServletRequest) sre.getServletRequest();
21
22 String sessionID = "null";
23 if (req.getSession() != null) {
24 sessionID = req.getSession().getId();
25 }
26
27 String mimeType = req.getContentType();
28
29 String remoteInfo = "remoteAddr=" + req.getRemoteAddr() + " remoteHost=" + req.getRemoteHost() + " referer="
30 + req.getHeader("Referer") + " user=" + req.getRemoteUser() + " remotePort=" + req.getRemotePort()
31 + " sessionID=" + sessionID;
32 String servletInfo = "servletPath=" + req.getServletPath();
33
34 DateFormat df = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.S", Locale.GERMAN);
35
36 System.out.println(df.format(Calendar.getInstance().getTime()) + " request: " + remoteInfo + " " + servletInfo
37 + " mimeType=" + mimeType);
38
39 }
40
41 }
|