Example usage for org.apache.commons.httpclient.params HttpMethodParams RETRY_HANDLER

List of usage examples for org.apache.commons.httpclient.params HttpMethodParams RETRY_HANDLER

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpMethodParams RETRY_HANDLER.

Prototype

String RETRY_HANDLER

To view the source code for org.apache.commons.httpclient.params HttpMethodParams RETRY_HANDLER.

Click Source Link

Usage

From source file:com.cloudmaster.cmp.util.AlarmSystem.transfer.HttpSender.java

public ResponseObject send(Object object, Map<String, String> paramMap) throws Exception {
    ResponseObject rs = new ResponseObject();
    ByteArrayOutputStream bOs = null;
    DataOutputStream dOs = null;/*from  www.  j a v a  2 s . c o  m*/
    DataInputStream dIs = null;
    HttpClient client;
    PostMethod meth = null;
    byte[] rawData;
    try {
        client = new HttpClient();
        client.setConnectionTimeout(this.timeout);
        client.setTimeout(this.datatimeout);
        client.setHttpConnectionFactoryTimeout(this.timeout);

        meth = new PostMethod(paramMap.get("SERVER_URL"));
        // meth = new UTF8PostMethod(url);
        meth.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, ENCODING);
        // meth.addParameter(SERVER_ARGS, new String(rawData,"UTF-8"));
        meth.setRequestBody(object.toString());
        System.out.println(object.toString());

        /**
         * "type"="ruleSync",XML? "syncType"="***"
         * 1??2??3? "ruleName"="***"
         * XML?XML???XML
         */
        meth.addRequestHeader("type", paramMap.get("type"));
        meth.addRequestHeader("syncType", paramMap.get("syncType"));
        meth.addRequestHeader("ruleName", URLEncoder.encode(paramMap.get("ruleName"), "UTF-8"));
        client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(1, false));

        client.executeMethod(meth);

        dIs = new DataInputStream(meth.getResponseBodyAsStream());

        if (meth.getStatusCode() == HttpStatus.SC_OK) {

            Header errHeader = meth.getResponseHeader(HDR_ERROR);

            if (errHeader != null) {
                rs.setError(meth.getResponseBodyAsString());
                return rs;
            }

            rs = ResponseObject.fromStream(dIs);

            return rs;
        } else {
            meth.releaseConnection();
            throw new IOException("Connection failure: " + meth.getStatusLine().toString());
        }
    } finally {
        if (meth != null) {
            meth.releaseConnection();
        }
        if (bOs != null) {
            bOs.close();
        }
        if (dOs != null) {
            dOs.close();
        }
        if (dIs != null) {
            dIs.close();
        }
    }
}

From source file:com.hp.alm.ali.rest.client.AliRestClient.java

private AliRestClient(String location, String domain, String project, String userName, String password,
        SessionStrategy sessionStrategy) {
    if (location == null) {
        throw new IllegalArgumentException("location==null");
    }//from  w w w  .  ja va  2  s .  c o m
    validateProjectAndDomain(domain, project);
    this.location = location;
    this.userName = userName;
    this.password = password;
    this.domain = domain;
    this.project = project;
    this.sessionStrategy = sessionStrategy;
    setTimeout(DEFAULT_CLIENT_TIMEOUT);
    httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(0, false));

    responseFilters = new LinkedList<ResponseFilter>();
    responseFilters.add(new IssueTicketFilter());
}

From source file:com.sun.faban.driver.transport.hc3.ApacheHC3Transport.java

/**
 * Sets whether the client should retry or not.
 * @param retry Whether to retry failed attempts
 *///from ww  w . j  a  va  2s  .c  om
public void setRetry(boolean retry) {
    if (retry)
        hc.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(1, true));
    else
        hc.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(0, false));
}

From source file:net.bpelunit.framework.control.deploy.ode.ODEDeployer.java

public void undeploy(String testPath, ProcessUnderTest put) throws DeploymentException {

    HttpClient client = new HttpClient(new NoPersistenceConnectionManager());
    PostMethod method = new PostMethod(fDeploymentAdminServiceURL);

    RequestEntity re = fFactory.getUndeployRequestEntity(fProcessId);
    method.setRequestEntity(re);/*from  w w w  .  j  a  v a2 s.  co  m*/

    LOGGER.info("ODE deployer about to send SOAP request to undeploy " + put);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(1, false));
    method.addRequestHeader("SOAPAction", "");

    int statusCode = 0;
    String responseBody = null;
    try {
        statusCode = client.executeMethod(method);
        responseBody = method.getResponseBodyAsString();
    } catch (Exception e) {
        throw new DeploymentException("Problem contacting the ODE Server: " + e.getMessage(), e);
    } finally {
        method.releaseConnection();
    }

    if (isHttpErrorCode(statusCode)) {
        throw new DeploymentException("ODE Server reported a undeployment Error: " + responseBody);
    }
}

From source file:eu.eco2clouds.scheduler.em.EMClientHC.java

private String postMethod(String url, String payload, String contentType, Boolean exception) {
    // Create an instance of HttpClient.
    HttpClient client = getHttpClient();

    logger.debug("Connecting to: " + url);
    // Create a method instance.
    PostMethod method = new PostMethod(url);
    //setHeaders(method, contentType);
    setHeaders(method, Configuration.bonfireApiGroup);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    String response = "";

    try {//from w w  w.j  a v  a2  s  . c  om
        RequestEntity requestEntity = new StringRequestEntity(payload, contentType, null);
        method.setRequestEntity(requestEntity);

        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode >= 200 && statusCode > 300) { //TODO test for this case... 
            logger.warn(
                    "post managed experiments information... : " + url + " failed: " + method.getStatusLine());
        } else {
            // Read the response body.
            byte[] responseBody = method.getResponseBody();
            response = new String(responseBody);
        }

    } catch (HttpException e) {
        logger.warn("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
        exception = true;
    } catch (IOException e) {
        logger.warn("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
        exception = true;
    } finally {
        // Release the connection.
        method.releaseConnection();
    }

    return response;
}

From source file:com.htmlhifive.tools.jslint.engine.download.AbstractDownloadEngineSupport.java

/**
 * ?url????eclipse?????HttpClient??.<br>
 * ??/*  w w  w  .  j  a  va 2 s  .  c  o m*/
 * {@link AbstractDownloadEngineSupport#getConnectionTimeout()}.<br>
 * ? {@link AbstractDownloadEngineSupport#getRetryTimes()}
 * 
 * @param url URL
 * @return HttpClient
 */
private HttpClient createHttpClient(String url) {
    ServiceTracker<IProxyService, IProxyService> proxyTracker = new ServiceTracker<IProxyService, IProxyService>(
            JSLintPlugin.getDefault().getBundle().getBundleContext(), IProxyService.class, null);
    boolean useProxy = false;
    String proxyHost = null;
    int proxyPort = 0;
    String userId = null;
    String password = null;
    try {
        proxyTracker.open();
        IProxyService service = proxyTracker.getService();
        IProxyData[] datas = service.select(new URI(url));
        for (IProxyData proxyData : datas) {
            if (proxyData.getHost() != null) {
                useProxy = true;
                proxyHost = proxyData.getHost();
                proxyPort = proxyData.getPort();
                userId = proxyData.getUserId();
                password = proxyData.getPassword();
            }
        }
    } catch (URISyntaxException e) {
        throw new RuntimeException(Messages.EM0100.getText(), e);
    } finally {
        proxyTracker.close();
    }
    HttpClient client = new HttpClient();
    if (useProxy) {
        client.getHostConfiguration().setProxy(proxyHost, proxyPort);
        if (StringUtils.isNotEmpty(userId)) {
            // ?????
            client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort, "realm"),
                    new UsernamePasswordCredentials(userId, password));
        }
    }
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(getRetryTimes(), true));
    client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, getConnectionTimeout());
    return client;
}

From source file:es.mityc.firmaJava.ts.TSCliente.java

/**
 * Este mtodo genera el Sello de Tiempo/*from   ww  w .  j  av  a 2  s  .  c  om*/
 * @param binarioaSellar fichero binario que se va a sellar
 * @return TimeStampToken en formato binario
 * @throws TSClienteError
 */
public byte[] generarSelloTiempo(byte[] binarioaSellar) throws TSClienteError {

    if (binarioaSellar == null) {
        log.error(MENSAJE_NO_DATOS_SELLO_TIEMPO);
        throw new TSClienteError(I18n.getResource(LIBRERIA_TSA_ERROR_1));
    } else {
        log.info(MENSAJE_GENERANDO_SELLO_TIEMPO);
        TimeStampRequestGenerator generadorPeticion = new TimeStampRequestGenerator();
        TimeStampRequest peticion = null;
        TimeStampResponse respuesta = null;

        try {
            MessageDigest resumen = MessageDigest.getInstance(algoritmoHash);
            resumen.update(binarioaSellar);
            peticion = generadorPeticion.generate(TSPAlgoritmos.getOID(algoritmoHash), resumen.digest());
            log.info(MENSAJE_PETICION_TSA_GENERADA);
        } catch (Exception e) {
            log.error(MENSAJE_ERROR_PETICION_TSA);
            throw new TSClienteError(I18n.getResource(LIBRERIA_TSA_ERROR_10));
        }

        cliente.getParams().setParameter(HttpClientParams.SO_TIMEOUT, INT5000);

        // Comprueba si hay configurado un proxy
        String servidorProxy = System.getProperty("http.proxyHost");
        if (servidorProxy != null && !servidorProxy.trim().equals(CADENA_VACIA)) {
            int puertoProxy = 80;
            try {
                puertoProxy = Integer.parseInt(System.getProperty("http.proxyPort"));
            } catch (NumberFormatException ex) {
            }
            cliente.getHostConfiguration().setProxy(servidorProxy, puertoProxy);

            Credentials defaultcreds = new AuthenticatorProxyCredentials(servidorProxy, CADENA_VACIA);
            cliente.getState().setProxyCredentials(AuthScope.ANY, defaultcreds);
        }

        PostMethod metodo = new PostMethod(servidorTSA);
        metodo.addRequestHeader(CONTENT_TYPE, APPLICATION_TIMESTAMP_QUERY);
        ByteArrayInputStream datos = null;
        try {
            datos = new ByteArrayInputStream(peticion.getEncoded());
        } catch (IOException e) {
            log.error(MENSAJE_ERROR_PETICION + e.getMessage());
            throw new TSClienteError(
                    I18n.getResource(LIBRERIA_TSA_ERROR_11) + DOS_PUNTOS_ESPACIO + e.getMessage());
        }

        InputStreamRequestEntity rq = new InputStreamRequestEntity(datos);
        metodo.setRequestEntity(rq);

        metodo.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));

        byte[] cuerpoRespuesta = null;
        try {
            int estadoCodigo = cliente.executeMethod(metodo);
            log.info(MENSAJE_PETICION_TSA_ENVIADA);

            if (estadoCodigo != HttpStatus.SC_OK) {

                log.error(MENSAJE_FALLO_EJECUCION_METODO + metodo.getStatusLine());
                throw new TSClienteError(
                        I18n.getResource(LIBRERIA_TSA_ERROR_12) + DOS_PUNTOS_ESPACIO + metodo.getStatusLine());
            }

            cuerpoRespuesta = metodo.getResponseBody();
            log.info(MENSAJE_RESPUESTA_TSA_OBTENIDA);

            try {
                respuesta = new TimeStampResponse(cuerpoRespuesta);
                try {

                    respuesta.validate(peticion);

                    log.info(MENSAJE_RESPUESTA_TSA_VALIDADA_OK);
                    // Para solucionar bug en libreria bouncycastle
                    //return respuesta.getTimeStampToken().getEncoded();
                    //AppPerfect: Falso positivo
                    ASN1InputStream is = new ASN1InputStream(cuerpoRespuesta);
                    ASN1Sequence seq = ASN1Sequence.getInstance(is.readObject());
                    DEREncodable enc = seq.getObjectAt(1);
                    if (enc == null)
                        return null;
                    return enc.getDERObject().getEncoded();
                    //Fin Para solucionar bug en libreria bouncycastle
                } catch (TSPException e) {
                    log.error(MENSAJE_RESPUESTA_NO_VALIDA + e.getMessage());
                    throw new TSClienteError(
                            I18n.getResource(LIBRERIA_TSA_ERROR_9) + DOS_PUNTOS_ESPACIO + e.getMessage());
                }
            } catch (TSPException e) {
                log.error(MENSAJE_RESPUESTA_MAL_FORMADA + e.getMessage());
                throw new TSClienteError(
                        I18n.getResource(LIBRERIA_TSA_ERROR_8) + DOS_PUNTOS_ESPACIO + e.getMessage());
            } catch (IOException e) {

                log.error(MENSAJE_SECUENCIA_BYTES_MAL_CODIFICADA + e.getMessage());
                throw new TSClienteError(
                        I18n.getResource(LIBRERIA_TSA_ERROR_7) + DOS_PUNTOS_ESPACIO + e.getMessage());
            }
        } catch (HttpException e) {
            log.error(MENSAJE_VIOLACION_PROTOCOLO_HTTP + e.getMessage());
            throw new TSClienteError(
                    I18n.getResource(LIBRERIA_TSA_ERROR_6) + DOS_PUNTOS_ESPACIO + e.getMessage());
        } catch (IOException e) {
            String mensajeError = I18n.getResource(LIBRERIA_TSA_ERROR_4) + DOS_PUNTOS_ESPACIO + servidorTSA;
            log.error(MENSAJE_ERROR_CONEXION_SERVIDOR_OCSP + e.getMessage());

            throw new TSClienteError(mensajeError);
        } finally {
            // Termina la conexin
            metodo.releaseConnection();
        }
    }
}

From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java

public static HttpClient makeHttpClient3(boolean usePool) {
    HttpClient httpClient;//  w  ww.j a va2 s. c o  m

    if (usePool) {
        MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();

        int maxTotalConnections = 100;
        try {
            maxTotalConnections = new Integer(
                    EnginePropertiesManager.getProperty(PropertyName.HTTP_CLIENT_MAX_TOTAL_CONNECTIONS))
                            .intValue();
        } catch (NumberFormatException e) {
            Engine.logEngine.warn("Unable to retrieve the max number of connections; defaults to 100.");
        }

        int maxConnectionsPerHost = 50;
        try {
            maxConnectionsPerHost = new Integer(
                    EnginePropertiesManager.getProperty(PropertyName.HTTP_CLIENT_MAX_CONNECTIONS_PER_HOST))
                            .intValue();
        } catch (NumberFormatException e) {
            Engine.logEngine
                    .warn("Unable to retrieve the max number of connections per host; defaults to 100.");
        }

        HttpConnectionManagerParams httpConnectionManagerParams = new HttpConnectionManagerParams();
        httpConnectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
        httpConnectionManagerParams.setMaxTotalConnections(maxTotalConnections);
        connectionManager.setParams(httpConnectionManagerParams);

        httpClient = new HttpClient(connectionManager);
    } else {
        httpClient = new HttpClient();
    }

    HttpClientParams httpClientParams = (HttpClientParams) HttpClientParams.getDefaultParams();
    httpClientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    /** #741 : belambra wants only one Set-Cookie header */
    httpClientParams.setParameter("http.protocol.single-cookie-header", Boolean.TRUE);

    /** #5066 : httpClient auto retries failed request up to 3 times by default */
    httpClientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));

    httpClient.setParams(httpClientParams);

    return httpClient;
}

From source file:edu.utah.further.core.ws.HttpClientTemplate.java

/**
 * Private {@link HttpClient} initialization.
 *//* w ww . java 2 s  . c o  m*/
@PostConstruct
private final void afterPropertiesSet() {
    // Client is higher in the hierarchy than manager so set the parameters here
    final HttpClientParams clientParams = new HttpClientParams();
    clientParams.setConnectionManagerClass(connectionManager.getClass());
    clientParams.setConnectionManagerTimeout(connectionTimeout);
    clientParams.setSoTimeout(readTimeout);
    clientParams.setParameter("http.connection.timeout", new Integer(connectionTimeout));
    // A retry handler for when a connection fails
    clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
        @Override
        public boolean retryMethod(final HttpMethod method, final IOException exception,
                final int executionCount) {
            if (executionCount >= retryCount) {
                // Do not retry if over max retry count
                return false;
            }
            if (instanceOf(exception, NoHttpResponseException.class)) {
                // Retry if the server dropped connection on us
                return true;
            }
            if (instanceOf(exception, SocketException.class)) {
                // Retry if the server reset connection on us
                return true;
            }
            if (instanceOf(exception, SocketTimeoutException.class)) {
                // Retry if the read timed out
                return true;
            }
            if (!method.isRequestSent()) {
                // Retry if the request has not been sent fully or
                // if it's OK to retry methods that have been sent
                return true;
            }
            // otherwise do not retry
            return false;
        }
    });
    httpClient.setParams(clientParams);

    final HttpConnectionManagerParams connectionManagerParams = connectionManager.getParams();
    connectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
    connectionManager.setParams(connectionManagerParams);
}

From source file:com.polarion.alm.ws.client.internal.connection.CommonsHTTPSender.java

/**
 * invoke creates a socket connection, sends the request SOAP message and
 * then reads the response SOAP message back from the SOAP server
 * //from w w w .j  av  a2s .  co  m
 * @param msgContext
 *            the messsage context
 * 
 * @throws AxisFault
 */
public void invoke(MessageContext msgContext) throws AxisFault {
    HttpMethodBase method = null;
    if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("enter00", "CommonsHTTPSender::invoke"));
    }
    try {
        URL targetURL = new URL(msgContext.getStrProp(MessageContext.TRANS_URL));

        // no need to retain these, as the cookies/credentials are
        // stored in the message context across multiple requests.
        // the underlying connection manager, however, is retained
        // so sockets get recycled when possible.
        HttpClient httpClient = new HttpClient(this.connectionManager);
        // the timeout value for allocation of connections from the pool
        httpClient.getParams().setConnectionManagerTimeout(this.clientProperties.getConnectionPoolTimeout());
        httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new RetryHandler());

        HostConfiguration hostConfiguration = getHostConfiguration(httpClient, msgContext, targetURL);

        boolean posting = true;

        // If we're SOAP 1.2, allow the web method to be set from the
        // MessageContext.
        if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS) {
            String webMethod = msgContext.getStrProp(SOAP12Constants.PROP_WEBMETHOD);
            if (webMethod != null) {
                posting = webMethod.equals(HTTPConstants.HEADER_POST);
            }
        }

        if (posting) {
            Message reqMessage = msgContext.getRequestMessage();
            method = new PostMethod(targetURL.toString());

            // set false as default, addContetInfo can overwrite
            method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false);

            addContextInfo(method, httpClient, msgContext, targetURL);

            MessageRequestEntity requestEntity = null;
            if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
                requestEntity = new GzipMessageRequestEntity(method, reqMessage, httpChunkStream);
            } else {
                requestEntity = new MessageRequestEntity(method, reqMessage, httpChunkStream);
            }
            ((PostMethod) method).setRequestEntity(requestEntity);
        } else {
            method = new GetMethod(targetURL.toString());
            addContextInfo(method, httpClient, msgContext, targetURL);
        }

        String httpVersion = msgContext.getStrProp(MessageContext.HTTP_TRANSPORT_VERSION);
        if (httpVersion != null) {
            if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_V10)) {
                method.getParams().setVersion(HttpVersion.HTTP_1_0);
            }
            // assume 1.1
        }

        // don't forget the cookies!
        // Cookies need to be set on HttpState, since HttpMethodBase
        // overwrites the cookies from HttpState
        if (msgContext.getMaintainSession()) {
            HttpState state = httpClient.getState();
            method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
            String host = hostConfiguration.getHost();
            String path = targetURL.getPath();
            boolean secure = hostConfiguration.getProtocol().isSecure();
            fillHeaders(msgContext, state, HTTPConstants.HEADER_COOKIE, host, path, secure);
            fillHeaders(msgContext, state, HTTPConstants.HEADER_COOKIE2, host, path, secure);
            httpClient.setState(state);
        }

        int returnCode = httpClient.executeMethod(hostConfiguration, method, null);

        String contentType = getHeader(method, HTTPConstants.HEADER_CONTENT_TYPE);
        String contentLocation = getHeader(method, HTTPConstants.HEADER_CONTENT_LOCATION);
        String contentLength = getHeader(method, HTTPConstants.HEADER_CONTENT_LENGTH);

        if ((returnCode > 199) && (returnCode < 300)) {

            // SOAP return is OK - so fall through
        } else if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS) {
            // For now, if we're SOAP 1.2, fall through, since the range of
            // valid result codes is much greater
        } else if ((contentType != null) && !contentType.equals("text/html")
                && ((returnCode > 499) && (returnCode < 600))) {

            // SOAP Fault should be in here - so fall through
        } else {
            String statusMessage = method.getStatusText();
            AxisFault fault = new AxisFault("HTTP", "(" + returnCode + ")" + statusMessage, null, null);

            try {
                fault.setFaultDetailString(
                        Messages.getMessage("return01", "" + returnCode, method.getResponseBodyAsString()));
                fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_HTTPERRORCODE, Integer.toString(returnCode));
                throw fault;
            } finally {
                method.releaseConnection(); // release connection back to
                // pool.
            }
        }

        // wrap the response body stream so that close() also releases
        // the connection back to the pool.
        InputStream releaseConnectionOnCloseStream = createConnectionReleasingInputStream(method);

        Header contentEncoding = method.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
        if (contentEncoding != null) {
            if (contentEncoding.getValue().equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) {
                releaseConnectionOnCloseStream = new GZIPInputStream(releaseConnectionOnCloseStream);
            } else {
                AxisFault fault = new AxisFault("HTTP",
                        "unsupported content-encoding of '" + contentEncoding.getValue() + "' found", null,
                        null);
                throw fault;
            }

        }
        Message outMsg = new Message(releaseConnectionOnCloseStream, false, contentType, contentLocation);
        // Transfer HTTP headers of HTTP message to MIME headers of SOAP
        // message
        Header[] responseHeaders = method.getResponseHeaders();
        MimeHeaders responseMimeHeaders = outMsg.getMimeHeaders();
        for (int i = 0; i < responseHeaders.length; i++) {
            Header responseHeader = responseHeaders[i];
            responseMimeHeaders.addHeader(responseHeader.getName(), responseHeader.getValue());
        }
        outMsg.setMessageType(Message.RESPONSE);
        msgContext.setResponseMessage(outMsg);
        if (log.isDebugEnabled()) {
            if (null == contentLength) {
                log.debug("\n" + Messages.getMessage("no00", "Content-Length"));
            }
            log.debug("\n" + Messages.getMessage("xmlRecd00"));
            log.debug("-----------------------------------------------");
            log.debug(outMsg.getSOAPPartAsString());
        }

        // if we are maintaining session state,
        // handle cookies (if any)
        if (msgContext.getMaintainSession()) {
            Header[] headers = method.getResponseHeaders();

            for (int i = 0; i < headers.length; i++) {
                if (headers[i].getName().equalsIgnoreCase(HTTPConstants.HEADER_SET_COOKIE)) {
                    handleCookie(HTTPConstants.HEADER_COOKIE, headers[i].getValue(), msgContext);
                } else if (headers[i].getName().equalsIgnoreCase(HTTPConstants.HEADER_SET_COOKIE2)) {
                    handleCookie(HTTPConstants.HEADER_COOKIE2, headers[i].getValue(), msgContext);
                }
            }
        }

        // always release the connection back to the pool if
        // it was one way invocation
        if (msgContext.isPropertyTrue("axis.one.way")) {
            method.releaseConnection();
        }

    } catch (Exception e) {
        log.debug(e);
        throw AxisFault.makeFault(e);
    }

    if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("exit00", "CommonsHTTPSender::invoke"));
    }
}