hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r545868 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
Date Sun, 10 Jun 2007 11:46:08 GMT
Author: olegk
Date: Sun Jun 10 04:46:07 2007
New Revision: 545868

URL: http://svn.apache.org/viewvc?view=rev&rev=545868
Log:
Some minor code refactoring in BufferingHttpClientHandler

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java?view=diff&rev=545868&r1=545867&r2=545868
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
Sun Jun 10 04:46:07 2007
@@ -191,7 +191,33 @@
         
         try {
             
-            submitRequest(conn, connState);                
+            HttpRequest request = this.execHandler.submitRequest(context);
+            if (request == null) {
+                return;
+            }
+            
+            HttpParamsLinker.link(request, this.params);
+            
+            context.setAttribute(HttpExecutionContext.HTTP_REQUEST, request);
+            this.httpProcessor.process(request, context);
+            connState.setRequest(request);
+            conn.submitRequest(request);
+            connState.setOutputState(ClientConnState.REQUEST_SENT);
+            
+            if (request instanceof HttpEntityEnclosingRequest) {
+                if (((HttpEntityEnclosingRequest) request).expectContinue()) {
+                    int timeout = conn.getSocketTimeout();
+                    connState.setTimeout(timeout);
+                    timeout = this.params.getIntParameter(
+                            HttpProtocolParams.WAIT_FOR_CONTINUE, 3000);
+                    conn.setSocketTimeout(timeout);
+                    connState.setOutputState(ClientConnState.EXPECT_CONTINUE);
+                } else {
+                    prepareRequestBody(
+                            (HttpEntityEnclosingRequest) request, 
+                            connState);
+                }
+            }
             
         } catch (IOException ex) {
             shutdownConnection(conn);
@@ -210,18 +236,16 @@
         HttpContext context = conn.getContext();
 
         ClientConnState connState = (ClientConnState) context.getAttribute(CONN_STATE);
-        
-        connState.setInputState(ClientConnState.RESPONSE_BODY_STREAM);
         ContentInputBuffer buffer = connState.getInbuffer();
 
         try {
 
             buffer.consumeContent(decoder);
             if (decoder.isCompleted()) {
-
                 connState.setInputState(ClientConnState.RESPONSE_BODY_DONE);
                 processResponse(conn, connState);
-                
+            } else {
+                connState.setInputState(ClientConnState.RESPONSE_BODY_STREAM);
             }
             
         } catch (IOException ex) {
@@ -241,22 +265,20 @@
         HttpContext context = conn.getContext();
 
         ClientConnState connState = (ClientConnState) context.getAttribute(CONN_STATE);
-        
-        if (connState.getOutputState() == ClientConnState.EXPECT_CONTINUE) {
-            conn.suspendOutput();
-            return;
-        }
-        
-        connState.setInputState(ClientConnState.REQUEST_BODY_STREAM);
         ContentOutputBuffer buffer = connState.getOutbuffer();
-
+        
         try {
+
+            if (connState.getOutputState() == ClientConnState.EXPECT_CONTINUE) {
+                conn.suspendOutput();
+                return;
+            }
             
             buffer.produceContent(encoder);
             if (encoder.isCompleted()) {
-
                 connState.setInputState(ClientConnState.REQUEST_BODY_DONE);
-                
+            } else {
+                connState.setInputState(ClientConnState.REQUEST_BODY_STREAM);
             }
             
         } catch (IOException ex) {
@@ -346,40 +368,6 @@
         this.execHandler.initalizeContext(context, attachment);
     }
     
-    private void submitRequest(
-            final NHttpClientConnection conn, 
-            final ClientConnState connState) throws IOException, HttpException {
-        
-        connState.resetOutput();
-        
-        HttpContext context = conn.getContext();
-        HttpRequest request = this.execHandler.submitRequest(context);
-        if (request == null) {
-            return;
-        }
-        
-        HttpParamsLinker.link(request, this.params);
-        
-        context.setAttribute(HttpExecutionContext.HTTP_REQUEST, request);
-        this.httpProcessor.process(request, context);
-        connState.setRequest(request);
-        conn.submitRequest(request);
-        connState.setOutputState(ClientConnState.REQUEST_SENT);
-        
-        if (request instanceof HttpEntityEnclosingRequest) {
-            if (((HttpEntityEnclosingRequest) request).expectContinue()) {
-                int timeout = conn.getSocketTimeout();
-                connState.setTimeout(timeout);
-                timeout = this.params.getIntParameter(
-                        HttpProtocolParams.WAIT_FOR_CONTINUE, 3000);
-                conn.setSocketTimeout(timeout);
-                connState.setOutputState(ClientConnState.EXPECT_CONTINUE);
-            } else {
-                prepareRequestBody((HttpEntityEnclosingRequest) request, connState);
-            }
-        }
-    }
-    
     private void continueRequest(
             final NHttpClientConnection conn, 
             final ClientConnState connState) throws IOException {
@@ -455,6 +443,7 @@
         } else {
             // Ready for another request
             connState.resetInput();
+            connState.resetOutput();
             conn.requestOutput();
         }
     }



Mime
View raw message