cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1379522 - /cxf/sandbox/dkulp_async_clients/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
Date Fri, 31 Aug 2012 17:36:19 GMT
Author: dkulp
Date: Fri Aug 31 17:36:19 2012
New Revision: 1379522

URL: http://svn.apache.org/viewvc?rev=1379522&view=rev
Log:
Handle partial responses, all non-https ws-specs systests now pass

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=1379522&r1=1379521&r2=1379522&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
Fri Aug 31 17:36:19 2012
@@ -22,7 +22,10 @@ package org.apache.cxf.transport.http.as
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.PushbackInputStream;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
+import java.net.SocketTimeoutException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -72,7 +75,7 @@ public class AsyncHTTPConduit extends UR
         Object o = message.getContextualProperty(USE_ASYNC);
         if (o == null) {
             //o = !message.getExchange().isSynchronous();
-            o = true;
+            o = "http".equals(s);
         }
         if (!MessageUtils.isTrue(o)) {
             message.put(USE_ASYNC, Boolean.FALSE);
@@ -164,7 +167,7 @@ public class AsyncHTTPConduit extends UR
                     for (String s : header.getValue()) {
                         entity.addHeader(HttpHeaderHelper.COOKIE, s);
                     }
-                } else {
+                } else if (!"Content-Length".equalsIgnoreCase(header.getKey())) {
                     StringBuilder b = new StringBuilder();
                     for (int i = 0; i < header.getValue().size(); i++) {
                         b.append(header.getValue().get(i));
@@ -311,7 +314,7 @@ public class AsyncHTTPConduit extends UR
                         throw new IOException(exception);
                     }
                     
-                    throw new IOException("Read Timeout");
+                    throw new SocketTimeoutException("Read Timeout");
                 }
             }
             return httpResponse;
@@ -322,6 +325,12 @@ public class AsyncHTTPConduit extends UR
         }
         
         protected void closeInputStream() throws IOException {
+            byte bytes[] = new byte[1024];
+            while (inbuf.read(bytes) > 0) {
+                //nothing
+            }
+            inbuf.close();
+            inbuf.shutdown();
         }
         
         protected synchronized InputStream getInputStream() throws IOException {
@@ -386,7 +395,39 @@ public class AsyncHTTPConduit extends UR
         }
         
         protected InputStream getPartialResponse() throws IOException {
-            return null;
+            InputStream in = null;
+            int responseCode = getResponseCode();
+            if (responseCode == HttpURLConnection.HTTP_ACCEPTED
+                || responseCode == HttpURLConnection.HTTP_OK) {
+                
+                Header head = httpResponse.getFirstHeader(HttpHeaderHelper.CONTENT_LENGTH);
+                int cli = 0;
+                if (head != null) {
+                    cli = Integer.parseInt(head.getValue());
+                }
+                head = httpResponse.getFirstHeader(HttpHeaderHelper.TRANSFER_ENCODING);
+                boolean isChunked = head != null &&  HttpHeaderHelper.CHUNKED.equalsIgnoreCase(head.getValue());
+                head = httpResponse.getFirstHeader(HttpHeaderHelper.CONNECTION);
+                boolean isEofTerminated = head != null &&  HttpHeaderHelper.CLOSE.equalsIgnoreCase(head.getValue());
+                if (cli > 0) {
+                    in = getInputStream();
+                } else if (isChunked || isEofTerminated) {
+                    // ensure chunked or EOF-terminated response is non-empty
+                    try {
+                        @SuppressWarnings("resource")
+                        PushbackInputStream pin = 
+                            new PushbackInputStream(getInputStream());
+                        int c = pin.read();
+                        if (c != -1) {
+                            pin.unread((byte)c);
+                            in = pin;
+                        }
+                    } catch (IOException ioe) {
+                        // ignore
+                    }    
+                }
+            }
+            return in;
         }
         
         protected void updateCookiesBeforeRetransmit() {



Mime
View raw message