Repository: cxf
Updated Branches:
  refs/heads/master 5b17d24cc -> 1f7d6ad5c


Fix a race condition that could cause many conduits to be created when only one 
is needed


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

Branch: refs/heads/master
Commit: 7d30cc4af87f0e33ffbc6754c8551e46343916c1
Parents: 5b17d24
Author: Daniel Kulp <[email protected]>
Authored: Tue Apr 1 15:59:05 2014 -0400
Committer: Daniel Kulp <[email protected]>
Committed: Tue Apr 1 16:53:46 2014 -0400

----------------------------------------------------------------------
 .../cxf/endpoint/AbstractConduitSelector.java   | 58 +++++++++++++-------
 1 file changed, 37 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/7d30cc4a/core/src/main/java/org/apache/cxf/endpoint/AbstractConduitSelector.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/cxf/endpoint/AbstractConduitSelector.java 
b/core/src/main/java/org/apache/cxf/endpoint/AbstractConduitSelector.java
index 40d1864..7a3f989 100644
--- a/core/src/main/java/org/apache/cxf/endpoint/AbstractConduitSelector.java
+++ b/core/src/main/java/org/apache/cxf/endpoint/AbstractConduitSelector.java
@@ -104,26 +104,7 @@ public abstract class AbstractConduitSelector implements 
ConduitSelector, Closea
                     ConduitInitiator conduitInitiator =
                         conduitInitiatorMgr.getConduitInitiator(transportID);
                     if (conduitInitiator != null) {
-                        String add = 
(String)message.get(Message.ENDPOINT_ADDRESS);
-                        String basePath = 
(String)message.get(Message.BASE_PATH);
-                        if (StringUtils.isEmpty(add)
-                            || add.equals(ei.getAddress())) {
-                            c = conduitInitiator.getConduit(ei, 
exchange.getBus());
-                            replaceEndpointAddressPropertyIfNeeded(message, 
add, c);
-                        } else {
-                            EndpointReferenceType epr = new 
EndpointReferenceType();
-                            AttributedURIType ad = new AttributedURIType();
-                            ad.setValue(StringUtils.isEmpty(basePath) ? add : 
basePath);
-                            epr.setAddress(ad);
-                            c = conduitInitiator.getConduit(ei, epr, 
exchange.getBus());
-                        }
-                        MessageObserver observer = 
-                            exchange.get(MessageObserver.class);
-                        if (observer != null) {
-                            c.setMessageObserver(observer);
-                        } else {
-                            getLogger().warning("MessageObserver not found");
-                        }
+                        c = createConduit(message, exchange, conduitInitiator);
                     } else {
                         getLogger().warning("ConduitInitiator not found: "
                                             + ei.getAddress());
@@ -136,7 +117,6 @@ public abstract class AbstractConduitSelector implements 
ConduitSelector, Closea
             } catch (IOException ex) {
                 throw new Fault(ex);
             }
-            conduits.add(c);
         } 
         if (c != null && c.getTarget() != null && c.getTarget().getAddress() 
!= null) {
             replaceEndpointAddressPropertyIfNeeded(message, 
c.getTarget().getAddress().getValue(), c);
@@ -146,6 +126,42 @@ public abstract class AbstractConduitSelector implements 
ConduitSelector, Closea
         message.put(Conduit.class, c);
         return c;
     }
+    
+    protected Conduit createConduit(Message message, Exchange exchange, 
ConduitInitiator conduitInitiator) 
+        throws IOException {
+        Conduit c = null;
+        synchronized (endpoint) {
+            if (!conduits.isEmpty()) {
+                c = findCompatibleConduit(message);
+                if (c != null) {
+                    return c;
+                }
+            }
+            EndpointInfo ei = endpoint.getEndpointInfo();
+            String add = (String)message.get(Message.ENDPOINT_ADDRESS);
+            String basePath = (String)message.get(Message.BASE_PATH);
+            if (StringUtils.isEmpty(add)
+                || add.equals(ei.getAddress())) {
+                c = conduitInitiator.getConduit(ei, exchange.getBus());
+                replaceEndpointAddressPropertyIfNeeded(message, add, c);
+            } else {
+                EndpointReferenceType epr = new EndpointReferenceType();
+                AttributedURIType ad = new AttributedURIType();
+                ad.setValue(StringUtils.isEmpty(basePath) ? add : basePath);
+                epr.setAddress(ad);
+                c = conduitInitiator.getConduit(ei, epr, exchange.getBus());
+            }
+            MessageObserver observer = 
+                exchange.get(MessageObserver.class);
+            if (observer != null) {
+                c.setMessageObserver(observer);
+            } else {
+                getLogger().warning("MessageObserver not found");
+            }
+            conduits.add(c);
+        }
+        return c;
+    }
 
     // Some conduits may replace the endpoint address after it has already 
been prepared
     // but before the invocation has been done (ex, 
org.apache.cxf.clustering.LoadDistributorTargetSelector)

Reply via email to