Adding correct response type for json validation

WW-2571


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@649878 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2008-04-20 03:38:49 +00:00
parent e584c30992
commit 21f3bcbbed
3 changed files with 12 additions and 1 deletions
@@ -98,6 +98,7 @@ public class JSONValidationInterceptor extends MethodFilterInterceptor {
if (validationFailedStatus >= 0)
response.setStatus(validationFailedStatus);
response.getWriter().print(buildResponse(validationAware));
response.setContentType("application/json");
return Action.NONE;
}
}
@@ -106,6 +107,7 @@ public class JSONValidationInterceptor extends MethodFilterInterceptor {
if (validateOnly != null && "true".equals(validateOnly)) {
//there were no errors
response.getWriter().print("/* {} */");
response.setContentType("application/json");
return Action.NONE;
} else {
return invocation.invoke();
@@ -78,6 +78,8 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
assertFalse(action.isExecuted());
//http status
assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
assertEquals("application/json", response.getContentType());
}
public void testValidationSucceeds() throws Exception {
@@ -119,6 +121,7 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
String normalizedActual = TestUtils.normalize(json, true);
assertEquals("/*{}*/", normalizedActual);
assertFalse(action.isExecuted());
assertEquals("application/json", response.getContentType());
}
protected void setUp() throws Exception {
@@ -37,6 +37,7 @@ public class StrutsMockHttpServletResponse extends MockHttpServletResponse {
private PrintWriter writer;
private int status;
private String redirectURL;
private String contentType;
public Locale getLocale() {
return locale;
@@ -47,7 +48,12 @@ public class StrutsMockHttpServletResponse extends MockHttpServletResponse {
}
public String getContentType() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return contentType; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void setContentType(String type) {
this.contentType = type;
}
public PrintWriter getWriter() throws IOException {