struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1485653 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/views/xslt/XSLTResult.java test/java/org/apache/struts2/views/xslt/XSLTResultTest.java
Date Thu, 23 May 2013 11:49:47 GMT
Author: lukaszlenart
Date: Thu May 23 11:49:47 2013
New Revision: 1485653

URL: http://svn.apache.org/r1485653
Log:
WW-3999 Allows set respond code

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java?rev=1485653&r1=1485652&r2=1485653&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java
Thu May 23 11:49:47 2013
@@ -238,6 +238,9 @@ public class XSLTResult implements Resul
     /** Indicates the ognl expression respresenting the bean which is to be exposed as xml.
*/
     private String exposedValue;
 
+    /** Indicates the status to return in the response */
+    private int status = 200;
+
     private boolean parse;
     private AdapterFactory adapterFactory;
 
@@ -307,6 +310,18 @@ public class XSLTResult implements Resul
         this.excludingPattern = excludingPattern;
     }
 
+    public String getStatus() {
+        return String.valueOf(status);
+    }
+
+    public void setStatus(String status) {
+        try {
+            this.status = Integer.valueOf(status);
+        } catch (NumberFormatException e) {
+            throw new IllegalArgumentException("Status value not number " + e.getMessage(),
e);
+        }
+    }
+
     /**
      * If true, parse the stylesheet location for OGNL expressions.
      *
@@ -328,7 +343,7 @@ public class XSLTResult implements Resul
 
         try {
             HttpServletResponse response = ServletActionContext.getResponse();
-
+            response.setStatus(status);
             PrintWriter writer = response.getWriter();
 
             // Create a transformer for the stylesheet.

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java?rev=1485653&r1=1485652&r2=1485653&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/xslt/XSLTResultTest.java
Thu May 23 11:49:47 2013
@@ -191,7 +191,20 @@ public class XSLTResultTest extends Stru
             assertEquals("Error transforming result", ex.getMessage());
         }
     }
-    
+
+    public void testStatusCode() throws Exception {
+        result.setParse(false);
+        result.setLocation("XSLTResultTest.xsl");
+        result.setStatus("302");
+        result.execute(mai);
+
+        String out = response.getContentAsString();
+
+        assertEquals(302, response.getStatus());
+        assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
+        assertTrue(out.indexOf("<result xmlns=\"http://www.w3.org/TR/xhtml1/strict\"")
> -1);
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         request = new MockHttpServletRequest();



Mime
View raw message