diff --git a/core/src/main/java/org/apache/struts2/ServletActionContext.java b/core/src/main/java/org/apache/struts2/ServletActionContext.java index cc6a5018d..4a618d904 100644 --- a/core/src/main/java/org/apache/struts2/ServletActionContext.java +++ b/core/src/main/java/org/apache/struts2/ServletActionContext.java @@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.jsp.PageContext; +import org.apache.struts2.dispatcher.mapper.ActionMapping; + import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; @@ -38,6 +40,7 @@ public class ServletActionContext extends ActionContext implements StrutsStatics private static final long serialVersionUID = -666854718275106687L; public static final String STRUTS_VALUESTACK_KEY = "struts.valueStack"; + public static final String ACTION_MAPPING = "struts.actionMapping"; @SuppressWarnings("unused") private ServletActionContext(Map context) { @@ -68,6 +71,15 @@ public class ServletActionContext extends ActionContext implements StrutsStatics public static ValueStack getValueStack(HttpServletRequest req) { return (ValueStack) req.getAttribute(STRUTS_VALUESTACK_KEY); } + + /** + * Gets the action mapping for this context + * + * @return The action mapping + */ + public static ActionMapping getActionMapping() { + return (ActionMapping) ActionContext.getContext().get(ACTION_MAPPING); + } /** * Returns the HTTP page context. diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index 5b7aad305..028e6a4f4 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -375,7 +375,9 @@ public class Dispatcher { // application map wrapping the ServletContext Map application = new ApplicationMap(context); - return createContextMap(requestMap, params, session, application, request, response, context); + Map extraContext = createContextMap(requestMap, params, session, application, request, response, context); + extraContext.put(ServletActionContext.ACTION_MAPPING, mapping); + return extraContext; } /** @@ -388,7 +390,7 @@ public class Dispatcher { * @param applicationMap a Map of all servlet context attributes. * @param request the HttpServletRequest object. * @param response the HttpServletResponse object. - * @param servletContext the ServletContext object. + * @param servletContext the ServletContextmapping object. * @return a HashMap representing the Action context. */ public HashMap createContextMap(Map requestMap, diff --git a/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java b/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java index 79bcadf49..06c621c6c 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java @@ -107,6 +107,7 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics { protected boolean parse = true; protected boolean encode = false; protected String location; + protected String lastFinalLocation; /** * The location to go to after action execution. This could be a JSP page or another action. @@ -119,6 +120,13 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics { public void setLocation(String location) { this.location = location; } + + /** + * Returns the last parsed and encoded location value + */ + public String getLastFinalLocation() { + return lastFinalLocation; + } /** * Set parse to true to indicate that the location should be parsed as an OGNL expression. This @@ -149,7 +157,8 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics { * @throws Exception if an error occurs while executing the result. */ public void execute(ActionInvocation invocation) throws Exception { - doExecute(conditionalParse(location, invocation), invocation); + lastFinalLocation = conditionalParse(location, invocation); + doExecute(lastFinalLocation, invocation); } /** diff --git a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java index 6e4c28ebe..4fad58c57 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java @@ -85,6 +85,8 @@ public class DebuggingInterceptor implements Interceptor { private final static String DEBUG_PARAM = "debug"; private final static String EXPRESSION_PARAM = "expression"; + + private boolean enableXmlWithConsole = false; /** @@ -126,13 +128,15 @@ public class DebuggingInterceptor implements Interceptor { inv.addPreResultListener( new PreResultListener() { public void beforeResult(ActionInvocation inv, String actionResult) { - StringWriter writer = new StringWriter(); - printContext(new PrettyPrintWriter(writer)); - String xml = writer.toString(); - xml = xml.replaceAll("&", "&"); - xml = xml.replaceAll(">", ">"); - xml = xml.replaceAll("<", "<"); - ActionContext.getContext().put("debugXML", xml); + if (enableXmlWithConsole) { + StringWriter writer = new StringWriter(); + printContext(new PrettyPrintWriter(writer)); + String xml = writer.toString(); + xml = xml.replaceAll("&", "&"); + xml = xml.replaceAll(">", ">"); + xml = xml.replaceAll("<", "<"); + ActionContext.getContext().put("debugXML", xml); + } FreemarkerResult result = new FreemarkerResult(); result.setContentType("text/html"); @@ -339,5 +343,15 @@ public class DebuggingInterceptor implements Interceptor { stack.remove(bean); } + + /** + * @param enableXmlWithConsole the enableXmlWithConsole to set + */ + public void setEnableXmlWithConsole(boolean enableXmlWithConsole) { + this.enableXmlWithConsole = enableXmlWithConsole; + } + + + } diff --git a/core/src/test/resources/struts.xml b/core/src/test/resources/struts.xml index f76d04e46..27b64adc9 100644 --- a/core/src/test/resources/struts.xml +++ b/core/src/test/resources/struts.xml @@ -2,8 +2,6 @@ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> - - hello.jsp