cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1467398 - in /cxf/trunk/rt: bindings/soap/src/main/java/org/apache/cxf/binding/soap/ transports/http/src/main/java/org/apache/cxf/transport/http/
Date Fri, 12 Apr 2013 18:28:47 GMT
Author: dkulp
Date: Fri Apr 12 18:28:46 2013
New Revision: 1467398

URL: http://svn.apache.org/r1467398
Log:
[CXF-4960] Fix a couple of startup race conditions

Modified:
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java?rev=1467398&r1=1467397&r2=1467398&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/SoapBindingFactory.java
Fri Apr 12 18:28:46 2013
@@ -882,79 +882,80 @@ public class SoapBindingFactory extends 
 
     @Override
     public synchronized void addListener(Destination d, Endpoint e) {
-        MessageObserver mo = d.getMessageObserver();
-        if (d.getAddress() != null 
-            && d.getAddress().getAddress() != null 
-            && d.getAddress().getAddress().getValue() != null 
-            && d.getAddress().getAddress().getValue().startsWith("soap.udp")) {
-            //soap.udp REQUIRES usage of WS-Addressing... we need to turn this on
-            setupUDP(e, e.getEndpointInfo());
-        }
-        if (mo == null) {
-            super.addListener(d, e);
-            return;
-        }
-
-        if (mo instanceof ChainInitiationObserver) {
-            ChainInitiationObserver cio = (ChainInitiationObserver) mo;
-            
-            Binding b = e.getBinding();
-            Binding b2 = cio.getEndpoint().getBinding();
-            if (b == b2) {
-                //re-registering the same endpoint?
-                return;
+        synchronized (d) {
+            MessageObserver mo = d.getMessageObserver();
+            if (d.getAddress() != null 
+                && d.getAddress().getAddress() != null 
+                && d.getAddress().getAddress().getValue() != null 
+                && d.getAddress().getAddress().getValue().startsWith("soap.udp"))
{
+                //soap.udp REQUIRES usage of WS-Addressing... we need to turn this on
+                setupUDP(e, e.getEndpointInfo());
             }
-            Object o = cio.getEndpoint().get("allow-multiplex-endpoint");
-            if (o instanceof String) {
-                o = Boolean.parseBoolean((String)o);
-            } else if (o == null) {
-                o = Boolean.FALSE;
+            if (mo == null) {
+                super.addListener(d, e);
+                return;
             }
-            
-            if (b instanceof org.apache.cxf.binding.soap.SoapBinding 
-                && b2 instanceof org.apache.cxf.binding.soap.SoapBinding
-                && ((org.apache.cxf.binding.soap.SoapBinding)b).getSoapVersion()
-                    .equals(((org.apache.cxf.binding.soap.SoapBinding)b2).getSoapVersion())
-                && Boolean.FALSE.equals(o)) {
+
+            if (mo instanceof ChainInitiationObserver) {
+                ChainInitiationObserver cio = (ChainInitiationObserver) mo;
                 
-                throw new RuntimeException("Soap " 
-                                           + ((org.apache.cxf.binding.soap.SoapBinding)b)
-                                               .getSoapVersion().getVersion()
-                                           + " endpoint already registered on address "
-                                           + e.getEndpointInfo().getAddress());
-            }
-            
-            MultipleEndpointObserver newMO = new MultipleEndpointObserver(getBus()) {
-                @Override
-                protected Message createMessage(Message message) {
-                    return new SoapMessage(message);
+                Binding b = e.getBinding();
+                Binding b2 = cio.getEndpoint().getBinding();
+                if (b == b2) {
+                    //re-registering the same endpoint?
+                    return;
                 }
-            };
-
-            newMO.getBindingInterceptors().add(new AttachmentInInterceptor());
-            newMO.getBindingInterceptors().add(new StaxInInterceptor());
-
-            // This will not work if one of the endpoints disables message
-            // processing. But, if you've disabled message processing, you
-            // probably aren't going to use this feature.
-            
-            newMO.getBindingInterceptors().add(new ReadHeadersInterceptor(getBus(), (SoapVersion)null));
-            newMO.getBindingInterceptors().add(new StartBodyInterceptor());
-            newMO.getBindingInterceptors().add(new CheckFaultInterceptor());
-
-            // Add in a default selection interceptor
-            newMO.getRoutingInterceptors().add(new EndpointSelectionInterceptor());
-
-            newMO.getEndpoints().add(cio.getEndpoint());
-
-            mo = newMO;
-        }
-
-        if (mo instanceof MultipleEndpointObserver) {
-            MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
-            meo.getEndpoints().add(e);
+                Object o = cio.getEndpoint().get("allow-multiplex-endpoint");
+                if (o instanceof String) {
+                    o = Boolean.parseBoolean((String)o);
+                } else if (o == null) {
+                    o = Boolean.FALSE;
+                }
+                if (b instanceof org.apache.cxf.binding.soap.SoapBinding 
+                    && b2 instanceof org.apache.cxf.binding.soap.SoapBinding
+                    && ((org.apache.cxf.binding.soap.SoapBinding)b).getSoapVersion()
+                        .equals(((org.apache.cxf.binding.soap.SoapBinding)b2).getSoapVersion())
+                    && Boolean.FALSE.equals(o)) {
+                    
+                    throw new RuntimeException("Soap " 
+                                               + ((org.apache.cxf.binding.soap.SoapBinding)b)
+                                                   .getSoapVersion().getVersion()
+                                               + " endpoint already registered on address
"
+                                               + e.getEndpointInfo().getAddress());
+                }
+                
+                MultipleEndpointObserver newMO = new MultipleEndpointObserver(getBus()) {
+                    @Override
+                    protected Message createMessage(Message message) {
+                        return new SoapMessage(message);
+                    }
+                };
+    
+                newMO.getBindingInterceptors().add(new AttachmentInInterceptor());
+                newMO.getBindingInterceptors().add(new StaxInInterceptor());
+    
+                // This will not work if one of the endpoints disables message
+                // processing. But, if you've disabled message processing, you
+                // probably aren't going to use this feature.
+                
+                newMO.getBindingInterceptors().add(new ReadHeadersInterceptor(getBus(), (SoapVersion)null));
+                newMO.getBindingInterceptors().add(new StartBodyInterceptor());
+                newMO.getBindingInterceptors().add(new CheckFaultInterceptor());
+    
+                // Add in a default selection interceptor
+                newMO.getRoutingInterceptors().add(new EndpointSelectionInterceptor());
+    
+                newMO.getEndpoints().add(cio.getEndpoint());
+    
+                mo = newMO;
+            }
+    
+            if (mo instanceof MultipleEndpointObserver) {
+                MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
+                meo.getEndpoints().add(e);
+            }
+    
+            d.setMessageObserver(mo);
         }
-
-        d.setMessageObserver(mo);
     }
 }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java?rev=1467398&r1=1467397&r2=1467398&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java
Fri Apr 12 18:28:46 2013
@@ -42,20 +42,29 @@ public class DestinationRegistryImpl imp
     public DestinationRegistryImpl() {
     }
 
-    public void addDestination(AbstractHTTPDestination destination) {
+    public synchronized void addDestination(AbstractHTTPDestination destination) {
         String path = getTrimmedPath(destination.getEndpointInfo().getAddress());
-        destinations.putIfAbsent(path, destination);
+        AbstractHTTPDestination dest = destinations.putIfAbsent(path, destination);
+        if (dest != null && dest != destination) {
+            throw new RuntimeException("Already a destination on " + path);
+        }
         try {
-            decodedDestinations.put(URLDecoder.decode(path, "ISO-8859-1"), destination);
+            String path2 = URLDecoder.decode(path, "ISO-8859-1");
+            if (!path.equals(path2)) {
+                decodedDestinations.put(URLDecoder.decode(path, "ISO-8859-1"), destination);
+            }
         } catch (UnsupportedEncodingException e) {
             throw new RuntimeException("Unsupported Encoding", e);
         }
     }
 
-    public void removeDestination(String path) {
+    public synchronized void removeDestination(String path) {
         destinations.remove(path);
         try {
-            decodedDestinations.remove(URLDecoder.decode(path, "ISO-8859-1"));
+            String path2 = URLDecoder.decode(path, "ISO-8859-1");
+            if (!path.equals(path2)) {
+                decodedDestinations.remove(URLDecoder.decode(path, "ISO-8859-1"));
+            }
         } catch (UnsupportedEncodingException e) {
             throw new RuntimeException("Unsupported Encoding", e);
         }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java?rev=1467398&r1=1467397&r2=1467398&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
Fri Apr 12 18:28:46 2013
@@ -283,30 +283,32 @@ public class HTTPTransportFactory 
         if (endpointInfo == null) {
             throw new IllegalArgumentException("EndpointInfo cannot be null");
         }
-        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);
+        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, getBus(), registry);
+                registry.addDestination(d);
+                configure(d);
+                d.finalizeConfig();
             }
-            HttpDestinationFactory factory = null;
-            if (jettyFactory != null && (addr == null || addr.startsWith("http")))
{
-                factory = jettyFactory;
-            } else {
-                factory = new ServletDestinationFactory();
-            }
-            
-            d = factory.createDestination(endpointInfo, getBus(), registry);
-            registry.addDestination(d);
-            configure(d);
-            d.finalizeConfig();
+            return d;
         }
-        return d;
     }
 
 }



Mime
View raw message