Author: veithen
Date: Sun Jan 22 22:48:36 2017
New Revision: 1779867

URL: http://svn.apache.org/viewvc?rev=1779867&view=rev
Log:
Unify the HTTP response processing.

Modified:
    
axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
    
axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java
    
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
    
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java
    
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java

Modified: 
axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java?rev=1779867&r1=1779866&r2=1779867&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
 Sun Jan 22 22:48:36 2017
@@ -19,24 +19,17 @@
 
 package org.apache.axis2.transport.http.impl.httpclient3;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
-import java.util.zip.GZIPInputStream;
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.http.AxisRequestEntity;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HTTPSender;
 import org.apache.axis2.transport.http.Request;
-import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.HttpConnectionManager;
 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.commons.logging.Log;
@@ -52,33 +45,6 @@ public class HTTPSenderImpl extends HTTP
         return new RequestImpl(this, msgContext, methodName, url, 
requestEntity);
     }
 
-    protected void processResponse(Request request, HttpMethodBase httpMethod, 
MessageContext msgContext)
-            throws IOException {
-        obtainHTTPHeaderInformation(request, msgContext);
-
-        InputStream in = httpMethod.getResponseBodyAsStream();
-        if (in == null) {
-            throw new AxisFault(Messages.getMessage("canNotBeNull", 
"InputStream"));
-        }
-        Header contentEncoding = httpMethod
-                .getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
-        if (contentEncoding != null) {
-            if 
(contentEncoding.getValue().equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) {
-                in = new GZIPInputStream(in);
-                // If the content-encoding is identity we can basically ignore
-                // it.
-            } else if 
(!"identity".equalsIgnoreCase(contentEncoding.getValue())) {
-                throw new AxisFault("HTTP :" + "unsupported content-encoding 
of '"
-                        + contentEncoding.getValue() + "' found");
-            }
-        }
-
-        OperationContext opContext = msgContext.getOperationContext();
-        if (opContext != null) {
-            opContext.setProperty(MessageContext.TRANSPORT_IN, in);
-        }
-    }
-
     /**
      * This is used to get the dynamically set time out values from the message
      * context. If the values are not available or invalid then the default

Modified: 
axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java?rev=1779867&r1=1779866&r2=1779867&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java
 Sun Jan 22 22:48:36 2017
@@ -19,6 +19,7 @@
 package org.apache.axis2.transport.http.impl.httpclient3;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -28,21 +29,17 @@ import java.util.Map;
 import org.apache.axiom.mime.Header;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.http.AxisRequestEntity;
 import org.apache.axis2.transport.http.HTTPAuthenticator;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HTTPTransportConstants;
 import org.apache.axis2.transport.http.Request;
-import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.HeaderElement;
 import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.HttpVersion;
 import org.apache.commons.httpclient.NTCredentials;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
@@ -170,19 +167,12 @@ final class RequestImpl implements Reque
     }
 
     @Override
-    public void execute() throws AxisFault {
-        try {
-            executeMethod();
-            handleResponse();
-        } catch (IOException e) {
-            log.info("Unable to send to url[" + url + "]", e);
-            throw AxisFault.makeFault(e);
-        } finally {
-            cleanup();
-        }
+    public InputStream getResponseContent() throws IOException {
+        return method.getResponseBodyAsStream();
     }
 
-    private void executeMethod() throws IOException {
+    @Override
+    public void execute() throws IOException {
         populateHostConfiguration();
 
         // add compression headers if needed
@@ -208,61 +198,9 @@ final class RequestImpl implements Reque
         httpClient.executeMethod(config, method, httpState);
     }
 
-    private void handleResponse() throws IOException {
-        int statusCode = getStatusCode();
-        log.trace("Handling response - " + statusCode);
-        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. */
-            sender.obtainHTTPHeaderInformation(this, msgContext);
-            // Since we don't expect any content with a 202 response, we must 
release the connection
-            method.releaseConnection();            
-        } else if (statusCode >= 200 && statusCode < 300) {
-            // Save the HttpMethod so that we can release the connection when 
cleaning up
-            msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
-            sender.processResponse(this, 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
-            // cleaning up
-            msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
-            org.apache.commons.httpclient.Header contenttypeHeader = 
method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
-            String value = null;
-            if (contenttypeHeader != null) {
-                value = contenttypeHeader.getValue();
-            }
-            OperationContext opContext = msgContext.getOperationContext();
-            if (opContext != null) {
-                MessageContext inMessageContext = opContext
-                        
.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
-                if (inMessageContext != null) {
-                    inMessageContext.setProcessingFault(true);
-                }
-            }
-            if (value != null) {
-
-                sender.processResponse(this, method, msgContext);
-            }
-
-            if 
(org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
-                throw new AxisFault(Messages.getMessage("transportError",
-                        String.valueOf(statusCode), getStatusText()));
-            }
-        } else {
-            // Since we don't process the response, we must release the
-            // connection immediately
-            method.releaseConnection();
-            throw new AxisFault(Messages.getMessage("transportError", 
String.valueOf(statusCode),
-                    getStatusText()));
-        }
-    }
-
-    private void cleanup() {
-        if (msgContext.isPropertyTrue(HTTPConstants.AUTO_RELEASE_CONNECTION)) {
-            log.trace("AutoReleasing " + method);
-            method.releaseConnection();
-        }
+    @Override
+    public void releaseConnection() {
+        method.releaseConnection();
     }
 
     /**

Modified: 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java?rev=1779867&r1=1779866&r2=1779867&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
 Sun Jan 22 22:48:36 2017
@@ -29,18 +29,20 @@ import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.NamedValue;
+import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.MessageFormatter;
 import org.apache.axis2.util.MessageProcessorSelector;
+import org.apache.axis2.util.Utils;
 import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.HeaderElement;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
+import org.apache.http.HttpStatus;
 import org.apache.http.protocol.HTTP;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 import java.text.ParseException;
 import java.util.HashMap;
@@ -48,6 +50,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.zip.GZIPInputStream;
 
 import javax.xml.namespace.QName;
 
@@ -184,7 +187,81 @@ public abstract class HTTPSender {
             request.enableAuthentication(authenticator);
         }
 
-        request.execute();
+        try {
+            request.execute();
+            boolean cleanup = true;
+            try {
+                int statusCode = request.getStatusCode();
+                log.trace("Handling response - " + statusCode);
+                boolean processResponse;
+                boolean fault;
+                if (statusCode == HttpStatus.SC_ACCEPTED) {
+                    processResponse = false;
+                    fault = false;
+                } else if (statusCode >= 200 && statusCode < 300) {
+                    processResponse = true;
+                    fault = false;
+                } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
+                           || statusCode == HttpStatus.SC_BAD_REQUEST) {
+                    processResponse = true;
+                    fault = true;
+                } else {
+                    throw new AxisFault(Messages.getMessage("transportError", 
String.valueOf(statusCode),
+                                                            
request.getStatusText()));
+                }
+                obtainHTTPHeaderInformation(request, msgContext);
+                if (processResponse) {
+                    OperationContext opContext = 
msgContext.getOperationContext();
+                    MessageContext inMessageContext = opContext == null ? null
+                            : 
opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+                    if (opContext != null) {
+                        InputStream in = request.getResponseContent();
+                        if (in != null) {
+                            String contentEncoding = 
request.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
+                            if (contentEncoding != null) {
+                                if 
(contentEncoding.equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) {
+                                    in = new GZIPInputStream(in);
+                                    // If the content-encoding is identity we 
can basically ignore
+                                    // it.
+                                } else if 
(!"identity".equalsIgnoreCase(contentEncoding)) {
+                                    throw new AxisFault("HTTP :" + 
"unsupported content-encoding of '"
+                                                        + contentEncoding + "' 
found");
+                                }
+                            }
+                            opContext.setProperty(MessageContext.TRANSPORT_IN, 
in);
+                            // This implements the behavior of the HTTPClient 
3.x based transport in
+                            // Axis2 1.7: if AUTO_RELEASE_CONNECTION is 
enabled, we set the input stream
+                            // in the message context, but we nevertheless 
release the connection.
+                            // It is unclear in which situation this would 
actually be the right thing
+                            // to do.
+                            if 
(msgContext.isPropertyTrue(HTTPConstants.AUTO_RELEASE_CONNECTION)) {
+                                log.debug("AUTO_RELEASE_CONNECTION enabled; 
are you sure that you really want that?");
+                            } else {
+                                cleanup = false;
+                            }
+                        }
+                    }
+                    if (fault) {
+                        if (inMessageContext != null) {
+                            inMessageContext.setProcessingFault(true);
+                        }
+                        if 
(Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
+                            throw new AxisFault(Messages.
+                                    getMessage("transportError",
+                                               String.valueOf(statusCode),
+                                               request.getStatusText()));
+                        }
+                    }
+                }
+            } finally {
+                if (cleanup) {
+                    request.releaseConnection();
+                }
+            }
+        } catch (IOException e) {
+            log.info("Unable to send to url[" + url + "]", e);
+            throw AxisFault.makeFault(e);
+        }
     }   
 
     private void addCustomHeaders(MessageContext msgContext, Request request) {
@@ -309,7 +386,7 @@ public abstract class HTTPSender {
         return userAgentString;
     }
 
-    public void obtainHTTPHeaderInformation(Request request, MessageContext 
msgContext) throws AxisFault {
+    private void obtainHTTPHeaderInformation(Request request, MessageContext 
msgContext) throws AxisFault {
         // Set RESPONSE properties onto the REQUEST message context. They will
         // need to be copied off the request context onto
         // the response context elsewhere, for example in the

Modified: 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java?rev=1779867&r1=1779866&r2=1779867&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java
 Sun Jan 22 22:48:36 2017
@@ -18,10 +18,11 @@
  */
 package org.apache.axis2.transport.http;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Map;
 
 import org.apache.axiom.mime.Header;
-import org.apache.axis2.AxisFault;
 
 /**
  * Interface to prepare and execute an HTTP request.
@@ -32,10 +33,12 @@ public interface Request {
     void addHeader(String name, String value);
     Header[] getRequestHeaders();
     void enableAuthentication(HTTPAuthenticator authenticator);
-    void execute() throws AxisFault;
+    void execute() throws IOException;
     int getStatusCode();
     String getStatusText();
     String getResponseHeader(String name);
     Header[] getResponseHeaders();
     Map<String,String> getCookies();
+    InputStream getResponseContent() throws IOException;
+    void releaseConnection();
 }

Modified: 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java?rev=1779867&r1=1779866&r2=1779867&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java
 Sun Jan 22 22:48:36 2017
@@ -26,27 +26,21 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.zip.GZIPInputStream;
 
 import org.apache.axiom.mime.Header;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.http.AxisRequestEntity;
 import org.apache.axis2.transport.http.HTTPAuthenticator;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HTTPTransportConstants;
 import org.apache.axis2.transport.http.Request;
-import org.apache.axis2.util.Utils;
-import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.HeaderElement;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.Credentials;
@@ -185,17 +179,13 @@ final class RequestImpl implements Reque
     }
 
     @Override
-    public void execute() throws AxisFault {
-        try {
-            executeMethod();
-            handleResponse();
-        } catch (IOException e) {
-            log.info("Unable to send to url[" + url + "]", e);
-            throw AxisFault.makeFault(e);
-        }
+    public InputStream getResponseContent() throws IOException {
+        HttpEntity entity = response.getEntity();
+        return entity == null ? null : entity.getContent();
     }
 
-    private void executeMethod() throws IOException {
+    @Override
+    public void execute() throws IOException {
         populateHostConfiguration();
 
         // add compression headers if needed
@@ -221,72 +211,8 @@ final class RequestImpl implements Reque
         response = httpClient.execute(httpHost, method, localContext);
     }
 
-    private void handleResponse() throws IOException {
-        boolean cleanup = true;
-        try {
-            int statusCode = getStatusCode();
-            log.trace("Handling response - " + statusCode);
-            boolean processResponse;
-            boolean fault;
-            if (statusCode == HttpStatus.SC_ACCEPTED) {
-                processResponse = false;
-                fault = false;
-            } else if (statusCode >= 200 && statusCode < 300) {
-                processResponse = true;
-                fault = false;
-            } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
-                       || statusCode == HttpStatus.SC_BAD_REQUEST) {
-                processResponse = true;
-                fault = true;
-            } else {
-                throw new AxisFault(Messages.getMessage("transportError", 
String.valueOf(statusCode),
-                                                        getStatusText()));
-            }
-            sender.obtainHTTPHeaderInformation(this, msgContext);
-            if (processResponse) {
-                OperationContext opContext = msgContext.getOperationContext();
-                MessageContext inMessageContext = opContext == null ? null
-                        : 
opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
-                if (opContext != null) {
-                    HttpEntity httpEntity = response.getEntity();
-                    if (httpEntity != null) {
-                        InputStream in = httpEntity.getContent();
-                        org.apache.http.Header contentEncoding = 
httpEntity.getContentEncoding();
-                        if (contentEncoding != null) {
-                            if 
(contentEncoding.getValue().equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) {
-                                in = new GZIPInputStream(in);
-                                // If the content-encoding is identity we can 
basically ignore
-                                // it.
-                            } else if 
(!"identity".equalsIgnoreCase(contentEncoding.getValue())) {
-                                throw new AxisFault("HTTP :" + "unsupported 
content-encoding of '"
-                                                    + 
contentEncoding.getValue() + "' found");
-                            }
-                        }
-                        opContext.setProperty(MessageContext.TRANSPORT_IN, in);
-                        cleanup = false;
-                    }
-                }
-                if (fault) {
-                    if (inMessageContext != null) {
-                        inMessageContext.setProcessingFault(true);
-                    }
-                    if 
(Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
-                        throw new AxisFault(Messages.
-                                getMessage("transportError",
-                                           String.valueOf(statusCode),
-                                           getStatusText()));
-                    }
-                }
-            }
-        } finally {
-            if (cleanup) {
-                cleanup(response);
-            }
-        }
-
-    }
-
-    private void cleanup(HttpResponse response) {
+    @Override
+    public void releaseConnection() {
         log.trace("Cleaning response : " + response);
         HttpEntity entity = response.getEntity();
         if (entity != null) {


Reply via email to