You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by sa...@apache.org on 2012/04/11 16:45:06 UTC

svn commit: r1324789 - in /axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http: src/org/apache/axis2/transport/http/ src/org/apache/axis2/transport/http/impl/httpclient3/ test/org/apache/axis2/transport/http/ test/org/apache/axis2/transport...

Author: sagara
Date: Wed Apr 11 14:45:06 2012
New Revision: 1324789

URL: http://svn.apache.org/viewvc?rev=1324789&view=rev
Log:
Merged r1324778 to the AXIS2-4318 branch.

Modified:
    axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
    axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
    axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
    axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
    axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java

Modified: axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java?rev=1324789&r1=1324788&r2=1324789&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java (original)
+++ axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java Wed Apr 11 14:45:06 2012
@@ -121,6 +121,37 @@ public abstract class HTTPSender extends
         }
 
         this.sendViaPost(msgContext, url, soapActionString);
-    }    
-       
+    }   
+
+    /**
+     * Used to determine the family of HTTP status codes to which the given code
+     * belongs.
+     * 
+     * @param statusCode
+     *            - The HTTP status code
+     */
+    protected HTTPStatusCodeFamily getHTTPStatusCodeFamily(int statusCode) {
+        switch (statusCode / 100) {
+        case 1:
+            return HTTPStatusCodeFamily.INFORMATIONAL;
+        case 2:
+            return HTTPStatusCodeFamily.SUCCESSFUL;
+        case 3:
+            return HTTPStatusCodeFamily.REDIRECTION;
+        case 4:
+            return HTTPStatusCodeFamily.CLIENT_ERROR;
+        case 5:
+            return HTTPStatusCodeFamily.SERVER_ERROR;
+        default:
+            return HTTPStatusCodeFamily.OTHER;
+        }
+    }
+
+    /**
+     * The set of HTTP status code families.
+     */
+    protected enum HTTPStatusCodeFamily {
+        INFORMATIONAL, SUCCESSFUL, REDIRECTION, CLIENT_ERROR, SERVER_ERROR, OTHER
+    }
+
 }

Modified: axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java?rev=1324789&r1=1324788&r2=1324789&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java (original)
+++ axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java Wed Apr 11 14:45:06 2012
@@ -296,23 +296,19 @@ public class HTTPSenderImpl extends HTTP
             return;
         }
         int statusCode = method.getStatusCode();
+        HTTPStatusCodeFamily family = getHTTPStatusCodeFamily(statusCode);
         log.trace("Handling response - " + statusCode);
-        if (statusCode == HttpStatus.SC_OK) {
-            // Save the HttpMethod so that we can release the connection when
-            // cleaning up
-            msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
-            processResponse(method, msgContext);
-        } else if (statusCode == HttpStatus.SC_ACCEPTED) {
-            /*
-             * When an HTTP 202 Accepted code has been received, this will be
-             * the case of an execution of an in-only operation. In such a
-             * scenario, the HTTP response headers should be returned, i.e.
-             * session cookies.
-             */
+        if (statusCode == HttpStatus.SC_ACCEPTED) {
+            /* When an HTTP 202 Accepted code has been received, this will be the case of an execution 
+             * of an in-only operation. In such a scenario, the HTTP response headers should be returned,
+             * i.e. session cookies. */
             obtainHTTPHeaderInformation(method, msgContext);
-            // Since we don't expect any content with a 202 response, we must
-            // release the connection
-            method.releaseConnection();
+            // Since we don't expect any content with a 202 response, we must release the connection
+            method.releaseConnection();            
+        } else if (HTTPStatusCodeFamily.SUCCESSFUL.equals(family)) {
+            // Save the HttpMethod so that we can release the connection when cleaning up
+            msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
+            processResponse(method, msgContext);            
         } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
                 || statusCode == HttpStatus.SC_BAD_REQUEST) {
             // Save the HttpMethod so that we can release the connection when

Modified: axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java?rev=1324789&r1=1324788&r2=1324789&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java (original)
+++ axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java Wed Apr 11 14:45:06 2012
@@ -31,6 +31,7 @@ import org.apache.axis2.context.Configur
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.transport.http.mock.server.AbstractHTTPServerTest;
+import org.apache.axis2.transport.http.mock.server.BasicHttpServer;
 
 /**
  * The Class HTTPSenderTest.
@@ -253,5 +254,45 @@ public abstract class HTTPSenderTest ext
                 getHeaders().get(HttpHeaders.USER_AGENT));
 
     }
+    public void testHandleResponseHTTPStatusCode200() throws Exception {
+        httpSender = getHTTPSender();
+        int port = getBasicHttpServer().getPort();
+        getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_200);
+        sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+                "http://localhost:" + port + "/postService", true);
+    }
+    
+    public void testHandleResponseHTTPStatusCode201() throws Exception {
+        httpSender = getHTTPSender();
+        int port = getBasicHttpServer().getPort();
+        getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_201);
+        sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+                "http://localhost:" + port + "/postService", true);
+    }
+    
+    public void testHandleResponseHTTPStatusCode202() throws Exception {
+        httpSender = getHTTPSender();
+        int port = getBasicHttpServer().getPort();
+        getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_202);
+        sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+                "http://localhost:" + port + "/postService", true);
+    }
+    
+    public void testHandleResponseHTTPStatusCode400() throws Exception {
+        httpSender = getHTTPSender();
+        int port = getBasicHttpServer().getPort();
+        getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_400);
+        sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+                "http://localhost:" + port + "/postService", true);
+    }
+    
+    public void testHandleResponseHTTPStatusCode500() throws Exception {
+        httpSender = getHTTPSender();
+        int port = getBasicHttpServer().getPort();
+        getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_500);
+        sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+                "http://localhost:" + port + "/postService", true);
+    }
+    
 
 }

Modified: axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java?rev=1324789&r1=1324788&r2=1324789&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java (original)
+++ axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java Wed Apr 11 14:45:06 2012
@@ -148,5 +148,11 @@ public interface BasicHttpServer {
     public static final String RESPONSE_HTTP_404 = "response.http.404";
     public static final String RESPONSE_HTTP_OK_XML = "response.http.ok.xml";
     public static final String RESPONSE_HTTP_OK_LOOP_BACK = "response.http.ok.loop.back";
+    public static final String RESPONSE_HTTP_200 = "response.http.200";
+    public static final String RESPONSE_HTTP_201 = "response.http.201";
+    public static final String RESPONSE_HTTP_202 = "response.http.202";
+    public static final String RESPONSE_HTTP_400 = "response.http.400";
+    public static final String RESPONSE_HTTP_500 = "response.http.500";
+
 
 }

Modified: axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java?rev=1324789&r1=1324788&r2=1324789&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java (original)
+++ axis/axis2/java/core/branches/AXIS2-4318/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java Wed Apr 11 14:45:06 2012
@@ -238,7 +238,66 @@ public class BasicHttpServerImpl impleme
                     }
 
                 });
-            }
+                
+            } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_200)) {
+                response.setStatusCode(HttpStatus.SC_OK);
+                body = new EntityTemplate(new ContentProducer() {
+
+                    public void writeTo(final OutputStream outstream) throws IOException {
+                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+                        writer.write("<Response> SC_ACCEPTED 202 <Response>");
+                        writer.flush();
+                    }
+
+                });
+                
+            } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_201)) {
+                response.setStatusCode(HttpStatus.SC_CREATED);
+                body = new EntityTemplate(new ContentProducer() {
+
+                    public void writeTo(final OutputStream outstream) throws IOException {
+                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+                        //writer.write("<Response> SC_ACCEPTED 202 <Response>");
+                        writer.flush();
+                    }
+
+                });
+                
+            } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_202)) {
+                response.setStatusCode(HttpStatus.SC_ACCEPTED);
+                body = new EntityTemplate(new ContentProducer() {
+                    public void writeTo(final OutputStream outstream) throws IOException {
+                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+                        //writer.write("<Response> SC_ACCEPTED 202 <Response>");
+                        writer.flush();
+                    }
+
+                });
+                
+            } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_400)) {
+                response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
+                body = new EntityTemplate(new ContentProducer() {
+                    public void writeTo(final OutputStream outstream) throws IOException {
+                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+                        //writer.write("<Response> SC_ACCEPTED 202 <Response>");
+                        writer.flush();
+                    }
+
+                });
+                
+            } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_500)) {
+                response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+                body = new EntityTemplate(new ContentProducer() {
+                    public void writeTo(final OutputStream outstream) throws IOException {
+                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+                        writer.write(" Server Error");
+                        writer.flush();
+                    }
+
+                });
+                
+            }            
+            
             // TODO - customize to send content type depend on expectations.
             body.setContentType("text/html; charset=UTF-8");
             response.setEntity(body);