Author: pbenedict
Date: Fri Dec 26 17:10:18 2008
New Revision: 729574

URL: http://svn.apache.org/viewvc?rev=729574&view=rev
Log:
STR-3168: Skip processing if no action is specified

Modified:
    
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java

Modified: 
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
URL: 
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java?rev=729574&r1=729573&r2=729574&view=diff
==============================================================================
--- 
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
 (original)
+++ 
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
 Fri Dec 26 17:10:18 2008
@@ -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()) {
-            return CONTINUE_PROCESSING;
-        }
+       // 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 dispatcher type specified
-        String dispatcherType = getDispatcherType(context);
-        if (dispatcherType == null) {
+        // Skip processing if no action is specified
+        if (context.getAction() == 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);
-        }
+       // 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);
+       }
+
+       // 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);
 
-        // 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);
+       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;
-        }
-
-        // A forward is the classical response
-        if (result instanceof ForwardConfig) {
-            context.setForwardConfig((ForwardConfig) result);
-            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;
+       }
+
+       // 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;
+       }
 
-        // 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;
-        }
+       // 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;
     }
 
 }


Reply via email to