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 ve...@apache.org on 2017/01/16 14:23:35 UTC

svn commit: r1779033 - in /axis/axis2/java/core/trunk/modules/transport: http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/ http/src/org/apache/axis2/transport/http/ http/src/org/apache/axis2/transport/http/impl/httpclient4/

Author: veithen
Date: Mon Jan 16 14:23:35 2017
New Revision: 1779033

URL: http://svn.apache.org/viewvc?rev=1779033&view=rev
Log:
Move the executeMethod, handleRequest and cleanup methods to RequestImpl.

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/impl/httpclient4/HTTPSenderImpl.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=1779033&r1=1779032&r2=1779033&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 Mon Jan 16 14:23:35 2017
@@ -52,7 +52,6 @@ import org.apache.commons.httpclient.Hea
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.HttpMethodBase;
-import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.HeaderElement;
 import org.apache.commons.httpclient.HostConfiguration;
@@ -68,7 +67,6 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.apache.commons.httpclient.protocol.Protocol;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -102,13 +100,6 @@ public class HTTPSenderImpl extends HTTP
         return new RequestImpl(this, msgContext, url, null, new GetMethod());
     }
 
-    protected void cleanup(MessageContext msgContext, HttpMethod httpMmethod) {
-        if (msgContext.isPropertyTrue(HTTPConstants.AUTO_RELEASE_CONNECTION)) {
-            log.trace("AutoReleasing " + httpMmethod);
-            ((HttpMethod) httpMmethod).releaseConnection();
-        }
-    }
-
     /**
      * Used to send a request via HTTP Delete Method
      * 
@@ -158,68 +149,6 @@ public class HTTPSenderImpl extends HTTP
     }
 
     /**
-     * Used to handle the HTTP Response
-     * 
-     * @param msgContext
-     *            - The MessageContext of the message
-     * @param method
-     *            - The HTTP method used
-     * @throws IOException
-     *             - Thrown in case an exception occurs
-     */
-    protected void handleResponse(MessageContext msgContext, HttpMethodBase method)
-            throws IOException {
-        int statusCode = method.getStatusCode();
-        HTTPStatusCodeFamily family = getHTTPStatusCodeFamily(statusCode);
-        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. */
-            obtainHTTPHeaderInformation(method, msgContext);
-            // 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
-            // cleaning up
-            msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
-            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) {
-
-                processResponse(method, msgContext);
-            }
-
-            if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
-                throw new AxisFault(Messages.getMessage("transportError",
-                        String.valueOf(statusCode), method.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),
-                    method.getStatusText()));
-        }
-    }
-
-    /**
      * Collect the HTTP header information and set them in the message context
      * 
      * @param method
@@ -685,41 +614,6 @@ public class HTTPSenderImpl extends HTTP
         }
     }
 
-    protected void executeMethod(HttpClient httpClient, MessageContext msgContext, URL url,
-            HttpMethod method) throws IOException {
-        HostConfiguration config = this.getHostConfiguration(httpClient, msgContext, url);
-
-        // set the custom headers, if available
-        addCustomHeaders(method, msgContext);
-
-        // add compression headers if needed
-        if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) {
-            method.addRequestHeader(HTTPConstants.HEADER_ACCEPT_ENCODING,
-                    HTTPConstants.COMPRESSION_GZIP);
-        }
-
-        if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
-            method.addRequestHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
-                    HTTPConstants.COMPRESSION_GZIP);
-        }
-
-        if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) {
-            HttpMethodParams params = (HttpMethodParams) msgContext
-                    .getProperty(HTTPConstants.HTTP_METHOD_PARAMS);
-            method.setParams(params);
-        }
-
-        String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY);
-        if (cookiePolicy != null) {
-            method.getParams().setCookiePolicy(cookiePolicy);
-        }
-        HttpState httpState = (HttpState) msgContext.getProperty(HTTPConstants.CACHED_HTTP_STATE);
-
-        setTimeouts(msgContext, method);
-
-        httpClient.executeMethod(config, method, httpState);
-    }
-
     public void addCustomHeaders(HttpMethod method, MessageContext msgContext) {
 
         boolean isCustomUserAgentSet = false;

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=1779033&r1=1779032&r2=1779033&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 Mon Jan 16 14:23:35 2017
@@ -23,13 +23,22 @@ import java.net.URL;
 
 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.HTTPConstants;
 import org.apache.axis2.transport.http.Request;
+import org.apache.axis2.transport.http.HTTPSender.HTTPStatusCodeFamily;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.httpclient.Header;
+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.methods.EntityEnclosingMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -71,13 +80,105 @@ final class RequestImpl implements Reque
     @Override
     public void execute() throws AxisFault {
         try {
-            sender.executeMethod(httpClient, msgContext, url, method);
-            sender.handleResponse(msgContext, method);
+            executeMethod();
+            handleResponse();
         } catch (IOException e) {
             log.info("Unable to send to url[" + url + "]", e);
             throw AxisFault.makeFault(e);
         } finally {
-            sender.cleanup(msgContext, method);
+            cleanup();
+        }
+    }
+
+    private void executeMethod() throws IOException {
+        HostConfiguration config = sender.getHostConfiguration(httpClient, msgContext, url);
+
+        // set the custom headers, if available
+        sender.addCustomHeaders(method, msgContext);
+
+        // add compression headers if needed
+        if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) {
+            method.addRequestHeader(HTTPConstants.HEADER_ACCEPT_ENCODING,
+                    HTTPConstants.COMPRESSION_GZIP);
+        }
+
+        if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
+            method.addRequestHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
+                    HTTPConstants.COMPRESSION_GZIP);
+        }
+
+        if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) {
+            HttpMethodParams params = (HttpMethodParams) msgContext
+                    .getProperty(HTTPConstants.HTTP_METHOD_PARAMS);
+            method.setParams(params);
+        }
+
+        String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY);
+        if (cookiePolicy != null) {
+            method.getParams().setCookiePolicy(cookiePolicy);
+        }
+        HttpState httpState = (HttpState) msgContext.getProperty(HTTPConstants.CACHED_HTTP_STATE);
+
+        sender.setTimeouts(msgContext, method);
+
+        httpClient.executeMethod(config, method, httpState);
+    }
+
+    private void handleResponse() throws IOException {
+        int statusCode = method.getStatusCode();
+        HTTPStatusCodeFamily family = sender.getHTTPStatusCodeFamily(statusCode);
+        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(method, msgContext);
+            // 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);
+            sender.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
+            // cleaning up
+            msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
+            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(method, msgContext);
+            }
+
+            if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
+                throw new AxisFault(Messages.getMessage("transportError",
+                        String.valueOf(statusCode), method.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),
+                    method.getStatusText()));
+        }
+    }
+
+    private void cleanup() {
+        if (msgContext.isPropertyTrue(HTTPConstants.AUTO_RELEASE_CONNECTION)) {
+            log.trace("AutoReleasing " + method);
+            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=1779033&r1=1779032&r2=1779033&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 Mon Jan 16 14:23:35 2017
@@ -146,7 +146,7 @@ public abstract class HTTPSender extends
      * @param statusCode
      *            - The HTTP status code
      */
-    protected HTTPStatusCodeFamily getHTTPStatusCodeFamily(int statusCode) {
+    public HTTPStatusCodeFamily getHTTPStatusCodeFamily(int statusCode) {
         switch (statusCode / 100) {
         case 1:
             return HTTPStatusCodeFamily.INFORMATIONAL;
@@ -165,7 +165,7 @@ public abstract class HTTPSender extends
     /**
      * The set of HTTP status code families.
      */
-    protected enum HTTPStatusCodeFamily {
+    public enum HTTPStatusCodeFamily {
         INFORMATIONAL, SUCCESSFUL, REDIRECTION, CLIENT_ERROR, SERVER_ERROR, OTHER
     }
 

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java?rev=1779033&r1=1779032&r2=1779033&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java Mon Jan 16 14:23:35 2017
@@ -42,7 +42,6 @@ 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.NameValuePair;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.Credentials;
@@ -70,10 +69,7 @@ import org.apache.http.params.BasicHttpP
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HTTP;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.util.EntityUtils;
 
 import javax.xml.namespace.QName;
 import java.io.IOException;
@@ -114,20 +110,6 @@ public class HTTPSenderImpl extends HTTP
         return new RequestImpl(this, msgContext, url, null, new HttpGet());
     }
 
-    protected void cleanup(MessageContext msgContext, HttpResponse response) {
-        if (msgContext.isPropertyTrue(HTTPConstants.CLEANUP_RESPONSE)) {
-            log.trace("Cleaning response : " + response);
-            HttpEntity entity = response.getEntity();
-            if (entity != null) {
-                try {
-                    EntityUtils.consume(entity);
-                } catch (IOException e) {
-                    log.error("Error while cleaning response : " + response, e);
-                }
-            }
-        }
-    }
-
     /**
      * Used to send a request via HTTP Delete Method
      *
@@ -169,67 +151,6 @@ public class HTTPSenderImpl extends HTTP
     }
 
     /**
-     * Used to handle the HTTP Response
-     *
-     * @param msgContext - The MessageContext of the message
-     * @param -          The HTTP method used
-     * @throws java.io.IOException - Thrown in case an exception occurs
-     */
-    protected void handleResponse(MessageContext msgContext, HttpResponse response)
-            throws IOException {
-        int statusCode = response.getStatusLine().getStatusCode();
-        HTTPStatusCodeFamily family = getHTTPStatusCodeFamily(statusCode);
-        log.trace("Handling response - " + statusCode);
-        if (statusCode == HttpStatus.SC_ACCEPTED) {
-            msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.TRUE);
-            /*
-            * 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(response, msgContext);
-
-        } else if (HTTPStatusCodeFamily.SUCCESSFUL.equals(family)) {
-            // We don't clean the response here because the response will be used afterwards
-            msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.FALSE);
-            processResponse(response, msgContext);
-
-        } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
-                   || statusCode == HttpStatus.SC_BAD_REQUEST) {
-            msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.TRUE);
-            Header contentTypeHeader = response.getFirstHeader(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) {
-                msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.FALSE);
-                processResponse(response, msgContext);
-            }
-
-            if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
-                throw new AxisFault(Messages.
-                        getMessage("transportError",
-                                   String.valueOf(statusCode),
-                                   response.getStatusLine().toString()));
-            }
-        } else {
-            msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.TRUE);
-            throw new AxisFault(Messages.getMessage("transportError", String.valueOf(statusCode),
-                                                    response.getStatusLine().toString()));
-        }
-    }
-
-    /**
      * Collect the HTTP header information and set them in the message context
      *
      * @param httpResponse which holds the header information
@@ -671,42 +592,6 @@ public class HTTPSenderImpl extends HTTP
         }
     }
 
-    protected HttpResponse executeMethod(AbstractHttpClient httpClient, MessageContext msgContext,
-                                         URL url,
-                                         HttpRequestBase method) throws IOException {
-        HttpHost httpHost = this.getHostConfiguration(httpClient, msgContext, url);
-
-        // set the custom headers, if available
-        addCustomHeaders(method, msgContext);
-
-        // add compression headers if needed
-        if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) {
-            method.addHeader(HTTPConstants.HEADER_ACCEPT_ENCODING,
-                             HTTPConstants.COMPRESSION_GZIP);
-        }
-
-        if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
-            method.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
-                             HTTPConstants.COMPRESSION_GZIP);
-        }
-
-        if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) {
-            HttpParams params = (HttpParams) msgContext
-                    .getProperty(HTTPConstants.HTTP_METHOD_PARAMS);
-            method.setParams(params);
-        }
-
-        String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY);
-        if (cookiePolicy != null) {
-            method.getParams().setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
-        }
-
-        setTimeouts(msgContext, method);
-        HttpContext localContext = new BasicHttpContext();
-        // Why do we have add context here
-        return httpClient.execute(httpHost, method, localContext);
-    }
-
     public void addCustomHeaders(HttpRequestBase method, MessageContext msgContext) {
 
         boolean isCustomUserAgentSet = false;

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=1779033&r1=1779032&r2=1779033&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 Mon Jan 16 14:23:35 2017
@@ -23,17 +23,30 @@ import java.net.URL;
 
 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.HTTPConstants;
 import org.apache.axis2.transport.http.Request;
+import org.apache.axis2.transport.http.HTTPSender.HTTPStatusCodeFamily;
+import org.apache.axis2.wsdl.WSDLConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.params.ClientPNames;
 import org.apache.http.impl.client.AbstractHttpClient;
 import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
 
 final class RequestImpl implements Request {
     private static final Log log = LogFactory.getLog(RequestImpl.class);
@@ -76,13 +89,115 @@ final class RequestImpl implements Reque
     public void execute() throws AxisFault {
         HttpResponse response = null;
         try {
-            response = sender.executeMethod(httpClient, msgContext, url, method);
-            sender.handleResponse(msgContext, response);
+            response = executeMethod();
+            handleResponse(response);
         } catch (IOException e) {
             log.info("Unable to send to url[" + url + "]", e);
             throw AxisFault.makeFault(e);
         } finally {
-            sender.cleanup(msgContext, response);
+            cleanup(response);
+        }
+    }
+
+    private HttpResponse executeMethod() throws IOException {
+        HttpHost httpHost = sender.getHostConfiguration(httpClient, msgContext, url);
+
+        // set the custom headers, if available
+        sender.addCustomHeaders(method, msgContext);
+
+        // add compression headers if needed
+        if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) {
+            method.addHeader(HTTPConstants.HEADER_ACCEPT_ENCODING,
+                             HTTPConstants.COMPRESSION_GZIP);
+        }
+
+        if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
+            method.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
+                             HTTPConstants.COMPRESSION_GZIP);
+        }
+
+        if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) {
+            HttpParams params = (HttpParams) msgContext
+                    .getProperty(HTTPConstants.HTTP_METHOD_PARAMS);
+            method.setParams(params);
+        }
+
+        String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY);
+        if (cookiePolicy != null) {
+            method.getParams().setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
+        }
+
+        sender.setTimeouts(msgContext, method);
+        HttpContext localContext = new BasicHttpContext();
+        // Why do we have add context here
+        return httpClient.execute(httpHost, method, localContext);
+    }
+
+    private void handleResponse(HttpResponse response)
+            throws IOException {
+        int statusCode = response.getStatusLine().getStatusCode();
+        HTTPStatusCodeFamily family = sender.getHTTPStatusCodeFamily(statusCode);
+        log.trace("Handling response - " + statusCode);
+        if (statusCode == HttpStatus.SC_ACCEPTED) {
+            msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.TRUE);
+            /*
+            * 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(response, msgContext);
+
+        } else if (HTTPStatusCodeFamily.SUCCESSFUL.equals(family)) {
+            // We don't clean the response here because the response will be used afterwards
+            msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.FALSE);
+            sender.processResponse(response, msgContext);
+
+        } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
+                   || statusCode == HttpStatus.SC_BAD_REQUEST) {
+            msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.TRUE);
+            Header contentTypeHeader = response.getFirstHeader(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) {
+                msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.FALSE);
+                sender.processResponse(response, msgContext);
+            }
+
+            if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
+                throw new AxisFault(Messages.
+                        getMessage("transportError",
+                                   String.valueOf(statusCode),
+                                   response.getStatusLine().toString()));
+            }
+        } else {
+            msgContext.setProperty(HTTPConstants.CLEANUP_RESPONSE, Boolean.TRUE);
+            throw new AxisFault(Messages.getMessage("transportError", String.valueOf(statusCode),
+                                                    response.getStatusLine().toString()));
+        }
+    }
+
+    private void cleanup(HttpResponse response) {
+        if (msgContext.isPropertyTrue(HTTPConstants.CLEANUP_RESPONSE)) {
+            log.trace("Cleaning response : " + response);
+            HttpEntity entity = response.getEntity();
+            if (entity != null) {
+                try {
+                    EntityUtils.consume(entity);
+                } catch (IOException e) {
+                    log.error("Error while cleaning response : " + response, e);
+                }
+            }
         }
     }
 }