|
3 | 3 |
|
4 | 4 | import com.amazonaws.serverless.proxy.spring.echoapp.model.SingleValueModel; |
5 | 5 |
|
| 6 | +import org.springframework.context.annotation.Configuration; |
| 7 | +import org.springframework.http.MediaType; |
6 | 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
7 | 9 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
8 | 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
| 11 | +import org.springframework.web.accept.ContentNegotiationStrategy; |
| 12 | +import org.springframework.web.bind.annotation.PathVariable; |
9 | 13 | import org.springframework.web.bind.annotation.RequestMapping; |
10 | 14 | import org.springframework.web.bind.annotation.RequestMethod; |
11 | 15 | 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; |
12 | 21 |
|
13 | 22 |
|
14 | 23 | @RestController |
15 | 24 | @EnableWebSecurity |
16 | | -public class TestController extends WebSecurityConfigurerAdapter{ |
| 25 | +public class TestController extends WebSecurityConfigurerAdapter { |
17 | 26 | public static final String TEST_VALUE = "test"; |
18 | 27 |
|
| 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 | + |
19 | 42 | @RequestMapping(path = "/test", method = { RequestMethod.GET }) |
20 | 43 | public SingleValueModel testGet() { |
21 | 44 | SingleValueModel value = new SingleValueModel(); |
22 | 45 | value.setValue(TEST_VALUE); |
23 | 46 | return value; |
24 | 47 | } |
25 | 48 |
|
| 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 | + |
26 | 56 | @Override |
27 | 57 | protected void configure(HttpSecurity http) throws Exception { |
28 | 58 | http.sessionManagement().disable(); |
|
0 commit comments