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-6369] Preventing duplicate registrations in ConfigurationImpl
Date Fri, 24 Apr 2015 11:21:59 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 2982a61a7 -> 90873c41a


[CXF-6369] Preventing duplicate registrations in ConfigurationImpl


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

Branch: refs/heads/master
Commit: 90873c41ab1e632f71a355ef63e67a4b29252ef4
Parents: 2982a61
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Apr 24 12:21:41 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Apr 24 12:21:41 2015 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/ConfigurationImpl.java       | 13 ++++-
 .../cxf/jaxrs/impl/ConfigurationImplTest.java   | 58 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/90873c41/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
index fa29eb0..5333298 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
@@ -25,14 +25,17 @@ import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.logging.Logger;
 
 import javax.ws.rs.RuntimeType;
 import javax.ws.rs.core.Configuration;
 import javax.ws.rs.core.Feature;
 
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 
 public class ConfigurationImpl implements Configuration {
+    private static final Logger LOG = LogUtils.getL7dLogger(ConfigurationImpl.class);
     private Map<String, Object> props = new HashMap<String, Object>();
     private RuntimeType runtimeType;
     private Map<Object, Map<Class<?>, Integer>> providers = 
@@ -144,7 +147,7 @@ public class ConfigurationImpl implements Configuration {
     @Override
     public boolean isRegistered(Class<?> cls) {
         for (Object o : getInstances()) {
-            if (cls.isAssignableFrom(o.getClass())) {
+            if (cls == o.getClass()) {
                 return true;
             }
         }
@@ -168,10 +171,15 @@ public class ConfigurationImpl implements Configuration {
         register(provider, initContractsMap(bindingPriority, contracts));
     }
     
-    public void register(Object provider, Map<Class<?>, Integer> contracts) {
+    public boolean register(Object provider, Map<Class<?>, Integer> contracts)
{
         if (provider.getClass() == Class.class) {
             provider = createProvider((Class<?>)provider);
         }
+        if (isRegistered(provider)) {
+            LOG.warning("Provider " + provider.getClass().getName() + " has already been
registered");
+            return false;
+        }
+        
         Map<Class<?>, Integer> metadata = providers.get(provider);
         if (metadata == null) {
             metadata = new HashMap<Class<?>, Integer>();
@@ -182,6 +190,7 @@ public class ConfigurationImpl implements Configuration {
                 metadata.put(contract, contracts.get(contract));
             }
         }
+        return true;
     }
     
     public static Map<Class<?>, Integer> initContractsMap(int bindingPriority,
Class<?>... contracts) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/90873c41/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ConfigurationImplTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ConfigurationImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ConfigurationImplTest.java
new file mode 100644
index 0000000..21645b2
--- /dev/null
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ConfigurationImplTest.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.impl;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import javax.ws.rs.RuntimeType;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ConfigurationImplTest extends Assert {
+    
+    @Test
+    public void testIsRegistered() {
+        ConfigurationImpl c = new ConfigurationImpl(RuntimeType.SERVER);
+        ContainerResponseFilter filter = new ContainerResponseFilterImpl();
+        assertTrue(c.register(filter, 
+                   Collections.<Class<?>, Integer>singletonMap(ContainerResponseFilter.class,
1000)));
+        assertTrue(c.isRegistered(filter));
+        assertTrue(c.isRegistered(ContainerResponseFilterImpl.class));
+        assertFalse(c.isRegistered(ContainerResponseFilter.class));
+        assertFalse(c.register(filter, 
+                              Collections.<Class<?>, Integer>singletonMap(ContainerResponseFilter.class,
1000)));
+    }
+    private static class ContainerResponseFilterImpl implements ContainerResponseFilter {
+
+        @Override
+        public void filter(ContainerRequestContext requestContext, ContainerResponseContext
responseContext)
+            throws IOException {
+            // TODO Auto-generated method stub
+            
+        }
+        
+    }
+    
+}


Mime
View raw message