sun.com Sun Java System Access Manager
 
Sun Microsystems, Inc.

J2EE Policy Agent Sample Application
 
Sample Application

Welcome
J2EE Declarative Security
J2EE Security API
URL Policy Enforcement
Show HTTP Headers
Other Resources

J2EE Agents Guide

J2EE Documentation


 

Showing Request Headers


 
 
<%@ page import="java.util.*" %> <%@ page import="java.net.URLDecoder" %> <% /** Shows all the request headers sent on the current request. */ String fetchMode= request.getParameter("fetch_mode"); Cookie[] cookies = request.getCookies(); String striPlanetDirectoryPro =""; for (int p=0 ; pFetchMode: " + fetchMode + "
\n" + "Request Method : " + request.getMethod() + "
\n" + "Request URI: " + request.getRequestURI() + "
\n" + "Request Protocol : " + request.getProtocol() + "
\n" + "Request Scheme : " + request.getScheme() + "
\n" + "Request Server Name : " + request.getServerName() + "
\n" + "Request Server Port : " + request.getServerPort() + "
\n" + "Request Remote User : " + "REMOTE_USER:"+request.getRemoteUser() + "
\n" + "Cookie iPlanetDirectoryPro : " + "iPlanetDirectoryPro:" + striPlanetDirectoryPro + "|
\n" + "

\n"); if (fetchMode == null) { out.println("Header Attributes can be fetched as either" + " HTTP_HEADER or REQUEST_ATTRIBUTE or HTTP_COOKIE." + "
\n" + " To view attributes specific to the fetch mode, append" + "
\n" + "\t \t
  • ?fetch_mode=HTTP_HEADER or" + "\n" + "
  • ?fetch_mode=REQUEST_ATTRIBUTE or" + "
  • \n" + "
  • ?fetch_mode=HTTP_COOKIE
  • "); fetchMode="HTTP_HEADER"; } if (fetchMode.equals("HTTP_HEADER") || fetchMode.equals("ALL")) { out.println("\n" + "\n" + "
    Header NameHeader Value"); Enumeration headerNames = request.getHeaderNames(); ArrayList alAttrNames = new ArrayList(); while(headerNames.hasMoreElements()) { String headerName = (String)headerNames.nextElement(); out.println("
    " + headerName); out.print(" " + headerName+":"); Enumeration headers = request.getHeaders(headerName); while(headers.hasMoreElements()) { String header = (String)headers.nextElement(); alAttrNames.add((String)header); } Collections.sort(alAttrNames); for(int i=0;i\n"); }else if(fetchMode.equals("REQUEST_ATTRIBUTE") || fetchMode.equals("ALL") ){ %>  
     
    <% /** Shows all the request attributes sent on the current request. */ out.println("

    \n" + "\n" + "\n" + "
    Attribute NameAttribute Value"); Enumeration attrNames = request.getAttributeNames(); ArrayList alAttrNames = new ArrayList(); while(attrNames.hasMoreElements()) { String attrName = (String)attrNames.nextElement(); out.println("
    " + attrName); out.print(" " + attrName+":"); Set attributeSet; if (request.getAttribute(attrName) instanceof Set){ attributeSet=(Set)request.getAttribute(attrName); //out.print((request.getAttribute(attrName)).getClass().getName()); Iterator it = attributeSet.iterator(); while(it.hasNext()) { String attr = (String)it.next(); alAttrNames.add((String)attr); } Collections.sort(alAttrNames); for(int i=0;i cookie"); out.print(" cookie:"); out.print(request.getHeader("cookie")); out.print("$$"); out.print("
    \n"); } else if(fetchMode.equals("HTTP_COOKIE") || fetchMode.equals("ALL")){ %>
     
     
    <% String cookieName; String cookieValue; String cookieValueDecoded; out.println("

    \n" + "\n" + "\n" + "
    Cookie NameCookie Value"); for(int i=0; i" + cookieName); out.print("" + cookieName +":"); cookieValue=cookie.getValue(); int i1; ArrayList alAttrNames; if((cookieValue.indexOf("%") != -1)){ cookieValueDecoded=URLDecoder.decode(cookieValue) +"|"; alAttrNames = new ArrayList(); if (cookieValueDecoded.contains("|")) { while (cookieValueDecoded.contains("|")){ i1 = cookieValueDecoded.indexOf("|"); alAttrNames.add(cookieValueDecoded.substring(0, i1)); cookieValueDecoded = cookieValueDecoded.substring(i1+1,cookieValueDecoded.length()); } Collections.sort(alAttrNames); for (int j=0;j < alAttrNames.size(); j++) { out.print(alAttrNames.get(j) + "|" ); } } out.print("$$"); } else { cookieValue = cookieValue + "|"; // out.print(cookie.getValue() + "|"); //out.println(); alAttrNames = new ArrayList(); if (cookieValue.contains("|")) { while (cookieValue.contains("|")){ i1 = cookieValue.indexOf("|"); alAttrNames.add(cookieValue.substring(0, i1)); cookieValue = cookieValue.substring(i1+1,cookieValue.length()); } Collections.sort(alAttrNames); for (int j=0;j < alAttrNames.size(); j++) { out.print(alAttrNames.get(j) + "|" ); } } out.print("$$"); } } out.print("
    \n"); } %>