From bebf26d91e306a97911180c4125191d0f4db4bf9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 17 Nov 2014 17:18:31 +0000 Subject: [PATCH] Restore compatibility with Jetty 8 when SSL is being used ServerConnector is in different packages in Jetty 8 and Jetty 9 which was leading to a NoClassDefFounderError when SSL was used with Jetty 8. This commit updates SslServerConnectorFactory to return an AbstractConnector, a super class of ServerConnector, that is in the same package in both Jetty 8 and Jetty 9. This class does not provide a setPort method so the setting of the port has been pushed down into the SslServerConnectorFactory implementation. SSL samples for both Jetty 8 and Jetty 9 have been added to verify SSL with both supported versions of Jetty. Closes gh-1925 --- spring-boot-samples/pom.xml | 2 + .../spring-boot-sample-jetty-ssl/pom.xml | 53 +++++++++++++ .../jetty/SampleJettySslApplication.java | 29 +++++++ .../jetty/service/HelloWorldService.java | 32 ++++++++ .../sample/jetty/web/SampleController.java | 37 +++++++++ .../src/main/resources/application.properties | 4 + .../src/main/resources/sample.jks | Bin 0 -> 2264 bytes .../jetty/SampleJettySslApplicationTests.java | 72 ++++++++++++++++++ .../spring-boot-sample-jetty8-ssl/pom.xml | 56 ++++++++++++++ .../jetty/SampleJetty8SslApplication.java | 29 +++++++ .../jetty/service/HelloWorldService.java | 32 ++++++++ .../sample/jetty/web/SampleController.java | 37 +++++++++ .../src/main/resources/application.properties | 4 + .../src/main/resources/sample.jks | Bin 0 -> 2264 bytes .../SampleJetty8SslApplicationTests.java | 72 ++++++++++++++++++ ...java => SampleJetty8ApplicationTests.java} | 2 +- .../JettyEmbeddedServletContainerFactory.java | 31 +++++--- 17 files changed, 479 insertions(+), 13 deletions(-) create mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml create mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/SampleJettySslApplication.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/service/HelloWorldService.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/web/SampleController.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/application.properties create mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/sample.jks create mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/SampleJettySslApplicationTests.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty8-ssl/pom.xml create mode 100644 spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/SampleJetty8SslApplication.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/service/HelloWorldService.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/web/SampleController.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/application.properties create mode 100644 spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/sample.jks create mode 100644 spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty/SampleJetty8SslApplicationTests.java rename spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty/{SampleJettyApplicationTests.java => SampleJetty8ApplicationTests.java} (97%) diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 4c0aaecd61..b74248f595 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -41,7 +41,9 @@ spring-boot-sample-jersey spring-boot-sample-jersey1 spring-boot-sample-jetty + spring-boot-sample-jetty-ssl spring-boot-sample-jetty8 + spring-boot-sample-jetty8-ssl spring-boot-sample-jta-atomikos spring-boot-sample-jta-bitronix spring-boot-sample-jta-jndi diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml b/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml new file mode 100644 index 0000000000..9d822169bf --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 1.2.0.BUILD-SNAPSHOT + + spring-boot-sample-jetty-ssl + Spring Boot Jetty SSL Sample + Spring Boot Jetty SSL Sample + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-jetty + + + org.springframework + spring-webmvc + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.httpcomponents + httpclient + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/SampleJettySslApplication.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/SampleJettySslApplication.java new file mode 100644 index 0000000000..8953530d68 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/SampleJettySslApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jetty; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJettySslApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleJettySslApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/service/HelloWorldService.java new file mode 100644 index 0000000000..3fe540e33e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/service/HelloWorldService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jetty.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Value("${name:World}") + private String name; + + public String getHelloMessage() { + return "Hello " + this.name; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/web/SampleController.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/web/SampleController.java new file mode 100644 index 0000000000..d3eb1f70a9 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/web/SampleController.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jetty.web; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import sample.jetty.service.HelloWorldService; + +@Controller +public class SampleController { + + @Autowired + private HelloWorldService helloWorldService; + + @RequestMapping("/") + @ResponseBody + public String helloWorld() { + return this.helloWorldService.getHelloMessage(); + } +} diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/application.properties new file mode 100644 index 0000000000..953abe0d6c --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/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 \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/sample.jks b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/sample.jks new file mode 100644 index 0000000000000000000000000000000000000000..6aa9a28053a591e41453e665e5024e8a8cb78b3d GIT binary patch literal 2264 zcmchYX*3iJ7sqE|hQS!q5Mv)4GM2$i#uAFqC`%7x7baWA*i&dRX>3`uq(XS?3XSYp z%38`&ib7E$8j~$cF^}gt?|I+noW8#w?uYxk=iGD8|K9Vzd#pVc0002(2k@T|2@MMI zqxqr2AhQO*TVi`j@((S;e;g;l$#dAA{>vf0kX$R(Qn4oKgGEYjZ5zti2dw?Z6A zh%LuFCNI?9o+Z1duJL-++e#cjO`zlK?u9s030=k_*wD1#-$FbIDRDnA^vo@fm( zzjt(3VJrGOr0iHXSTM|rYN#>RZ@Dp`PwB2zrDQffLvuoR2~V3ReYa0&vU^dXd8isV zsAf*@!8s%xBvHLseXn6f?1kefe(8uAmAbaF$x{Ykzb6c6jdUwY1$y4tFzsj7 zIghr!T#ODfu@Po!a29@kXQ8kY#(LE<0o7?7PQ|eMeY@Equ?R-6*f@Na3o&stDQ=6( zQzDSQhCnS(9Bu9W_~giknP0vECqUsr4_9y_}nEU`cy z4}dApnAip92wMwgzciAFpc3i}+-#Zlq+iF7d1y}d4Qsp8=%l1N8NIs161I`HmkcpQ zY4*CUCFJJf(2!M{`&qQ}3($KeTQ=)mMrBs`DOb;%Of0tC)9he_p~w&CO#DfCgx(%s z{@|D(brX_Gb}ZDLmGej*JgEl0Et>q~kgTXuJg-PwvRjNx8sBbIShxD=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696Kw1-{IzSOTnFF+0@k$o3%ZHS;Q#;t literal 0 HcmV?d00001 diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/SampleJettySslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/SampleJettySslApplicationTests.java new file mode 100644 index 0000000000..a682ed4e2c --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/SampleJettySslApplicationTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jetty; + +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.impl.client.HttpClients; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import static org.junit.Assert.assertEquals; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleJettySslApplication.class) +@WebAppConfiguration +@IntegrationTest("server.port:0") +@DirtiesContext +public class SampleJettySslApplicationTests { + + @Value("${local.server.port}") + private int port; + + @Test + public void testHome() throws Exception { + SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( + new SSLContextBuilder().loadTrustMaterial(null, + new TrustSelfSignedStrategy()).build()); + + HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory) + .build(); + + TestRestTemplate testRestTemplate = new TestRestTemplate(); + ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory()) + .setHttpClient(httpClient); + ResponseEntity entity = testRestTemplate.getForEntity( + "https://localhost:" + this.port, String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertEquals("Hello World", entity.getBody()); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/pom.xml b/spring-boot-samples/spring-boot-sample-jetty8-ssl/pom.xml new file mode 100644 index 0000000000..f157d309fe --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 1.2.0.BUILD-SNAPSHOT + + spring-boot-sample-jetty8-ssl + Spring Boot Jetty 8 SSL Sample + Spring Boot Jetty 8 SSL Sample + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + 8.1.15.v20140411 + 2.2.0.v201112011158 + 3.0.1 + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-jetty + + + org.springframework + spring-webmvc + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.httpcomponents + httpclient + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/SampleJetty8SslApplication.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/SampleJetty8SslApplication.java new file mode 100644 index 0000000000..a548f27b4c --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/SampleJetty8SslApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jetty; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJetty8SslApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleJetty8SslApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/service/HelloWorldService.java new file mode 100644 index 0000000000..3fe540e33e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/service/HelloWorldService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jetty.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Value("${name:World}") + private String name; + + public String getHelloMessage() { + return "Hello " + this.name; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/web/SampleController.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/web/SampleController.java new file mode 100644 index 0000000000..d3eb1f70a9 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/java/sample/jetty/web/SampleController.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jetty.web; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import sample.jetty.service.HelloWorldService; + +@Controller +public class SampleController { + + @Autowired + private HelloWorldService helloWorldService; + + @RequestMapping("/") + @ResponseBody + public String helloWorld() { + return this.helloWorldService.getHelloMessage(); + } +} diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/application.properties new file mode 100644 index 0000000000..953abe0d6c --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/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 \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/sample.jks b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/sample.jks new file mode 100644 index 0000000000000000000000000000000000000000..6aa9a28053a591e41453e665e5024e8a8cb78b3d GIT binary patch literal 2264 zcmchYX*3iJ7sqE|hQS!q5Mv)4GM2$i#uAFqC`%7x7baWA*i&dRX>3`uq(XS?3XSYp z%38`&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uF~WhsR_w(q7;vV5d4P zr%ZUA2}kO+L^2ePTgGT9Ua71w<+)poSyjTdLq&xbUn`<6&SpwFp(HRHUyU6J3WZ_! zfztko79+94Tq%mTYj53(RYcL&1~5`I#+w3`(Q|r+P(aT z%?r(^?IWw~19CB&uvXf(f7&BnEE{zwK4piVU`I4j1j?v5d4N<7VUJ8nM`$7S*mfKR z#9-JzPRZ?{M!@L+0N^V)IyeeP2T|^UK|m0QD+Ibs!wEoml^N!YO#vW~j~jraX(0A3 z6Kux?IRLez`O^X;{!4g%BhcRn>^H*qKZ3*|{_YGuz)KCJcu;)DSES5D2tDE`C02YR0R%Vy1T7k|RQ;3g<0icA$AuP0pOvc~jGl zz+NeKv_FT_;GWK&8XlDUv&hv9kxg?@c!bu?83i=YQ$S!K09Y)Glg3Hz?@|)ZCBlVz zP8i}#XZkMoje3I=h&I!!s_m?Qi@1MR`yv7X*yEs47qOs^t^?&=;*IQ!q&)gq_Sx5* z?fhU8Q*PSe*w7y)FH#P!9R^Xw!lTT+zI39L<&8cViaj$A(Z2Cg7!{V?uuyi#vlNCg z40i}2ivw&y&1-&Nh&WMG`&aIt>)(#tKTJ}^@696Kw1-{IzSOTnFF+0@k$o3%ZHS;Q#;t literal 0 HcmV?d00001 diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty/SampleJetty8SslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty/SampleJetty8SslApplicationTests.java new file mode 100644 index 0000000000..8ac26477e0 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty/SampleJetty8SslApplicationTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.jetty; + +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.impl.client.HttpClients; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import static org.junit.Assert.assertEquals; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleJetty8SslApplication.class) +@WebAppConfiguration +@IntegrationTest("server.port:0") +@DirtiesContext +public class SampleJetty8SslApplicationTests { + + @Value("${local.server.port}") + private int port; + + @Test + public void testHome() throws Exception { + SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( + new SSLContextBuilder().loadTrustMaterial(null, + new TrustSelfSignedStrategy()).build()); + + HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory) + .build(); + + TestRestTemplate testRestTemplate = new TestRestTemplate(); + ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory()) + .setHttpClient(httpClient); + ResponseEntity entity = testRestTemplate.getForEntity( + "https://localhost:" + this.port, String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertEquals("Hello World", entity.getBody()); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty/SampleJettyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty/SampleJetty8ApplicationTests.java similarity index 97% rename from spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty/SampleJettyApplicationTests.java rename to spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty/SampleJetty8ApplicationTests.java index abe3f2f996..535df11217 100644 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty/SampleJettyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty/SampleJetty8ApplicationTests.java @@ -40,7 +40,7 @@ import static org.junit.Assert.assertEquals; @WebAppConfiguration @IntegrationTest("server.port:0") @DirtiesContext -public class SampleJettyApplicationTests { +public class SampleJetty8ApplicationTests { @Value("${local.server.port}") private int port; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java index ac9826be92..9fb837f0a6 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java @@ -27,6 +27,7 @@ import java.util.List; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.MimeTypes; +import org.eclipse.jetty.server.AbstractConnector; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; @@ -120,9 +121,8 @@ public class JettyEmbeddedServletContainerFactory extends if (getSsl() != null) { SslContextFactory sslContextFactory = new SslContextFactory(); configureSsl(sslContextFactory, getSsl()); - ServerConnector connector = getSslServerConnectorFactory().getConnector( - server, sslContextFactory); - connector.setPort(port); + AbstractConnector connector = getSslServerConnectorFactory().getConnector( + server, sslContextFactory, port); server.setConnectors(new Connector[] { connector }); } @@ -473,7 +473,8 @@ public class JettyEmbeddedServletContainerFactory extends */ private static interface SslServerConnectorFactory { - ServerConnector getConnector(Server server, SslContextFactory sslContextFactory); + AbstractConnector getConnector(Server server, + SslContextFactory sslContextFactory, int port); } @@ -485,10 +486,12 @@ public class JettyEmbeddedServletContainerFactory extends @Override public ServerConnector getConnector(Server server, - SslContextFactory sslContextFactory) { - return new ServerConnector(server, new SslConnectionFactory( - sslContextFactory, HttpVersion.HTTP_1_1.asString()), - new HttpConnectionFactory()); + SslContextFactory sslContextFactory, int port) { + ServerConnector serverConnector = new ServerConnector(server, + new SslConnectionFactory(sslContextFactory, + HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory()); + serverConnector.setPort(port); + return serverConnector; } } @@ -499,13 +502,17 @@ public class JettyEmbeddedServletContainerFactory extends SslServerConnectorFactory { @Override - public ServerConnector getConnector(Server server, - SslContextFactory sslContextFactory) { + public AbstractConnector getConnector(Server server, + SslContextFactory sslContextFactory, int port) { try { Class connectorClass = Class .forName("org.eclipse.jetty.server.ssl.SslSocketConnector"); - return (ServerConnector) connectorClass.getConstructor( - SslContextFactory.class).newInstance(sslContextFactory); + AbstractConnector connector = (AbstractConnector) connectorClass + .getConstructor(SslContextFactory.class).newInstance( + sslContextFactory); + connector.getClass().getMethod("setPort", int.class) + .invoke(connector, port); + return connector; } catch (Exception ex) { throw new IllegalStateException(ex);