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-7092] Adding a warning if duplicate providers or features are detected
Date Fri, 21 Oct 2016 19:24:13 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 1e56cc54d -> b6b0b305a


[CXF-7092] Adding a warning if duplicate providers or features are detected


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

Branch: refs/heads/master
Commit: b6b0b305a7d53df16b09db02cba8345c6cafe413
Parents: 1e56cc5
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Oct 21 20:23:28 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Oct 21 20:23:28 2016 +0100

----------------------------------------------------------------------
 .../spring/AbstractSpringComponentScanServer.java   | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b6b0b305/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
index a2a7094..fb8ee4b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
@@ -20,14 +20,18 @@ package org.apache.cxf.jaxrs.spring;
 
 import java.lang.annotation.Annotation;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
 
 import javax.ws.rs.Path;
 import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.annotations.Provider.Scope;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.ClasspathScanner;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.feature.Feature;
@@ -48,6 +52,7 @@ import org.springframework.context.annotation.FilterType;
 )
 public abstract class AbstractSpringComponentScanServer extends AbstractSpringConfigurationFactory
{
 
+    private static final Logger LOG = LogUtils.getL7dLogger(AbstractSpringComponentScanServer.class);
     @Value("${cxf.jaxrs.classes-scan-packages:}")
     private String classesScanPackages;
     
@@ -92,6 +97,7 @@ public abstract class AbstractSpringComponentScanServer extends AbstractSpringCo
                                           
                 jaxrsProviders.addAll(JAXRSServerFactoryBeanDefinitionParser
                     .createBeansFromDiscoveredClasses(super.applicationContext, classes.get(Provider.class),
null));
+                warnIfDuplicatesAvailable(jaxrsProviders);
                 List<Object> cxfProviders = JAXRSServerFactoryBeanDefinitionParser
                     .createBeansFromDiscoveredClasses(super.applicationContext, 
                                                       classes.get(org.apache.cxf.annotations.Provider.class),

@@ -99,6 +105,7 @@ public abstract class AbstractSpringComponentScanServer extends AbstractSpringCo
                 for (Object cxfProvider : cxfProviders) {
                     addCxfProvider(cxfProvider);
                 }
+                warnIfDuplicatesAvailable(cxfFeatures);
             } catch (Exception ex) {
                 throw new ServiceConstructionException(ex);
             }
@@ -112,6 +119,15 @@ public abstract class AbstractSpringComponentScanServer extends AbstractSpringCo
         
     }
     
+    private static void warnIfDuplicatesAvailable(List<? extends Object> providers)
{
+        Set<String> classNames = new HashSet<String>();
+        for (Object o : providers) {
+            if (!classNames.add(o.getClass().getName())) {
+                LOG.warning("Duplicate Provider " + o.getClass().getName() + " has been detected");
+            }
+        }
+        
+    }
     private Object getProviderBean(String beanName) {
         return applicationContext.getBean(beanName);
     }


Mime
View raw message