Author: sergeyb
Date: Fri Nov 15 16:37:39 2013
New Revision: 1542316
URL: http://svn.apache.org/r1542316
Log:
[CXF-5309] Adding another patch from Andriy, with few minor updates
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/AbstractJAXRSValidationTest.java
(with props)
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidationPerRequest.java
(with props)
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSPerRequestValidationTest.java
(with props)
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookStoreWithValidation.java
(with props)
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java
(with props)
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
(with props)
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/web.xml
(with props)
Modified:
cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java
cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationProvider.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInvoker.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
Modified:
cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java?rev=1542316&r1=1542315&r2=1542316&view=diff
==============================================================================
---
cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java
(original)
+++
cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationOutInterceptor.java
Fri Nov 15 16:37:39 2013
@@ -35,7 +35,7 @@ public class ValidationOutInterceptor ex
@Override
protected void handleValidation(final Message message, final Object
resourceInstance,
final Method method, final List<Object>
arguments) {
- if (arguments.size() == 1 && arguments.get(0) != null) {
+ if (arguments.size() == 1) {
getOutProvider(message).validateReturnValue(resourceInstance,
method, arguments.get(0));
}
}
Modified:
cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationProvider.java?rev=1542316&r1=1542315&r2=1542316&view=diff
==============================================================================
---
cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationProvider.java
(original)
+++
cxf/trunk/core/src/main/java/org/apache/cxf/validation/ValidationProvider.java
Fri Nov 15 16:37:39 2013
@@ -27,6 +27,7 @@ import javax.validation.Configuration;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ParameterNameProvider;
+import javax.validation.Valid;
import javax.validation.Validation;
import javax.validation.ValidationException;
import javax.validation.ValidationProviderResolver;
@@ -137,6 +138,17 @@ public class ValidationProvider {
}
}
+ public< T > void validateReturnValue(Method m, final T returnValue) {
+ if (m.getAnnotation(Valid.class) == null) {
+ return;
+ }
+ //TODO: check Method annotations for Constraints
+
+ if (returnValue != null) {
+ validateReturnValue(returnValue);
+ }
+ }
+
public< T > void validateBean(final T bean) {
final Set<ConstraintViolation< T > > violations = doValidateBean(bean);
if (!violations.isEmpty()) {
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInvoker.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInvoker.java?rev=1542316&r1=1542315&r2=1542316&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInvoker.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationInvoker.java
Fri Nov 15 16:37:39 2013
@@ -22,7 +22,6 @@ import java.lang.reflect.Method;
import java.util.List;
import java.util.logging.Logger;
-import javax.validation.Valid;
import javax.validation.ValidationException;
import javax.ws.rs.core.Response;
@@ -31,6 +30,7 @@ import org.apache.cxf.jaxrs.JAXRSInvoker
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
import org.apache.cxf.validation.ValidationProvider;
@@ -59,14 +59,16 @@ public class JAXRSValidationInvoker exte
Object response = super.invoke(exchange, serviceObject, m, params);
- if (response != null) {
- if (response instanceof Response) {
- Object entity = ((Response)response).getEntity();
- if (entity != null && m.getAnnotation(Valid.class) != null) {
- theProvider.validateReturnValue(entity);
+ if (response instanceof MessageContentsList) {
+ MessageContentsList list = (MessageContentsList)response;
+ if (list.size() == 1) {
+ Object entity = ((MessageContentsList)list).get(0);
+
+ if (entity instanceof Response) {
+ theProvider.validateReturnValue(m,
((Response)entity).getEntity());
+ } else {
+ theProvider.validateReturnValue(serviceObject, m, entity);
}
- } else {
- theProvider.validateReturnValue(serviceObject, m, response);
}
}
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java?rev=1542316&r1=1542315&r2=1542316&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java
Fri Nov 15 16:37:39 2013
@@ -22,7 +22,6 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.util.List;
-import javax.validation.Valid;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
@@ -60,10 +59,7 @@ public class JAXRSValidationOutIntercept
final Method method, final List<Object>
arguments) {
if (arguments.size() == 1) {
if (arguments.get(0) instanceof Response) {
- Object entity = ((Response)arguments.get(0)).getEntity();
- if (entity != null && method.getAnnotation(Valid.class) !=
null) {
- getOutProvider(message).validateReturnValue(entity);
- }
+ getOutProvider(message).validateReturnValue(method,
((Response)arguments.get(0)).getEntity());
} else {
super.handleValidation(message, resourceInstance, method,
arguments);
}
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/AbstractJAXRSValidationTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/AbstractJAXRSValidationTest.java?rev=1542316&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/AbstractJAXRSValidationTest.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/AbstractJAXRSValidationTest.java
Fri Nov 15 16:37:39 2013
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.systest.jaxrs.validation;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+public abstract class AbstractJAXRSValidationTest extends
AbstractBusClientServerTestBase {
+ protected WebClient createWebClient(final String url) {
+ WebClient wc = WebClient
+ .create("http://localhost:" + getPort() + url)
+ .accept(MediaType.APPLICATION_JSON);
+
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
+ return wc;
+ }
+
+ protected abstract String getPort();
+}
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/AbstractJAXRSValidationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/AbstractJAXRSValidationTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java?rev=1542316&r1=1542315&r2=1542316&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
Fri Nov 15 16:37:39 2013
@@ -49,6 +49,7 @@ public class BookStoreWithValidation ext
@GET
@Path("/books/{bookId}")
@Override
+ @NotNull
public BookWithValidation getBook(@PathParam("bookId") String id) {
return books.get(id);
}
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidationPerRequest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidationPerRequest.java?rev=1542316&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidationPerRequest.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidationPerRequest.java
Fri Nov 15 16:37:39 2013
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.systest.jaxrs.validation;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
+@Path("/bookstore/")
+public class BookStoreWithValidationPerRequest {
+ private Map<String, BookWithValidation> books = new HashMap<String,
BookWithValidation>();
+ @NotNull private String id;
+
+ public BookStoreWithValidationPerRequest() {
+ books.put("123", new BookWithValidation("CXF", "123"));
+ books.put("124", new BookWithValidation("123"));
+ }
+
+ @QueryParam("id")
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ @GET
+ @Path("book")
+ @Valid @NotNull public BookWithValidation book() {
+ return books.get(id);
+ }
+
+ @GET
+ @Path("bookResponse")
+ @Valid @NotNull public Response bookResponse() {
+ return Response.ok(books.get(id)).build();
+ }
+}
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidationPerRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidationPerRequest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java?rev=1542316&r1=1542315&r2=1542316&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
Fri Nov 15 16:37:39 2013
@@ -22,13 +22,11 @@ import java.util.Arrays;
import java.util.Collections;
import javax.ws.rs.core.Form;
-import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.interceptor.JAXRSOutExceptionMapperInterceptor;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
@@ -37,7 +35,6 @@ import org.apache.cxf.jaxrs.validation.J
import org.apache.cxf.jaxrs.validation.JAXRSValidationOutInterceptor;
import org.apache.cxf.jaxrs.validation.ValidationExceptionMapper;
import org.apache.cxf.message.Message;
-import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
import org.apache.cxf.validation.ValidationProvider;
@@ -46,9 +43,8 @@ import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-public class JAXRSClientServerValidationTest extends
AbstractBusClientServerTestBase {
- public static final String PORT = allocatePort(Server.class);
-
+public class JAXRSClientServerValidationTest extends
AbstractJAXRSValidationTest {
+ public static final String PORT =
allocatePort(JAXRSClientServerValidationTest.class);
@Ignore
public static class Server extends AbstractBusTestServerBase {
@SuppressWarnings("unchecked")
@@ -90,7 +86,7 @@ public class JAXRSClientServerValidation
public static void startServers() throws Exception {
AbstractResourceInfo.clearAllMaps();
//keep out of process due to stack traces testing failures
- assertTrue("server did not launch correctly",
launchServer(Server.class, true));
+ assertTrue("server did not launch correctly",
launchServer(Server.class));
createStaticBus();
}
@@ -167,6 +163,24 @@ public class JAXRSClientServerValidation
}
@Test
+ public void testThatResponseValidationForOneBookNotFails() {
+ Response r = createWebClient("/bookstore/books").post(new
Form().param("id", "1234").param("name", "cxf"));
+ assertEquals(Status.CREATED.getStatusCode(), r.getStatus());
+
+ r = createWebClient("/bookstore/books/1234").get();
+ assertEquals(200, r.getStatus());
+ }
+
+ @Test
+ public void testThatResponseValidationForNullBookFails() {
+ Response r = createWebClient("/bookstore/books").post(new
Form().param("id", "1234").param("name", "cxf"));
+ assertEquals(Status.CREATED.getStatusCode(), r.getStatus());
+
+ r = createWebClient("/bookstore/books/1235").get();
+ assertEquals(500, r.getStatus());
+ }
+
+ @Test
public void testThatResponseValidationForOneResponseBookFails() {
Response r = createWebClient("/bookstore/books").post(new
Form().param("id", "1234"));
assertEquals(Status.CREATED.getStatusCode(), r.getStatus());
@@ -183,13 +197,12 @@ public class JAXRSClientServerValidation
r = createWebClient("/bookstore/books").get();
assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(),
r.getStatus());
}
+
+ @Override
+ protected String getPort() {
+ return PORT;
+ }
+
- private WebClient createWebClient(final String url) {
- WebClient wc = WebClient
- .create("http://localhost:" + PORT + url)
- .accept(MediaType.APPLICATION_JSON);
-
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
- return wc;
- }
}
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSPerRequestValidationTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSPerRequestValidationTest.java?rev=1542316&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSPerRequestValidationTest.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSPerRequestValidationTest.java
Fri Nov 15 16:37:39 2013
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.systest.jaxrs.validation;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.validation.JAXRSValidationInvoker;
+import org.apache.cxf.jaxrs.validation.ValidationExceptionMapper;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JAXRSPerRequestValidationTest extends AbstractJAXRSValidationTest
{
+ public static final String PORT =
allocatePort(JAXRSPerRequestValidationTest.class);
+ @Ignore
+ public static class Server extends AbstractBusTestServerBase {
+ protected void run() {
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+
+ sf.setResourceClasses(BookStoreWithValidationPerRequest.class);
+ sf.setProvider(new ValidationExceptionMapper());
+
+ sf.setAddress("http://localhost:" + PORT + "/");
+ sf.setInvoker(new JAXRSValidationInvoker());
+
+ sf.create();
+ }
+
+ public static void main(String[] args) {
+ try {
+ Server s = new Server();
+ s.start();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(-1);
+ } finally {
+ System.out.println("done!");
+ }
+ }
+ }
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ //keep out of process due to stack traces testing failures
+ assertTrue("server did not launch correctly",
launchServer(Server.class, true));
+ createStaticBus();
+ }
+
+ @Test
+ public void testThatNoValidationConstraintsAreViolatedWhenBookIdIsSet() {
+ final Response r = createWebClient("/bookstore/book").query("id",
"123").get();
+ assertEquals(Status.OK.getStatusCode(), r.getStatus());
+ }
+
+ @Test
+ public void testThatValidationConstraintsAreViolatedWhenBookIdIsNotSet() {
+ final Response r = createWebClient("/bookstore/book").get();
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
+ }
+
+ @Test
+ public void testThatValidationConstraintsAreViolatedWhenBookDoesNotExist()
{
+ final Response r = createWebClient("/bookstore/book").query("id",
"3333").get();
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(),
r.getStatus());
+ }
+ @Test
+ @Ignore
+ public void
testThatValidationConstraintsAreViolatedWhenBookDoesNotExistResponse() {
+ final Response r =
createWebClient("/bookstore/bookResponse").query("id", "3333").get();
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(),
r.getStatus());
+ }
+
+ @Test
+ public void testThatValidationConstraintsAreViolatedWhenBookNameIsNotSet()
{
+ final Response r = createWebClient("/bookstore/book").query("id",
"124").get();
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(),
r.getStatus());
+ }
+
+ @Override
+ protected String getPort() {
+ return PORT;
+ }
+}
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSPerRequestValidationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSPerRequestValidationTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookStoreWithValidation.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookStoreWithValidation.java?rev=1542316&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookStoreWithValidation.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookStoreWithValidation.java
Fri Nov 15 16:37:39 2013
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.systest.jaxrs.validation.spring;
+
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.systest.jaxrs.validation.BookWithValidation;
+import org.apache.cxf.validation.ValidationProvider;
+
+@Path("/bookstore/")
+public class BookStoreWithValidation {
+ private ValidationProvider provider;
+
+ public void setProvider(ValidationProvider provider) {
+ this.provider = provider;
+ }
+
+ @POST
+ @Path("/books")
+ public Response addBook(@Context final UriInfo uriInfo,
+ @NotNull @FormParam("id") String id,
+ @FormParam("name") String name) {
+
+ final BookWithValidation book = new BookWithValidation(name, id);
+ provider.validateBean(book);
+
+ return
Response.created(uriInfo.getRequestUriBuilder().path(id).build()).build();
+ }
+}
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookStoreWithValidation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/BookStoreWithValidation.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java?rev=1542316&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java
Fri Nov 15 16:37:39 2013
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.cxf.systest.jaxrs.validation.spring;
+
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.systest.jaxrs.AbstractSpringServer;
+import org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest;
+
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JAXRSClientServerValidationSpringTest extends
AbstractJAXRSValidationTest {
+ public static final String PORT =
allocatePort(JAXRSClientServerValidationSpringTest.class);
+
+ @Ignore
+ public static class Server extends AbstractSpringServer {
+ public Server() {
+ super("/jaxrs_spring_validation", Integer.parseInt(PORT));
+ }
+
+ public static void main(String[] args) {
+ try {
+ Server s = new Server();
+ s.start();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(-1);
+ } finally {
+ System.out.println("done!");
+ }
+ }
+ }
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ //keep out of process due to stack traces testing failures
+ assertTrue("server did not launch correctly",
launchServer(Server.class));
+ }
+
+ @Test
+ public void testProgrammaticValidationFailsIfNameIsNull() {
+ final Response r = createWebClient("/bookstore/books").post(new
Form().param("id", "1"));
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
+ }
+
+ @Test
+ public void
testProgrammaticValidationPassesButParameterValidationFailesIfIdIsNull() {
+ final Response r = createWebClient("/bookstore/books").post(new
Form().param("name", "aa"));
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
+ }
+
+ @Override
+ protected String getPort() {
+ return PORT;
+ }
+}
+
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/spring/JAXRSClientServerValidationSpringTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml?rev=1542316&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
(added)
+++
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
Fri Nov 15 16:37:39 2013
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans
+http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxrs
+http://cxf.apache.org/schemas/jaxrs.xsd">
+ <import resource="classpath:/META-INF/cxf/cxf.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+
+ <jaxrs:server address="/">
+ <jaxrs:inInterceptors>
+ <ref bean="validationInInterceptor" />
+ </jaxrs:inInterceptors>
+ <jaxrs:outInterceptors>
+ <ref bean="validationOutInterceptor" />
+ </jaxrs:outInterceptors>
+ <jaxrs:serviceBeans>
+ <ref bean="bookStoreWithValidation"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <ref bean="exceptionMapper"/>
+ </jaxrs:providers>
+ </jaxrs:server>
+
+ <bean id="exceptionMapper"
class="org.apache.cxf.jaxrs.validation.ValidationExceptionMapper"/>
+ <bean id="validationProvider"
class="org.apache.cxf.validation.ValidationProvider">
+ <constructor-arg name="parameterNameProvider">
+ <bean id="parameterNameProvider"
class="org.apache.cxf.jaxrs.validation.JAXRSParameterNameProvider" />
+ </constructor-arg>
+ </bean>
+
+ <bean id="bookStoreWithValidation"
class="org.apache.cxf.systest.jaxrs.validation.spring.BookStoreWithValidation">
+ <property name="provider" ref="validationProvider" />
+ </bean>
+ <bean id="validationInInterceptor"
class="org.apache.cxf.jaxrs.validation.JAXRSValidationInInterceptor">
+ <property name="provider" ref="validationProvider" />
+ </bean>
+ <bean id="validationOutInterceptor"
class="org.apache.cxf.jaxrs.validation.JAXRSValidationOutInterceptor">
+ <property name="provider" ref="validationProvider" />
+ </bean>
+</beans>
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/web.xml?rev=1542316&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/web.xml
(added)
+++
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/web.xml
Fri Nov 15 16:37:39 2013
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<!-- START SNIPPET: webxml -->
+<web-app>
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>WEB-INF/beans.xml</param-value>
+ </context-param>
+
+ <listener>
+ <listener-class>
+ org.springframework.web.context.ContextLoaderListener
+ </listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>CXFServlet</servlet-name>
+ <display-name>CXF Servlet</display-name>
+
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>CXFServlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
+<!-- END SNIPPET: webxml -->
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml