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

Commit 1ed6aff

Browse files
committed
Add project for SPR-17457
1 parent f1d283e commit 1ed6aff

File tree

8 files changed

+230
-0
lines changed

8 files changed

+230
-0
lines changed

SPR-17457/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Spring MVC project with Java config
2+
3+
This is a simple template for creating issue reproduction projects per
4+
the [README in the root of this repository](https://github.com/spring-projects/spring-framework-issues#readme).
5+
Please review that document before starting.
6+
7+
As described at the link above, do not edit this project directly! Rather
8+
use the `./create-repro-project.sh` script to create a fresh copy to
9+
a new directory having the same name as the JIRA issue you're trying
10+
to reproduce and edit from there.
11+
12+
## Deploying
13+
14+
It is possible to deploy your application directly from the command-line
15+
using maven. See the next two sections on Cargo and Jetty.
16+
17+
### Cargo
18+
19+
You can deploy with the [Cargo Maven plugin](http://cargo.codehaus.org/) which
20+
supports a wide [range of servers](http://cargo.codehaus.org/Containers).
21+
The required command is `mvn package cargo:run`.
22+
23+
By default Cargo is configured to start with `Tomcat 8` but you can easily
24+
edit the plugin settings in `pom.xml` to switch to a different server
25+
and version. The pom.xml or to switch to debug settings.
26+
27+
### Jetty
28+
29+
You can also deploy with the
30+
[Jetty Maven plugin](http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html).
31+
The required command is `mvn jetty:run` or `mvnDebug jetty:run`.
32+
33+
## Logging
34+
35+
This project contains a `log4j.properties` file in `src/main/resources` that you
36+
may wish to configure to emit more detailed logging. The root logger is set to
37+
`INFO` and a custom `org.springframework.web` logger is set to `DEBUG`.

SPR-17457/pom.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.example</groupId>
8+
9+
<artifactId>url.redirect</artifactId>
10+
<name>URL rewriting with forwarding</name>
11+
<packaging>jar</packaging>
12+
<properties>
13+
<maven.deploy.skip>true</maven.deploy.skip>
14+
<maven.compiler.source>1.8</maven.compiler.source>
15+
<maven.compiler.target>1.8</maven.compiler.target>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
18+
</properties>
19+
20+
<parent>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-parent</artifactId>
23+
<version>2.0.2.RELEASE</version>
24+
</parent>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>javax.servlet</groupId>
29+
<artifactId>javax.servlet-api</artifactId>
30+
<scope>provided</scope>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<pluginManagement>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-maven-plugin</artifactId>
50+
<version>${spring-boot.version}</version>
51+
</plugin>
52+
</plugins>
53+
</pluginManagement>
54+
55+
</build>
56+
57+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2000-2018 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.example.url.redirect;
17+
18+
import java.io.IOException;
19+
import java.io.PrintWriter;
20+
21+
import javax.servlet.ServletException;
22+
import javax.servlet.http.HttpServlet;
23+
import javax.servlet.http.HttpServletRequest;
24+
import javax.servlet.http.HttpServletResponse;
25+
26+
public class MyServlet extends HttpServlet {
27+
28+
@Override
29+
protected void service(HttpServletRequest request,
30+
HttpServletResponse response) throws ServletException, IOException {
31+
32+
response.setContentType("text/html");
33+
34+
// Actual logic goes here.
35+
PrintWriter out = response.getWriter();
36+
out.println("<h1>Servlet path is '" + request.getServletPath()
37+
+ "', path info is '" + request.getPathInfo() + ";</h1>");
38+
}
39+
40+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2000-2017 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.example.url.redirect;
17+
18+
import java.util.Collections;
19+
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.boot.SpringApplication;
22+
import org.springframework.boot.autoconfigure.SpringBootApplication;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
24+
import org.springframework.boot.web.servlet.ServletRegistrationBean;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
27+
import org.springframework.core.Ordered;
28+
import org.springframework.web.context.WebApplicationContext;
29+
import org.springframework.web.servlet.DispatcherServlet;
30+
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
31+
import org.springframework.web.servlet.mvc.Controller;
32+
import org.springframework.web.servlet.mvc.ServletForwardingController;
33+
34+
@SpringBootApplication
35+
@Configuration
36+
public class MyServletInitializer {
37+
38+
@Autowired
39+
private WebApplicationContext context;
40+
41+
private static final String MY_SERVLET = "my-servlet";
42+
43+
public static void main(String[] args) {
44+
SpringApplication.run(MyServletInitializer.class, args);
45+
}
46+
47+
@Bean
48+
public ServletRegistrationBean<MyServlet> servletRegistrationBean() {
49+
ServletRegistrationBean<MyServlet> registration = new ServletRegistrationBean<>(
50+
new MyServlet(), "/myServlet/*");
51+
registration.setName(MY_SERVLET);
52+
return registration;
53+
}
54+
55+
@Bean
56+
public SimpleUrlHandlerMapping vaadinRootMapping() {
57+
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
58+
mapping.setOrder(Ordered.LOWEST_PRECEDENCE - 1);
59+
60+
mapping.setUrlMap(
61+
Collections.singletonMap("/*", vaadinForwardingController()));
62+
63+
return mapping;
64+
}
65+
66+
@Bean
67+
public Controller vaadinForwardingController() {
68+
ServletForwardingController controller = new ServletForwardingController();
69+
controller.setServletName(MY_SERVLET);
70+
return controller;
71+
}
72+
73+
// @Bean
74+
// @ConditionalOnMissingClass("org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean")
75+
// public ServletRegistrationBean<DispatcherServlet> dispatcherServletRegistration() {
76+
// DispatcherServlet servlet = context.getBean(DispatcherServlet.class);
77+
// ServletRegistrationBean<DispatcherServlet> registration = new ServletRegistrationBean<>(servlet, "/*");
78+
// registration.setName("dispatcher");
79+
// return registration;
80+
// }
81+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
logging.level.org.springframework.web=DEBUG
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log4j.rootCategory=INFO, stdout
2+
3+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5+
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
6+
7+
log4j.category.org.springframework.web=DEBUG

SPR-17457/src/test/java/org/springframework/issues/.gitignore

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log4j.rootCategory=INFO, stdout
2+
3+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5+
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
6+
7+
log4j.category.org.springframework.web=DEBUG

0 commit comments

Comments
 (0)