You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by pb...@apache.org on 2007/11/11 03:57:43 UTC
svn commit: r593842 - in
/struts/struts1/trunk/core/src/main/java/org/apache/struts:
action/ActionResources.properties chain/commands/AbstractSelectInput.java
chain/commands/servlet/SelectInput.java
Author: pbenedict
Date: Sat Nov 10 18:57:41 2007
New Revision: 593842
URL: http://svn.apache.org/viewvc?rev=593842&view=rev
Log:
STR-3094: Log error when input forward does not exist
Modified:
struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionResources.properties
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractSelectInput.java
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/SelectInput.java
Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionResources.properties
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionResources.properties?rev=593842&r1=593841&r2=593842&view=diff
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionResources.properties (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/action/ActionResources.properties Sat Nov 10 18:57:41 2007
@@ -33,6 +33,7 @@
formBean=Error creating form bean of class {0}
forwardPathNull=The path of an ForwardConfig cannot be null
initProcessor=Exception initializing RequestProcessor
+inputUnknown=Action \'{0}\' declares input forward \'{1}\' but no such forward exists
mappingType=Must specify one of "forward", "include" or "type" for path {0}
notAuthorized=User is not authorized to access action {0}
noInput=No input attribute for mapping path {0}
Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractSelectInput.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractSelectInput.java?rev=593842&r1=593841&r2=593842&view=diff
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractSelectInput.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractSelectInput.java Sat Nov 10 18:57:41 2007
@@ -67,51 +67,28 @@
ModuleConfig moduleConfig = actionConfig.getModuleConfig();
// Cache an ForwardConfig back to our input page
- ForwardConfig forwardConfig;
+ ForwardConfig forwardConfig = null;
String input = actionConfig.getInput();
if (moduleConfig.getControllerConfig().getInputForward()) {
if (LOG.isTraceEnabled()) {
LOG.trace("Finding ForwardConfig for '" + input + "'");
}
-
- // If the input parameter is specified, use that, otherwise try
- // to find one in the mapping or the module under the standard
- // conventional "input" name.
- if (input != null) {
- forwardConfig = actionConfig.findForwardConfig(input);
- if (forwardConfig == null) {
- forwardConfig = moduleConfig.findForwardConfig(input);
- }
- } else {
- forwardConfig = actionConfig.findForwardConfig(Action.INPUT);
- if (forwardConfig == null) {
- forwardConfig = moduleConfig.findForwardConfig(Action.INPUT);
- }
+ forwardConfig = inputForward(actionConfig, moduleConfig, input);
+ if (forwardConfig == null) {
+ LOG.error(getErrorMessage(actionCtx, actionConfig));
}
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Delegating to forward() for '" + input + "'");
}
-
- // If no input parameter is specified, try to find one in the
- // module under the standard conventional "input" name. Because
- // the Controller is not setup to treat the input parameter as
- // a mapping, the action mapping check is skipped.
- if (input == null) {
- forwardConfig = moduleConfig.findForwardConfig(Action.INPUT);
- if (forwardConfig != null) {
- input = Action.INPUT;
- }
- }
-
forwardConfig = forward(actionCtx, moduleConfig, input);
}
-
+
if (LOG.isDebugEnabled()) {
LOG.debug("Forwarding back to " + forwardConfig);
}
-
+
actionCtx.setForwardConfig(forwardConfig);
return (false);
@@ -130,4 +107,48 @@
*/
protected abstract ForwardConfig forward(ActionContext context,
ModuleConfig moduleConfig, String uri);
+
+ /**
+ * <p> Retrieve error message from context. </p>
+ *
+ * @param context The <code>Context</code> for the current request
+ * @param actionConfig The current action mapping
+ * @return error message
+ */
+ protected abstract String getErrorMessage(ActionContext context,
+ ActionConfig actionConfig);
+
+ /**
+ * Attempts to resolve the input as a {@link ForwardConfig} attribute.
+ * This method should only invoked if the Controller has its
+ * <code>inputForward</code> property set to <code>true</code>.
+ * If the input parameter is specified, use that, otherwise try
+ * to find one in the mapping or the module under the standard
+ * conventional <code>input</code> name.
+ *
+ * @param actionConfig the config for the target action
+ * @param moduleConfig the config for the module of the action
+ * @param input the name of the input
+ * @return ForwardConfig representing destination
+ * @see Action#INPUT
+ */
+ protected ForwardConfig inputForward(ActionConfig actionConfig,
+ ModuleConfig moduleConfig, String input) {
+ ForwardConfig forwardConfig;
+
+ if (input != null) {
+ forwardConfig = actionConfig.findForwardConfig(input);
+ if (forwardConfig == null) {
+ forwardConfig = moduleConfig.findForwardConfig(input);
+ }
+ } else {
+ forwardConfig = actionConfig.findForwardConfig(Action.INPUT);
+ if (forwardConfig == null) {
+ forwardConfig = moduleConfig.findForwardConfig(Action.INPUT);
+ }
+ }
+
+ return forwardConfig;
+ }
+
}
Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/SelectInput.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/SelectInput.java?rev=593842&r1=593841&r2=593842&view=diff
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/SelectInput.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/SelectInput.java Sat Nov 10 18:57:41 2007
@@ -21,10 +21,14 @@
package org.apache.struts.chain.commands.servlet;
import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionServlet;
import org.apache.struts.chain.commands.AbstractSelectInput;
import org.apache.struts.chain.contexts.ActionContext;
+import org.apache.struts.chain.contexts.ServletActionContext;
+import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.util.MessageResources;
/**
* <p>Validate the properties of the form bean for this request. If there are
@@ -49,4 +53,17 @@
ModuleConfig moduleConfig, String uri) {
return (new ActionForward(null, uri, false, moduleConfig.getPrefix()));
}
+
+ protected String getErrorMessage(ActionContext context,
+ ActionConfig actionConfig) {
+ ServletActionContext servletActionContext =
+ (ServletActionContext) context;
+
+ // Retrieve internal message resources
+ ActionServlet servlet = servletActionContext.getActionServlet();
+ MessageResources resources = servlet.getInternal();
+
+ return resources.getMessage("inputUnknown", actionConfig.getPath(), actionConfig.getInput());
+ }
+
}