WW-3687 adds Context Path to the error message

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1210360 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Lukasz Lenart
2011-12-05 08:31:39 +00:00
parent 61478a9537
commit bbfd03dfb5
3 changed files with 57 additions and 37 deletions
@@ -26,8 +26,10 @@ package org.apache.struts2.impl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.DefaultActionProxy;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import org.apache.struts2.ServletActionContext;
import java.util.Map;
import java.util.Locale;
public class StrutsActionProxy extends DefaultActionProxy {
@@ -48,7 +50,7 @@ public class StrutsActionProxy extends DefaultActionProxy {
// return invocation.invoke();
// }
// });
return invocation.invoke();
} finally {
if (cleanupContext)
@@ -61,4 +63,18 @@ public class StrutsActionProxy extends DefaultActionProxy {
super.prepare();
}
@Override
protected String getErrorMessage() {
if ((namespace != null) && (namespace.trim().length() > 0)) {
String contextPath = ServletActionContext.getRequest().getContextPath();
return LocalizedTextUtil.findDefaultText(
"struts.exception.missing-package-action.with-context",
Locale.getDefault(),
new String[]{namespace, actionName, contextPath}
);
} else {
return super.getErrorMessage();
}
}
}
@@ -32,3 +32,5 @@ struts.messages.error.content.type.not.allowed=Content-Type not allowed: {0} "{1
struts.messages.error.file.extension.not.allowed=File extension not allowed: {0} "{1}" "{2}" {3}
devmode.notification=Developer Notification (set struts.devMode to false to disable this message):\n{0}
struts.exception.missing-package-action.with-context = There is no Action mapped for namespace [{0}] and action name [{1}] associated with context path [{2}].
@@ -41,15 +41,14 @@ import java.util.Locale;
* @author Rainer Hermanns
* @author Revised by <a href="mailto:hu_pengfei@yahoo.com.cn">Henry Hu</a>
* @author tmjee
*
* @version $Date$ $Id$
* @since 2005-8-6
*/
public class DefaultActionProxy implements ActionProxy, Serializable {
private static final long serialVersionUID = 3293074152487468527L;
private static final Logger LOG = LoggerFactory.getLogger(DefaultActionProxy.class);
private static final long serialVersionUID = 3293074152487468527L;
private static final Logger LOG = LoggerFactory.getLogger(DefaultActionProxy.class);
protected Configuration configuration;
protected ActionConfig config;
@@ -65,7 +64,7 @@ public class DefaultActionProxy implements ActionProxy, Serializable {
protected ActionEventListener actionEventListener;
private boolean methodSpecified=true;
private boolean methodSpecified = true;
/**
* This constructor is private so the builder methods (create*) should be used to create an DefaultActionProxy.
@@ -74,35 +73,35 @@ public class DefaultActionProxy implements ActionProxy, Serializable {
* (like a RMIActionProxy).
*/
protected DefaultActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext) {
this.invocation = inv;
this.cleanupContext = cleanupContext;
if (LOG.isDebugEnabled()) {
LOG.debug("Creating an DefaultActionProxy for namespace " + namespace + " and action name " + actionName);
}
this.cleanupContext = cleanupContext;
if (LOG.isDebugEnabled()) {
LOG.debug("Creating an DefaultActionProxy for namespace " + namespace + " and action name " + actionName);
}
this.actionName = StringEscapeUtils.escapeHtml(actionName);
this.namespace = namespace;
this.executeResult = executeResult;
this.method = StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(methodName));
}
@Inject
public void setObjectFactory(ObjectFactory factory) {
this.objectFactory = factory;
}
@Inject
public void setConfiguration(Configuration config) {
this.configuration = config;
}
@Inject
public void setUnknownHandler(UnknownHandlerManager unknownHandlerManager) {
this.unknownHandlerManager = unknownHandlerManager;
}
@Inject(required=false)
@Inject(required = false)
public void setActionEventListener(ActionEventListener listener) {
this.actionEventListener = listener;
}
@@ -118,7 +117,7 @@ public class DefaultActionProxy implements ActionProxy, Serializable {
public ActionConfig getConfig() {
return config;
}
public void setExecuteResult(boolean executeResult) {
this.executeResult = executeResult;
}
@@ -143,8 +142,8 @@ public class DefaultActionProxy implements ActionProxy, Serializable {
String profileKey = "execute: ";
try {
UtilTimerStack.push(profileKey);
UtilTimerStack.push(profileKey);
retCode = invocation.invoke();
} finally {
if (cleanupContext) {
@@ -169,38 +168,27 @@ public class DefaultActionProxy implements ActionProxy, Serializable {
if (StringUtils.isEmpty(this.method)) {
this.method = ActionConfig.DEFAULT_METHOD;
}
methodSpecified=false;
methodSpecified = false;
}
}
protected void prepare() {
protected void prepare() {
String profileKey = "create DefaultActionProxy: ";
try {
UtilTimerStack.push(profileKey);
config = configuration.getRuntimeConfiguration().getActionConfig(namespace, actionName);
if (config == null && unknownHandlerManager.hasUnknownHandlers()) {
config = unknownHandlerManager.handleUnknownAction(namespace, actionName);
}
if (config == null) {
String message;
if ((namespace != null) && (namespace.trim().length() > 0)) {
message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION, Locale.getDefault(), new String[]{
namespace, actionName
});
} else {
message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_ACTION_EXCEPTION, Locale.getDefault(), new String[]{
actionName
});
}
throw new ConfigurationException(message);
throw new ConfigurationException(getErrorMessage());
}
resolveMethod();
if (!config.isAllowedMethod(method)) {
throw new ConfigurationException("Invalid method: "+method+" for action "+actionName);
throw new ConfigurationException("Invalid method: " + method + " for action " + actionName);
}
invocation.init(this);
@@ -210,6 +198,20 @@ public class DefaultActionProxy implements ActionProxy, Serializable {
}
}
protected String getErrorMessage() {
if ((namespace != null) && (namespace.trim().length() > 0)) {
return LocalizedTextUtil.findDefaultText(
XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION,
Locale.getDefault(),
new String[]{namespace, actionName});
} else {
return LocalizedTextUtil.findDefaultText(
XWorkMessages.MISSING_ACTION_EXCEPTION,
Locale.getDefault(),
new String[]{actionName});
}
}
public boolean isMethodSpecified() {
return methodSpecified;
}