From 492cf4ef541c38113ac9ad81c155c12b87fd7a5b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 15 Jan 2015 09:50:05 +0000 Subject: [PATCH] Add jersey-bean-validation to spring-boot-starter-jersey MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A dependency on org.glassfish.jersey.ext:jersey-bean-validation has been added to spring-boot-starter-jersey. jersey-bean-validation’s EL dependencies have been excluded in favour of those provided by spring-boot-starter-tomcat (or starter-jetty or starter-undertow should the user choose to use a different embedded container). Closes gh-2315 --- spring-boot-dependencies/pom.xml | 5 +++ .../main/java/sample/jersey/JerseyConfig.java | 3 +- .../java/sample/jersey/ReverseEndpoint.java | 35 +++++++++++++++++++ .../jersey/SampleJerseyApplicationTests.java | 17 ++++++++- .../spring-boot-starter-jersey/pom.xml | 14 ++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/ReverseEndpoint.java diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 48589fb442..8699ee2fff 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -1053,6 +1053,11 @@ jersey-server ${jersey.version} + + org.glassfish.jersey.ext + jersey-bean-validation + ${jersey.version} + org.glassfish.jersey.ext jersey-spring3 diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java index 85c763f7b1..c1c5b364b2 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java +++ b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.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. @@ -24,6 +24,7 @@ public class JerseyConfig extends ResourceConfig { public JerseyConfig() { register(Endpoint.class); + register(ReverseEndpoint.class); } } diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/ReverseEndpoint.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/ReverseEndpoint.java new file mode 100644 index 0000000000..722e89844e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/ReverseEndpoint.java @@ -0,0 +1,35 @@ +/* + * 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. + * 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.jersey; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +import org.springframework.stereotype.Component; + +@Component +@Path("/reverse") +public class ReverseEndpoint { + + @GET + public String reverse(@QueryParam("input") @NotNull String input) { + return new StringBuilder(input).reverse().toString(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java index 2902f7c924..724c716dd5 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.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. @@ -48,4 +48,19 @@ public class SampleJerseyApplicationTests { assertEquals(HttpStatus.OK, entity.getStatusCode()); } + @Test + public void reverse() { + ResponseEntity entity = this.restTemplate.getForEntity( + "http://localhost:" + this.port + "/reverse?input=olleh", String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertEquals("hello", entity.getBody()); + } + + @Test + public void validation() { + ResponseEntity entity = this.restTemplate.getForEntity( + "http://localhost:" + this.port + "/reverse", String.class); + assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode()); + } + } diff --git a/spring-boot-starters/spring-boot-starter-jersey/pom.xml b/spring-boot-starters/spring-boot-starter-jersey/pom.xml index 47700b5af6..8430b1650e 100644 --- a/spring-boot-starters/spring-boot-starter-jersey/pom.xml +++ b/spring-boot-starters/spring-boot-starter-jersey/pom.xml @@ -60,6 +60,20 @@ org.glassfish.jersey.containers jersey-container-servlet + + org.glassfish.jersey.ext + jersey-bean-validation + + + javax.el + javax.el-api + + + org.glassfish.web + javax.el + + + org.glassfish.jersey.ext jersey-spring3