From 48d651c7531ae32afb14ab68c365264e9104eff9 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 5 Nov 2014 09:14:14 -0800 Subject: [PATCH] Add Jetty 9 sample See gh-369 --- spring-boot-samples/pom.xml | 1 + .../spring-boot-sample-jetty9/pom.xml | 50 +++++++++++++++++ .../sample/jetty/SampleJetty9Application.java | 33 +++++++++++ .../jetty/service/HelloWorldService.java | 32 +++++++++++ .../sample/jetty/web/SampleController.java | 37 ++++++++++++ .../jetty/SampleJettyApplicationTests.java | 56 +++++++++++++++++++ 6 files changed, 209 insertions(+) create mode 100644 spring-boot-samples/spring-boot-sample-jetty9/pom.xml create mode 100644 spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/SampleJetty9Application.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/service/HelloWorldService.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/web/SampleController.java create mode 100644 spring-boot-samples/spring-boot-sample-jetty9/src/test/java/sample/jetty/SampleJettyApplicationTests.java diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index a7ec0496a6..f0f48f457d 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -41,6 +41,7 @@ spring-boot-sample-jersey spring-boot-sample-jersey1 spring-boot-sample-jetty + spring-boot-sample-jetty9 spring-boot-sample-jta-atomikos spring-boot-sample-jta-bitronix spring-boot-sample-jta-jndi diff --git a/spring-boot-samples/spring-boot-sample-jetty9/pom.xml b/spring-boot-samples/spring-boot-sample-jetty9/pom.xml new file mode 100644 index 0000000000..a6fba953e8 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty9/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 1.2.0.BUILD-SNAPSHOT + + spring-boot-sample-jetty9 + Spring Boot Jetty Sample + Spring Boot Jetty 9 Sample + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + 9.2.3.v20140905 + 3.1.0 + + + + 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.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/SampleJetty9Application.java b/spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/SampleJetty9Application.java new file mode 100644 index 0000000000..fd41955b10 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/SampleJetty9Application.java @@ -0,0 +1,33 @@ +/* + * 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.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableAutoConfiguration +@ComponentScan +public class SampleJetty9Application { + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleJetty9Application.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/service/HelloWorldService.java new file mode 100644 index 0000000000..3fe540e33e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty9/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-jetty9/src/main/java/sample/jetty/web/SampleController.java b/spring-boot-samples/spring-boot-sample-jetty9/src/main/java/sample/jetty/web/SampleController.java new file mode 100644 index 0000000000..d3eb1f70a9 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty9/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-jetty9/src/test/java/sample/jetty/SampleJettyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty9/src/test/java/sample/jetty/SampleJettyApplicationTests.java new file mode 100644 index 0000000000..84a4a57cba --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jetty9/src/test/java/sample/jetty/SampleJettyApplicationTests.java @@ -0,0 +1,56 @@ +/* + * 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.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.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 = SampleJetty9Application.class) +@WebAppConfiguration +@IntegrationTest("server.port:0") +@DirtiesContext +public class SampleJettyApplicationTests { + + @Value("${local.server.port}") + private int port; + + @Test + public void testHome() throws Exception { + ResponseEntity entity = new TestRestTemplate().getForEntity( + "http://localhost:" + this.port, String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertEquals("Hello World", entity.getBody()); + } + +}