struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r592670 - in /struts/sandbox/trunk/struts2-rest-plugin: ./ showcase/ showcase/src/main/java/org/apache/struts2/rest/example/ showcase/src/main/resources/ showcase/src/main/webapp/ src/main/java/org/apache/struts2/rest/ src/main/resources/ s...
Date Wed, 07 Nov 2007 09:35:49 GMT
Author: mrdon
Date: Wed Nov  7 01:35:48 2007
New Revision: 592670

URL: http://svn.apache.org/viewvc?rev=592670&view=rev
Log:
Fixing a caching issue (disable cache wasn't stopping a 304 from being returned), cleaned
up the example, updated to struts 2 trunk

Modified:
    struts/sandbox/trunk/struts2-rest-plugin/pom.xml
    struts/sandbox/trunk/struts2-rest-plugin/showcase/pom.xml
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersController.java
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/resources/struts.properties
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp
    struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/DefaultHttpHeaders.java
    struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
    struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml
    struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/DefaultHttpHeadersTest.java

Modified: struts/sandbox/trunk/struts2-rest-plugin/pom.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/pom.xml?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/pom.xml (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/pom.xml Wed Nov  7 01:35:48 2007
@@ -5,11 +5,11 @@
 	<parent>
         <groupId>org.apache.struts</groupId>
         <artifactId>struts2-plugins</artifactId>
-        <version>2.1.0-SNAPSHOT</version>
+        <version>2.1.1-SNAPSHOT</version>
     </parent>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-rest-plugin</artifactId>
-   <version>2.1.0-SNAPSHOT</version>
+   <version>2.1.1-SNAPSHOT</version>
    <name>Struts 2 Plugin</name>
 
     <dependencies>

Modified: struts/sandbox/trunk/struts2-rest-plugin/showcase/pom.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/pom.xml?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/pom.xml (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/pom.xml Wed Nov  7 01:35:48 2007
@@ -5,13 +5,13 @@
     <parent>
         <groupId>org.apache.struts</groupId>
         <artifactId>struts2-apps</artifactId>
-        <version>2.1.0-SNAPSHOT</version>
+        <version>2.1.1-SNAPSHOT</version>
     </parent>
 
 	<groupId>org.apache.struts</groupId>
 	<artifactId>struts2-rest-showcase</artifactId>
 	<packaging>war</packaging>
-	<version>2.1.0-SNAPSHOT</version>
+	<version>2.1.1-SNAPSHOT</version>
 	<name>Struts 2 Rest Showcase Example</name>
 	<description>Struts 2 Rest Showcase Example</description>
 	
@@ -19,7 +19,7 @@
         <dependency>
             <groupId>org.apache.struts</groupId>
             <artifactId>struts2-rest-plugin</artifactId>
-            <version>2.1.0-SNAPSHOT</version>
+            <version>2.1.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>junit</groupId>

Modified: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java
(original)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java
Wed Nov  7 01:35:48 2007
@@ -2,7 +2,7 @@
 
 import com.thoughtworks.xstream.annotations.XStreamAlias;
 
-public class Order {
+public class Order implements Cloneable {
     String id;
     String clientName;
     int amount;
@@ -32,12 +32,6 @@
     }
     public void setId(String id) {
         this.id = id;
-    }
-    
-    public void copyTo(Order order) {
-        order.setId(getId());
-        order.setAmount(getAmount());
-        order.setClientName(getClientName());
     }
 
     @Override

Modified: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersController.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersController.java?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersController.java
(original)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersController.java
Wed Nov  7 01:35:48 2007
@@ -20,10 +20,12 @@
 @Results({
     @Result(name="success", type=ServletActionRedirectResult.class, value="orders") 
 })
-public class OrdersController extends ValidationAwareSupport implements ModelDriven<Object>,
ParameterAware, Validateable{
+public class OrdersController extends ValidationAwareSupport implements ModelDriven<Object>,
Validateable{
     
     private Order model = new Order();
     private static Map<String,Order> orders = new HashMap<String,Order>();
+    private static int nextId = 6;
+    private String id;
     
     static {
         orders.put("3", new Order("3", "Bob", 33));
@@ -31,10 +33,17 @@
         orders.put("5", new Order("5", "Jim", 66));
     }
     private Collection<Order> list;
+
+    public void setId(String id) {
+        if (id != null && orders.containsKey(id)) {
+            this.model = orders.get(id);
+        }
+        this.id = id;
+    }
     
     public void validate() {
-        if (model.getId() == null || model.getId().length() ==0) {
-            addFieldError("id", "ID is wrong");
+        if (model.getClientName() == null || model.getClientName().length() ==0) {
+            addFieldError("clientName", "The client name is empty");
         }
     }
     
@@ -47,6 +56,7 @@
     }
     
     public String editNew() {
+        model = new Order();
         return "editNew";
     }
     
@@ -57,11 +67,11 @@
     }
     
     public HttpHeaders create() {
+        model.setId(String.valueOf(nextId++));
         orders.put(model.getId(), model);
         addActionMessage("New order created successfully");
-        return new DefaultHttpHeaders()
-            .setLocationId(model.getId())
-            .renderResult("success");
+        return new DefaultHttpHeaders("success")
+            .setLocationId(model.getId());
     }
     
     public String update() {
@@ -81,12 +91,4 @@
         return (list != null ? list : model);
     }
 
-    // Silly workaround since modeldriven doesn't work right in xwork 2.1.0
-    public void setParameters(Map<String,String[]> parameters) {
-        if (parameters.get("id") != null && orders.get(parameters.get("id")[0]) !=
null) {
-            orders.get(parameters.get("id")[0]).copyTo(model);
-        }
-    }
-    
-    
 }

Modified: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/resources/struts.properties
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/resources/struts.properties?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/resources/struts.properties
(original)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/resources/struts.properties
Wed Nov  7 01:35:48 2007
@@ -1,4 +1,4 @@
 
-struts.action.extension=,,xhtml,xml,json
+struts.action.extension=xhtml,xml,json
 
 struts.devMode = true

Modified: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp Wed
Nov  7 01:35:48 2007
@@ -8,19 +8,19 @@
 <head>
 	<title>Order <s:property value="id" /></title>
 </head>
-<body>
-    <s:form method="post" action="%{#request.contextPath}/orders/%{id}.xhtml">
-    <s:hidden name="_method" value="put" />
-    <table>
-        <s:textfield name="id" label="ID" />
-        <s:textfield name="clientName" label="Client"/>
-        <s:textfield name="amount" label="Amount" />
-        <tr>
-            <td colspan="2">
-                <s:submit />
-            </td>
-    </table>
-    </s:form>    	
+<body>
+    <s:form method="post" action="%{#request.contextPath}/orders/%{id}.xhtml">
+    <s:hidden name="_method" value="put" />
+    <table>
+        <s:textfield name="id" label="ID" disabled="true"/>
+        <s:textfield name="clientName" label="Client"/>
+        <s:textfield name="amount" label="Amount" />
+        <tr>
+            <td colspan="2">
+                <s:submit />
+            </td>
+    </table>
+    </s:form>    	
     <a href="<%=request.getContextPath() %>/orders.xhtml">Back to Orders</a>
 </body>
 </html>

Modified: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp Wed
Nov  7 01:35:48 2007
@@ -8,18 +8,17 @@
 <head>
 	<title>New Order</title>
 </head>
-<body>
-    <s:form method="post" action="%{#request.contextPath}/orders.xhtml">
-    <table>
-        <s:textfield name="id" label="ID" />
-        <s:textfield name="clientName" label="Client"/>
-        <s:textfield name="amount" label="Amount" />
-        <tr>
-            <td colspan="2">
-                <s:submit />
-            </td>
-    </table>
-    </s:form>    	
+<body>
+    <s:form method="post" action="%{#request.contextPath}/orders.xhtml">
+    <table>
+        <s:textfield name="clientName" label="Client"/>
+        <s:textfield name="amount" label="Amount" />
+        <tr>
+            <td colspan="2">
+                <s:submit />
+            </td>
+    </table>
+    </s:form>    	
     <a href="<%=request.getContextPath() %>/orders.xhtml">Back to Orders</a>
 </body>
 </html>

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/DefaultHttpHeaders.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/DefaultHttpHeaders.java?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/DefaultHttpHeaders.java
(original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/DefaultHttpHeaders.java
Wed Nov  7 01:35:48 2007
@@ -117,7 +117,7 @@
             response.setHeader("Location", location);
         }
 
-        if (status == SC_OK) {
+        if (status == SC_OK && !disableCaching) {
             boolean etagNotChanged = false;
             boolean lastModifiedNotChanged = false;
             String reqETag = request.getHeader("If-None-Match");

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
(original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
Wed Nov  7 01:35:48 2007
@@ -164,7 +164,7 @@
 	 */
     protected String doIntercept(ActionInvocation invocation) throws Exception {
         Object action = invocation.getAction();
-        
+
         if (action instanceof ValidationAware) {
             ValidationAware validationAwareAction = (ValidationAware) action;
 

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml Wed Nov
 7 01:35:48 2007
@@ -25,6 +25,15 @@
     <constant name="struts.configuration.classpath.defaultParentPackage" value="rest-default"
/>
     
     <package name="rest-default" extends="struts-default">
+        <result-types>
+            <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult">
+                <param name="statusCode">303</param>
+            </result-type>
+            <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult">
+                <param name="statusCode">303</param>
+            </result-type>
+        </result-types>
+
         <interceptors>
             <interceptor name="rest" class="org.apache.struts2.rest.ContentTypeInterceptor"/>
             <interceptor name="restWorkflow" class="org.apache.struts2.rest.RestWorkflowInterceptor"/>
@@ -53,8 +62,11 @@
                 <interceptor-ref name="chain"/>
                 <interceptor-ref name="debugging"/>
                 <interceptor-ref name="profiling"/>
+                <interceptor-ref name="actionMappingParams"/>
                 <interceptor-ref name="scopedModelDriven"/>
-                <interceptor-ref name="modelDriven"/>
+                <interceptor-ref name="modelDriven">
+                    <param name="refreshModelBeforeResult">true</param>
+                </interceptor-ref>
                 <interceptor-ref name="fileUpload"/>
                 <interceptor-ref name="checkbox"/>
                 <interceptor-ref name="staticParams"/>
@@ -73,16 +85,6 @@
     
         </interceptors>
 
-        <result-types>
-            <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult">
-                <param name="statusCode">303</param>
-            </result-type>
-            <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult">
-                <param name="statusCode">303</param>
-            </result-type>
-        </result-types>
-    
-    
         <default-interceptor-ref name="restDefaultStack"/>
     </package>
 

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/DefaultHttpHeadersTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/DefaultHttpHeadersTest.java?rev=592670&r1=592669&r2=592670&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/DefaultHttpHeadersTest.java
(original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/DefaultHttpHeadersTest.java
Wed Nov  7 01:35:48 2007
@@ -154,6 +154,19 @@
         assertEquals(SC_NOT_MODIFIED, mockResponse.getStatus());
     }
 
+    public void testConditionalGetForLastModifiedAndETagButNoCache() {
+        Date now = new Date();
+        DefaultHttpHeaders headers = new DefaultHttpHeaders()
+                .lastModified(now)
+                .withETag("asdf")
+                .disableCaching();
+        mockRequest.addHeader("If-None-Match", "asdf");
+        mockRequest.addHeader("If-Modified-Since", String.valueOf(now.getTime()));
+        headers.apply(mockRequest, mockResponse, new Object());
+
+        assertEquals(SC_OK, mockResponse.getStatus());
+    }
+
     public void testConditionalGetForLastModifiedAndETagWithBadETag() {
         Date now = new Date();
         DefaultHttpHeaders headers = new DefaultHttpHeaders()



Mime
View raw message