cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1539372 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSValidationOutInterceptor.java systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
Date Wed, 06 Nov 2013 15:49:54 GMT
Author: sergeyb
Date: Wed Nov  6 15:49:54 2013
New Revision: 1539372

URL: http://svn.apache.org/r1539372
Log:
[CXF-5309] Validating Response values only if Valid annotation is present, review comment
from Andriy R.

Modified:
    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

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=1539372&r1=1539371&r2=1539372&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
Wed Nov  6 15:49:54 2013
@@ -22,6 +22,7 @@ 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;
@@ -58,8 +59,11 @@ public class JAXRSValidationOutIntercept
     protected void handleValidation(final Message message, final Object resourceInstance,
                                     final Method method, final List<Object> arguments)
{  
         if (arguments.size() == 1) {
-            if (arguments.get(0) instanceof Response && ((Response)arguments.get(0)).getEntity()
!= null) {
-                getOutProvider(message).validateReturnValue(((Response)arguments.get(0)).getEntity());
+            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);    
+                }
             } else {
                 super.handleValidation(message, resourceInstance, method, arguments);
             }

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=1539372&r1=1539371&r2=1539372&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
Wed Nov  6 15:49:54 2013
@@ -22,6 +22,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 import javax.ws.rs.DELETE;
@@ -52,6 +53,7 @@ public class BookStoreWithValidation ext
     
     @GET
     @Path("/booksResponse/{bookId}")
+    @Valid
     public Response getBookResponse(@PathParam("bookId") String id) {
         return Response.ok(books.get(id)).build();
     }



Mime
View raw message