Skip to content

Commit

Permalink
Merge pull request apache#17 from apache/master
Browse files Browse the repository at this point in the history
update pull
  • Loading branch information
victorsosa committed May 26, 2016
2 parents ffdacf1 + 095960b commit 7985fd1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public class DefaultActionMapper implements ActionMapper {
protected boolean allowSlashesInActionNames = false;
protected boolean alwaysSelectFullNamespace = false;
protected PrefixTrie prefixTrie = null;
protected Pattern allowedActionNames = Pattern.compile("[a-zA-Z0-9._!/\\-]*");
protected Pattern allowedActionNames = Pattern.compile("^[a-zA-Z0-9_!/\\-]*((.htm[l]?)|(.action))?$");
private boolean allowActionPrefix = false;
private boolean allowActionCrossNamespaceAccess = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public Configuration getConfiguration() {

public void testGetMappingWithNamespaceSlash() throws Exception {

req.setupGetRequestURI("/my.hh/abc.action");
req.setupGetServletPath("/my.hh/abc.action");
req.setupGetRequestURI("/my-hh/abc.action");
req.setupGetServletPath("/my-hh/abc.action");
req.setupGetAttribute(null);
req.addExpectedGetAttributeName("javax.servlet.include.servlet_path");

Expand All @@ -181,7 +181,7 @@ public void testGetMappingWithNamespaceSlash() throws Exception {
mapping = mapper.getMapping(req, configManager);

assertEquals("", mapping.getNamespace());
assertEquals("my.hh/abc", mapping.getName());
assertEquals("my-hh/abc", mapping.getName());
}

public void testGetMappingWithUnknownNamespace() throws Exception {
Expand Down Expand Up @@ -855,7 +855,7 @@ public void testAllowedActionNames() throws Exception {
expected = t;
}
assertTrue(expected instanceof StrutsException);
assertEquals("Action [${action}] does not match allowed action names pattern [[a-zA-Z0-9._!/\\-]*]!", expected.getMessage());
assertEquals("Action [${action}] does not match allowed action names pattern [" + mapper.allowedActionNames.pattern() + "]!", expected.getMessage());

actionName = "${${%{action}}}";
try {
Expand All @@ -865,7 +865,7 @@ public void testAllowedActionNames() throws Exception {
expected = t;
}
assertTrue(expected instanceof StrutsException);
assertEquals("Action [${${%{action}}}] does not match allowed action names pattern [[a-zA-Z0-9._!/\\-]*]!", expected.getMessage());
assertEquals("Action [${${%{action}}}] does not match allowed action names pattern [" + mapper.allowedActionNames.pattern() + "]!", expected.getMessage());

actionName = "${#foo='action',#foo}";
try {
Expand All @@ -875,7 +875,7 @@ public void testAllowedActionNames() throws Exception {
expected = t;
}
assertTrue(expected instanceof StrutsException);
assertEquals("Action [${#foo='action',#foo}] does not match allowed action names pattern [[a-zA-Z0-9._!/\\-]*]!", expected.getMessage());
assertEquals("Action [${#foo='action',#foo}] does not match allowed action names pattern [" + mapper.allowedActionNames.pattern() + "]!", expected.getMessage());

actionName = "test-action";
assertEquals("test-action", mapper.cleanupActionName(actionName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class JSONInterceptor extends AbstractInterceptor {
private boolean enableGZIP = false;
private boolean wrapWithComments;
private boolean prefix;
private String defaultEncoding = "ISO-8859-1";
private String defaultEncoding = "UTF-8";
private boolean ignoreHierarchy = true;
private String root;
private List<Pattern> excludeProperties;
Expand All @@ -70,19 +70,18 @@ public class JSONInterceptor extends AbstractInterceptor {
private boolean noCache = false;
private boolean excludeNullProperties;
private String callbackParameter;
private String contentType;
private String accept;

@SuppressWarnings("unchecked")
public String intercept(ActionInvocation invocation) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String contentType = request.getHeader("content-type");
if (contentType != null) {
int iSemicolonIdx;
if ((iSemicolonIdx = contentType.indexOf(";")) != -1)
contentType = contentType.substring(0, iSemicolonIdx);

//parameter wasn't set by the interceptor
if (accept == null) {
accept = request.getHeader("accept");
}

Object rootObject = null;
final ValueStack stack = invocation.getStack();
if (this.root != null) {
Expand All @@ -93,7 +92,7 @@ public String intercept(ActionInvocation invocation) throws Exception {
}
}

if ((contentType != null) && contentType.equalsIgnoreCase("application/json")) {
if ((accept != null) && accept.equalsIgnoreCase("application/json")) {
// load JSON object
Object obj = JSONUtil.deserialize(request.getReader());

Expand Down Expand Up @@ -133,7 +132,7 @@ public String intercept(ActionInvocation invocation) throws Exception {
LOG.error("Unable to deserialize JSON object from request");
throw new JSONException("Unable to deserialize JSON object from request");
}
} else if ((contentType != null) && contentType.equalsIgnoreCase("application/json-rpc")) {
} else if ((accept != null) && accept.equalsIgnoreCase("application/json-rpc")) {
Object result;
if (this.enableSMD) {
// load JSON object
Expand Down Expand Up @@ -181,7 +180,8 @@ public String intercept(ActionInvocation invocation) throws Exception {

return Action.NONE;
} else {
LOG.debug("Content type must be 'application/json' or 'application/json-rpc'. Ignoring request with content type ", contentType);

LOG.debug("Accept header parameter must be 'application/json' or 'application/json-rpc'. Ignoring request with accept ", accept);
}

return invocation.invoke();
Expand Down Expand Up @@ -535,7 +535,7 @@ public void setPrefix(boolean prefix) {
this.prefix = prefix;
}

public void setContentType(String contentType) {
this.contentType = contentType;
public void setAccept(String accept) {
this.accept = accept;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testBadToTheBoneJSON4() throws Exception {
private void tryBadJSON(String fileName) throws Exception {
// request
setRequestContent(fileName);
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
Expand All @@ -92,7 +92,7 @@ private void tryBadJSON(String fileName) throws Exception {
public void testSMDDisabledSMD() throws Exception {
// request
setRequestContent("smd-3.txt");
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
SMDActionTest1 action = new SMDActionTest1();
Expand All @@ -111,7 +111,7 @@ public void testSMDDisabledSMD() throws Exception {
public void testSMDAliasedMethodCall1() throws Exception {
// request
setRequestContent("smd-14.txt");
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
Expand All @@ -129,7 +129,7 @@ public void testSMDAliasedMethodCall1() throws Exception {
public void testSMDAliasedMethodCall2() throws Exception {
// request
setRequestContent("smd-15.txt");
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
Expand All @@ -147,7 +147,7 @@ public void testSMDAliasedMethodCall2() throws Exception {
public void testSMDNoMethod() throws Exception {
// request
setRequestContent("smd-4.txt");
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
Expand All @@ -171,7 +171,7 @@ public void testSMDNoMethod() throws Exception {
public void testSMDMethodWithoutAnnotations() throws Exception {
// request
setRequestContent("smd-9.txt");
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
Expand All @@ -192,7 +192,7 @@ public void testSMDMethodWithoutAnnotations() throws Exception {
public void testSMDPrimitivesNoResult() throws Exception {
// request
setRequestContent("smd-6.txt");
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
Expand Down Expand Up @@ -221,13 +221,13 @@ public void testSMDPrimitivesNoResult() throws Exception {
String normalizedExpected = TestUtils.normalize(JSONResultTest.class.getResource("smd-11.txt"));
assertEquals(normalizedExpected, normalizedActual);

assertEquals("application/json;charset=ISO-8859-1", response.getContentType());
assertEquals("application/json;charset=UTF-8", response.getContentType());
}

public void testSMDReturnObject() throws Exception {
// request
setRequestContent("smd-10.txt");
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
Expand All @@ -245,14 +245,14 @@ public void testSMDReturnObject() throws Exception {
String normalizedExpected = TestUtils.normalize(JSONResultTest.class.getResource("smd-12.txt"));
assertEquals(normalizedExpected, normalizedActual);

assertEquals("application/json;charset=ISO-8859-1", response.getContentType());
assertEquals("application/json;charset=UTF-8", response.getContentType());
}

@SuppressWarnings("unchecked")
public void testSMDObjectsNoResult() throws Exception {
// request
setRequestContent("smd-7.txt");
this.request.addHeader("content-type", "application/json-rpc");
this.request.addHeader("accept", "application/json-rpc");

JSONInterceptor interceptor = new JSONInterceptor();
interceptor.setEnableSMD(true);
Expand Down Expand Up @@ -293,14 +293,14 @@ public void testSMDObjectsNoResult() throws Exception {
String normalizedExpected = TestUtils.normalize(JSONResultTest.class.getResource("smd-11.txt"));
assertEquals(normalizedExpected, normalizedActual);

assertEquals("application/json;charset=ISO-8859-1", response.getContentType());
assertEquals("application/json;charset=UTF-8", response.getContentType());
}

@SuppressWarnings( { "unchecked", "unchecked" })
public void testReadEmpty() throws Exception {
// request
setRequestContent("json-6.txt");
this.request.addHeader("content-type", "application/json");
this.request.addHeader("accept", "application/json");

// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
Expand All @@ -315,7 +315,7 @@ public void testReadEmpty() throws Exception {
public void test() throws Exception {
// request
setRequestContent("json-1.txt");
this.request.addHeader("content-type", "application/json");
this.request.addHeader("accept", "application/json");

// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
Expand Down Expand Up @@ -437,7 +437,7 @@ public void test() throws Exception {

public void testRoot() throws Exception {
setRequestContent("json-5.txt");
this.request.addHeader("content-type", "application/json");
this.request.addHeader("accept", "application/json");

// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
Expand All @@ -462,7 +462,7 @@ public void testRoot() throws Exception {

public void testJSONArray() throws Exception {
setRequestContent("json-12.txt");
this.request.addHeader("content-type", "application/json");
this.request.addHeader("accept", "application/json");

// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
Expand All @@ -488,7 +488,7 @@ public void testJSONArray() throws Exception {

public void testJSONArray2() throws Exception {
setRequestContent("json-12.txt");
this.request.addHeader("content-type", "application/json");
this.request.addHeader("accept", "application/json");

// interceptor
JSONInterceptor interceptor = new JSONInterceptor();
Expand Down Expand Up @@ -536,6 +536,9 @@ protected void setUp() throws Exception {
}

class MockActionInvocationEx extends MockActionInvocation {

private static final long serialVersionUID = 3057703805130170757L;

private boolean invoked;

@Override
Expand Down

0 comments on commit 7985fd1

Please sign in to comment.