cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1043325 - in /cxf/trunk/rt/transports/http-jetty/src: main/java/org/apache/cxf/transport/http_jetty/ test/java/org/apache/cxf/transport/http_jetty/
Date Wed, 08 Dec 2010 07:27:08 GMT
Author: cschneider
Date: Wed Dec  8 07:27:08 2010
New Revision: 1043325

URL: http://svn.apache.org/viewvc?rev=1043325&view=rev
Log:
CXF-3160 Patch 3: Reduce Code duplication between http transport variants - using DestinationRegistry
for all http transport variants

Modified:
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java
    cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java?rev=1043325&r1=1043324&r2=1043325&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
Wed Dec  8 07:27:08 2010
@@ -43,6 +43,7 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.DestinationRegistry;
 import org.apache.cxf.transport.http.HTTPSession;
 import org.apache.cxf.transport.http_jetty.continuations.JettyContinuationProvider;
 import org.apache.cxf.transport.https.CertConstraintsJaxBUtils;
@@ -58,7 +59,6 @@ public class JettyHTTPDestination extend
         LogUtils.getL7dLogger(JettyHTTPDestination.class);
 
     protected JettyHTTPServerEngine engine;
-    protected JettyHTTPTransportFactory transportFactory;
     protected JettyHTTPServerEngineFactory serverEngineFactory;
     protected ServletContext servletContext;
     protected URL nurl;
@@ -77,18 +77,18 @@ public class JettyHTTPDestination extend
      * @param b the associated Bus
      * @param ci the associated conduit initiator
      * @param endpointInfo the endpoint info of the destination
+     * @param serverEngineFactory 
      * @throws IOException
      */
     public JettyHTTPDestination(
-            Bus                       b,
-            JettyHTTPTransportFactory ci, 
-            EndpointInfo              endpointInfo
+            Bus bus,
+            DestinationRegistry registry, 
+            EndpointInfo ei, 
+            JettyHTTPServerEngineFactory serverEngineFactory
     ) throws IOException {
-        
         //Add the defualt port if the address is missing it
-        super(b, endpointInfo, true);
-        this.transportFactory = ci;
-        this.serverEngineFactory = ci.getJettyHTTPServerEngineFactory();
+        super(bus, registry, ei, getAddressValue(ei, true).getAddress(), true);
+        this.serverEngineFactory = serverEngineFactory;
         nurl = new URL(endpointInfo.getAddress());
     }
 
@@ -331,14 +331,7 @@ public class JettyHTTPDestination extend
             }
         }
     }
-
-    @Override
-    public void shutdown() {
-        transportFactory.removeDestination(endpointInfo);
-        
-        super.shutdown();
-    }
-    
+ 
     public ServerEngine getEngine() {
         return engine;
     }

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java?rev=1043325&r1=1043324&r2=1043325&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPTransportFactory.java
Wed Dec  8 07:27:08 2010
@@ -20,8 +20,6 @@ package org.apache.cxf.transport.http_je
 
 import java.io.IOException;
 import java.security.GeneralSecurityException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
@@ -31,14 +29,12 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Destination;
 import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.apache.cxf.transport.http.AbstractHTTPTransportFactory;
 
 public class JettyHTTPTransportFactory extends AbstractHTTPTransportFactory
     implements DestinationFactory {
 
-    private Map<String, JettyHTTPDestination> destinations = 
-        new ConcurrentHashMap<String, JettyHTTPDestination>();
-    
     public JettyHTTPTransportFactory() {
         super();
     }
@@ -77,11 +73,11 @@ public class JettyHTTPTransportFactory e
         return serverEngineFactory;
     }
     
-    public Destination getDestination(EndpointInfo endpointInfo) 
+    public synchronized Destination getDestination(EndpointInfo endpointInfo) 
         throws IOException {
         
         String addr = endpointInfo.getAddress();
-        JettyHTTPDestination destination = addr == null ? null : destinations.get(addr);
+        AbstractHTTPDestination destination = registry.getDestinationForPath(addr);
         if (destination == null) {
             destination = createDestination(endpointInfo);
         }
@@ -89,32 +85,23 @@ public class JettyHTTPTransportFactory e
         return destination;
     }
     
-    private synchronized JettyHTTPDestination createDestination(
+    private synchronized AbstractHTTPDestination createDestination(
         EndpointInfo endpointInfo
     ) throws IOException {
-        
-        String addr = endpointInfo.getAddress();
-        JettyHTTPDestination destination = addr == null ? null : destinations.get(addr);
-        if (destination == null) {
-            destination = 
-                new JettyHTTPDestination(getBus(), this, endpointInfo);
-            
-            destinations.put(endpointInfo.getAddress(), destination);
-            
-            configure(destination);
-            try {
-                destination.finalizeConfig();
-            } catch (GeneralSecurityException ex) {
-                throw new IIOException("JSSE Security Exception ", ex);
-            }
+        JettyHTTPDestination destination = 
+            new JettyHTTPDestination(getBus(), 
+                                     registry,  
+                                     endpointInfo, 
+                                     this.getJettyHTTPServerEngineFactory());
+
+        registry.addDestination(endpointInfo.getAddress(), destination);
+        configure(destination);
+        try {
+            destination.finalizeConfig();
+        } catch (GeneralSecurityException ex) {
+            throw new IIOException("JSSE Security Exception ", ex);
         }
         return destination;
     }
-    
-    /**
-     * This function removes the destination for a particular endpoint.
-     */
-    void removeDestination(EndpointInfo ei) {
-        destinations.remove(ei.getAddress());
-    }
+
 }

Modified: cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java?rev=1043325&r1=1043324&r2=1043325&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/test/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestinationTest.java
Wed Dec  8 07:27:08 2010
@@ -59,6 +59,7 @@ import org.apache.cxf.transport.ConduitI
 import org.apache.cxf.transport.Destination;
 import org.apache.cxf.transport.MessageObserver;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.DestinationRegistry;
 import org.apache.cxf.transports.http.QueryHandler;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
 import org.apache.cxf.transports.http.StemMatchingQueryHandler;
@@ -116,13 +117,12 @@ public class JettyHTTPDestinationTest ex
     private class EasyMockJettyHTTPDestination
         extends JettyHTTPDestination {
 
-        public EasyMockJettyHTTPDestination(
-                Bus                       b,
-                JettyHTTPTransportFactory ci, 
-                EndpointInfo              endpointInfo,
-                JettyHTTPServerEngine     easyMockEngine
-        ) throws IOException {
-            super(b, ci, endpointInfo);
+        public EasyMockJettyHTTPDestination(Bus bus,
+                                            DestinationRegistry registry,
+                                            EndpointInfo endpointInfo,
+                                            JettyHTTPServerEngineFactory serverEngineFactory,
+                                            JettyHTTPServerEngine easyMockEngine) throws
IOException {
+            super(bus, registry, endpointInfo, serverEngineFactory);
             engine = easyMockEngine;
         }
         
@@ -228,7 +228,9 @@ public class JettyHTTPDestinationTest ex
         
         TestJettyDestination testDestination = 
             new TestJettyDestination(transportFactory.getBus(), 
-                                     transportFactory, ei);
+                                     transportFactory.getRegistry(), 
+                                     ei, 
+                                     transportFactory.getJettyHTTPServerEngineFactory());
         testDestination.finalizeConfig();
         Message mi = testDestination.retrieveFromContinuation(httpRequest);
         assertNull("Continuations must be ignored", mi);
@@ -247,11 +249,14 @@ public class JettyHTTPDestinationTest ex
         Destination d1 = transportFactory.getDestination(ei);
         
         Destination d2 = transportFactory.getDestination(ei);
+        
+        // Second get should not generate a new destination. It should just retrieve the
existing one
         assertEquals(d1, d2);
         
         d2.shutdown();
         
         Destination d3 = transportFactory.getDestination(ei);
+        // Now a new destination should have been created
         assertNotSame(d1, d3);
     }
     
@@ -441,7 +446,7 @@ public class JettyHTTPDestinationTest ex
         
         JettyHTTPDestination dest = 
             new EasyMockJettyHTTPDestination(
-                    bus, transportFactory, endpointInfo, engine);
+                    bus, transportFactory.getRegistry(), endpointInfo, null, engine);
         assertEquals(policy, dest.getServer());
     }
         
@@ -596,8 +601,9 @@ public class JettyHTTPDestinationTest ex
         EasyMock.replay(engine);
         
         JettyHTTPDestination dest = new EasyMockJettyHTTPDestination(bus,
-                                                             transportFactory,
+                                                             transportFactory.getRegistry(),
                                                              endpointInfo,
+                                                             null,
                                                              engine);
         dest.retrieveEngine();
         policy = dest.getServer();
@@ -954,10 +960,11 @@ public class JettyHTTPDestinationTest ex
     }
     
     private static class TestJettyDestination extends JettyHTTPDestination {
-        public TestJettyDestination(Bus b,
-                                    JettyHTTPTransportFactory ci, 
-                                    EndpointInfo endpointInfo) throws IOException {
-            super(b, ci, endpointInfo);
+        public TestJettyDestination(Bus bus,
+                                    DestinationRegistry registry,
+                                    EndpointInfo endpointInfo,
+                                    JettyHTTPServerEngineFactory serverEngineFactory) throws
IOException {
+            super(bus, registry, endpointInfo, serverEngineFactory);
         }
         
         @Override



Mime
View raw message