diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/SampleTomcatTwoConnectorsApplication.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/SampleTomcatTwoConnectorsApplication.java index 65bd6a958fd..24d5f6e151a 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/SampleTomcatTwoConnectorsApplication.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/SampleTomcatTwoConnectorsApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,26 +16,20 @@ package sample.tomcat; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - import org.apache.catalina.connector.Connector; -import org.apache.coyote.http11.Http11NioProtocol; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; -import org.springframework.core.io.ClassPathResource; -import org.springframework.util.FileCopyUtils; import org.springframework.util.SocketUtils; /** - * Sample Application to show Tomcat running 2 connectors + * Sample Application to show Tomcat running two connectors * * @author Brock Mills + * @author Andy Wilkinson */ @SpringBootApplication public class SampleTomcatTwoConnectorsApplication { @@ -54,37 +48,8 @@ public class SampleTomcatTwoConnectorsApplication { private Connector createSslConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); - Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); - try { - File keystore = getKeyStoreFile(); - File truststore = keystore; - connector.setScheme("https"); - connector.setSecure(true); - connector.setPort(port()); - protocol.setSSLEnabled(true); - protocol.setKeystoreFile(keystore.getAbsolutePath()); - protocol.setKeystorePass("changeit"); - protocol.setTruststoreFile(truststore.getAbsolutePath()); - protocol.setTruststorePass("changeit"); - protocol.setKeyAlias("apitester"); - return connector; - } - catch (IOException ex) { - throw new IllegalStateException("cant access keystore: [" + "keystore" - + "] or truststore: [" + "keystore" + "]", ex); - } - } - - private File getKeyStoreFile() throws IOException { - ClassPathResource resource = new ClassPathResource("keystore"); - try { - return resource.getFile(); - } - catch (Exception ex) { - File temp = File.createTempFile("keystore", ".tmp"); - FileCopyUtils.copy(resource.getInputStream(), new FileOutputStream(temp)); - return temp; - } + connector.setPort(port()); + return connector; } public static void main(String[] args) throws Exception { diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/application.properties new file mode 100644 index 00000000000..37199bfd256 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/application.properties @@ -0,0 +1,4 @@ +server.port = 8443 +server.ssl.key-store = classpath:sample.jks +server.ssl.key-store-password = secret +server.ssl.key-password = password diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/keystore b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/keystore deleted file mode 100644 index 6547e5b5194..00000000000 Binary files a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/keystore and /dev/null differ diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/sample.jks b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/sample.jks new file mode 100644 index 00000000000..6aa9a28053a Binary files /dev/null and b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/sample.jks differ diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/SampleTomcatTwoConnectorsApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/SampleTomcatTwoConnectorsApplicationTests.java index 55e479a624c..2d9465d20c6 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/SampleTomcatTwoConnectorsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/SampleTomcatTwoConnectorsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,9 +46,10 @@ import org.springframework.web.client.RestTemplate; import static org.junit.Assert.assertEquals; /** - * Basic integration tests for 2 connector demo application. + * Basic integration tests for {@link SampleTomcatTwoConnectorsApplication}. * * @author Brock Mills + * @author Andy Wilkinson */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = SampleTomcatTwoConnectorsApplication.class) @@ -109,14 +110,14 @@ public class SampleTomcatTwoConnectorsApplicationTests { }); template.setRequestFactory(factory); - ResponseEntity entity = template - .getForEntity("http://localhost:" + this.port + "/hello", String.class); + ResponseEntity entity = template.getForEntity( + "http://localhost:" + this.context.getBean("port") + "/hello", + String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("hello", entity.getBody()); - ResponseEntity httpsEntity = template.getForEntity( - "https://localhost:" + this.context.getBean("port") + "/hello", - String.class); + ResponseEntity httpsEntity = template + .getForEntity("https://localhost:" + this.port + "/hello", String.class); assertEquals(HttpStatus.OK, httpsEntity.getStatusCode()); assertEquals("hello", httpsEntity.getBody());