Author: germuska
Date: Thu Feb 10 19:17:21 2005
New Revision: 153331

URL: http://svn.apache.org/viewcvs?view=rev&rev=153331
Log:
Adjust chain: now, ComposableRequestProcessor ensures that an ActionContext 
instance is created and
used as the initial context to the chain.  ComposableRequestProcessor now 
exposes a protected method
to make it easier for users to instantiate and populate an alternative 
implementation of ActionContext.

Adjusted all command classes to use ActionContext (or ServletActionContext) 
instead of the chain ServletWebContext.

Modified:
    struts/core/trunk/conf/share/chain-config.xml
    struts/core/trunk/src/share/org/apache/struts/actions/ChainAction.java
    
struts/core/trunk/src/share/org/apache/struts/actions/DispatchChainAction.java
    
struts/core/trunk/src/share/org/apache/struts/chain/ComposableRequestProcessor.java
    
struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractSelectModule.java
    
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExceptionHandler.java
    
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java
    
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectForward.java
    
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectInput.java
    
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectModule.java
    
struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java

Modified: struts/core/trunk/conf/share/chain-config.xml
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/conf/share/chain-config.xml?view=diff&r1=153330&r2=153331
==============================================================================
--- struts/core/trunk/conf/share/chain-config.xml (original)
+++ struts/core/trunk/conf/share/chain-config.xml Thu Feb 10 19:17:21 2005
@@ -34,7 +34,7 @@
 <catalog       name="struts">
 
     <define name= "lookup"
-            className= 
"org.apache.struts.chain.commands.generic.WrappingLookupCommand" />
+            className= "org.apache.commons.chain.generic.LookupCommand" />
     <!-- ========== Servlet Complete Request Chain ========================= 
-->
 
     <chain     name="servlet-standard">
@@ -46,7 +46,6 @@
    exceptionCommand="servlet-exception"/>
 
       <lookup
-        
wrapperClassName="org.apache.struts.chain.contexts.ServletActionContext"
         catalogName="struts"
                name="process-action"
            optional="false"/>

Modified: struts/core/trunk/src/share/org/apache/struts/actions/ChainAction.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/actions/ChainAction.java?view=diff&r1=153330&r2=153331
==============================================================================
--- struts/core/trunk/src/share/org/apache/struts/actions/ChainAction.java 
(original)
+++ struts/core/trunk/src/share/org/apache/struts/actions/ChainAction.java Thu 
Feb 10 19:17:21 2005
@@ -22,13 +22,11 @@
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-import org.apache.commons.chain.web.servlet.ServletWebContext;
-
 import org.apache.struts.action.Action;
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
+import org.apache.struts.chain.contexts.ServletActionContext;
 
 /**
  * <p>An <code>Action</code> implementation that delegates to a
@@ -101,10 +99,10 @@
         throws Exception {
 
         // Set up a context for this request
-        Context context = new ServletWebContext
+        ServletActionContext context = new ServletActionContext
             (getServlet().getServletContext(), request, response);
-        context.put("mapping", mapping);
-        context.put("form", form);
+        context.setActionConfig(mapping);
+        context.setActionForm(form);
 
         // Delegate to the specified command
         Command command = getCatalog().getCommand(mapping.getParameter());

Modified: 
struts/core/trunk/src/share/org/apache/struts/actions/DispatchChainAction.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/actions/DispatchChainAction.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/actions/DispatchChainAction.java 
(original)
+++ 
struts/core/trunk/src/share/org/apache/struts/actions/DispatchChainAction.java 
Thu Feb 10 19:17:21 2005
@@ -22,13 +22,11 @@
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
-import org.apache.commons.chain.web.servlet.ServletWebContext;
-
 import org.apache.struts.action.Action;
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
+import org.apache.struts.chain.contexts.ServletActionContext;
 
 /**
  * <p>An <code>Action</code> implementation that delegates to a
@@ -100,10 +98,10 @@
         throws Exception {
 
         // Set up a context for this request
-        Context context = new ServletWebContext
+        ServletActionContext context = new ServletActionContext
             (getServlet().getServletContext(), request, response);
-        context.put("mapping", mapping);
-        context.put("form", form);
+        context.setActionConfig(mapping);
+        context.setActionForm(form);
 
         // Delegate to the specified command
         String name = mapping.getParameter();

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/ComposableRequestProcessor.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/ComposableRequestProcessor.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/ComposableRequestProcessor.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/ComposableRequestProcessor.java
 Thu Feb 10 19:17:21 2005
@@ -18,18 +18,20 @@
 
 
 import java.io.IOException;
+
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 import org.apache.commons.chain.Command;
-import org.apache.commons.chain.web.servlet.ServletWebContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.action.ActionServlet;
 import org.apache.struts.action.RequestProcessor;
-import org.apache.struts.chain.Constants;
+import org.apache.struts.chain.contexts.ActionContext;
+import org.apache.struts.chain.contexts.ServletActionContext;
 import org.apache.struts.config.ControllerConfig;
 import org.apache.struts.config.ModuleConfig;
 import org.apache.struts.upload.MultipartRequestWrapper;
@@ -149,12 +151,7 @@
         request = processMultipart(request);
         
         // Create and populate a Context for this request
-        ServletWebContext context = new ServletWebContext();
-        context.initialize(getServletContext(), request, response);
-        context.put(Constants.ACTION_SERVLET_KEY,
-                    this.servlet);
-        context.put(Constants.MODULE_CONFIG_KEY,
-                    this.moduleConfig);
+        ActionContext context = contextInstance(request, response);
 
         // Create and execute the command.
         try {
@@ -171,7 +168,15 @@
         context.release();
     }
     
-
+    protected ActionContext contextInstance(HttpServletRequest request,
+                                            HttpServletResponse response) {
+        // Create and populate a Context for this request
+        ServletActionContext context = new 
ServletActionContext(getServletContext(), request, response);
+        context.setActionServlet(this.servlet);
+        context.setModuleConfig(this.moduleConfig);
+        return context;
+    }
+    
     /**
      * If this is a multipart request, wrap it with a special wrapper.
      * Otherwise, return the request unchanged.

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractSelectModule.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractSelectModule.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractSelectModule.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/commands/AbstractSelectModule.java
 Thu Feb 10 19:17:21 2005
@@ -19,9 +19,9 @@
 
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
-import org.apache.commons.chain.web.WebContext;
 import org.apache.struts.Globals;
 import org.apache.struts.chain.Constants;
+import org.apache.struts.chain.contexts.ActionContext;
 import org.apache.struts.config.ModuleConfig;
 import org.apache.struts.util.MessageResources;
 
@@ -121,21 +121,21 @@
         String prefix = getPrefix(context);
 
         // Cache the corresponding ModuleConfig and MessageResources instances
-        WebContext wcontext = (WebContext) context;
+        ActionContext actionCtx = (ActionContext) context;
         ModuleConfig moduleConfig = (ModuleConfig)
-            wcontext.getApplicationScope().get(Globals.MODULE_KEY + prefix);
+            actionCtx.getApplicationScope().get(Globals.MODULE_KEY + prefix);
         if (moduleConfig == null) {
             throw new IllegalArgumentException("No module config for prefix '" 
+
                                                prefix + "'");
         }
-        wcontext.put(getModuleConfigKey(), moduleConfig);
-        wcontext.getRequestScope().put(Globals.MODULE_KEY, moduleConfig);
+        actionCtx.put(getModuleConfigKey(), moduleConfig);
+        actionCtx.getRequestScope().put(Globals.MODULE_KEY, moduleConfig);
         MessageResources messageResources = (MessageResources)
-            wcontext.getApplicationScope().get(Globals.MESSAGES_KEY + prefix);
+            actionCtx.getApplicationScope().get(Globals.MESSAGES_KEY + prefix);
         if (messageResources != null) {
-            wcontext.put(getMessageResourcesKey(),
+            actionCtx.put(getMessageResourcesKey(),
                                          messageResources);
-            wcontext.getRequestScope().put(Globals.MESSAGES_KEY,
+            actionCtx.getRequestScope().put(Globals.MESSAGES_KEY,
                                            messageResources);
         }
 

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExceptionHandler.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExceptionHandler.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExceptionHandler.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExceptionHandler.java
 Thu Feb 10 19:17:21 2005
@@ -19,15 +19,16 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import org.apache.commons.chain.Context;
-import org.apache.commons.chain.web.servlet.ServletWebContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.struts.chain.commands.AbstractExceptionHandler;
-import org.apache.struts.chain.Constants;
-import org.apache.struts.chain.commands.util.ClassUtils;
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionMapping;
+import org.apache.struts.chain.Constants;
+import org.apache.struts.chain.commands.AbstractExceptionHandler;
+import org.apache.struts.chain.commands.util.ClassUtils;
+import org.apache.struts.chain.contexts.ServletActionContext;
 import org.apache.struts.config.ActionConfig;
 import org.apache.struts.config.ExceptionConfig;
 import org.apache.struts.config.ForwardConfig;
@@ -91,11 +92,11 @@
         throws Exception {
 
         // Look up the remaining properties needed for this handler
-        ServletWebContext swcontext = (ServletWebContext) context;
+        ServletActionContext sacontext = (ServletActionContext) context;
         ActionForm actionForm = (ActionForm)
-            swcontext.get(getActionFormKey());
-        HttpServletRequest request = swcontext.getRequest();
-        HttpServletResponse response = swcontext.getResponse();
+            sacontext.get(getActionFormKey());
+        HttpServletRequest request = sacontext.getRequest();
+        HttpServletResponse response = sacontext.getResponse();
 
         // Handle this exception
         org.apache.struts.action.ExceptionHandler handler =

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java
 Thu Feb 10 19:17:21 2005
@@ -21,8 +21,8 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.chain.Context;
-import org.apache.commons.chain.web.servlet.ServletWebContext;
 import org.apache.struts.chain.commands.AbstractPerformForward;
+import org.apache.struts.chain.contexts.ServletActionContext;
 import org.apache.struts.config.ForwardConfig;
 import org.apache.struts.config.ModuleConfig;
 import org.apache.struts.upload.MultipartRequestWrapper;
@@ -52,14 +52,14 @@
     protected void perform(Context context,ForwardConfig forwardConfig)
         throws Exception {
 
-        ServletWebContext swcontext = (ServletWebContext) context;
+        ServletActionContext sacontext = (ServletActionContext) context;
         String forwardPath = forwardConfig.getPath();
         String uri = null;
 
         ModuleConfig moduleConfig  = (ModuleConfig) 
context.get(getModuleConfigKey());
         // Resolve module-relative paths
         if (forwardPath.startsWith("/")) {
-            uri = RequestUtils.forwardURL(swcontext.getRequest(),
+            uri = RequestUtils.forwardURL(sacontext.getRequest(),
                                           forwardConfig,
                                           moduleConfig);
         } else {
@@ -67,7 +67,7 @@
         }
 
         // Get the underlying request in the case of a multipart wrapper
-        HttpServletRequest request = swcontext.getRequest();
+        HttpServletRequest request = sacontext.getRequest();
         if (request instanceof MultipartRequestWrapper) {
             request = ((MultipartRequestWrapper) request).getRequest();
         }
@@ -77,12 +77,12 @@
             if (uri.startsWith("/")) {
                 uri = request.getContextPath() + uri;
             }
-            swcontext.getResponse().sendRedirect
-                (swcontext.getResponse().encodeRedirectURL(uri));
+            sacontext.getResponse().sendRedirect
+                (sacontext.getResponse().encodeRedirectURL(uri));
         } else {
             RequestDispatcher rd =
-                swcontext.getContext().getRequestDispatcher(uri);
-            rd.forward(request, swcontext.getResponse());
+                sacontext.getContext().getRequestDispatcher(uri);
+            rd.forward(request, sacontext.getResponse());
         }
 
     }

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectForward.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectForward.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectForward.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectForward.java
 Thu Feb 10 19:17:21 2005
@@ -49,8 +49,8 @@
                                     ModuleConfig moduleConfig,
                                     String uri) {
 
-        return (new ActionForward(null, moduleConfig.getPrefix() + uri,
-                                  false, true));
+        return (new ActionForward(null,  uri,
+                                  false, moduleConfig.getPrefix()));
 
     }
 

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectInput.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectInput.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectInput.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectInput.java
 Thu Feb 10 19:17:21 2005
@@ -50,8 +50,8 @@
                                     ModuleConfig moduleConfig,
                                     String uri) {
 
-        return (new ActionForward(null, moduleConfig.getPrefix() + uri,
-                                  false, true));
+        return (new ActionForward(null, uri,
+                                  false, moduleConfig.getPrefix()));
 
     }
 

Modified: 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectModule.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectModule.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectModule.java
 (original)
+++ 
struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectModule.java
 Thu Feb 10 19:17:21 2005
@@ -18,11 +18,12 @@
 
 
 import javax.servlet.http.HttpServletRequest;
+
 import org.apache.commons.chain.Context;
-import org.apache.commons.chain.web.servlet.ServletWebContext;
 import org.apache.struts.Globals;
-import org.apache.struts.chain.commands.AbstractSelectModule;
 import org.apache.struts.chain.Constants;
+import org.apache.struts.chain.commands.AbstractSelectModule;
+import org.apache.struts.chain.contexts.ServletActionContext;
 
 
 /**
@@ -43,8 +44,8 @@
     protected String getPrefix(Context context) {
 
         // Identify the URI from which we will match a module prefix
-        ServletWebContext swcontext = (ServletWebContext) context;
-        HttpServletRequest request = swcontext.getRequest();
+        ServletActionContext sacontext = (ServletActionContext) context;
+        HttpServletRequest request = sacontext.getRequest();
         String uri =
             (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
         if (uri == null) {
@@ -58,7 +59,7 @@
         // Identify the module prefix for the current module
         String prefix = "";  // Initialize to default prefix
         String prefixes[] = (String[])
-            swcontext.getApplicationScope().get(Globals.MODULE_PREFIXES_KEY);
+            sacontext.getApplicationScope().get(Globals.MODULE_PREFIXES_KEY);
         int lastSlash = 0;
         while (prefix.equals("") &&
                ((lastSlash = uri.lastIndexOf("/")) > 0)) {

Modified: 
struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java?view=diff&r1=153330&r2=153331
==============================================================================
--- 
struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java
 (original)
+++ 
struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java
 Thu Feb 10 19:17:21 2005
@@ -38,8 +38,7 @@
         MockActionServlet servlet = new MockActionServlet(servletContext, 
servletConfig);
         servlet.initInternal();
 
-        this.swContext = new ServletWebContext(servletContext, request, new 
MockHttpServletResponse());
-        this.saContext = new ServletActionContext(swContext);
+        this.saContext = new ServletActionContext(servletContext, request, new 
MockHttpServletResponse());
 
         this.saContext.setActionServlet(servlet);
         this.command = new AuthorizeAction();



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to