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-7091] Avoiding the second out validation by default
Date Fri, 21 Oct 2016 16:21:10 GMT
Repository: cxf
Updated Branches:
  refs/heads/master cbac9a908 -> 1e56cc54d


[CXF-7091] Avoiding the second out validation by default


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

Branch: refs/heads/master
Commit: 1e56cc54d146704842b2e4ac09204e45524dc1d1
Parents: cbac9a9
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Oct 21 17:20:53 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Oct 21 17:20:53 2016 +0100

----------------------------------------------------------------------
 .../jaxrs/validation/JAXRSBeanValidationFeature.java |  9 ++++++---
 .../JAXRSBeanValidationOutInterceptor.java           | 15 ++++++++++++++-
 .../jaxrs_spring_validation/WEB-INF/beans.xml        |  4 +---
 3 files changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1e56cc54/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationFeature.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationFeature.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationFeature.java
index 186a3e6..318a2b6 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationFeature.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationFeature.java
@@ -22,18 +22,18 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.interceptor.InterceptorProvider;
 import org.apache.cxf.validation.BeanValidationInInterceptor;
-import org.apache.cxf.validation.BeanValidationOutInterceptor;
 import org.apache.cxf.validation.BeanValidationProvider;
 
 
 public class JAXRSBeanValidationFeature extends AbstractFeature {
 
     private BeanValidationProvider validationProvider;
-    
+    private boolean supportMultipleValidations;
     @Override
     protected void initializeProvider(InterceptorProvider interceptorProvider, Bus bus) {
         BeanValidationInInterceptor in = new JAXRSBeanValidationInInterceptor();
-        BeanValidationOutInterceptor out = new JAXRSBeanValidationOutInterceptor();
+        JAXRSBeanValidationOutInterceptor out = new JAXRSBeanValidationOutInterceptor();
+        out.setSupportMultipleValidations(supportMultipleValidations);
         if (validationProvider != null) {
             in.setProvider(validationProvider);
             out.setProvider(validationProvider);
@@ -45,4 +45,7 @@ public class JAXRSBeanValidationFeature extends AbstractFeature {
     public void setProvider(BeanValidationProvider provider) {
         this.validationProvider = provider;
     }
+    public void setSupportMultipleValidations(boolean supportMultipleValidations) {
+        this.supportMultipleValidations = supportMultipleValidations;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/1e56cc54/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationOutInterceptor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationOutInterceptor.java
index 386e427..d477f47 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationOutInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/JAXRSBeanValidationOutInterceptor.java
@@ -33,6 +33,8 @@ import org.apache.cxf.validation.BeanValidationOutInterceptor;
 @Provider
 public class JAXRSBeanValidationOutInterceptor extends BeanValidationOutInterceptor
     implements ContainerResponseFilter {
+    private static final String OUT_VALIDATION_DONE = "out.bean.validation.done";
+    private boolean supportMultipleValidations;
     public JAXRSBeanValidationOutInterceptor() {
     }
     public JAXRSBeanValidationOutInterceptor(String phase) {
@@ -51,6 +53,17 @@ public class JAXRSBeanValidationOutInterceptor extends BeanValidationOutIntercep
     
     @Override
     public void filter(ContainerRequestContext in, ContainerResponseContext out) throws IOException
{
-        super.handleMessage(PhaseInterceptorChain.getCurrentMessage());
+        Message message = PhaseInterceptorChain.getCurrentMessage();
+        if (Boolean.TRUE != message.get(OUT_VALIDATION_DONE)
+            || supportMultipleValidations) { 
+            try {
+                super.handleMessage(message);
+            } finally {
+                message.put(OUT_VALIDATION_DONE, Boolean.TRUE);
+            }
+        }
+    }
+    public void setSupportMultipleValidations(boolean supportMultipleValidations) {
+        this.supportMultipleValidations = supportMultipleValidations;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/1e56cc54/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
index 1149e51..f46f88f 100644
--- a/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
+++ b/systests/jaxrs/src/test/resources/jaxrs_spring_validation/WEB-INF/beans.xml
@@ -35,14 +35,12 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
         <jaxrs:inInterceptors>
             <ref bean="jaxrsValidationInInterceptor" />
         </jaxrs:inInterceptors>
-        <jaxrs:outInterceptors>
-            <ref bean="jaxrsValidationOutInterceptor" />
-        </jaxrs:outInterceptors>
         <jaxrs:serviceBeans>
             <ref bean="bookStoreWithValidation"/>
         </jaxrs:serviceBeans>
         <jaxrs:providers>
             <ref bean="exceptionMapper"/>
+            <ref bean="jaxrsValidationOutInterceptor" />
         </jaxrs:providers>
     </jaxrs:server>
     


Mime
View raw message