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/08/30 20:44:36 UTC

svn commit: r1379053 - /cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java

Author: dkulp
Date: Thu Aug 30 18:44:35 2012
New Revision: 1379053

URL: http://svn.apache.org/viewvc?rev=1379053&view=rev
Log:
Non POST requests now working.  Make sure content-type is set on message.
ALL systests/jaxws tests now pass with a forced Async conduit.


Modified:
    cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java

Modified: cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java?rev=1379053&r1=1379052&r2=1379053&view=diff
==============================================================================
--- cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java (original)
+++ cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java Thu Aug 30 18:44:35 2012
@@ -22,6 +22,7 @@ package org.apache.cxf.transport.http.as
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -63,9 +64,15 @@ public class AsyncHTTPConduit extends UR
     }
 
     protected void setupConnection(Message message, URI uri, HTTPClientPolicy csPolicy) throws IOException {
+        String s = uri.getScheme();
+        if (!"http".equals(s) && !"https".equals(s)) {
+            throw new MalformedURLException("unknown protocol: " + s);
+        }
+        
         Object o = message.getContextualProperty(USE_ASYNC);
         if (o == null) {
-            o = !message.getExchange().isSynchronous();
+            //o = !message.getExchange().isSynchronous();
+            o = true;
         }
         if (!MessageUtils.isTrue(o)) {
             message.put(USE_ASYNC, Boolean.FALSE);
@@ -181,10 +188,15 @@ public class AsyncHTTPConduit extends UR
             basicEntity.setChunked(true);
         }
 
+        protected void handleNoOutput() throws IOException {
+            executeRequest(false);
+        }
         protected void setupWrappedStream() throws IOException {
+            executeRequest(true);
+        }        
+        protected void executeRequest(boolean output) throws IOException {
                        
             CXFResponseCallback responseCallback = new CXFResponseCallback() {
-
                 @Override
                 public void responseReceived(HttpResponse response) {
                     setHttpResponse(response);
@@ -214,31 +226,40 @@ public class AsyncHTTPConduit extends UR
             
             //FIXME - what to do for SSL/TLS?
             //tlsClientParameters.*
-
+            
+            
+            if (!output) {
+                entity.removeHeaders("Transfer-Encoding");
+                entity.removeHeaders("Content-Type");
+                entity.setEntity(null);
+            }
             factory.getRequester().execute(
                         csPolicy,
                         new CXFHttpAsyncRequestProducer(entity, outbuf),
                         new CXFHttpAsyncResponseConsumer(inbuf, responseCallback),
                         new BasicHttpContext(),
                         callback);
-            
-            wrappedStream = new OutputStream() {
-                public void write(byte b[], int off, int len) throws IOException {
-                    outbuf.write(b, off, len);
-                }
-                public void write(int b) throws IOException {
-                    outbuf.write(b);
-                }
-                public void close() throws IOException {
-                    outbuf.writeCompleted();
+            if (output) {
+                wrappedStream = new OutputStream() {
+                    public void write(byte b[], int off, int len) throws IOException {
+                        outbuf.write(b, off, len);
+                    }
+                    public void write(int b) throws IOException {
+                        outbuf.write(b);
+                    }
+                    public void close() throws IOException {
+                        outbuf.writeCompleted();
+                    }
+                };
+                            
+                // If we need to cache for retransmission, store data in a
+                // CacheAndWriteOutputStream. Otherwise write directly to the output stream.
+                if (cachingForRetransmission) {
+                    cachedStream = new CacheAndWriteOutputStream(wrappedStream);
+                    wrappedStream = cachedStream;
                 }
-            };
-                        
-            // If we need to cache for retransmission, store data in a
-            // CacheAndWriteOutputStream. Otherwise write directly to the output stream.
-            if (cachingForRetransmission) {
-                cachedStream = new CacheAndWriteOutputStream(wrappedStream);
-                wrappedStream = cachedStream;
+            } else {
+                outbuf.writeCompleted();
             }
         }
 
@@ -341,19 +362,24 @@ public class AsyncHTTPConduit extends UR
             return getHttpResponse().getStatusLine().getReasonPhrase();
         }
         
-        private void readHeaders(Headers h) {
+        private String readHeaders(Headers h) {
             Header headers[] = httpResponse.getAllHeaders();
             h.headerMap().clear();
+            String ct = null;
             for (Header header : headers) {
                 List<String> s = new ArrayList<String>(1);
                 s.add(header.getValue());
                 h.headerMap().put(header.getName(), s);
+                if ("Content-Type".equals(header.getName())) {
+                    ct = header.getValue();
+                }
             } 
+            return ct;
         }
         
         protected void updateResponseHeaders(Message inMessage) {
             Headers h = new Headers(inMessage);
-            readHeaders(h);
+            inMessage.put(Message.CONTENT_TYPE, readHeaders(h));
         }
         
         protected InputStream getPartialResponse() throws IOException {