diff --git a/SPR-14397/README.md b/SPR-14397/README.md new file mode 100644 index 00000000..4ad5ba32 --- /dev/null +++ b/SPR-14397/README.md @@ -0,0 +1,37 @@ +# Repro project for SPR-14397 + +## Deploying + +It is possible to deploy your application directly from the command-line +using maven. You can use either [cargo](http://cargo.codehaus.org/) or +the [jetty plugin](http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html) +to run on a wide range of containers. + +### Cargo + +By default Cargo is configured to start `Tomcat7` and can be invoked by +running `mvn package cargo:run`. Cargo can also run a [wide range of other +containers](http://cargo.codehaus.org/Containers) and you can easily add +yours by editing the `pom.xml`. For instance, a `tomcat8` profile +has been added and can be invoked via `mvn package cargo:run -Ptomcat8`. + +You can remote debug the application, in your IDE, by using the following command: + `mvn package cargo:run -Ptomcat8 -Pdebug`. Note that you can customize the debug + port used with the `cargo.jvm.debug.port` maven property. + +### Jetty + +To deploy your application to jetty9, simply invoke `mvn jetty:run`. It +is possible to tune the exact jetty9 version you want to use by specifying +the version of the command line, e.g. `mvn jetty:run -Djetty.version=9.0.6.v20130930` + +To run a different version of jetty, please fallback to cargo as the +coordinates of the maven plugin have changed. A sample `jetty8` profile is +created for reference and can be tuned to suit your needs. To deploy your +sample application to jetty8 run `mvn cargo:run -Pjetty8` + +## Logging + +This project contains a `log4j.properties` file in `src/main/resources` that you +may wish to configure to emit more detailed logging. The root logger is set to +`INFO` and a custom `org.springframework.web` logger is set to `DEBUG`. diff --git a/SPR-14397/pom.xml b/SPR-14397/pom.xml new file mode 100644 index 00000000..0f135256 --- /dev/null +++ b/SPR-14397/pom.xml @@ -0,0 +1,103 @@ + + 4.0.0 + org.springframework.issues + SPR-14397 + 1.0-SNAPSHOT + jar + + + org.springframework.boot + spring-boot-starter-parent + 1.4.0.BUILD-SNAPSHOT + + + + UTF-8 + + 1.6 + + + + + org.springframework + spring-context + + + + org.springframework.boot + spring-boot-starter-web + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Tests.java + **/*Test.java + + + **/*Abstract*.java + + + + + + + + + spring-maven-snapshot + Springframework Maven Snapshot Repository + http://repo.spring.io/snapshot + + true + + + + spring-releases + https://repo.spring.io/libs-release + + + + + spring-releases + https://repo.spring.io/libs-release + + + spring-maven-snapshot + Springframework Maven Snapshot Repository + http://repo.spring.io/snapshot + + true + + + + + diff --git a/SPR-14397/src/main/java/org/springframework/issues/Application.java b/SPR-14397/src/main/java/org/springframework/issues/Application.java new file mode 100644 index 00000000..baf41970 --- /dev/null +++ b/SPR-14397/src/main/java/org/springframework/issues/Application.java @@ -0,0 +1,13 @@ +package org.springframework.issues; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableAutoConfiguration +public class Application { + public static void main(String[] args) throws Exception { + SpringApplication.run(Application.class, args); + } +} diff --git a/SPR-14397/src/main/java/org/springframework/issues/Controller.java b/SPR-14397/src/main/java/org/springframework/issues/Controller.java new file mode 100644 index 00000000..bfde9c4e --- /dev/null +++ b/SPR-14397/src/main/java/org/springframework/issues/Controller.java @@ -0,0 +1,28 @@ +package org.springframework.issues; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/test") +public class Controller { + @RequestMapping(value = "", + method = { RequestMethod.POST }, + consumes = { MediaType.APPLICATION_JSON_VALUE }, + produces = { MediaType.APPLICATION_JSON_VALUE } + ) + public String post1() { + return "Accept: JSON"; + } + + @RequestMapping(value = "", + method = { RequestMethod.POST }, + consumes = { MediaType.TEXT_PLAIN_VALUE }, + produces = { MediaType.APPLICATION_JSON_VALUE } + ) + public String post2() { + return "Accept: TEXT"; + } +} diff --git a/SPR-14397/src/test/java/org/springframework/issues/ReproTests.java b/SPR-14397/src/test/java/org/springframework/issues/ReproTests.java new file mode 100644 index 00000000..f8f13806 --- /dev/null +++ b/SPR-14397/src/test/java/org/springframework/issues/ReproTests.java @@ -0,0 +1,70 @@ +package org.springframework.issues; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +/** + * Unit test that reproduces an issue reported against SPR JIRA. @Test methods within + * need not pass with the green bar! Rather they should fail in such a way that + * demonstrates the reported issue. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = Application.class) +public class ReproTests { + @Autowired + private WebApplicationContext wac; + + private MockMvc mockMvc; + + @Before + public void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); + } + + @Test + public void testInputJson() throws Exception { + // Works fine, matches post1() + this.mockMvc.perform(post("/test") + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + } + + @Test + public void testInputText() throws Exception { + // Works fine, matches post2() + this.mockMvc.perform(post("/test") + .contentType(MediaType.TEXT_PLAIN) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + } + + @Test + public void testInputJsonBadAccept() throws Exception { + // Mismatches post1() by specifying an invalid Accept header but a valid Content-Type header + this.mockMvc.perform(post("/test") + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_XML)) + .andExpect(status().isNotAcceptable()); + } + + @Test + public void testInputTextBadAccept() throws Exception { + // Mismatches post2() by specifying an invalid Accept header but a valid Content-Type header + this.mockMvc.perform(post("/test") + .contentType(MediaType.TEXT_PLAIN) + .accept(MediaType.APPLICATION_XML)) + .andExpect(status().isNotAcceptable()); + } +} diff --git a/SPR-14397/src/test/resources/log4j.properties b/SPR-14397/src/test/resources/log4j.properties new file mode 100644 index 00000000..82776b7b --- /dev/null +++ b/SPR-14397/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootCategory=ERROR, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n + +log4j.category.org.springframework=WARN \ No newline at end of file diff --git a/SPR-14397/src/test/resources/org/springframework/issues/ReproTests-context.xml b/SPR-14397/src/test/resources/org/springframework/issues/ReproTests-context.xml new file mode 100644 index 00000000..d429656c --- /dev/null +++ b/SPR-14397/src/test/resources/org/springframework/issues/ReproTests-context.xml @@ -0,0 +1,8 @@ + + + +