Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b6251e1

Browse filesBrowse files
More Examples
1 parent 914cbc0 commit b6251e1
Copy full SHA for b6251e1

File tree

Expand file treeCollapse file tree

13 files changed

+264
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

13 files changed

+264
-0
lines changed
Open diff view settings
Collapse file

‎packaging-war/.gitignore‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.settings/
Collapse file

‎packaging-war/pom.xml‎

Copy file name to clipboard
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<packaging>war</packaging>
7+
<parent>
8+
<groupId>com.springexamples.demo</groupId>
9+
<artifactId>SpringExamples</artifactId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
</parent>
12+
<groupId>com.springexamples.demo</groupId>
13+
<artifactId>packaging-war</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
<name>packaging-war</name>
16+
<url>http://maven.apache.org</url>
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-web</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-tomcat</artifactId>
29+
<scope>provided</scope>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-test</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
</dependencies>
38+
</project>
Collapse file
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.springexamples.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application
8+
{
9+
public static void main( String[] args )
10+
{
11+
SpringApplication.run(Application.class, args);
12+
}
13+
}
Collapse file
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.springexamples.demo.web;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
public class HelloController {
8+
9+
@RequestMapping("/")
10+
public String index() {
11+
return "Greetings from Spring Examples !!";
12+
}
13+
14+
}
Collapse file
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.springexamples.demo;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}
Collapse file

‎pom.xml‎

Copy file name to clipboardExpand all lines: pom.xml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@
3434
<module>template-thymeleaf</module>
3535
<module>template-mustache</module>
3636
<module>template-jsp</module>
37+
<module>ssl-https</module>
38+
<module>packaging-war</module>
3739
</modules>
3840
</project>
Collapse file

‎ssl-https/pom.xml‎

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.springexamples.demo</groupId>
8+
<artifactId>SpringExamples</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
</parent>
11+
<groupId>com.springexamples.demo</groupId>
12+
<artifactId>ssl-https</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>ssl-https</name>
15+
<url>http://maven.apache.org</url>
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-web</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-test</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
</dependencies>
31+
</project>
Collapse file
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.springexamples.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application
8+
{
9+
public static void main( String[] args )
10+
{
11+
SpringApplication.run(Application.class, args);
12+
}
13+
}
Collapse file
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.springexamples.demo.config;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
6+
import org.apache.catalina.connector.Connector;
7+
import org.apache.coyote.http11.Http11NioProtocol;
8+
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
9+
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.context.annotation.Configuration;
12+
import org.springframework.core.io.ClassPathResource;
13+
14+
@Configuration
15+
public class SSLConfig {
16+
17+
@Bean
18+
public ServletWebServerFactory servletContainer() {
19+
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
20+
tomcat.addAdditionalTomcatConnectors(redirectConnector());
21+
tomcat.addAdditionalTomcatConnectors(createSslConnector());
22+
return tomcat;
23+
}
24+
25+
private Connector createSslConnector() {
26+
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
27+
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
28+
try {
29+
File keystore = new ClassPathResource("keystore.jks").getFile();
30+
File truststore = new ClassPathResource("keystore.jks").getFile();
31+
connector.setScheme("https");
32+
connector.setSecure(true);
33+
connector.setPort(8443);
34+
protocol.setSSLEnabled(true);
35+
protocol.setKeystoreFile(keystore.getAbsolutePath());
36+
protocol.setKeystorePass("password");
37+
protocol.setTruststoreFile(truststore.getAbsolutePath());
38+
protocol.setTruststorePass("password");
39+
protocol.setKeyAlias("tomcat");
40+
return connector;
41+
} catch (IOException ex) {
42+
throw new IllegalStateException(
43+
"can't access keystore: [" + "keystore" + "] or truststore: [" + "keystore" + "]", ex);
44+
}
45+
}
46+
47+
private Connector redirectConnector() {
48+
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
49+
connector.setScheme("http");
50+
connector.setPort(8080);
51+
connector.setSecure(false);
52+
connector.setRedirectPort(8443);
53+
54+
return connector;
55+
}
56+
}
Collapse file
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.springexamples.demo.web;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
public class HelloController {
8+
9+
@RequestMapping("/")
10+
public String index() {
11+
return "Greetings from Spring Examples !!";
12+
}
13+
14+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.