[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpcomponents-commits
Subject:    svn commit: r516114 - in
From:       olegk () apache ! org
Date:       2007-03-08 17:35:42
Message-ID: 20070308173543.61A4E1A9838 () eris ! apache ! org
[Download RAW message or body]

Author: olegk
Date: Thu Mar  8 09:35:33 2007
New Revision: 516114

URL: http://svn.apache.org/viewvc?view=rev&rev=516114
Log:
HTTPCORE-45: 
* Improved handling of pipelined requests in the buffering HTTP request service \
                handler
* Improved NIO integration tests

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
  jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java


Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?view=diff&rev=516114&r1=516113&r2=516114
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java \
Thu Mar  8 09:35:33 2007 @@ -71,7 +71,6 @@
         this.request = null;
         this.contentDecoder = null;
         this.requestParser.reset();
-        this.session.setEvent(EventMask.READ);
     }
     
     private void resetOutput() {

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=516114&r1=516113&r2=516114
 ==============================================================================
--- 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 \
Thu Mar  8 09:35:33 2007 @@ -172,6 +172,9 @@
         HttpContext context = conn.getContext();
 
         ClientConnState connState = (ClientConnState) \
context.getAttribute(CONN_STATE); +        if (connState.getInputState() != \
ClientConnState.READY) { +            return;
+        }
         
         try {
             
@@ -459,11 +462,11 @@
         private SimpleInputBuffer inbuffer; 
         private ContentOutputBuffer outbuffer;
 
-        private volatile int inputState;
-        private volatile int outputState;
+        private int inputState;
+        private int outputState;
         
-        private volatile HttpRequest request;
-        private volatile HttpResponse response;
+        private HttpRequest request;
+        private HttpResponse response;
 
         private int timeout;
         

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java?view=diff&rev=516114&r1=516113&r2=516114
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java \
Thu Mar  8 09:35:33 2007 @@ -200,6 +200,7 @@
             } else {
                 // No request content is expected. 
                 // Process request right away
+                conn.suspendInput();
                 processRequest(conn, request);
             }
             
@@ -279,6 +280,7 @@
                             entityReq.getEntity(), 
                             connState.getInbuffer()));
                 }
+                conn.suspendInput();
                 processRequest(conn, request);
             }
             
@@ -317,6 +319,8 @@
                 connState.resetOutput();
                 if (!this.connStrategy.keepAlive(response, context)) {
                     conn.close();
+                } else {
+                    conn.requestInput();
                 }
             }
             
@@ -421,7 +425,6 @@
         conn.submitResponse(response);
 
         // Update connection state
-        connState.setResponse(response);
         connState.setOutputState(ServerConnState.RESPONSE_SENT);
         
         if (response.getEntity() != null) {
@@ -434,6 +437,7 @@
             }
         } else {
             connState.resetOutput();
+            conn.requestInput();
         }
     }
 
@@ -450,11 +454,10 @@
         private SimpleInputBuffer inbuffer; 
         private ContentOutputBuffer outbuffer;
 
-        private volatile int inputState;
-        private volatile int outputState;
+        private int inputState;
+        private int outputState;
         
-        private volatile HttpRequest request;
-        private volatile HttpResponse response;
+        private HttpRequest request;
         
         public ServerConnState() {
             super();
@@ -500,14 +503,6 @@
             this.request = request;
         }
 
-        public HttpResponse getResponse() {
-            return this.response;
-        }
-
-        public void setResponse(final HttpResponse response) {
-            this.response = response;
-        }
-
         public void resetInput() {
             this.inbuffer = null;
             this.request = null;
@@ -516,7 +511,6 @@
         
         public void resetOutput() {
             this.outbuffer = null;
-            this.response = null;
             this.outputState = READY;
         }
         

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src \
/test/java/org/apache/http/nio/protocol/TestNIOHttp.java?view=diff&rev=516114&r1=516113&r2=516114
 ==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java \
                (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOHttp.java \
Thu Mar  8 09:35:33 2007 @@ -158,36 +158,17 @@
 
             public void initalizeContext(final HttpContext context, final Object \
attachment) {  context.setAttribute("LIST", (List) attachment);
-                context.setAttribute("STATUS", "ready");
+                context.setAttribute("REQ-COUNT", new Integer(0));
+                context.setAttribute("RES-COUNT", new Integer(0));
             }
 
             public HttpRequest submitRequest(final HttpContext context) {
-                NHttpConnection conn = (NHttpConnection) context.getAttribute(
-                        HttpExecutionContext.HTTP_CONNECTION);
-                String status = (String) context.getAttribute("STATUS");
-                if (!status.equals("ready")) {
-                    return null;
-                }
-                int index = 0;
-                
-                Integer intobj = (Integer) context.getAttribute("INDEX");
-                if (intobj != null) {
-                    index = intobj.intValue();
-                }
-
+                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
                 HttpGet get = null;
-                if (index < reqNo) {
-                    get = new HttpGet("/?" + index);
-                    context.setAttribute("INDEX", new Integer(index + 1));
-                    context.setAttribute("STATUS", "busy");
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                        ex.printStackTrace();
-                    }
+                if (i < reqNo) {
+                    get = new HttpGet("/?" + i);
+                    context.setAttribute("REQ-COUNT", new Integer(i + 1));
                 }
-                
                 return get;
             }
             
@@ -196,6 +177,10 @@
                         HttpExecutionContext.HTTP_CONNECTION);
                 
                 List list = (List) context.getAttribute("LIST");
+                int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
+                i++;
+                context.setAttribute("RES-COUNT", new Integer(i));
+
                 try {
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
@@ -204,8 +189,15 @@
                     fail(ex.getMessage());
                 }
 
-                context.setAttribute("STATUS", "ready");
-                conn.requestInput();
+                if (i < reqNo) {
+                    conn.requestInput();
+                } else {
+                    try {
+                        conn.close();
+                    } catch (IOException ex) {
+                        fail(ex.getMessage());
+                    }
+                }
             }
             
         });
@@ -230,7 +222,7 @@
         for (int c = 0; c < responseData.length; c++) {
             List receivedPackets = responseData[c];
             List expectedPackets = testData;
-            assertEquals(receivedPackets.size(), expectedPackets.size());
+            assertEquals(expectedPackets.size(), receivedPackets.size());
             for (int p = 0; p < testData.size(); p++) {
                 byte[] expected = (byte[]) testData.get(p);
                 byte[] received = (byte[]) receivedPackets.get(p);
@@ -297,40 +289,21 @@
 
             public void initalizeContext(final HttpContext context, final Object \
attachment) {  context.setAttribute("LIST", (List) attachment);
-                context.setAttribute("STATUS", "ready");
+                context.setAttribute("REQ-COUNT", new Integer(0));
+                context.setAttribute("RES-COUNT", new Integer(0));
             }
 
             public HttpRequest submitRequest(final HttpContext context) {
-                NHttpConnection conn = (NHttpConnection) context.getAttribute(
-                        HttpExecutionContext.HTTP_CONNECTION);
-                String status = (String) context.getAttribute("STATUS");
-                if (!status.equals("ready")) {
-                    return null;
-                }
-                int index = 0;
-                
-                Integer intobj = (Integer) context.getAttribute("INDEX");
-                if (intobj != null) {
-                    index = intobj.intValue();
-                }
-
+                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
                 HttpPost post = null;
-                if (index < reqNo) {
-                    post = new HttpPost("/?" + index);
-                    byte[] data = (byte[]) testData.get(index);
+                if (i < reqNo) {
+                    post = new HttpPost("/?" + i);
+                    byte[] data = (byte[]) testData.get(i);
                     ByteArrayEntity outgoing = new ByteArrayEntity(data);
                     post.setEntity(outgoing);
                     
-                    context.setAttribute("INDEX", new Integer(index + 1));
-                    context.setAttribute("STATUS", "busy");
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                        ex.printStackTrace();
-                    }
+                    context.setAttribute("REQ-COUNT", new Integer(i + 1));
                 }
-                
                 return post;
             }
             
@@ -339,6 +312,10 @@
                         HttpExecutionContext.HTTP_CONNECTION);
                 
                 List list = (List) context.getAttribute("LIST");
+                int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
+                i++;
+                context.setAttribute("RES-COUNT", new Integer(i));
+
                 try {
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
@@ -347,8 +324,15 @@
                     fail(ex.getMessage());
                 }
 
-                context.setAttribute("STATUS", "ready");
-                conn.requestInput();
+                if (i < reqNo) {
+                    conn.requestInput();
+                } else {
+                    try {
+                        conn.close();
+                    } catch (IOException ex) {
+                        fail(ex.getMessage());
+                    }
+                }
             }
             
         });
@@ -373,7 +357,7 @@
         for (int c = 0; c < responseData.length; c++) {
             List receivedPackets = responseData[c];
             List expectedPackets = testData;
-            assertEquals(receivedPackets.size(), expectedPackets.size());
+            assertEquals(expectedPackets.size(), receivedPackets.size());
             for (int p = 0; p < testData.size(); p++) {
                 byte[] expected = (byte[]) testData.get(p);
                 byte[] received = (byte[]) receivedPackets.get(p);
@@ -439,41 +423,22 @@
 
             public void initalizeContext(final HttpContext context, final Object \
attachment) {  context.setAttribute("LIST", (List) attachment);
-                context.setAttribute("STATUS", "ready");
+                context.setAttribute("REQ-COUNT", new Integer(0));
+                context.setAttribute("RES-COUNT", new Integer(0));
             }
 
             public HttpRequest submitRequest(final HttpContext context) {
-                NHttpConnection conn = (NHttpConnection) context.getAttribute(
-                        HttpExecutionContext.HTTP_CONNECTION);
-                String status = (String) context.getAttribute("STATUS");
-                if (!status.equals("ready")) {
-                    return null;
-                }
-                int index = 0;
-                
-                Integer intobj = (Integer) context.getAttribute("INDEX");
-                if (intobj != null) {
-                    index = intobj.intValue();
-                }
-
+                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
                 HttpPost post = null;
-                if (index < reqNo) {
-                    post = new HttpPost("/?" + index);
-                    byte[] data = (byte[]) testData.get(index);
+                if (i < reqNo) {
+                    post = new HttpPost("/?" + i);
+                    byte[] data = (byte[]) testData.get(i);
                     ByteArrayEntity outgoing = new ByteArrayEntity(data);
                     outgoing.setChunked(true);
                     post.setEntity(outgoing);
                     
-                    context.setAttribute("INDEX", new Integer(index + 1));
-                    context.setAttribute("STATUS", "busy");
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                        ex.printStackTrace();
-                    }
+                    context.setAttribute("REQ-COUNT", new Integer(i + 1));
                 }
-                
                 return post;
             }
             
@@ -482,6 +447,9 @@
                         HttpExecutionContext.HTTP_CONNECTION);
                 
                 List list = (List) context.getAttribute("LIST");
+                int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
+                i++;
+                context.setAttribute("RES-COUNT", new Integer(i));
                 
                 try {
                     HttpEntity entity = response.getEntity();
@@ -491,8 +459,15 @@
                     fail(ex.getMessage());
                 }
 
-                context.setAttribute("STATUS", "ready");
-                conn.requestInput();
+                if (i < reqNo) {
+                    conn.requestInput();
+                } else {
+                    try {
+                        conn.close();
+                    } catch (IOException ex) {
+                        fail(ex.getMessage());
+                    }
+                }
             }
             
         });
@@ -517,7 +492,7 @@
         for (int c = 0; c < responseData.length; c++) {
             List receivedPackets = responseData[c];
             List expectedPackets = testData;
-            assertEquals(receivedPackets.size(), expectedPackets.size());
+            assertEquals(expectedPackets.size(), receivedPackets.size());
             for (int p = 0; p < testData.size(); p++) {
                 byte[] expected = (byte[]) testData.get(p);
                 byte[] received = (byte[]) receivedPackets.get(p);
@@ -588,48 +563,33 @@
 
             public void initalizeContext(final HttpContext context, final Object \
attachment) {  context.setAttribute("LIST", (List) attachment);
-                context.setAttribute("STATUS", "ready");
+                context.setAttribute("REQ-COUNT", new Integer(0));
+                context.setAttribute("RES-COUNT", new Integer(0));
             }
 
             public HttpRequest submitRequest(final HttpContext context) {
-                NHttpConnection conn = (NHttpConnection) context.getAttribute(
-                        HttpExecutionContext.HTTP_CONNECTION);
-                String status = (String) context.getAttribute("STATUS");
-                if (!status.equals("ready")) {
-                    return null;
-                }
-                int index = 0;
-                
-                Integer intobj = (Integer) context.getAttribute("INDEX");
-                if (intobj != null) {
-                    index = intobj.intValue();
-                }
-
+                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
                 HttpPost post = null;
-                if (index < reqNo) {
-                    post = new HttpPost("/?" + index);
-                    byte[] data = (byte[]) testData.get(index);
+                if (i < reqNo) {
+                    post = new HttpPost("/?" + i);
+                    byte[] data = (byte[]) testData.get(i);
                     ByteArrayEntity outgoing = new ByteArrayEntity(data);
                     post.setEntity(outgoing);
                     
-                    context.setAttribute("INDEX", new Integer(index + 1));
-                    context.setAttribute("STATUS", "busy");
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                        ex.printStackTrace();
-                    }
+                    context.setAttribute("REQ-COUNT", new Integer(i + 1));
                 }
-                
                 return post;
             }
             
             public void handleResponse(final HttpResponse response, final \
                HttpContext context) {
                 NHttpConnection conn = (NHttpConnection) context.getAttribute(
                         HttpExecutionContext.HTTP_CONNECTION);
-                
+
                 List list = (List) context.getAttribute("LIST");
+                int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
+                i++;
+                context.setAttribute("RES-COUNT", new Integer(i));
+
                 try {
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
@@ -638,8 +598,15 @@
                     fail(ex.getMessage());
                 }
 
-                context.setAttribute("STATUS", "ready");
-                conn.requestInput();
+                if (i < reqNo) {
+                    conn.requestInput();
+                } else {
+                    try {
+                        conn.close();
+                    } catch (IOException ex) {
+                        fail(ex.getMessage());
+                    }
+                }
             }
             
         });
@@ -664,7 +631,7 @@
         for (int c = 0; c < responseData.length; c++) {
             List receivedPackets = responseData[c];
             List expectedPackets = testData;
-            assertEquals(receivedPackets.size(), expectedPackets.size());
+            assertEquals(expectedPackets.size(), receivedPackets.size());
             for (int p = 0; p < testData.size(); p++) {
                 byte[] expected = (byte[]) testData.get(p);
                 byte[] received = (byte[]) receivedPackets.get(p);
@@ -732,41 +699,22 @@
 
             public void initalizeContext(final HttpContext context, final Object \
attachment) {  context.setAttribute("LIST", (List) attachment);
-                context.setAttribute("STATUS", "ready");
+                context.setAttribute("REQ-COUNT", new Integer(0));
+                context.setAttribute("RES-COUNT", new Integer(0));
             }
 
             public HttpRequest submitRequest(final HttpContext context) {
-                NHttpConnection conn = (NHttpConnection) context.getAttribute(
-                        HttpExecutionContext.HTTP_CONNECTION);
-                String status = (String) context.getAttribute("STATUS");
-                if (!status.equals("ready")) {
-                    return null;
-                }
-                int index = 0;
-                
-                Integer intobj = (Integer) context.getAttribute("INDEX");
-                if (intobj != null) {
-                    index = intobj.intValue();
-                }
-
+                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
                 HttpPost post = null;
-                if (index < reqNo) {
-                    post = new HttpPost("/?" + index);
-                    byte[] data = (byte[]) testData.get(index);
+                if (i < reqNo) {
+                    post = new HttpPost("/?" + i);
+                    byte[] data = (byte[]) testData.get(i);
                     ByteArrayEntity outgoing = new ByteArrayEntity(data);
                     outgoing.setChunked(true);
                     post.setEntity(outgoing);
                     
-                    context.setAttribute("INDEX", new Integer(index + 1));
-                    context.setAttribute("STATUS", "busy");
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                        ex.printStackTrace();
-                    }
+                    context.setAttribute("REQ-COUNT", new Integer(i + 1));
                 }
-                
                 return post;
             }
             
@@ -775,6 +723,9 @@
                         HttpExecutionContext.HTTP_CONNECTION);
                 
                 List list = (List) context.getAttribute("LIST");
+                int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
+                i++;
+                context.setAttribute("RES-COUNT", new Integer(i));
                 
                 try {
                     HttpEntity entity = response.getEntity();
@@ -784,8 +735,15 @@
                     fail(ex.getMessage());
                 }
 
-                context.setAttribute("STATUS", "ready");
-                conn.requestInput();
+                if (i < reqNo) {
+                    conn.requestInput();
+                } else {
+                    try {
+                        conn.close();
+                    } catch (IOException ex) {
+                        fail(ex.getMessage());
+                    }
+                }
             }
             
         });
@@ -810,7 +768,7 @@
         for (int c = 0; c < responseData.length; c++) {
             List receivedPackets = responseData[c];
             List expectedPackets = testData;
-            assertEquals(receivedPackets.size(), expectedPackets.size());
+            assertEquals(expectedPackets.size(), receivedPackets.size());
             for (int p = 0; p < testData.size(); p++) {
                 byte[] expected = (byte[]) testData.get(p);
                 byte[] received = (byte[]) receivedPackets.get(p);
@@ -880,41 +838,22 @@
 
             public void initalizeContext(final HttpContext context, final Object \
attachment) {  context.setAttribute("LIST", (List) attachment);
-                context.setAttribute("STATUS", "ready");
+                context.setAttribute("REQ-COUNT", new Integer(0));
+                context.setAttribute("RES-COUNT", new Integer(0));
             }
 
             public HttpRequest submitRequest(final HttpContext context) {
-                NHttpConnection conn = (NHttpConnection) context.getAttribute(
-                        HttpExecutionContext.HTTP_CONNECTION);
-                String status = (String) context.getAttribute("STATUS");
-                if (!status.equals("ready")) {
-                    return null;
-                }
-                int index = 0;
-                
-                Integer intobj = (Integer) context.getAttribute("INDEX");
-                if (intobj != null) {
-                    index = intobj.intValue();
-                }
-
+                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
                 HttpPost post = null;
-                if (index < reqNo) {
+                if (i < reqNo) {
                     post = new HttpPost("/");
-                    post.addHeader("Secret", Integer.toString(index));
+                    post.addHeader("Secret", Integer.toString(i));
                     ByteArrayEntity outgoing = new ByteArrayEntity(
                             EncodingUtils.getAsciiBytes("No content")); 
                     post.setEntity(outgoing);
                     
-                    context.setAttribute("INDEX", new Integer(index + 1));
-                    context.setAttribute("STATUS", "busy");
-                } else {
-                    try {
-                        conn.close();
-                    } catch (IOException ex) {
-                        ex.printStackTrace();
-                    }
+                    context.setAttribute("REQ-COUNT", new Integer(i + 1));
                 }
-                
                 return post;
             }
             
@@ -922,6 +861,11 @@
                 NHttpConnection conn = (NHttpConnection) context.getAttribute(
                         HttpExecutionContext.HTTP_CONNECTION);
                 
+                List list = (List) context.getAttribute("LIST");
+                int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
+                i++;
+                context.setAttribute("RES-COUNT", new Integer(i));
+                
                 HttpEntity entity = response.getEntity();
                 if (entity != null) {
                     try {
@@ -931,10 +875,17 @@
                     }
                 }
                 
-                List list = (List) context.getAttribute("LIST");
                 list.add(response);
-                context.setAttribute("STATUS", "ready");
-                conn.requestInput();
+
+                if (i < reqNo) {
+                    conn.requestInput();
+                } else {
+                    try {
+                        conn.close();
+                    } catch (IOException ex) {
+                        fail(ex.getMessage());
+                    }
+                }
             }
             
         });


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic