Anonymous avatar Anonymous committed 0224f47

Upgrading to new Xwork.xml and fixing up example war

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@103 573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (9)

Add a comment to this file

lib/core/xwork-1.0-beta.jar

Binary file modified.

src/java/com/opensymphony/webwork/dispatcher/FilterDispatcher.java

 
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void destroy() {
-    }
-    
     /**
      * getter for {@link #filterConfig}
      * <p>
      * Since {@link #filterConfig} is declared private, this getter is
      * needed for subclasses to retrieve it.  Subclasses need this
      * to make this filter work for Weblogic 6.1.
-     * 
+     *
      * @return the filter configuration.
      */
     public FilterConfig getFilterConfig() {
         return filterConfig;
     }
 
+    public void destroy() {
+    }
+
     /**
     * @param servletRequest
     * @param servletResponse
 
                 try {
                     ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
-                    request.setAttribute("webwork.valueStack", proxy.getValueStack());
+                    request.setAttribute("webwork.valueStack", proxy.getInvocation().getStack());
                     proxy.execute();
                 } catch (Exception e) {
                     try {

src/java/com/opensymphony/webwork/dispatcher/ServletDispatcher.java

     }
 
     /**
-	* Service a request - get the namespace, actionName, paramMap, sessionMap, applicationMap from the providers
-	* and delegate to the service call
-	* 
-	* @param request
-	* @param response
-	* @exception javax.servlet.ServletException
-	*/
+ * Service a request - get the namespace, actionName, paramMap, sessionMap, applicationMap from the providers
+ * and delegate to the service call
+ *
+ * @param request
+ * @param response
+ * @exception javax.servlet.ServletException
+ */
     public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {
         serviceAction(request, response, getNameSpace(request), getActionName(request), getParameterMap(request), getSessionMap(request), getApplicationMap());
     }
 
     /**
-	* The request is first checked to see if it is a multi-part. If it is, then the request
-	* is wrapped so WW will be able to work with the multi-part as if it was a normal request.
-	* Then the request is handed to GenericDispatcher and executed.
-	*/
+ * The request is first checked to see if it is a multi-part. If it is, then the request
+ * is wrapped so WW will be able to work with the multi-part as if it was a normal request.
+ * Then the request is handed to GenericDispatcher and executed.
+ */
     public void serviceAction(HttpServletRequest request, HttpServletResponse response, String namespace, String actionName, Map parameterMap, Map sessionMap, Map applicationMap) {
         //wrap request if needed
         try {
         extraContext.put(ActionContext.PARAMETERS, parameterMap);
         extraContext.put(ActionContext.SESSION, sessionMap);
         extraContext.put(ActionContext.APPLICATION, applicationMap);
-        
+
         extraContext.put(HTTP_REQUEST, request);
         extraContext.put(HTTP_RESPONSE, response);
         extraContext.put(SERVLET_CONFIG, getServletConfig());
 
         try {
             ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
-            request.setAttribute("webwork.valueStack", proxy.getValueStack());
+            request.setAttribute("webwork.valueStack", proxy.getInvocation().getStack());
             proxy.execute();
         } catch (ConfigurationException e) {
             log.error("Could not find action", e);
             // make the exception availible to the web.xml defined error page
             request.setAttribute("javax.servlet.error.exception", e);
 
-            // for compatibility 
+            // for compatibility
             request.setAttribute("javax.servlet.jsp.jspException", e);
 
             // send the error response
             response.sendError(code, e.getMessage());
 
             /*
-         response.setContentType("text/html");
-    response.setLocale(Configuration.getLocale());
-
-    PrintWriter writer = response.getWriter();
-    writer.write("Error executing action: " + e.getMessage());
-    writer.println("<pre>\n");
-    e.printStackTrace(response.getWriter());
-    writer.print("</pre>\n");
+response.setContentType("text/html");
+response.setLocale(Configuration.getLocale());
+
+PrintWriter writer = response.getWriter();
+writer.write("Error executing action: " + e.getMessage());
+writer.println("<pre>\n");
+e.printStackTrace(response.getWriter());
+writer.print("</pre>\n");
 */
         } catch (IOException e1) {
         }
     }
 
     /**
-* Determine action name by extracting last string and removing
-* extension. (/.../.../Foo.action -> Foo)
-*/
+ * Determine action name by extracting last string and removing
+ * extension. (/.../.../Foo.action -> Foo)
+ */
     String getActionName(String name) {
         // Get action name ("Foo.action" -> "Foo" action)
         int beginIdx = name.lastIndexOf("/");
     }
 
     /**
-* Wrap servlet request with the appropriate request. It will check to
-* see if request is a multipart request and wrap in appropriately.
-*
-* @param request
-* @return wrapped request or original request
-*/
+ * Wrap servlet request with the appropriate request. It will check to
+ * see if request is a multipart request and wrap in appropriately.
+ *
+ * @param request
+ * @return wrapped request or original request
+ */
     private HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException {
         // don't wrap more than once
         if (request instanceof MultiPartRequestWrapper) {

src/java/com/opensymphony/webwork/util/InvocationSessionStore.java

     //~ Methods ////////////////////////////////////////////////////////////////
 
     /**
-     * Checks the Map in the Session for the key and the token. If the
-     * ActionInvocation is saved in the Session, the ValueStack from the
-     * ActionProxy associated with the ActionInvocation is set into the
-     * ActionContext and the ActionInvocation is returned.
-     * @param key the name the DefaultActionInvocation and ActionContext were saved as
-     * @return the DefaultActionInvocation saved using the key, or null if none was found
-     */
+ * Checks the Map in the Session for the key and the token. If the
+ * ActionInvocation is saved in the Session, the ValueStack from the
+ * ActionProxy associated with the ActionInvocation is set into the
+ * ActionContext and the ActionInvocation is returned.
+ * @param key the name the DefaultActionInvocation and ActionContext were saved as
+ * @return the DefaultActionInvocation saved using the key, or null if none was found
+ */
     public static ActionInvocation loadInvocation(String key, String token) {
         InvocationContext invocationContext = (InvocationContext) getInvocationMap().get(key);
 
             return null;
         }
 
-        OgnlValueStack stack = invocationContext.invocation.getProxy().getValueStack();
+        OgnlValueStack stack = invocationContext.invocation.getStack();
         ActionContext.getContext().setValueStack(stack);
 
         return invocationContext.invocation;
     }
 
     /**
-    * Stores the DefaultActionInvocation and ActionContext into the Session using the provided key for loading later using
-    * {@link #loadInvocation}
-    * @param key
-    * @param invocation
-    */
+* Stores the DefaultActionInvocation and ActionContext into the Session using the provided key for loading later using
+* {@link #loadInvocation}
+* @param key
+* @param invocation
+*/
     public static void storeInvocation(String key, String token, ActionInvocation invocation) {
         InvocationContext invocationContext = new InvocationContext(invocation, token);
         Map invocationMap = getInvocationMap();

src/test/com/opensymphony/webwork/interceptor/TokenInterceptorTest.java

  * Created Apr 9, 2003 11:42:01 PM
  */
 public class TokenInterceptorTest extends TestCase {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private ActionContext oldContext;
+    private HttpSession httpSession;
+    private Map extraContext;
+    private Map params;
+    private Map session;
+    private WebWorkMockHttpServletRequest request;
+
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void testNoTokenInParams() {
         }
     }
 
-    public void testNoTokenInSession() {
-        try {
-            ActionProxy proxy = buildProxy(getActionName());
-            setToken();
-            ActionContext.getContext().getSession().clear();
-            assertEquals(TokenInterceptor.INVALID_TOKEN_CODE, proxy.execute());
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail();
-        }
+    public void testNoTokenInSession() throws Exception {
+        assertEquals(oldContext, ActionContext.getContext());
+
+        ActionProxy proxy = buildProxy(getActionName());
+        setToken();
+        ActionContext.getContext().getSession().clear();
+        assertEquals(TokenInterceptor.INVALID_TOKEN_CODE, proxy.execute());
     }
 
-    public void testTokenInterceptorSuccess() {
-        try {
-            ActionProxy proxy = buildProxy(getActionName());
-            setToken();
-            assertEquals(Action.SUCCESS, proxy.execute());
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail();
-        }
+    public void testTokenInterceptorSuccess() throws Exception {
+        ActionProxy proxy = buildProxy(getActionName());
+        setToken();
+        assertEquals(Action.SUCCESS, proxy.execute());
     }
 
     protected String getActionName() {
         ConfigurationManager.clearConfigurationProviders();
         ConfigurationManager.addConfigurationProvider(new TestConfigurationProvider());
         ConfigurationManager.getConfiguration().reload();
-    }
 
-    protected ActionProxy buildProxy(String actionName) throws Exception {
-        Map session = new HashMap();
-        Map params = new HashMap();
-        Map extraContext = new HashMap();
+        session = new HashMap();
+        params = new HashMap();
+        extraContext = new HashMap();
         extraContext.put(ActionContext.SESSION, session);
         extraContext.put(ActionContext.PARAMETERS, params);
 
-        WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
-        HttpSession httpSession = new MockHttpSession();
+        request = new WebWorkMockHttpServletRequest();
+        httpSession = new MockHttpSession();
         request.setSession(httpSession);
         extraContext.put(ServletActionContext.HTTP_REQUEST, request);
 
+        // we need to create an ActionContext that exists before the Proxy is created
+        // so that the values can be set into our data structures by the TokenHelper.
+        // These same data structures will be in the new ActionContext, so it will mimic
+        // the values being set in during the proxy.execute()
+        oldContext = new ActionContext(extraContext);
+        ActionContext.setContext(oldContext);
+    }
+
+    protected ActionProxy buildProxy(String actionName) throws Exception {
         return ActionProxyFactory.getFactory().createActionProxy("", actionName, extraContext, true);
     }
+
+    protected void tearDown() throws Exception {
+        ConfigurationManager.destroyConfiguration();
+        ActionContext.setContext(null);
+    }
 }

src/test/com/opensymphony/webwork/interceptor/TokenSessionStoreInterceptorTest.java

 import com.opensymphony.webwork.TestConfigurationProvider;
 
 import com.opensymphony.xwork.Action;
-import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionProxy;
 
-import java.util.Map;
-
 
 /**
  * TokenSessionStoreInterceptorTest
 public class TokenSessionStoreInterceptorTest extends TokenInterceptorTest {
     //~ Methods ////////////////////////////////////////////////////////////////
 
+    /**
+ * @see {@link com.opensymphony.webwork.TestConfigurationProvider#init}
+ */
     public void testDuplicateToken() {
         try {
             ActionProxy proxy = buildProxy(getActionName());
             String token = setToken();
-            Map session = ActionContext.getContext().getSession();
             assertEquals(Action.SUCCESS, proxy.execute());
             proxy = buildProxy(getActionName());
-            ActionContext.getContext().setSession(session);
             setToken(token);
             assertEquals(Action.SUCCESS, proxy.execute());
         } catch (Exception e) {

src/test/com/opensymphony/webwork/util/InvocationSessionStoreTest.java

 
         stack = new OgnlValueStack();
         actionContext.setValueStack(stack);
+        invocationMock.matchAndReturn("getStack", stack);
 
         Mock proxyMock = new Mock(ActionProxy.class);
-        proxyMock.matchAndReturn("getValueStack", stack);
+        proxyMock.matchAndReturn("getInvocation", invocation);
 
         ActionProxy proxy = (ActionProxy) proxyMock.proxy();
 

src/test/com/opensymphony/webwork/views/jsp/ui/TextfieldTest.java

         tag.setName("foo");
         tag.setValue("bar");
 
+        testAction.addFieldError("foo", "bar error message");
+        testAction.addFieldError("bar", "bar error message");
         tag.doEndTag();
 
         verify(TextFieldTag.class.getResource("Textfield-2.txt"));

src/webapp/bean.jsp

 <%@ taglib prefix="ww" uri="webwork" %>
 <%@ taglib uri="c" prefix="c" %>
 
-<ww:bean name="com.opensymphony.webwork.example.counter.BeanCounter" id="counter">
+<ww:bean name="com.opensymphony.webwork.example.counter.SimpleCounter" id="counter">
  <ww:param name="foo" value="'BAR'"/>
 
  Inside the Bean tag, the value of foo is : <ww:property value="foo"/><br />
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.