Skip to content

Commit e4266e1

Browse files
committed
Added unit test to verify that issue #158 is actually supported in the framework
1 parent c0b3b29 commit e4266e1

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringBootAppTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void testMethod_springSecurity_doesNotThrowException() {
3030
AwsProxyRequest req = new AwsProxyRequestBuilder("/test", "GET").build();
3131
AwsProxyResponse resp = handler.handleRequest(req, context);
3232
assertNotNull(resp);
33+
assertEquals(200, resp.getStatusCode());
3334
validateSingleValueModel(resp, TestController.TEST_VALUE);
3435
}
3536

@@ -53,7 +54,16 @@ public void defaultError_requestForward_springBootForwardsToDefaultErrorPage() {
5354
e.printStackTrace();
5455
fail();
5556
}
57+
}
58+
59+
@Test
60+
public void requestUri_dotInPathParam_expectRoutingToMethod() {
61+
AwsProxyRequest req = new AwsProxyRequestBuilder("/test/testdomain.com", "GET").build();
5662

63+
AwsProxyResponse resp = handler.handleRequest(req, context);
64+
assertNotNull(resp);
65+
assertEquals(200, resp.getStatusCode());
66+
validateSingleValueModel(resp, "testdomain.com");
5767
}
5868

5969
private void validateSingleValueModel(AwsProxyResponse output, String value) {

aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/springbootapp/TestController.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,56 @@
33

44
import com.amazonaws.serverless.proxy.spring.echoapp.model.SingleValueModel;
55

6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.http.MediaType;
68
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
79
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
810
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11+
import org.springframework.web.accept.ContentNegotiationStrategy;
12+
import org.springframework.web.bind.annotation.PathVariable;
913
import org.springframework.web.bind.annotation.RequestMapping;
1014
import org.springframework.web.bind.annotation.RequestMethod;
1115
import org.springframework.web.bind.annotation.RestController;
16+
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
17+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
18+
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
19+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
20+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
1221

1322

1423
@RestController
1524
@EnableWebSecurity
16-
public class TestController extends WebSecurityConfigurerAdapter{
25+
public class TestController extends WebSecurityConfigurerAdapter {
1726
public static final String TEST_VALUE = "test";
1827

28+
// workaround to address the most annoying issue in the world: https://blog.georgovassilis.com/2015/10/29/spring-mvc-rest-controller-says-406-when-emails-are-part-url-path/
29+
@Configuration
30+
public static class CustomConfig extends WebMvcConfigurerAdapter {
31+
@Override
32+
public void configurePathMatch(PathMatchConfigurer configurer) {
33+
configurer.setUseSuffixPatternMatch(false);
34+
}
35+
36+
@Override
37+
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
38+
configurer.favorPathExtension(false);
39+
}
40+
}
41+
1942
@RequestMapping(path = "/test", method = { RequestMethod.GET })
2043
public SingleValueModel testGet() {
2144
SingleValueModel value = new SingleValueModel();
2245
value.setValue(TEST_VALUE);
2346
return value;
2447
}
2548

49+
@RequestMapping(path = "/test/{domain}", method = { RequestMethod.GET})
50+
public SingleValueModel testDomainInPath(@PathVariable("domain") String domainName) {
51+
SingleValueModel value = new SingleValueModel();
52+
value.setValue(domainName);
53+
return value;
54+
}
55+
2656
@Override
2757
protected void configure(HttpSecurity http) throws Exception {
2858
http.sessionManagement().disable();

0 commit comments

Comments
 (0)