Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 49c0466

Browse files
committed
Add repro project for SPR-13983
1 parent 3de97eb commit 49c0466

File tree

8 files changed

+168
-0
lines changed

8 files changed

+168
-0
lines changed

SPR-13983/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
To reproduce the issue:
2+
- http://localhost:8080/json/test : output OK {"result":true}
3+
- http://localhost:8080/html/test
4+
- http://localhost:8080/json/test : output NOK {"result":true}{"result":true}
5+
6+
The issue is reproducible only when RequestMappingHandlerAdapter.setSynchronizeOnSession(true)
7+
is invoked (cf. SynchronizeOnSessionPostProcessor) with Spring Framework 4.2.5.
8+
9+
Works fine with Spring Framework 4.2.4.

SPR-13983/pom.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.springframework.issues</groupId>
7+
<artifactId>SPR-13983</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Spring MVC Issue Reproduction Project for issue SPR-13983</name>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>1.3.3.RELEASE</version>
17+
<relativePath/> <!-- lookup parent from repository -->
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<java.version>1.8</java.version>
23+
<spring.version>4.2.5.RELEASE</spring.version>
24+
<jackson.version>2.4.2</jackson.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.apache.tomcat.embed</groupId>
35+
<artifactId>tomcat-embed-jasper</artifactId>
36+
<scope>compile</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>javax.servlet</groupId>
41+
<artifactId>jstl</artifactId>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-test</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
</dependencies>
50+
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-maven-plugin</artifactId>
56+
</plugin>
57+
</plugins>
58+
</build>
59+
60+
61+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.example;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.builder.SpringApplicationBuilder;
6+
import org.springframework.boot.context.web.SpringBootServletInitializer;
7+
8+
@SpringBootApplication
9+
public class DemoApplication extends SpringBootServletInitializer {
10+
11+
@Override
12+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
13+
return application.sources(DemoApplication.class);
14+
}
15+
16+
public static void main(String[] args) {
17+
SpringApplication.run(DemoApplication.class, args);
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.servlet.ModelAndView;
6+
7+
@Controller
8+
public class HtmlController {
9+
10+
@RequestMapping(value = "/html/test")
11+
public ModelAndView test1() {
12+
return new ModelAndView("test");
13+
}
14+
15+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example;
2+
3+
import java.util.LinkedHashMap;
4+
import java.util.Map;
5+
6+
import org.springframework.http.MediaType;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController
11+
public class JsonTestController {
12+
13+
@RequestMapping(value = "/json/test", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
14+
public Map<String, Object> test() {
15+
Map<String, Object> map = new LinkedHashMap<>();
16+
map.put("result", Boolean.TRUE);
17+
return map;
18+
}
19+
20+
@RequestMapping(value = "/json/test2", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
21+
public Map<String, Object> test2() {
22+
Map<String, Object> map = new LinkedHashMap<>();
23+
map.put("result", Boolean.TRUE);
24+
return map;
25+
}
26+
27+
@RequestMapping(value = "/json/test3", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
28+
public Map<String, Object> test3() {
29+
Map<String, Object> map = new LinkedHashMap<>();
30+
map.put("result", Boolean.TRUE);
31+
return map;
32+
}
33+
34+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example;
2+
3+
import org.springframework.beans.BeansException;
4+
import org.springframework.beans.factory.config.BeanPostProcessor;
5+
import org.springframework.stereotype.Component;
6+
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
7+
8+
@Component
9+
public class SynchronizeOnSessionPostProcessor implements BeanPostProcessor {
10+
11+
@Override
12+
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
13+
return bean;
14+
}
15+
16+
@Override
17+
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
18+
// do synchronize each http request
19+
if (bean instanceof RequestMappingHandlerAdapter) {
20+
RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
21+
adapter.setSynchronizeOnSession(true);
22+
}
23+
return bean;
24+
}
25+
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
spring.mvc.view.prefix=/WEB-INF/jsp/
2+
spring.mvc.view.suffix=.jsp
3+
logging.level.org.springframework.web=DEBUG
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

0 commit comments

Comments
 (0)