cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7418] Initial support for ValidateOnExecution
Date Wed, 21 Jun 2017 12:59:01 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes d21ab1efa -> 662e4b1ee


[CXF-7418] Initial support for ValidateOnExecution


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/662e4b1e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/662e4b1e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/662e4b1e

Branch: refs/heads/3.1.x-fixes
Commit: 662e4b1eea09239cdba9ffcc3be793409d02e7d2
Parents: d21ab1e
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Jun 21 13:54:14 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Jun 21 13:58:42 2017 +0100

----------------------------------------------------------------------
 .../validation/AbstractValidationInterceptor.java    | 12 +++++++++++-
 .../jaxrs/validation/BookStoreWithValidation.java    | 15 +++++++++++++++
 .../validation/JAXRSClientServerValidationTest.java  | 12 +++++++++++-
 3 files changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/662e4b1e/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
b/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
index 821d7d1..f79468f 100644
--- a/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
+++ b/core/src/main/java/org/apache/cxf/validation/AbstractValidationInterceptor.java
@@ -23,6 +23,9 @@ import java.util.List;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
+import javax.validation.executable.ExecutableType;
+import javax.validation.executable.ValidateOnExecution;
+
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.Endpoint;
@@ -66,7 +69,14 @@ public abstract class AbstractValidationInterceptor extends AbstractPhaseInterce
             return;
         }
         
-        
+        ValidateOnExecution validateOnExec = method.getAnnotation(ValidateOnExecution.class);
+        if (validateOnExec != null) {
+            ExecutableType[] execTypes = validateOnExec.type();
+            if (execTypes.length == 1 && execTypes[0] == ExecutableType.NONE) {
+                return;
+            }
+        }
+
         final List< Object > arguments = MessageContentsList.getContentsList(message);
         
         handleValidation(message, theServiceObject, method, arguments);

http://git-wip-us.apache.org/repos/asf/cxf/blob/662e4b1e/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
index 7b6d463..929bdb1 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/BookStoreWithValidation.java
@@ -26,6 +26,8 @@ import java.util.Map;
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
+import javax.validation.executable.ExecutableType;
+import javax.validation.executable.ValidateOnExecution;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
@@ -82,6 +84,19 @@ public class BookStoreWithValidation extends AbstractBookStoreWithValidation
imp
     }
     
     @POST
+    @Path("/booksNoValidate")
+    @ValidateOnExecution(type = ExecutableType.NONE)
+    public Response addBookNoValidation(@NotNull @FormParam("id") String id) {
+        return Response.ok().build();
+    }
+    @POST
+    @Path("/booksValidate")
+    @ValidateOnExecution(type = ExecutableType.IMPLICIT)
+    public Response addBookValidate(@NotNull @FormParam("id") String id) {
+        return Response.ok().build();
+    }
+
+    @POST
     @Path("/books/direct")
     @Consumes("text/xml")
     public Response addBookDirect(@Valid BookWithValidation book, @Context final UriInfo
uriInfo) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/662e4b1e/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
index 08d6bae..a4d2dc4 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/validation/JAXRSClientServerValidationTest.java
@@ -116,7 +116,17 @@ public class JAXRSClientServerValidationTest extends AbstractJAXRSValidationTest
         final Response r = createWebClient("/bookstore/books").post(new Form());
         assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
     }
-    
+    @Test
+    public void testThatNotNullValidationSkipped()  {
+        final Response r = createWebClient("/bookstore/booksNoValidate").post(new Form());
+        assertEquals(200, r.getStatus());
+    }
+    @Test
+    public void testThatNotNullValidationNotSkipped()  {
+        final Response r = createWebClient("/bookstore/booksValidate").post(new Form());
+        assertEquals(400, r.getStatus());
+    }
+
     @Test
     public void testThatSizeValidationFails()  {
         final Response r = createWebClient("/bookstore/books").post(new Form().param("id",
""));


Mime
View raw message