cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject [3/3] cxf git commit: [CXF-6706]: use current versions of all things hibernate-validator to make this work. Improve generic signatures in BeanValidationProvider.
Date Thu, 17 Dec 2015 19:27:59 GMT
[CXF-6706]: use current versions of all things hibernate-validator
to make this work. Improve generic signatures in BeanValidationProvider.


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

Branch: refs/heads/master
Commit: 40dc07cea0667abbcc120f4424449776f252e7c1
Parents: 7264f54
Author: Benson Margulies <benson@basistech.com>
Authored: Thu Dec 17 21:26:22 2015 +0200
Committer: Benson Margulies <benson@basistech.com>
Committed: Thu Dec 17 21:27:39 2015 +0200

----------------------------------------------------------------------
 .../cxf/validation/BeanValidationProvider.java  | 31 ++++--------------
 .../apache/cxf/osgi/itests/jaxrs/BookStore.java | 34 ++++++++++----------
 .../features/src/main/resources/features.xml    |  7 +---
 parent/pom.xml                                  |  6 ++--
 4 files changed, 28 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/40dc07ce/core/src/main/java/org/apache/cxf/validation/BeanValidationProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/validation/BeanValidationProvider.java b/core/src/main/java/org/apache/cxf/validation/BeanValidationProvider.java
index 31e12e1..da285a0 100644
--- a/core/src/main/java/org/apache/cxf/validation/BeanValidationProvider.java
+++ b/core/src/main/java/org/apache/cxf/validation/BeanValidationProvider.java
@@ -32,6 +32,7 @@ import javax.validation.ValidationException;
 import javax.validation.ValidationProviderResolver;
 import javax.validation.ValidatorFactory;
 import javax.validation.executable.ExecutableValidator;
+import javax.validation.spi.ValidationProvider;
 
 import org.apache.cxf.common.logging.LogUtils;
 
@@ -39,8 +40,7 @@ public class BeanValidationProvider {
     private static final Logger LOG = LogUtils.getL7dLogger(BeanValidationProvider.class);
     
     private final ValidatorFactory factory;
-    private ClassLoader validateContextClassloader;
-    
+
     public BeanValidationProvider() {
         try {
             factory = Validation.buildDefaultValidatorFactory();
@@ -76,15 +76,15 @@ public class BeanValidationProvider {
         this(resolver, null);
     }
     
-    public <T extends Configuration<T>> BeanValidationProvider(
+    public <T extends Configuration<T>, U extends ValidationProvider<T>>
BeanValidationProvider(
         ValidationProviderResolver resolver,
-        Class<javax.validation.spi.ValidationProvider<T>> providerType) {
+        Class<U> providerType) {
         this(resolver, providerType, null);
     }
 
-    public <T extends Configuration<T>> BeanValidationProvider(
+    public <T extends Configuration<T>, U extends ValidationProvider<T>>
BeanValidationProvider(
         ValidationProviderResolver resolver,
-        Class<javax.validation.spi.ValidationProvider<T>> providerType,
+        Class<U> providerType,
         ValidationConfiguration cfg) {
         try {
             Configuration<?> factoryCfg = providerType != null 
@@ -98,14 +98,6 @@ public class BeanValidationProvider {
         }
     }
 
-    public ClassLoader getValidateContextClassloader() {
-        return validateContextClassloader;
-    }
-
-    public void setValidateContextClassloader(ClassLoader validateContextClassloader) {
-        this.validateContextClassloader = validateContextClassloader;
-    }
-
     private static void initFactoryConfig(Configuration<?> factoryCfg, ValidationConfiguration
cfg) {
         if (cfg != null) {
             factoryCfg.parameterNameProvider(cfg.getParameterNameProvider());
@@ -154,16 +146,7 @@ public class BeanValidationProvider {
     }
     
     private< T > Set<ConstraintViolation< T > > doValidateBean(final T
bean) {
-        ClassLoader oldTccl = Thread.currentThread().getContextClassLoader();
-        try {
-            // In OSGi, hibernate's hunt for an EL provided can fail without this.
-            if (validateContextClassloader != null) {
-                Thread.currentThread().setContextClassLoader(validateContextClassloader);
-            }
-            return factory.getValidator().validate(bean);
-        } finally {
-            Thread.currentThread().setContextClassLoader(oldTccl);
-        }
+        return factory.getValidator().validate(bean);
     }
     
     private ExecutableValidator getExecutableValidator() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/40dc07ce/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
index ebe3a02..07a55bb 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/BookStore.java
@@ -21,13 +21,15 @@ package org.apache.cxf.osgi.itests.jaxrs;
 
 
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.validation.ConstraintViolation;
 import javax.validation.ConstraintViolationException;
-import javax.validation.Validation;
-import javax.validation.ValidatorFactory;
+import javax.validation.ValidationProviderResolver;
+import javax.validation.spi.ValidationProvider;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -97,19 +99,17 @@ public class BookStore {
     @Path("/books-validate")
     public Response createBookValidate(Book book) {
         assertInjections();
-        BeanValidationProvider prov;
-        ClassLoader oldtccl = Thread.currentThread().getContextClassLoader();
-        try {
-            Thread.currentThread().setContextClassLoader(HibernateValidator.class.getClassLoader());
-            HibernateValidatorConfiguration configuration =
-                    Validation.byProvider(HibernateValidator.class)
-                            .configure();
-            ValidatorFactory factory = configuration.buildValidatorFactory();
-            prov = new BeanValidationProvider(factory);
-        } finally {
-            Thread.currentThread().setContextClassLoader(oldtccl);
-        }
-        prov.setValidateContextClassloader(getClass().getClassLoader());
+
+        BeanValidationProvider prov = new BeanValidationProvider(
+                new ValidationProviderResolver() {
+                    @Override
+                    public List<ValidationProvider<?>> getValidationProviders()
{
+                        ValidationProvider<HibernateValidatorConfiguration> prov =
new HibernateValidator();
+                        List<ValidationProvider<?>> provs = new ArrayList<>();
+                        provs.add(prov);
+                        return provs;
+                    }
+                }, HibernateValidator.class);
         try {
             prov.validateBean(book);
         } catch (ConstraintViolationException cve) {
@@ -118,8 +118,8 @@ public class BookStore {
                 violationMessages.append(constraintViolation.getPropertyPath())
                         .append(": ").append(constraintViolation.getMessage()).append("\n");
             }
-            return Response.status(Response.Status.BAD_REQUEST).type("text/plain")
-                    .entity(violationMessages.toString()).build();
+            return Response.status(Response.Status.BAD_REQUEST)
+                    .type("text/plain").entity(violationMessages.toString()).build();
         }
         return createBook(book);
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/40dc07ce/osgi/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/osgi/karaf/features/src/main/resources/features.xml b/osgi/karaf/features/src/main/resources/features.xml
index 2312881..3d3a128 100644
--- a/osgi/karaf/features/src/main/resources/features.xml
+++ b/osgi/karaf/features/src/main/resources/features.xml
@@ -443,10 +443,7 @@
     <feature name="cxf-bean-validation-core" version="${project.version}" resolver="(obr)">
         <!-- This feature has the wrong name; it's hibernate-only. Fix up in 3.2.0? Move
all this to the
         hibernate-bean-validation-helper feature -->
-        <bundle start-level="10" dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-${cxf.osgi.validation.api.version}/${cxf.servicemix.specs.version}</bundle>
-        <bundle start-level="30" dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.hibernate-validator/${cxf.hibernate-validator.bundle.version}</bundle>
-        <!-- The hibernate bundle demands 1.1.0 of javax.validator, but servicemix only
provides 1.0.0. So
-                 we add in the API bundle and hope that the split-package declaration in
servicemix does the job. -->
+        <bundle start-level="30" dependency="true">mvn:org.hibernate/hibernate-validator/${cxf.hibernate.validator.version}</bundle>
         <bundle start-level="30" dependency="true">mvn:javax.validation/validation-api/${cxf.validation.api.version}</bundle>
         <!-- The servicemix bundle for hibernate demands joda-time -->
         <bundle start-level="30" dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.joda-time/${cxf.servicemix.jodatime.version}</bundle>
@@ -464,8 +461,6 @@
         <bundle start-level="30" dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.aspectj/${cxf.servicemix.aspectj.version}</bundle>
     </feature>
 
-
-    
     <feature name="cxf-bean-validation" version="${project.version}" resolver="(obr)">
         <feature version="${project.version}">cxf-bean-validation-core</feature>
         <bundle start-level="30" dependency="true">mvn:javax.el/javax.el-api/${cxf.javax.el.version}</bundle>


http://git-wip-us.apache.org/repos/asf/cxf/blob/40dc07ce/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index d50212d..0141dfd 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -164,12 +164,11 @@
         <cxf.cdi.api.version>1.1</cxf.cdi.api.version>
         <cxf.json.api.version>1.0</cxf.json.api.version>
         <cxf.jboss.weld.version>2.1.2.Final</cxf.jboss.weld.version>
-        <cxf.jboss.logging.version>3.1.3.GA</cxf.jboss.logging.version>
+        <cxf.jboss.logging.version>3.3.0.Final</cxf.jboss.logging.version>
         <cxf.osgi.validation.api.version>1.1.0</cxf.osgi.validation.api.version>
-        <cxf.hibernate.validator.version>5.0.2.Final</cxf.hibernate.validator.version>
+        <cxf.hibernate.validator.version>5.2.2.Final</cxf.hibernate.validator.version>
         <cxf.glassfish.json.version>1.0.4</cxf.glassfish.json.version>
         <cxf.javax.el.version>3.0.0</cxf.javax.el.version>
-        <cxf.hibernate-validator.bundle.version>5.0.2.Final_1</cxf.hibernate-validator.bundle.version>
         <!-- various OSGi related versions -->
         <cxf.aries.version>1.0.0</cxf.aries.version>
         <cxf.aries.parser.version>1.3.1</cxf.aries.parser.version> 
@@ -590,6 +589,7 @@
                         </Export-Service>
                         <Bundle-Activator>${cxf.bundle.activator}</Bundle-Activator>
                     </instructions>
+                    <niceManifest>true</niceManifest>
                 </configuration>
             </plugin>
         </plugins>


Mime
View raw message