You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/07/27 20:41:36 UTC

svn commit: r1366485 - in /cxf/sandbox/dkulp_async_clients/http-ahc: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/cxf/ src/main/java/org/apache/cxf/transport/ src/main/java/org/apache/cxf/transp...

Author: dkulp
Date: Fri Jul 27 18:41:36 2012
New Revision: 1366485

URL: http://svn.apache.org/viewvc?rev=1366485&view=rev
Log:
Add experiment with Sonatypes async client (previously called ning)
Abandoned at this point due to it not handling chunked output correctly at all.  Sets the chunked Transfer-Encoding header, but doesn't put the chunk headers.


Added:
    cxf/sandbox/dkulp_async_clients/http-ahc/
    cxf/sandbox/dkulp_async_clients/http-ahc/pom.xml
    cxf/sandbox/dkulp_async_clients/http-ahc/src/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
    cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/transport/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/transport/http/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/transport/http/asyncclient/
    cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java

Added: cxf/sandbox/dkulp_async_clients/http-ahc/pom.xml
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-ahc/pom.xml?rev=1366485&view=auto
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-ahc/pom.xml (added)
+++ cxf/sandbox/dkulp_async_clients/http-ahc/pom.xml Fri Jul 27 18:41:36 2012
@@ -0,0 +1,106 @@
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.cxf</groupId>
+    <artifactId>cxf-rt-transports-http-ahc</artifactId>
+    <packaging>jar</packaging>
+    <version>2.7.0-SNAPSHOT</version>
+    <name>Apache CXF Runtime HTTP Transport</name>
+    <description>Apache CXF Runtime HTTP Async Transport</description>
+    <url>http://cxf.apache.org</url>
+
+    <parent>
+        <groupId>org.apache.cxf</groupId>
+        <artifactId>cxf-parent</artifactId>
+        <version>2.7.0-SNAPSHOT</version>
+        <relativePath>../../../parent/pom.xml</relativePath>
+    </parent>
+    <properties>
+        <cxf.osgi.import>
+            javax.servlet*;version="${cxf.osgi.javax.servlet.version}",
+        </cxf.osgi.import>
+        <cxf.osgi.export>
+            org.apache.cxf.*,
+        </cxf.osgi.export>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.ning</groupId>
+            <artifactId>async-http-client</artifactId>
+            <version>1.7.5</version>
+        </dependency>
+
+
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http-jetty</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxws</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-testutils</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+
+</project>

Added: cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java?rev=1366485&view=auto
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java (added)
+++ cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java Fri Jul 27 18:41:36 2012
@@ -0,0 +1,319 @@
+/**
+ * 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.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Map;
+
+import com.ning.http.client.AsyncHandler;
+import com.ning.http.client.AsyncHttpClient;
+import com.ning.http.client.Body;
+import com.ning.http.client.BodyGenerator;
+import com.ning.http.client.HttpResponseBodyPart;
+import com.ning.http.client.HttpResponseHeaders;
+import com.ning.http.client.HttpResponseStatus;
+import com.ning.http.client.RequestBuilder;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.helpers.HttpHeaderHelper;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.http.Headers;
+import org.apache.cxf.transport.https.HttpsURLConnectionInfo;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.cxf.version.Version;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+
+/**
+ * 
+ */
+public class AsyncHTTPConduit extends HTTPConduit {
+    final AsyncHttpClient httpclient;
+    
+    public AsyncHTTPConduit(Bus b, EndpointInfo ei, EndpointReferenceType t,
+                            AsyncHttpClient httpclient) throws IOException {
+        super(b, ei, t);
+        this.httpclient = httpclient;
+    }
+
+    protected void setupConnection(Message message, URL url, HTTPClientPolicy csPolicy) throws IOException {
+        String httpRequestMethod = 
+            (String)message.get(Message.HTTP_REQUEST_METHOD);
+        if (httpRequestMethod == null) {
+            httpRequestMethod = "POST";
+            message.put(Message.HTTP_REQUEST_METHOD, httpRequestMethod);
+        }
+        
+        
+        RequestBuilder builder = new RequestBuilder(httpRequestMethod);
+        builder.setUrl(url.toString());
+        message.put(RequestBuilder.class, builder);
+    }
+    
+    
+    protected OutputStream createOutputStream(Message message, 
+                                              boolean needToCacheRequest, 
+                                              boolean isChunking,
+                                              int chunkThreshold) {
+        HttpURLConnection connection = (HttpURLConnection)message.get(KEY_HTTP_CONNECTION);
+        
+        if (isChunking && chunkThreshold <= 0) {
+            chunkThreshold = 0;
+            connection.setChunkedStreamingMode(-1);                    
+        }
+        //RequestBuilder builder = message.get(RequestBuilder.class);
+        String url = null;  //FIXME get the URL
+        return new AsyncWrappedOutputStream(message,
+                                            needToCacheRequest, 
+                                            isChunking,
+                                            chunkThreshold,
+                                            getConduitName(),
+                                            url);
+    }
+    
+    
+    class AsyncWrappedOutputStream extends WrappedOutputStream {
+        final RequestBuilder builder;
+        final CXFBody body = new CXFBody();
+        
+        public AsyncWrappedOutputStream(Message message,
+                                        boolean needToCacheRequest, 
+                                        boolean isChunking,
+                                        int chunkThreshold, 
+                                        String conduitName,
+                                        String url) {
+            super(message, needToCacheRequest, isChunking,
+                  chunkThreshold, conduitName,
+                  url);
+            builder = message.get(RequestBuilder.class);
+        }
+        
+        class CXFBody implements Body {
+            long contentLength = -1;
+            byte buffer[] = new byte[8192];
+            int len;
+            boolean closed;
+            
+            public synchronized void addBytes(byte bytes[], int off, int l) throws IOException {
+                int max = off + l;
+                while (off < max) {
+                    int toCopy = buffer.length - len;
+                    if (toCopy > l) {
+                        toCopy = l;
+                    }
+                    if (toCopy > 0) {
+                        System.arraycopy(bytes, off, buffer, len, toCopy);
+                        len += toCopy;
+                        off += toCopy;
+                    } else {
+                        try {
+                            wait(30000);
+                        } catch (InterruptedException e) {
+                            throw new IOException(e);
+                        }
+                    }
+                }
+            }
+            
+            public void setContentLength(long l) {
+                contentLength = l;
+            }
+            public long getContentLength() {
+                return contentLength;
+            }
+            public synchronized long read(ByteBuffer b) throws IOException {
+                if (len == 0 && closed) {
+                    return -1;
+                }
+                int toCopy = b.remaining();
+                if (len < toCopy) {
+                    toCopy = len;
+                }
+                b.put(buffer, 0, toCopy);
+                if (toCopy == len) {
+                    len = 0;
+                } else {
+                    System.arraycopy(buffer, toCopy, buffer, 0, len - toCopy);
+                }
+                notifyAll();
+                return toCopy;
+            }
+            public void setClosed() {
+                closed = true;
+            }
+            public void close() throws IOException {
+            }
+
+            public synchronized void flush() throws IOException {
+                while (len > 0) {
+                    try {
+                        wait(30000);
+                    } catch (InterruptedException e) {
+                        throw new IOException(e);
+                    }
+                }
+            }
+        };
+        protected void setProtocolHeaders() throws IOException {
+            Headers h = new Headers(outMessage);
+            builder.setHeader("Content-Type", h.determineContentType());
+            for (Map.Entry<String, List<String>> header : h.headerMap().entrySet()) {
+                if (HttpHeaderHelper.CONTENT_TYPE.equalsIgnoreCase(header.getKey())) {
+                    continue;
+                }
+
+                StringBuilder b = new StringBuilder();
+                for (int i = 0; i < header.getValue().size(); i++) {
+                    b.append(header.getValue().get(i));
+                    if (i + 1 < header.getValue().size()) {
+                        b.append(',');
+                    }
+                }
+                builder.setHeader(header.getKey(), b.toString());
+            }
+            if (!h.headerMap().containsKey("User-Agent")) {
+                builder.setHeader("User-Agent", Version.getCompleteVersionString());
+            }
+        }
+        
+        protected void setFixedLengthStreamingMode(int i) {
+            body.setContentLength(i);
+        }
+        public void thresholdReached() throws IOException {
+        }
+        class CXFAsyncHandler implements AsyncHandler<Object> {
+            public void onThrowable(Throwable t) {
+                t.printStackTrace();
+            }
+            public com.ning.http.client.AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
+                throws Exception {
+                System.out.println("part");
+                return com.ning.http.client.AsyncHandler.STATE.CONTINUE;
+            }
+
+            public com.ning.http.client.AsyncHandler.STATE onStatusReceived(HttpResponseStatus responseStatus)
+                throws Exception {
+                System.out.println("status");
+                return com.ning.http.client.AsyncHandler.STATE.CONTINUE;
+            }
+
+            public com.ning.http.client.AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
+                throws Exception {
+                System.out.println("headers");
+                return com.ning.http.client.AsyncHandler.STATE.CONTINUE;
+            }
+
+            public Object onCompleted() throws Exception {
+                System.out.println("complete");
+                return Boolean.TRUE;
+            }
+        }
+        
+        protected void setupWrappedStream() throws IOException {
+            builder.setBody(new BodyGenerator() {
+                public Body createBody() throws IOException {
+                    return body;
+                }
+            });
+            wrappedStream = new OutputStream() {
+                public void write(byte[] b) throws IOException {
+                    write(b, 0, b.length);
+                }
+                public void write(byte[] b, int off, int len) throws IOException {
+                    body.addBytes(b, off, len);
+                }
+                public void flush() throws IOException {
+                    body.flush();
+                }
+                public void close() throws IOException {
+                    body.setClosed();
+                }
+                public void write(int b) throws IOException {
+                    write(new byte[] {(byte)b});
+                }
+            };
+            httpclient.executeRequest(builder.build(), new CXFAsyncHandler());
+        }
+        
+        protected void handleResponseAsync() throws IOException {
+        }
+        protected void closeInputStream() throws IOException {
+        }
+        
+        protected boolean usingProxy() {
+            return false;
+        }
+        protected HttpsURLConnectionInfo getHttpsURLConnectionInfo() throws IOException {
+            return null;
+        }
+        protected int getResponseCode() throws IOException {
+            try {
+                Thread.sleep(5000);
+            } catch (InterruptedException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            return 0;
+        }
+        protected String getResponseMessage() throws IOException {
+            return null;
+        }
+        
+        private void readHeaders(Headers h) {
+            /*
+            Header headers[] = httpResponse.getAllHeaders();
+            h.headerMap().clear();
+            for (Header header : headers) {
+                List<String> s = new ArrayList<String>(1);
+                s.add(header.getValue());
+                h.headerMap().put(header.getName(), s);
+            } 
+            */
+        }
+        protected void updateResponseHeaders(Message inMessage) {
+            Headers h = new Headers(inMessage);
+            readHeaders(h);
+        }
+        protected void updateCookiesBeforeRetransmit() {
+            Headers h = new Headers();
+            readHeaders(h);
+            cookies.readFromHeaders(h);
+        }
+        protected void retransmitStream() throws IOException {
+        }
+        protected void setupNewConnection(String newURL) throws IOException {           
+        }
+        protected InputStream getInputStream() throws IOException {
+            return null;
+        }
+        protected InputStream getPartialResponse() throws IOException {
+            return null;
+        }
+
+    }
+    
+}

Added: cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java?rev=1366485&view=auto
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java (added)
+++ cxf/sandbox/dkulp_async_clients/http-ahc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPTransportFactory.java Fri Jul 27 18:41:36 2012
@@ -0,0 +1,126 @@
+/**
+ * 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 javax.annotation.Resource;
+
+import com.ning.http.client.AsyncHttpClient;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.http.HTTPConduitConfigurer;
+import org.apache.cxf.transport.http.HTTPTransportFactory;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+
+/**
+ * 
+ */
+@NoJSR250Annotations(unlessNull = "bus")
+public class AsyncHTTPTransportFactory extends HTTPTransportFactory implements BusLifeCycleListener {
+    AsyncHttpClient asyncHttpClient;
+    
+    
+    public AsyncHTTPTransportFactory() {
+        super();
+    }
+    public AsyncHTTPTransportFactory(Bus b) {
+        super(b);
+        addListener(b);
+    }
+    public AsyncHTTPTransportFactory(Bus b, DestinationRegistry registry) {
+        super(b, registry);
+        addListener(b);
+    }
+
+    public AsyncHTTPTransportFactory(DestinationRegistry registry) {
+        super(registry);
+    }
+    
+    @Resource 
+    public void setBus(Bus b) {
+        super.setBus(b);
+        addListener(b);
+    }
+    public void initComplete() {
+    }
+    public synchronized void preShutdown() {
+        if (asyncHttpClient != null) {
+            asyncHttpClient.closeAsynchronously();
+        }
+    }
+    public void postShutdown() {
+        if (asyncHttpClient != null) {
+            asyncHttpClient.close();
+        }
+        asyncHttpClient.close();
+    }    
+    
+    private void addListener(Bus b) {
+        b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
+    }
+    
+    
+    public synchronized AsyncHttpClient getHttpClient() {
+        if (asyncHttpClient == null) {
+            asyncHttpClient = getBus().getExtension(AsyncHttpClient.class);
+            if (asyncHttpClient == null) {
+                asyncHttpClient = (AsyncHttpClient)getBus().getProperty(AsyncHttpClient.class.getName());
+            }
+            if (asyncHttpClient == null) {
+                asyncHttpClient = new AsyncHttpClient();
+            }
+        }
+        return asyncHttpClient;
+    }
+    
+    /**
+     * This call creates a new HTTP Conduit based on the EndpointInfo and
+     * EndpointReferenceType.
+     * TODO: What are the formal constraints on EndpointInfo and 
+     * EndpointReferenceType values?
+     */
+    public Conduit getConduit(
+            EndpointInfo endpointInfo,
+            EndpointReferenceType target
+    ) throws IOException {
+        HTTPConduit conduit = new AsyncHTTPConduit(bus, endpointInfo, target, getHttpClient());
+        // 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(conduit, conduit.getBeanName(), address);
+        conduit.finalizeConfig();
+        return conduit;
+    }
+
+}

Added: cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java?rev=1366485&view=auto
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java (added)
+++ cxf/sandbox/dkulp_async_clients/http-ahc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java Fri Jul 27 18:41:36 2012
@@ -0,0 +1,125 @@
+/**
+ * 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.net.URL;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.hello_world.Greeter;
+import org.apache.hello_world.services.SOAPService;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+
+public class AsyncHTTPConduitTest extends AbstractBusClientServerTestBase {
+    public static final String PORT = allocatePort(AsyncHTTPConduitTest.class);
+    public static final String PORT2 = allocatePort(AsyncHTTPConduitTest.class, 2);
+    
+    static Endpoint ep;
+    @BeforeClass
+    public static void start() throws Exception {
+        Bus b = createStaticBus();
+        new AsyncHTTPTransportFactory(b);
+        ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort",
+                              new org.apache.hello_world.GreeterImpl());
+        ep = Endpoint.publish("http://localhost:" + PORT2 + "/SoapContext/SoapPort",
+                              new org.apache.hello_world.GreeterImpl());
+    }
+    
+    @AfterClass
+    public static void stop() throws Exception {
+        ep.stop();
+        ep = null;
+    }
+    
+    @Test
+    public void testCall() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/hello_world_services.wsdl");
+        assertNotNull("WSDL is null", wsdl);
+
+        SOAPService service = new SOAPService();
+        assertNotNull("Service is null", service);
+
+        StringBuilder builder = new StringBuilder("NaNaNa");
+        for (int x = 0; x < 1; x++) {
+            builder.append(" NaNaNa ");
+        }
+        
+        Greeter g = service.getSoapPort();
+        assertNotNull("Port is null", g);
+        updateAddressPort(g, PORT);
+        g.greetMe(builder.toString());
+    }
+        
+    @Test
+    public void testCalls() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/hello_world_services.wsdl");
+        assertNotNull("WSDL is null", wsdl);
+
+        SOAPService service = new SOAPService();
+        assertNotNull("Service is null", service);
+
+        StringBuilder builder = new StringBuilder("NaNaNa");
+        for (int x = 0; x < 1; x++) {
+            builder.append(" NaNaNa ");
+        }
+        
+        Greeter g = service.getSoapPort();
+        assertNotNull("Port is null", g);
+        updateAddressPort(g, PORT);
+
+        //warmup
+        for (int x = 0; x < 100; x++) {
+            //builder.append("a");
+            //long s1 = System.nanoTime();
+            //System.out.println("aa1: " + s1);
+            String value = g.greetMe(builder.toString());
+            //long s2 = System.nanoTime();
+            //System.out.println("aa2: " + s2 + " " + (s2 - s1));
+            assertEquals("Hello " + builder.toString(), value);
+            //System.out.println();
+        }
+
+        long start = System.currentTimeMillis();
+        for (int x = 0; x < 10000; x++) {
+            //builder.append("a");
+            //long s1 = System.nanoTime();
+            //System.out.println("aa1: " + s1);
+            g.greetMe(builder.toString());
+            //long s2 = System.nanoTime();
+            //System.out.println("aa2: " + s2 + " " + (s2 - s1));
+            //System.out.println();
+        }
+        long end = System.currentTimeMillis();
+        System.out.println("Total: " + (end - start));
+        /*
+        updateAddressPort(g, PORT2);
+        String value = g.greetMe(builder.toString());
+        assertEquals("Hello " + builder.toString(), value);
+        */
+    }
+
+}