cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1499951 - in /cxf/trunk/rt/transports/http-netty: netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/ netty-client/src/main/resources/META-INF/cxf/ netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/in...
Date Fri, 05 Jul 2013 09:00:04 GMT
Author: ningjiang
Date: Fri Jul  5 09:00:04 2013
New Revision: 1499951

URL: http://svn.apache.org/r1499951
Log:
CXF-5109 Added the support of loading the netty transport with 'netty://' perfix

Added:
    cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java
    cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpTransportFactory.java
Modified:
    cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java
    cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java
    cxf/trunk/rt/transports/http-netty/netty-client/src/main/resources/META-INF/cxf/bus-extensions.txt
    cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/integration/NettyClientTest.java
    cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpDestination.java
    cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/META-INF/cxf/bus-extensions.txt
    cxf/trunk/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/integration/NettyServerTest.java

Modified: cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java?rev=1499951&r1=1499950&r2=1499951&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduit.java
Fri Jul  5 09:00:04 2013
@@ -90,6 +90,15 @@ public class NettyHttpConduit extends UR
     // Using Netty API directly
     protected void setupConnection(Message message, URI uri, HTTPClientPolicy csPolicy) throws
IOException {
 
+        // need to do some clean up work on the URI address
+        String uriString = uri.toString();
+        if (uriString.startsWith("netty://")) {
+            try {
+                uri = new URI(uriString.substring(8));
+            } catch (URISyntaxException ex) {
+                throw new MalformedURLException("unsupport uri: "  + uriString);
+            }
+        }
         String s = uri.getScheme();
         if (!"http".equals(s) && !"https".equals(s)) {
             throw new MalformedURLException("unknown protocol: " + s);

Modified: cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java?rev=1499951&r1=1499950&r2=1499951&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpConduitFactory.java
Fri Jul  5 09:00:04 2013
@@ -45,6 +45,14 @@ public class NettyHttpConduitFactory imp
         throws IOException {
         return new NettyHttpConduit(bus, localInfo, target, this);
     }
+    
+    
+    public HTTPConduit createConduit(Bus bus, 
+                                     EndpointInfo localInfo,
+                                     EndpointReferenceType target)
+        throws IOException {
+        return new NettyHttpConduit(bus, localInfo, target, this);
+    }
 
     @Override
     public void initComplete() {

Added: cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java?rev=1499951&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java
(added)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/main/java/org/apache/cxf/transport/http/netty/client/NettyHttpTransportFactory.java
Fri Jul  5 09:00:04 2013
@@ -0,0 +1,122 @@
+/**
+ * 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.transport.http.netty.client;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.AbstractTransportFactory;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.ConduitInitiator;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.http.HTTPConduitConfigurer;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+
+public class NettyHttpTransportFactory extends AbstractTransportFactory implements ConduitInitiator
{
+
+    public static final List<String> DEFAULT_NAMESPACES = Arrays
+        .asList("http://cxf.apache.org/transports/http/netty/client");
+   
+    /**
+     * This constant holds the prefixes served by this factory.
+     */
+    private static final Set<String> URI_PREFIXES = new HashSet<String>();
+    
+    static {
+        URI_PREFIXES.add("netty://");
+    }
+    
+    private final NettyHttpConduitFactory factory = new NettyHttpConduitFactory();
+    
+    public NettyHttpTransportFactory() {
+        super(DEFAULT_NAMESPACES);
+    }
+    
+    /**
+     * This call is used by CXF ExtensionManager to inject the activationNamespaces
+     * @param ans The transport ids.
+     */
+    public void setActivationNamespaces(Collection<String> ans) {
+        setTransportIds(new ArrayList<String>(ans));
+    }
+    
+    public Set<String> getUriPrefixes() {
+        return URI_PREFIXES;
+    }
+    
+    protected void configure(Bus b, Object bean) {
+        configure(b, bean, null, null);
+    }
+    
+    protected void configure(Bus bus, Object bean, String name, String extraName) {
+        Configurer configurer = bus.getExtension(Configurer.class);
+        if (null != configurer) {
+            configurer.configureBean(name, bean);
+            if (extraName != null) {
+                configurer.configureBean(extraName, bean);
+            }
+        }
+    }
+    
+    protected String getAddress(EndpointInfo endpointInfo) {
+        String address = endpointInfo.getAddress();
+        if (address.startsWith("netty://")) {
+            address = address.substring(8);
+        }
+        return address;
+    }
+    
+    @Override
+    public Conduit getConduit(EndpointInfo endpointInfo, Bus bus) throws IOException {
+        return getConduit(endpointInfo, endpointInfo.getTarget(), bus);
+    }
+
+    @Override
+    public Conduit getConduit(EndpointInfo endpointInfo, EndpointReferenceType target, Bus
bus)
+        throws IOException {
+        
+        HTTPConduit conduit = null;
+        // need to updated the endpointInfo
+        endpointInfo.setAddress(getAddress(endpointInfo));
+        
+        conduit = factory.createConduit(bus, endpointInfo, target);
+
+        // Spring configure the conduit.  
+        String address = conduit.getAddress();
+        if (address != null && address.indexOf('?') != -1) {
+            address = address.substring(0, address.indexOf('?'));
+        }
+        HTTPConduitConfigurer c1 = bus.getExtension(HTTPConduitConfigurer.class);
+        if (c1 != null) {
+            c1.configure(conduit.getBeanName(), address, conduit);
+        }
+        configure(bus, conduit, conduit.getBeanName(), address);
+        conduit.finalizeConfig();
+        return conduit;
+    }
+
+}

Modified: cxf/trunk/rt/transports/http-netty/netty-client/src/main/resources/META-INF/cxf/bus-extensions.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/main/resources/META-INF/cxf/bus-extensions.txt?rev=1499951&r1=1499950&r2=1499951&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/main/resources/META-INF/cxf/bus-extensions.txt
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/main/resources/META-INF/cxf/bus-extensions.txt
Fri Jul  5 09:00:04 2013
@@ -1 +1,2 @@
+org.apache.cxf.transport.http.netty.client.NettyHttpTransportFactory::true
 org.apache.cxf.transport.http.netty.client.NettyHttpConduitFactory::true

Modified: cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/integration/NettyClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/integration/NettyClientTest.java?rev=1499951&r1=1499950&r2=1499951&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/integration/NettyClientTest.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-client/src/test/java/org/apache/cxf/transport/http/netty/client/integration/NettyClientTest.java
Fri Jul  5 09:00:04 2013
@@ -25,6 +25,7 @@ import javax.xml.ws.Endpoint;
 import javax.xml.ws.Response;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.hello_world_soap_http.Greeter;
 import org.apache.hello_world_soap_http.SOAPService;
@@ -78,6 +79,29 @@ public class NettyClientTest extends Abs
         String response = g.greetMe("test");
         assertEquals("Get a wrong response", "Hello test", response);
     }
+    
+    @Test
+    public void testInovationWithNettyAddress() throws Exception {
+        String address =  "netty://http://localhost:" + PORT + "/SoapContext/SoapPort";
+        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+        factory.setServiceClass(Greeter.class);
+        factory.setAddress(address);
+        //factory.setTransportId("http://cxf.apache.org/transports/http/netty/client");
+        Greeter greeter = factory.create(Greeter.class);
+        String response = greeter.greetMe("test");
+        assertEquals("Get a wrong response", "Hello test", response);
+    }
+    
+    public void testInvocationWithTransportId() throws Exception {
+        String address =  "//http://localhost:" + PORT + "/SoapContext/SoapPort";
+        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+        factory.setServiceClass(Greeter.class);
+        factory.setAddress(address);
+        factory.setTransportId("http://cxf.apache.org/transports/http/netty/client");
+        Greeter greeter = factory.create(Greeter.class);
+        String response = greeter.greetMe("test");
+        assertEquals("Get a wrong response", "Hello test", response);
+    }
 
     @Test
     public void testCallAsync() throws Exception {

Modified: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpDestination.java?rev=1499951&r1=1499950&r2=1499951&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpDestination.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpDestination.java
Fri Jul  5 09:00:04 2013
@@ -33,6 +33,7 @@ import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.continuations.SuspendedInvocationException;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.ExchangeImpl;
@@ -71,7 +72,7 @@ public class NettyHttpDestination extend
         super(b, registry, ei, getAddressValue(ei, true).getAddress(), true);
         loader = bus.getExtension(ClassLoader.class);
         this.serverEngineFactory = serverEngineFactory;
-        nurl = new URL(endpointInfo.getAddress());
+        nurl = new URL(getAddress(endpointInfo));
     }
 
 
@@ -102,6 +103,21 @@ public class NettyHttpDestination extend
         }
         configFinalized = true;
     }
+    
+    protected String getAddress(EndpointInfo endpointInfo) {
+        String address = endpointInfo.getAddress();
+        if (address.startsWith("netty://")) {
+            address = address.substring(8);
+        }
+        return address;
+    }
+    
+    protected String getBasePath(String contextPath) throws IOException {
+        if (StringUtils.isEmpty(endpointInfo.getAddress())) {
+            return "";
+        }
+        return new URL(getAddress(endpointInfo)).getPath();
+    }
 
     /**
      * Activate receipt of incoming messages.
@@ -110,8 +126,9 @@ public class NettyHttpDestination extend
         super.activate();
         LOG.log(Level.FINE, "Activating receipt of incoming messages");
         URL url = null;
+        
         try {
-            url = new URL(endpointInfo.getAddress());
+            url = new URL(getAddress(endpointInfo));
         } catch (Exception e) {
             throw new Fault(e);
         }

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpTransportFactory.java?rev=1499951&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpTransportFactory.java
(added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpTransportFactory.java
Fri Jul  5 09:00:04 2013
@@ -0,0 +1,129 @@
+/**
+ * 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.transport.http.netty.server;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.AbstractTransportFactory;
+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.DestinationRegistry;
+import org.apache.cxf.transport.http.DestinationRegistryImpl;
+import org.apache.cxf.transport.http.HttpDestinationFactory;
+
+public class NettyHttpTransportFactory extends AbstractTransportFactory implements DestinationFactory
{
+    
+    public static final List<String> DEFAULT_NAMESPACES = Arrays
+        .asList("http://cxf.apache.org/transports/http/netty/server");
+   
+    /**
+     * This constant holds the prefixes served by this factory.
+     */
+    private static final Set<String> URI_PREFIXES = new HashSet<String>();
+    static {
+        URI_PREFIXES.add("netty://");
+    }
+    
+    protected final DestinationRegistry registry;
+    
+    protected final HttpDestinationFactory factory = new NettyHttpDestinationFactory();
+    
+    public NettyHttpTransportFactory() {
+        this(new DestinationRegistryImpl());
+    }
+    
+    public NettyHttpTransportFactory(DestinationRegistry registry) {
+        super(DEFAULT_NAMESPACES);
+        if (registry == null) {
+            registry = new DestinationRegistryImpl();
+        }
+        this.registry = registry;
+    }
+    
+    public DestinationRegistry getRegistry() {
+        return registry;
+    }
+    
+    /**
+     * This call is used by CXF ExtensionManager to inject the activationNamespaces
+     * @param ans The transport ids.
+     */
+    public void setActivationNamespaces(Collection<String> ans) {
+        setTransportIds(new ArrayList<String>(ans));
+    }
+    
+    public Set<String> getUriPrefixes() {
+        return URI_PREFIXES;
+    }
+    
+    /**
+     * This call uses the Configurer from the bus to configure
+     * a bean.
+     * 
+     * @param bean
+     */
+    protected void configure(Bus b, Object bean) {
+        configure(b, bean, null, null);
+    }
+    
+    protected void configure(Bus bus, Object bean, String name, String extraName) {
+        Configurer configurer = bus.getExtension(Configurer.class);
+        if (null != configurer) {
+            configurer.configureBean(name, bean);
+            if (extraName != null) {
+                configurer.configureBean(extraName, bean);
+            }
+        }
+    }
+    
+    protected String getAddress(EndpointInfo endpointInfo) {
+        String address = endpointInfo.getAddress();
+        if (address.startsWith("netty://")) {
+            address = address.substring(8);
+        }
+        return address;
+    }
+    
+    public Destination getDestination(EndpointInfo endpointInfo, Bus bus) throws IOException
{
+        if (endpointInfo == null) {
+            throw new IllegalArgumentException("EndpointInfo cannot be null");
+        }
+        synchronized (registry) {
+            AbstractHTTPDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
+            if (d == null) {
+                d = factory.createDestination(endpointInfo, bus, registry);
+                registry.addDestination(d);
+                configure(bus, d);
+                d.finalizeConfig();
+            }
+            return d;
+        }
+    }
+
+}

Modified: cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/META-INF/cxf/bus-extensions.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/META-INF/cxf/bus-extensions.txt?rev=1499951&r1=1499950&r2=1499951&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/META-INF/cxf/bus-extensions.txt
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/resources/META-INF/cxf/bus-extensions.txt
Fri Jul  5 09:00:04 2013
@@ -1,2 +1,3 @@
+org.apache.cxf.transport.http.netty.server.NettyHttpTransportFactory::true
 org.apache.cxf.transport.http.netty.server.NettyHttpDestinationFactory::true
 org.apache.cxf.transport.http.netty.server.NettyHttpServerEngineFactory::true

Modified: cxf/trunk/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/integration/NettyServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/integration/NettyServerTest.java?rev=1499951&r1=1499950&r2=1499951&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/integration/NettyServerTest.java
(original)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/integration/NettyServerTest.java
Fri Jul  5 09:00:04 2013
@@ -41,7 +41,7 @@ public class NettyServerTest extends Abs
     public static void start() throws Exception {
         Bus b = createStaticBus();
         BusFactory.setThreadDefaultBus(b);
-        ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort",
+        ep = Endpoint.publish("netty://http://localhost:" + PORT + "/SoapContext/SoapPort",
                 new org.apache.hello_world_soap_http.GreeterImpl());
         
         URL wsdl = NettyServerTest.class.getResource("/wsdl/hello_world.wsdl");



Mime
View raw message