KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > tomcat > security > WebUtil


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.web.tomcat.security;
8
9 import java.util.Enumeration JavaDoc;
10
11 import javax.servlet.http.HttpServletRequest JavaDoc;
12
13 /**
14  * Provides utility static methods for the web security integration
15  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
16  * @version $Revision$
17  * @since Aug 22, 2006
18  */

19 public class WebUtil
20 {
21    /**
22     * Obtain debug information from the servlet request object
23     * @param httpRequest
24     * @return
25     */

26    public static String JavaDoc deriveUsefulInfo(HttpServletRequest JavaDoc httpRequest)
27    {
28       StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
29       sb.append("[").append(httpRequest.getContextPath());
30       sb.append(":cookies=").append(httpRequest.getCookies()).append(":headers=");
31       //Append Header information
32
Enumeration JavaDoc en = httpRequest.getHeaderNames();
33       for(;en.hasMoreElements();)
34       {
35          String JavaDoc headerName = (String JavaDoc)en.nextElement();
36          sb.append(headerName).append("=");
37          sb.append(httpRequest.getHeader(headerName)).append(",");
38       }
39       sb.append("]");
40       //Append Request parameter information
41
sb.append("[parameters=");
42       Enumeration JavaDoc enparam = httpRequest.getParameterNames();
43       for(;enparam.hasMoreElements();)
44       {
45          String JavaDoc paramName = (String JavaDoc)enparam.nextElement();
46          String JavaDoc[] paramValues = httpRequest.getParameterValues(paramName);
47          int len = paramValues != null ? paramValues.length : 0;
48          for(int i = 0 ; i < len ; i++)
49             sb.append(paramValues[i]).append("::");
50          sb.append(",");
51       }
52       sb.append("][attributes=");
53       //Append Request attribute information
54
Enumeration JavaDoc enu = httpRequest.getAttributeNames();
55       for(;enu.hasMoreElements();)
56       {
57          String JavaDoc attrName = (String JavaDoc)enu.nextElement();
58          sb.append(attrName).append("=");
59          sb.append(httpRequest.getAttribute(attrName)).append(",");
60       }
61       sb.append("]");
62       return sb.toString();
63    }
64 }
65
Popular Tags