mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
WW-4223 Uses safe toString method to avoid exception during generating debug info
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1534977 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<p />
|
||||
|
||||
<h3>Value Stack Contents</h3>
|
||||
<table border="0" cellpadding="2" cellspacing="0" width="400" bgcolor="#DDDDDD">
|
||||
<table border="0" cellpadding="2" cellspacing="0" bgcolor="#DDDDDD">
|
||||
<tr><th>Object</th><th>Property Name</th><th>Property Value</th></tr>
|
||||
|
||||
<#assign index=1>
|
||||
@@ -65,7 +65,7 @@
|
||||
|
||||
<h3>Stack Context</h3>
|
||||
<i>These items are available using the #key notation</i>
|
||||
<table border="0" cellpadding="2" cellspacing="0" width="400" bgcolor="#DDDDDD">
|
||||
<table border="0" cellpadding="2" cellspacing="0" bgcolor="#DDDDDD">
|
||||
<tr>
|
||||
<th>Key</th><th>Value</th>
|
||||
</tr>
|
||||
@@ -73,9 +73,10 @@
|
||||
<#assign index=1>
|
||||
<#list stack.context.keySet() as contextKey>
|
||||
<tr bgcolor="<#if (index % 2) == 0>#BBBBBB<#else>#CCCCCC</#if>">
|
||||
<td>${contextKey}</td><td><#if stack.context.get(contextKey)??>${stack.context.get(contextKey).toString()?html}<#else>null</#if></td>
|
||||
<td>${contextKey}</td>
|
||||
<td><#if stack.context.get(contextKey)??>${struts.toStringSafe(stack.context.get(contextKey))?html}<#else>null</#if></td>
|
||||
</tr>
|
||||
<#assign index= index + 1>
|
||||
</#list>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user