mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
Merge branch 'support-2-3' of https://git-wip-us.apache.org/repos/asf/struts into support-2-3
Conflicts: plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
This commit is contained in:
@@ -300,9 +300,20 @@ public class RestActionMapper extends DefaultActionMapper {
|
||||
private void handleDynamicMethodInvocation(ActionMapping mapping, String name) {
|
||||
int exclamation = name.lastIndexOf("!");
|
||||
if (exclamation != -1) {
|
||||
mapping.setName(name.substring(0, exclamation));
|
||||
String actionName = name.substring(0, exclamation);
|
||||
String actionMethod = name.substring(exclamation + 1);
|
||||
|
||||
// WW-4585
|
||||
// add any ; appendix to name, it will be handled later in getMapping method
|
||||
int scPos = actionMethod.indexOf(';');
|
||||
if (scPos != -1) {
|
||||
actionName = actionName + actionMethod.substring(scPos);
|
||||
actionMethod = actionMethod.substring(0, scPos);
|
||||
}
|
||||
|
||||
mapping.setName(actionName);
|
||||
if (allowDynamicMethodCalls) {
|
||||
mapping.setMethod(name.substring(exclamation + 1));
|
||||
mapping.setMethod(actionMethod);
|
||||
} else {
|
||||
mapping.setMethod(null);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_CREATED;
|
||||
@@ -133,7 +135,7 @@ public class DefaultHttpHeadersTest extends TestCase {
|
||||
Date now = new Date();
|
||||
DefaultHttpHeaders headers = new DefaultHttpHeaders()
|
||||
.lastModified(now);
|
||||
mockRequest.addHeader("If-Modified-Since", new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(now));
|
||||
mockRequest.addHeader("If-Modified-Since", getGMTDateFormat().format(now));
|
||||
headers.apply(mockRequest, mockResponse, new Object());
|
||||
|
||||
assertEquals(SC_NOT_MODIFIED, mockResponse.getStatus());
|
||||
@@ -152,7 +154,7 @@ public class DefaultHttpHeadersTest extends TestCase {
|
||||
public void testLastModifiedSince() {
|
||||
Date now = new Date();
|
||||
DefaultHttpHeaders headers = new DefaultHttpHeaders().lastModified(now);
|
||||
mockRequest.addHeader("If-Modified-Since", new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(now));
|
||||
mockRequest.addHeader("If-Modified-Since", getGMTDateFormat().format(now));
|
||||
headers.apply(mockRequest, mockResponse, new Object());
|
||||
|
||||
assertEquals(SC_NOT_MODIFIED, mockResponse.getStatus());
|
||||
@@ -161,7 +163,7 @@ public class DefaultHttpHeadersTest extends TestCase {
|
||||
public void testLastModifiedSinceIsOlder() {
|
||||
Date now = new Date();
|
||||
DefaultHttpHeaders headers = new DefaultHttpHeaders().lastModified(now);
|
||||
mockRequest.addHeader("If-Modified-Since", new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(new Date(now.getTime() - 1000 * 60 * 60)));
|
||||
mockRequest.addHeader("If-Modified-Since", getGMTDateFormat().format(new Date(now.getTime() - 1000 * 60 * 60)));
|
||||
headers.apply(mockRequest, mockResponse, new Object());
|
||||
|
||||
assertEquals(SC_NOT_MODIFIED, mockResponse.getStatus());
|
||||
@@ -173,7 +175,7 @@ public class DefaultHttpHeadersTest extends TestCase {
|
||||
.lastModified(now)
|
||||
.withETag("asdf");
|
||||
mockRequest.addHeader("If-None-Match", "asdf");
|
||||
mockRequest.addHeader("If-Modified-Since", new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(now));
|
||||
mockRequest.addHeader("If-Modified-Since", getGMTDateFormat().format(now));
|
||||
headers.apply(mockRequest, mockResponse, new Object());
|
||||
|
||||
assertEquals(SC_NOT_MODIFIED, mockResponse.getStatus());
|
||||
@@ -219,4 +221,10 @@ public class DefaultHttpHeadersTest extends TestCase {
|
||||
assertEquals(SC_OK, mockResponse.getStatus());
|
||||
|
||||
}
|
||||
|
||||
private SimpleDateFormat getGMTDateFormat() {
|
||||
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class RestActionMapperTest extends TestCase {
|
||||
req.setRequestURI("/myapp/animals/dog/fido!update;jsessionid=29fefpv23do1g");
|
||||
req.setServletPath("/animals/dog/fido");
|
||||
req.setMethod("GET");
|
||||
|
||||
|
||||
ActionMapping mapping = mapper.getMapping(req, configManager);
|
||||
|
||||
assertEquals("/animals", mapping.getNamespace());
|
||||
@@ -196,10 +196,10 @@ public class RestActionMapperTest extends TestCase {
|
||||
req.setRequestURI("/myapp/animals/dog/fido!update;jsessionid=29fefpv23do1g");
|
||||
req.setServletPath("/animals/dog/fido");
|
||||
req.setMethod("GET");
|
||||
|
||||
|
||||
// allow DMI
|
||||
mapper.setAllowDynamicMethodCalls("true");
|
||||
|
||||
|
||||
ActionMapping mapping = mapper.getMapping(req, configManager);
|
||||
|
||||
assertEquals("/animals", mapping.getNamespace());
|
||||
|
||||
Reference in New Issue
Block a user