mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
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:
+2
@@ -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();
|
||||
|
||||
+3
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user