Example usage for org.apache.commons.httpclient HttpConnection close

List of usage examples for org.apache.commons.httpclient HttpConnection close

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpConnection close.

Prototype

public void close() 

Source Link

Document

Closes the socket and streams.

Usage

From source file:com.cyberway.issue.httpclient.SingleHttpConnectionManager.java

static void finishLast(HttpConnection conn) {
    // copied from superclass because it wasn't made available to subclasses
    InputStream lastResponse = conn.getLastResponseInputStream();
    if (lastResponse != null) {
        conn.setLastResponseInputStream(null);
        try {//from   w  ww  .j  a va2 s.  co  m
            lastResponse.close();
        } catch (IOException ioe) {
            //FIXME: badness - close to force reconnect.
            conn.close();
        }
    }
}

From source file:com.exalead.io.failover.MonitoredHttpConnectionManager.java

static void consumeLastResponse(HttpConnection conn) {
    InputStream lastResponse = conn.getLastResponseInputStream();
    if (lastResponse != null) {
        conn.setLastResponseInputStream(null);
        try {/*from  w ww.ja  v a2 s.  c  o m*/
            lastResponse.close();
        } catch (IOException ioe) {
            conn.close();
        }
    }
}

From source file:com.gs.jrpip.client.BufferedPostMethod.java

protected void cleanupConnection(HttpConnection conn) {
    conn.close();
    conn.releaseConnection();
}

From source file:com.cyberway.issue.httpclient.SingleHttpConnectionManager.java

public void releaseConnection(HttpConnection conn) {
    // ensure connection is closed
    conn.close();
    finishLast(conn);
}

From source file:com.vangent.hieos.xutil.soap.XUtilSimpleHttpConnectionManager.java

/**
 * Method description/*  w ww .  java  2s . co m*/
 *
 *
 * @param conn
 */
@Override
public void releaseConnection(HttpConnection conn) {

    super.releaseConnection(conn);

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Closing connection %s.", this.name));
    }

    // close the connection
    conn.close();
}

From source file:com.carrotsearch.util.httpclient.SingleHttpConnectionManager.java

/** */
@Override//  w w w  . ja v a  2s .com
public void releaseConnection(HttpConnection conn) {
    // copied from superclass because it wasn't made available to subclasses
    final InputStream lastResponse = conn.getLastResponseInputStream();
    if (lastResponse != null) {
        conn.setLastResponseInputStream(null);
        try {
            lastResponse.close();
        } catch (final IOException ioe) {
            // ignore.
        }
    }

    if (conn.isOpen()) {
        conn.close();
    }
}

From source file:es.gva.cit.catalog.DiscoveryServiceClient.java

/**
 * It tries if the server is ready/*  www. j  av  a  2 s .c  o  m*/
 * 
 * @return boolean true --> server is ready false --> server is not ready
 */
public boolean serverIsReady() throws ServerIsNotReadyException {
    Properties systemSettings = System.getProperties();

    Object isProxyEnabled = systemSettings.get("http.proxySet");
    if ((isProxyEnabled == null) || (isProxyEnabled.equals("false"))) {
        Socket sock;
        try {
            sock = new Socket(getUri().getHost(), getUri().getPort());
        } catch (UnknownHostException e) {
            throw new ServerIsNotReadyException(e);
        } catch (IOException e) {
            throw new ServerIsNotReadyException(e);
        }
        return (sock != null);
    } else {
        Object host = systemSettings.get("http.proxyHost");
        Object port = systemSettings.get("http.proxyPort");
        Object user = systemSettings.get("http.proxyUserName");
        Object password = systemSettings.get("http.proxyPassword");
        if ((host != null) && (port != null)) {
            int iPort = 80;
            try {
                iPort = Integer.parseInt((String) port);
            } catch (Exception e) {
                // Use 80
            }
            HttpConnection connection = new HttpConnection(getUri().getHost(), getUri().getPort());
            connection.setProxyHost((String) host);
            connection.setProxyPort(iPort);
            Authenticator.setDefault(new SimpleAuthenticator(user, password));

            try {
                connection.open();
                connection.close();
            } catch (IOException e) {
                throw new ServerIsNotReadyException(e);
            }
        }
    }
    return true;
}

From source file:io.aos.io.c24.HTTPInfo.java

private Form getInfo(String url) {
    Form form = new Form("HTTP Info");
    HttpConnection connection = null;
    try {/*from   w ww  .  ja  va  2  s .c o m*/
        connection = (HttpConnection) Connector.open(url);
        connection.setRequestMethod("HEAD");
        for (int i = 0;; i++) {
            String key = connection.getHeaderFieldKey(i);
            String value = connection.getHeaderField(i);
            if (value == null)
                break;
            if (key != null)
                form.append(key + ": " + value + "\n");
            else
                form.append("***" + value + "\n");
            ;
        }
    } catch (Exception ex) {
        form.append(ex.getMessage() + "\n");
    } finally {
        try {
            if (connection != null)
                connection.close();
        } catch (IOException ex) {
            /* Oh well. we tried.*/ }
    }

    return form;
}

From source file:edu.internet2.middleware.shibboleth.idp.profile.saml2.SLOProfileHandler.java

/**
 * Issues back channel logout request to session participant.
 *
 * @param sloContext/*from  w  w  w  .j ava 2s  . c o  m*/
 * @param serviceLogoutInfo
 * @throws ProfileException
 */
private void initiateBackChannelLogout(SingleLogoutContext sloContext, LogoutInformation serviceLogoutInfo)
        throws ProfileException {

    if (!serviceLogoutInfo.isLoggedIn()) {
        log.info("Logout status for entity is '{}', not attempting logout",
                serviceLogoutInfo.getLogoutStatus().toString());
        return;
    }

    String spEntityID = serviceLogoutInfo.getEntityID();
    Endpoint endpoint = getEndpointForBinding(spEntityID, SAMLConstants.SAML2_SOAP11_BINDING_URI);
    if (endpoint == null) {
        log.info("No SAML2 LogoutRequest SOAP endpoint found for entity '{}'", spEntityID);
        serviceLogoutInfo.setLogoutUnsupported();
        return;
    }

    serviceLogoutInfo.setLogoutAttempted();
    LogoutRequestContext requestCtx = createLogoutRequestContext(sloContext, serviceLogoutInfo, endpoint);
    if (requestCtx == null) {
        log.info("Cannot create LogoutRequest Context for entity '{}'", spEntityID);
        serviceLogoutInfo.setLogoutFailed();
        return;
    }
    HttpConnection httpConn = null;
    try {
        //prepare http message exchange for soap
        log.debug("Preparing HTTP transport for SOAP request");
        httpConn = createHttpConnection(serviceLogoutInfo, endpoint);
        if (httpConn == null) {
            log.warn("Unable to acquire usable http connection from the pool");
            serviceLogoutInfo.setLogoutFailed();
            return;
        }
        log.debug("Opening HTTP connection to '{}'", endpoint.getLocation());
        httpConn.open();
        if (!httpConn.isOpen()) {
            log.warn("HTTP connection could not be opened");
            serviceLogoutInfo.setLogoutFailed();
            return;
        }

        log.debug("Preparing transports and encoders/decoders");
        prepareSOAPTransport(requestCtx, httpConn, endpoint);
        SAMLMessageEncoder encoder = new HTTPSOAP11Encoder();
        SAMLMessageDecoder decoder = new HTTPSOAP11Decoder(getParserPool());

        //encode and sign saml request
        encoder.encode(requestCtx);
        //TODO: audit log is still missing

        log.info("Issuing back-channel logout request to SP '{}'", spEntityID);
        //execute SOAP/HTTP call
        log.debug("Executing HTTP POST");
        if (!requestCtx.execute(httpConn)) {
            log.warn("Logout execution failed on SP '{}', HTTP status is '{}'", spEntityID,
                    requestCtx.getHttpStatus());
            serviceLogoutInfo.setLogoutFailed();

            return;
        }

        //decode saml response
        decoder.decode(requestCtx);

        LogoutResponse spResponse = requestCtx.getInboundSAMLMessage();
        StatusCode statusCode = spResponse.getStatus().getStatusCode();
        if (statusCode.getValue().equals(StatusCode.SUCCESS_URI)) {
            log.info("Logout was successful on SP '{}'.", spEntityID);
            serviceLogoutInfo.setLogoutSucceeded();
        } else {
            log.warn("Logout failed on SP '{}', logout status code is '{}'.", spEntityID,
                    statusCode.getValue());
            StatusCode secondaryCode = statusCode.getStatusCode();
            if (secondaryCode != null) {
                log.warn("Additional status code: '{}'", secondaryCode.getValue());
            }
            serviceLogoutInfo.setLogoutFailed();
        }
    } catch (SocketTimeoutException e) { //socket connect or read timeout
        log.info("Socket timeout while sending SOAP request to SP '{}'", serviceLogoutInfo.getEntityID());
        serviceLogoutInfo.setLogoutFailed();
    } catch (IOException e) { //other networking error
        log.info("IOException caught while sending SOAP request", e);
        serviceLogoutInfo.setLogoutFailed();
    } catch (Throwable t) { //unexpected
        log.error("Unexpected exception caught while sending SAML Logout request", t);
        serviceLogoutInfo.setLogoutFailed();
    } finally { //
        requestCtx.releaseConnection();
        if (httpConn != null && httpConn.isOpen()) {
            log.debug("Closing HTTP connection");
            try {
                httpConn.close();
            } catch (Throwable t) {
                log.warn("Caught exception while closing HTTP Connection", t);
            }
        }
    }
}

From source file:nl.nn.adapterframework.http.HttpConnectionManager.java

public void releaseConnection(HttpConnection connection) {
    if (connection != null) {
        if (!reuseConnections) {
            connection.close();
            deleteClosedConnections();//from  w ww  .j  a v  a 2 s. c om
        }
    }
    super.releaseConnection(connection);
}