Friday, April 25, 2014

Gather session Information.

Hi there,

I will not be original, not share inventions or hot insider information. But this trinket could save your time.
There is a very simple yet nice looking servlet to show you full HTTP session state. Believe me, sometime  it's not easy when developer tools in Chrome or *Fox will not tell you truth show you encoded data only.
Personally, I use that for debug and troubleshoot identity management configurations.
It would be useful for any Single Sign-On protected resources.  Right now I'm using it to validate identity federation authentications.

There is a screenshot:
OAM headers visible only from inside session.
I hardly name this minimalist JSP page with couple standard java classes an application but there is a source code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="javax.servlet.http.Cookie" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.Enumeration" %>

<html>
 
<head>
   
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
   
<title>index</title>
   
<style type="text/css" >
        #thdr {
           
background-color: rgb(32,48,255);font-weight: 600;
           
color: white;
           
font-family: sans-serif;
        }
        #content {
           
width: 70%;
           
margin: 0 auto;
           
background-color: rgb(236,236,236);
        }
       
th {
           
text-align: left;
           
font-size: small;
           
font-family: sans-serif;
           
background-color: Silver;
            word-wrap:break-word
        }
       
td {font-size: small; word-wrap:break-word}
       
table {
            
border-spacing: 0px;
            
border-width: 0px;
            
width: 99.5%;
            
table-layout: fixed;
        }
       
body {
           
background-color: rgb(158,158,158);
        }
   
</style>
 
</head>
 
<body>
   
<div align="center" id="content">
     
<h2><strong>Session information </strong></h2>
   
<hr/>
   
<h4>Session Cookies</h4>
   
<% Cookie[] ccs = request.getCookies(); %>
   
<table id="CookieTbl" cellspacing="2" cellpadding="3" border="1" width="100%">
     
<tr ><th width="268" id="thdr">Name</th><th width="872" id="thdr">Value</th></tr>
    
<% for (int i=0;i<ccs.length;i++) {%>
     
<tr><th width="268"><%= ccs[i].getName()%></th><td width="872"><%=ccs[i].getValue()%></td></tr>
    
<% }%>
   
</table>
   
<p/>
   
<h4>Request Headers</h4>
   
<% Enumeration hdrs = request.getHeaderNames(); %>
   
<table id="RequestHdr" cellspacing="2" cellpadding="3" border="1" width="100%">
     
<tr id="thdr"><th width="268" id="thdr">Name</th><th width="872" id="thdr">Value</th></tr>
     
<% String hdr=null;
        
while(hdrs.hasMoreElements()){ hdr=hdrs.nextElement().toString();%>
         
<tr>
             
<th width="268"><%=hdr%></th>
             
<td width="872"><%= request.getHeader(hdr)%></td>
         
</tr>
     
<%}%>
   
</table>
   
<p/>
   
<h4>Request Parameters</h4>
   
<% Map<String,String[]> params = request.getParameterMap(); %>
   
<table id="RequestPrm" cellspacing="2" cellpadding="3" border="1"
          
width="100%">
     
<tr id="thdr"><th width="268" id="thdr" height="26">Name</th><th width="872" id="thdr"
                                                                      
height="26">Value</th></tr>
     
<% for (Map.Entry<String,String[]> param : params.entrySet()){ %>
     
<tr><th width="268" rowspan="<%=param.getValue().length%>">
         
<%= param.getKey()%></th>
         
<td width="872"><%= param.getValue()[0]%></td></tr>
         
<% for (int i=1;i<param.getValue().length;i++) {%>
             
<tr><td width="872"><%=param.getValue()[i]%></td></tr>
         
<%}%>
     
<%} %>
   
</table>
   
<hr/>
   
</div>
 
</body>
</html>
And if you use JDeveloper there is ready to project.

Save time for life and have a good weekend,