STR-3168: Skip processing if no action is specified

git-svn-id: https://svn.apache.org/repos/asf/struts/struts1/trunk@729574 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java b/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
index ca7ae0c..ec2dc48 100644
--- a/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
+++ b/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
@@ -39,6 +39,8 @@
 
     private static final Log log = LogFactory.getLog(ExecuteDispatcher.class);
 
+    private String defaultDispatcherType;
+
     /**
      * Creates the dispatcher of the specified type.
      * 
@@ -49,52 +51,65 @@
      * @see ClassUtils#getApplicationInstance(String)
      */
     protected Dispatcher createDispatcher(String type, ActionContext context) throws Exception {
-        log.info("Initializing dispatcher of type: " + type);
-        return (Dispatcher) ClassUtils.getApplicationInstance(type);
+	log.info("Initializing dispatcher of type: " + type);
+	return (Dispatcher) ClassUtils.getApplicationInstance(type);
     }
 
     public boolean execute(ActionContext context) throws Exception {
-        // Skip processing if the current request is not valid
-        Boolean valid = context.getFormValid();
-        if ((valid == null) || !valid.booleanValue()) {
+	// Skip processing if the current request is not valid
+	Boolean valid = context.getFormValid();
+	if ((valid == null) || !valid.booleanValue()) {
+	    return CONTINUE_PROCESSING;
+	}
+
+        // Skip processing if no action is specified
+        if (context.getAction() == null) {
             return CONTINUE_PROCESSING;
         }
 
-        // Skip processing if no dispatcher type specified
-        String dispatcherType = getDispatcherType(context);
-        if (dispatcherType == null) {
-            return CONTINUE_PROCESSING;
-        }
+	// Skip processing if no dispatcher type specified
+	String dispatcherType = getDispatcherType(context);
+	if (dispatcherType == null) {
+	    return CONTINUE_PROCESSING;
+	}
 
-        // Obtain (or create) the dispatcher cache
-        String cacheKey = Constants.DISPATCHERS_KEY + context.getModuleConfig().getPrefix();
-        Map dispatchers = (Map) context.getApplicationScope().get(cacheKey);
-        if (dispatchers == null) {
-            dispatchers = new HashMap();
-            context.getApplicationScope().put(cacheKey, dispatchers);
-        }
+	// Obtain (or create) the dispatcher cache
+	String cacheKey = Constants.DISPATCHERS_KEY + context.getModuleConfig().getPrefix();
+	Map dispatchers = (Map) context.getApplicationScope().get(cacheKey);
+	if (dispatchers == null) {
+	    dispatchers = new HashMap();
+	    context.getApplicationScope().put(cacheKey, dispatchers);
+	}
 
-        // Lookup (or create) the dispatch instance
-        Dispatcher dispatcher = null;
-        synchronized (dispatchers) {
-            ActionConfig actionConfig = context.getActionConfig();
-            String actionType = actionConfig.getType();
-            dispatcher = (Dispatcher) dispatchers.get(actionType);
-            if (dispatcher == null) {
-                dispatcher = createDispatcher(dispatcherType, context);
-                dispatchers.put(actionType, dispatcher);
-            }
-        }
+	// Lookup (or create) the dispatch instance
+	Dispatcher dispatcher = null;
+	synchronized (dispatchers) {
+	    ActionConfig actionConfig = context.getActionConfig();
+	    String actionType = actionConfig.getType();
+	    dispatcher = (Dispatcher) dispatchers.get(actionType);
+	    if (dispatcher == null) {
+		dispatcher = createDispatcher(dispatcherType, context);
+		dispatchers.put(actionType, dispatcher);
+	    }
+	}
 
-        // Dispatch
-        Object result = dispatcher.dispatch(context);
-        processDispatchResult(result, context);
+	// Dispatch
+	Object result = dispatcher.dispatch(context);
+	processDispatchResult(result, context);
 
-        return CONTINUE_PROCESSING;
+	return CONTINUE_PROCESSING;
+    }
+
+    public final String getDefaultDispatcherType() {
+	return defaultDispatcherType;
     }
 
     protected String getDispatcherType(ActionContext context) {
-        return (context != null) ? context.getActionConfig().getDispatcher() : null;
+	String dispatcherType = null;
+	if (context != null) {
+	    dispatcherType = context.getActionConfig().getDispatcher();
+	}
+	return (dispatcherType != null) ? dispatcherType : defaultDispatcherType;
     }
 
     /**
@@ -119,33 +134,37 @@
      * @see ActionMapping#findRequiredForward(String)
      */
     protected void processDispatchResult(Object result, ActionContext context) {
-        // Null means the response was handled directly
-        if (result == null) {
-            return;
-        }
+	// Null means the response was handled directly
+	if (result == null) {
+	    return;
+	}
 
-        // A forward is the classical response
-        if (result instanceof ForwardConfig) {
-            context.setForwardConfig((ForwardConfig) result);
-            return;
-        }
+	// A forward is the classical response
+	if (result instanceof ForwardConfig) {
+	    context.setForwardConfig((ForwardConfig) result);
+	    return;
+	}
 
-        // String represents the name of a forward
-        ActionConfig actionConfig = context.getActionConfig();
-        ActionMapping mapping = ((ActionMapping) actionConfig);
-        if (result instanceof String) {
-            context.setForwardConfig(mapping.findRequiredForward((String) result));
-            return;
-        }
+	// String represents the name of a forward
+	ActionConfig actionConfig = context.getActionConfig();
+	ActionMapping mapping = ((ActionMapping) actionConfig);
+	if (result instanceof String) {
+	    context.setForwardConfig(mapping.findRequiredForward((String) result));
+	    return;
+	}
 
-        // Select success if no return signature
-        if (result instanceof Void) {
-            context.setForwardConfig(mapping.findRequiredForward(Action.SUCCESS));
-            return;
-        }
+	// Select success if no return signature
+	if (result instanceof Void) {
+	    context.setForwardConfig(mapping.findRequiredForward(Action.SUCCESS));
+	    return;
+	}
 
-        // Unknown result type
-        throw new IllegalStateException("Unknown dispatch return type: " + result.getClass().getName());
+	// Unknown result type
+	throw new IllegalStateException("Unknown dispatch return type: " + result.getClass().getName());
+    }
+
+    public final void setDefaultDispatcherType(String defaultDispatcherType) {
+	this.defaultDispatcherType = defaultDispatcherType;
     }
 
 }