cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1505936 - in /cxf/trunk/rt/transports/http-hc/src: main/java/org/apache/cxf/transport/http/asyncclient/ main/resources/META-INF/cxf/ test/java/org/apache/cxf/transport/http/asyncclient/
Date Tue, 23 Jul 2013 08:46:25 GMT
Author: ningjiang
Date: Tue Jul 23 08:46:25 2013
New Revision: 1505936

URL: http://svn.apache.org/r1505936
Log:
CXF-5150 Support to load the HttpClient conduit when the address is started with hc://

Added:
    cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHttpTransportFactory.java
Modified:
    cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
    cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java
    cxf/trunk/rt/transports/http-hc/src/main/resources/META-INF/cxf/bus-extensions.txt
    cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java

Modified: cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java?rev=1505936&r1=1505935&r2=1505936&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
(original)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
Tue Jul 23 08:46:25 2013
@@ -127,7 +127,15 @@ public class AsyncHTTPConduit extends UR
             super.setupConnection(message, uri, csPolicy);
             return;
         }
-        
+        // need to do some clean up work on the URI address
+        String uriString = uri.toString();
+        if (uriString.startsWith("hc://")) {
+            try {
+                uri = new URI(uriString.substring(5));
+            } 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-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java?rev=1505936&r1=1505935&r2=1505936&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java
(original)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java
Tue Jul 23 08:46:25 2013
@@ -275,6 +275,13 @@ public class AsyncHTTPConduitFactory imp
                                      Bus bus,
                                      EndpointInfo localInfo,
                                      EndpointReferenceType target) throws IOException {
+       
+        return createConduit(bus, localInfo, target);
+    }
+    
+    public HTTPConduit createConduit(Bus bus,
+                                     EndpointInfo localInfo,
+                                     EndpointReferenceType target) throws IOException {
         if (isShutdown) {
             return null;
         }

Added: cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHttpTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHttpTransportFactory.java?rev=1505936&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHttpTransportFactory.java
(added)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHttpTransportFactory.java
Tue Jul 23 08:46:25 2013
@@ -0,0 +1,121 @@
+/**
+ * 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.asyncclient;
+
+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 AsyncHttpTransportFactory extends AbstractTransportFactory implements ConduitInitiator
{
+
+    public static final List<String> DEFAULT_NAMESPACES = Arrays
+        .asList("http://cxf.apache.org/transports/http/http-client");
+   
+    /**
+     * This constant holds the prefixes served by this factory.
+     */
+    private static final Set<String> URI_PREFIXES = new HashSet<String>();
+    
+    static {
+        URI_PREFIXES.add("hc://");
+    }
+    
+    private final AsyncHTTPConduitFactory factory = new AsyncHTTPConduitFactory();
+    
+    public AsyncHttpTransportFactory() {
+        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("hc://")) {
+            address = address.substring(5);
+        }
+        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-hc/src/main/resources/META-INF/cxf/bus-extensions.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/resources/META-INF/cxf/bus-extensions.txt?rev=1505936&r1=1505935&r2=1505936&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/resources/META-INF/cxf/bus-extensions.txt (original)
+++ cxf/trunk/rt/transports/http-hc/src/main/resources/META-INF/cxf/bus-extensions.txt Tue
Jul 23 08:46:25 2013
@@ -1,2 +1,3 @@
 org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduitFactory:org.apache.cxf.transport.http.HTTPConduitFactory:true:true
+org.apache.cxf.transport.http.asyncclient.AsyncHttpTransportFactory:org.apache.cxf.transport.ConduitInitiator:true:true
 

Modified: cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java?rev=1505936&r1=1505935&r2=1505936&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
(original)
+++ cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
Tue Jul 23 08:46:25 2013
@@ -33,6 +33,7 @@ import org.apache.cxf.BusFactory;
 import org.apache.cxf.continuations.Continuation;
 import org.apache.cxf.continuations.ContinuationProvider;
 import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.hello_world_soap_http.Greeter;
@@ -131,7 +132,30 @@ public class AsyncHTTPConduitTest extend
         } catch (Exception ex) {
             //expected
         }
-    }    
+    }
+    
+    @Test
+    public void testInovationWithHCAddress() throws Exception {
+        String address =  "hc://http://localhost:" + PORT + "/SoapContext/SoapPort";
+        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+        factory.setServiceClass(Greeter.class);
+        factory.setAddress(address);
+        Greeter greeter = factory.create(Greeter.class);
+        String response = greeter.greetMe("test");
+        assertEquals("Get a wrong response", "Hello test", response);
+    }
+    
+    @Test
+    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/http-client");
+        Greeter greeter = factory.create(Greeter.class);
+        String response = greeter.greetMe("test");
+        assertEquals("Get a wrong response", "Hello test", response);
+    }
     @Test
     public void testCall() throws Exception {
         updateAddressPort(g, PORT);



Mime
View raw message