<%@ page pageEncoding="UTF-8" session="false" language="java" import=" java.lang.Runtime, java.net.InetAddress, java.util.Collections, java.util.Date, java.util.Enumeration, java.util.ArrayList, java.util.List, java.util.Iterator, java.lang.reflect.Array, java.util.Map, java.util.HashMap, java.text.NumberFormat " %> <%@ include file="htmlescape.jsp" %> <%@ include file="httpheaderreferences.jsp" %> <%@ include file="util.jsp" %> <%! String CREATE_SESSION = "createSession"; String INVALIDATE_SESSION = "invalidateSession"; String MEMORY_INFO = "memoryinfo"; %> <% boolean createSession = request.getParameter(CREATE_SESSION) != null; boolean deleteSession = request.getParameter(INVALIDATE_SESSION) != null; boolean countMemory = request.getParameter(MEMORY_INFO) != null; HttpSession session = request.getSession(createSession); if(null != session && deleteSession) { session.invalidate(); session = null; } Runtime runtime = Runtime.getRuntime(); if("Request Garbage Collection".equals(request.getParameter("request_garbage_collection"))) { runtime.gc(); Thread.sleep(500); // Wait just a second for GC to happen. } %> SessionSnooper - <%=InetAddress.getLocalHost().getHostName()%>

<%= new Date() %>

<%=InetAddress.getLocalHost().getHostName()%>

JVM Memory Info

/>

<% if(countMemory) { %> <% long totalMemory = 0; long freeMemory = 0; long usedMemory = 0; long maxMemory = 0; long unusedMemory = 0; if(countMemory) { maxMemory = runtime.maxMemory(); totalMemory = runtime.totalMemory(); freeMemory = runtime.freeMemory(); usedMemory = totalMemory - freeMemory; unusedMemory = maxMemory - totalMemory; } double usedPercent = (double) usedMemory / (double)maxMemory; double freePercent = (double) freeMemory / (double)maxMemory; double unusedPercent = (double) unusedMemory / (double)maxMemory; int tableHeight = 300; int unusedHeight = (int)(unusedPercent * (double)tableHeight); int usedHeight = (int)(usedPercent * (double)tableHeight); int freeHeight = (int)(freePercent * (double)tableHeight); NumberFormat pf = NumberFormat.getPercentInstance(); pf.setMinimumFractionDigits(1); pf.setMaximumFractionDigits(1); %>
<%= unusedMemory / (1024 * 1024) %> MiB Unallocated <%= maxMemory / (1024 * 1024) %> MiB Maximum
<%= pf.format(new Double((double)freeMemory / (double)totalMemory)) %> Free <%= totalMemory / (1024 * 1024) %> MiB Allocated
<%= pf.format(new Double((double)usedMemory / (double)totalMemory)) %> Used

<% if ("Request Garbage Collection".equals(request.getParameter("request_garbage_collection"))) { %> <% } else { %> <% } %>

Maximum Memory JVM will use: <%= maxMemory %> bytes (<%= maxMemory / 1024 %> KiB, <%= maxMemory / (1024 * 1024) %> MiB)

Memory Not yet Allocated to JVM: <%= unusedMemory %> bytes (<%= unusedMemory / 1024 %> KiB, <%= unusedMemory / (1024*1024) %> MiB)

Total Memory Allocated to JVM: <%= totalMemory %> bytes (<%= (totalMemory / 1024) %> KiB, <%= (totalMemory/(1024*1024)) %> MiB)

Free Memory: <%= freeMemory %> (<%= (freeMemory / 1024) %> KiB, <%= (freeMemory/(1024*1024)) %> MiB)

Memory Used by JVM: <%= usedMemory %> (<%= (usedMemory / 1024) %> KiB, <%= (usedMemory/(1024*1024)) %> MiB)

<% } //if(countMemory) %>
HTTP Request Headers <% Enumeration e = request.getHeaderNames(); if(e.hasMoreElements()) { %> <% while(e.hasMoreElements()) { String name = (String)e.nextElement(); %> <% } %>
Name Value
<%= htmlescape(name) %> <% for(Enumeration hs = request.getHeaders(name); hs.hasMoreElements(); ) { %> <%= htmlescape(String.valueOf(hs.nextElement())) %>
<% } %>
<% } %>
Request Parameters <% List names = new ArrayList(); for(e = request.getParameterNames(); e.hasMoreElements(); ) names.add(e.nextElement()); Collections.sort(names); if(0 <= names.size()) { %> <% for(Iterator i=names.iterator(); i.hasNext(); ) { String name = (String)i.next(); String[] values = request.getParameterValues(name); %> <% } //foreach(request attribute) %>
Name Value(s)
<%= htmlescape(name) %> <% for(int j=0; j <%= htmlescape(values[j]) %>
<% } %>
<% } // if(0 < names.size()) %>
Request Attributes <% if(null == names) names = new ArrayList(); else names.clear(); for(e = request.getAttributeNames(); e.hasMoreElements(); ) names.add(e.nextElement()); Collections.sort(names); if(0 <= names.size()) { %> <% for(Iterator i=names.iterator(); i.hasNext(); ) { String name = (String)i.next(); Object value = request.getAttribute(name); String className = this.getClassName(value); String reqName = "request_" + name; boolean checked = request.getParameter(reqName) != null; %> <% } //foreach(request attribute) %>
Name Class Value
title="<%= (checked ? "Suppress the value of this attribute" : "Display the value of this attribute") %>" /> <%= className %> <%= (checked ? htmlescape(String.valueOf(this.getValue(value))) : "") %>
<% } // if(0 < names.size()) %>
Session <% if(null == session) { %> . <% } else { %>

Session ID: <%=session.getId()%>

<% if(null == names) names = new ArrayList(); else names.clear(); for(e = session.getAttributeNames(); e.hasMoreElements(); ) names.add(e.nextElement()); Collections.sort(names); if(0 <= names.size()) { %> <% for(Iterator i=names.iterator(); i.hasNext(); ) { String name = (String)i.next(); Object value = session.getAttribute(name); String className = this.getClassName(value); String reqName = "session_" + name; boolean checked = request.getParameter(reqName) != null; %> <% } //foreach(session attribute) %>
Name Class Value
title="<%= (checked ? "Suppress the value of this attribute" : "Display the value of this attribute") %>" /> <%= className %> <%= (checked ? htmlescape(String.valueOf(this.getValue(value))) : "") %>
<% } // if(session attributes) } // if(session) %>
Application <% if(null == names) names = new ArrayList(); else names.clear(); for(e = application.getAttributeNames(); e.hasMoreElements(); ) names.add(e.nextElement()); Collections.sort(names); if(0 < names.size()) { %> <% for(Iterator i=names.iterator(); i.hasNext(); ) { String name = (String)i.next(); Object value = application.getAttribute(name); String className = this.getClassName(value); String reqName = "application_" + name; boolean checked = request.getParameter(reqName) != null; %> <% } // foreach(application attribute) %>
Name Class Value
/> <%= className %> <%= (checked ? htmlescape(String.valueOf(this.getValue(value))) : "") %>
<% } // if(application attributes) %>

Creative Commons License Valid XHTML 1.0! Valid CSS!

This work is licensed under a Creative Commons License.