cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject git commit: [CXF-5678] Allow setting custom DestinationRegistry in HTTPTransportFactory
Date Tue, 08 Apr 2014 10:13:36 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 423c5abd4 -> 85ecae555


[CXF-5678] Allow setting custom DestinationRegistry in HTTPTransportFactory


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

Branch: refs/heads/master
Commit: 85ecae5551365fa8a11a5245db2b84ada543107f
Parents: 423c5ab
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Tue Apr 8 12:12:00 2014 +0200
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Tue Apr 8 12:12:00 2014 +0200

----------------------------------------------------------------------
 .../transport/http/HTTPTransportFactory.java    | 76 +++++++++++++-------
 .../cxf/transport/http/Messages.properties      |  3 +-
 2 files changed, 54 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/85ecae55/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
index 44b4592..5fbb3ce 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
@@ -27,6 +27,9 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -75,7 +78,11 @@ public class HTTPTransportFactory
         URI_PREFIXES.add("https://");
     }
 
-    protected final DestinationRegistry registry;
+    protected DestinationRegistry registry;
+    
+    private final ReadWriteLock lock = new ReentrantReadWriteLock();
+    private final Lock r = lock.readLock();
+    private final Lock w = lock.writeLock();
     
     public HTTPTransportFactory() {
         this(new DestinationRegistryImpl());
@@ -91,6 +98,22 @@ public class HTTPTransportFactory
         return registry;
     }
     
+    public void setRegistry(DestinationRegistry newRegistry) {
+        w.lock();
+        try {
+            if (registry.getDestinations().isEmpty()) {
+                this.registry = newRegistry;
+            } else {
+                String m = new org.apache.cxf.common.i18n.Message("CANNOT_CHANGE_REGISTRY_ALREADY_IN_USE",
+                                                                  LOG).toString();
+                LOG.log(Level.SEVERE, m);
+                throw new RuntimeException(m);
+            }
+        } finally {
+            w.unlock();
+        }
+    }
+    
     /**
      * This call is used by CXF ExtensionManager to inject the activationNamespaces
      * @param ans The transport ids.
@@ -231,31 +254,36 @@ public class HTTPTransportFactory
         if (endpointInfo == null) {
             throw new IllegalArgumentException("EndpointInfo cannot be null");
         }
-        synchronized (registry) {
-            AbstractHTTPDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
-            if (d == null) {
-                HttpDestinationFactory jettyFactory = bus.getExtension(HttpDestinationFactory.class);
-                String addr = endpointInfo.getAddress();
-                if (jettyFactory == null && addr != null && addr.startsWith("http"))
{
-                    String m = 
-                        new org.apache.cxf.common.i18n.Message("NO_HTTP_DESTINATION_FACTORY_FOUND"
-                                                               , LOG).toString();
-                    LOG.log(Level.SEVERE, m);
-                    throw new IOException(m);
-                }
-                HttpDestinationFactory factory = null;
-                if (jettyFactory != null && (addr == null || addr.startsWith("http")))
{
-                    factory = jettyFactory;
-                } else {
-                    factory = new ServletDestinationFactory();
+        r.lock();
+        try {
+            synchronized (registry) {
+                AbstractHTTPDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
+                if (d == null) {
+                    HttpDestinationFactory jettyFactory = bus.getExtension(HttpDestinationFactory.class);
+                    String addr = endpointInfo.getAddress();
+                    if (jettyFactory == null && addr != null && addr.startsWith("http"))
{
+                        String m = 
+                            new org.apache.cxf.common.i18n.Message("NO_HTTP_DESTINATION_FACTORY_FOUND"
+                                                                   , LOG).toString();
+                        LOG.log(Level.SEVERE, m);
+                        throw new IOException(m);
+                    }
+                    HttpDestinationFactory factory = null;
+                    if (jettyFactory != null && (addr == null || addr.startsWith("http")))
{
+                        factory = jettyFactory;
+                    } else {
+                        factory = new ServletDestinationFactory();
+                    }
+                    
+                    d = factory.createDestination(endpointInfo, bus, registry);
+                    registry.addDestination(d);
+                    configure(bus, d);
+                    d.finalizeConfig();
                 }
-                
-                d = factory.createDestination(endpointInfo, bus, registry);
-                registry.addDestination(d);
-                configure(bus, d);
-                d.finalizeConfig();
+                return d;
             }
-            return d;
+        } finally {
+            r.unlock();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/85ecae55/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
index e14479d..08d5ba9 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Messages.properties
@@ -26,4 +26,5 @@ MISSING_PATH_INFO = PATH_INFO not present in message context, multiplex
id is un
 INVALID_TIMEOUT_FORMAT = Invalid name/value pair {0}={1} set in RequestConext 
 NO_HTTP_DESTINATION_FACTORY_FOUND = Cannot find any registered HttpDestinationFactory from
the Bus.
 EXECUTOR_FULL = Executor rejected background task to retrieve the response, running on current
thread.
-EXECUTOR_FULL_WARNING = Executor rejected background task to retrieve the response.  Suggest
increasing the workqueue settings.
\ No newline at end of file
+EXECUTOR_FULL_WARNING = Executor rejected background task to retrieve the response.  Suggest
increasing the workqueue settings.
+CANNOT_CHANGE_REGISTRY_ALREADY_IN_USE = Cannot change registry already in use
\ No newline at end of file


Mime
View raw message