Dumping a Portlet Session for debugging
Below is Java code to dump a portlet session for debugging.
import org.apache.struts2.portlet.context.PortletActionContext;
/** Dump the portlet action context session, for debugging. */
private static void dumpPortletSession() {
System.out.println("=========================================================");
PortletSession session = PortletActionContext.getRequest().getPortletSession();
System.out.println("Session reference: " + session);
System.out.println("Session APPLICATION_SCOPE attributes:");
Enumeration attributeNames = session.getAttributeNames(PortletSession.APPLICATION_SCOPE);
while (attributeNames.hasMoreElements()) {
String attributeName = (String) attributeNames.nextElement();
Object value = session.getAttribute(attributeName);
System.out.println(" --> " + attributeName + " = " + value);
}
System.out.println("Session PORTLET_SCOPE attributes:");
attributeNames = session.getAttributeNames(PortletSession.PORTLET_SCOPE);
while (attributeNames.hasMoreElements()) {
String attributeName = (String) attributeNames.nextElement();
Object value = session.getAttribute(attributeName);
System.out.println(" --> " + attributeName + " = " + value);
}
System.out.println("");
System.out.println("=========================================================");
}