diff --git a/core/src/main/java/org/apache/struts2/util/AttributeMap.java b/core/src/main/java/org/apache/struts2/util/AttributeMap.java index cca191406..48498e3a9 100644 --- a/core/src/main/java/org/apache/struts2/util/AttributeMap.java +++ b/core/src/main/java/org/apache/struts2/util/AttributeMap.java @@ -21,15 +21,14 @@ package org.apache.struts2.util; +import org.apache.struts2.ServletActionContext; + +import javax.servlet.jsp.PageContext; import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.Set; -import javax.servlet.jsp.PageContext; - -import org.apache.struts2.ServletActionContext; - /** * A Map that holds 4 levels of scope. @@ -48,15 +47,12 @@ public class AttributeMap implements Map { protected static final String UNSUPPORTED = "method makes no sense for a simplified map"; - Map context; - public AttributeMap(Map context) { this.context = context; } - public boolean isEmpty() { throw new UnsupportedOperationException(UNSUPPORTED); } @@ -135,4 +131,25 @@ public class AttributeMap implements Map { private PageContext getPageContext() { return (PageContext) context.get(ServletActionContext.PAGE_CONTEXT); } + + @Override + public String toString() { + return "AttributeMap {" + + "request=" + toStringSafe(context.get("request")) + + ", session=" + toStringSafe(context.get("session")) + + ", application=" + toStringSafe(context.get("application")) + + '}'; + } + + private String toStringSafe(Object obj) { + try { + if (obj != null) { + return String.valueOf(obj); + } + return ""; + } catch (Exception e) { + return "Exception thrown: " + e; + } + } + } diff --git a/core/src/main/java/org/apache/struts2/util/StrutsUtil.java b/core/src/main/java/org/apache/struts2/util/StrutsUtil.java index e5ba2bedb..38aa3f3b7 100644 --- a/core/src/main/java/org/apache/struts2/util/StrutsUtil.java +++ b/core/src/main/java/org/apache/struts2/util/StrutsUtil.java @@ -250,6 +250,16 @@ public class StrutsUtil { return Integer.toString(anInt); } + public String toStringSafe(Object obj) { + try { + if (obj != null) { + return String.valueOf(obj); + } + return ""; + } catch (Exception e) { + return "Exception thrown: " + e; + } + } static class ResponseWrapper extends HttpServletResponseWrapper { StringWriter strout; diff --git a/core/src/main/resources/template/simple/debug.ftl b/core/src/main/resources/template/simple/debug.ftl index 821ba0f67..8b2db3d6e 100644 --- a/core/src/main/resources/template/simple/debug.ftl +++ b/core/src/main/resources/template/simple/debug.ftl @@ -43,7 +43,7 @@

Value Stack Contents

- +
<#assign index=1> @@ -65,7 +65,7 @@

Stack Context

These items are available using the #key notation -
ObjectProperty NameProperty Value
+
@@ -73,9 +73,10 @@ <#assign index=1> <#list stack.context.keySet() as contextKey> - + + <#assign index= index + 1>
KeyValue
${contextKey}<#if stack.context.get(contextKey)??>${stack.context.get(contextKey).toString()?html}<#else>null${contextKey}<#if stack.context.get(contextKey)??>${struts.toStringSafe(stack.context.get(contextKey))?html}<#else>null
- \ No newline at end of file +