mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
WW-3999 Allows set respond code
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1485653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -238,6 +238,9 @@ public class XSLTResult implements Result {
|
||||
/** 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 Result {
|
||||
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 Result {
|
||||
|
||||
try {
|
||||
HttpServletResponse response = ServletActionContext.getResponse();
|
||||
|
||||
response.setStatus(status);
|
||||
PrintWriter writer = response.getWriter();
|
||||
|
||||
// Create a transformer for the stylesheet.
|
||||
|
||||
@@ -191,7 +191,20 @@ public class XSLTResultTest extends StrutsTestCase {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user