Example usage for org.apache.commons.httpclient HttpMethodBase releaseConnection

List of usage examples for org.apache.commons.httpclient HttpMethodBase releaseConnection

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethodBase releaseConnection.

Prototype

@Override
public void releaseConnection() 

Source Link

Document

Releases the connection being used by this HTTP method.

Usage

From source file:com.eucalyptus.blockstorage.CreateSnapshotTest.java

@Test
public void testGetSnapshotInfo() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty("euca.objectstorage.url")
            + "/snapset-FuXLn1MUHJ66BkK0/snap-zVl2kZJmjhxnEg..";

    HttpMethodBase method = new GetMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");
    method.setRequestHeader("EucaOperation", "GetSnapshotInfo");
    httpClient.executeMethod(method);/*www  . ja v a2  s .c om*/
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

From source file:com.eucalyptus.blockstorage.tests.CreateSnapshotTest.java

@Test
public void testGetSnapshotInfo() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty(WalrusProperties.URL_PROPERTY)
            + "/snapset-FuXLn1MUHJ66BkK0/snap-zVl2kZJmjhxnEg..";

    HttpMethodBase method = new GetMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");
    method.setRequestHeader("EucaOperation", "GetSnapshotInfo");
    httpClient.executeMethod(method);// ww  w . jav a  2 s .c o  m
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

From source file:com.cloud.utils.rest.RESTValidationStrategy.java

public void executeMethod(final HttpMethodBase method, final HttpClient client, final String protocol)
        throws CloudstackRESTException, HttpException, IOException {
    if (host == null || host.isEmpty() || user == null || user.isEmpty() || password == null
            || password.isEmpty()) {//  w w  w  . jav  a  2s.co  m
        throw new CloudstackRESTException("Hostname/credentials are null or empty");
    }

    client.executeMethod(method);
    if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
        method.releaseConnection();
        // login and try again
        login(protocol, client);
        client.executeMethod(method);
    }
}

From source file:com.cloud.network.bigswitch.BigSwitchBcfApi.java

protected void executeMethod(final HttpMethodBase method) throws BigSwitchBcfApiException {
    try {//from  w w w . j  a v a  2 s . c o m
        _client.executeMethod(method);
        if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            method.releaseConnection();
        }
    } catch (HttpException e) {
        S_LOGGER.error("HttpException caught while trying to connect to the BigSwitch Controller", e);
        method.releaseConnection();
        throw new BigSwitchBcfApiException("API call to BigSwitch Controller Failed", e);
    } catch (IOException e) {
        S_LOGGER.error("IOException caught while trying to connect to the BigSwitch Controller", e);
        method.releaseConnection();
        throw new BigSwitchBcfApiException("API call to BigSwitch Controller Failed", e);
    }
}

From source file:com.cloud.utils.rest.RESTServiceConnector.java

public void executeMethod(final HttpMethodBase method) throws CloudstackRESTException {
    try {/*from w  ww. j  a v a  2s . c o m*/
        validation.executeMethod(method, client, protocol);
    } catch (final HttpException e) {
        s_logger.error("HttpException caught while trying to connect to the REST Service", e);
        method.releaseConnection();
        throw new CloudstackRESTException("API call to REST Service Failed", e);
    } catch (final IOException e) {
        s_logger.error("IOException caught while trying to connect to the REST Service", e);
        method.releaseConnection();
        throw new CloudstackRESTException("API call to Nicira REST Service Failed", e);
    }
}

From source file:com.github.rnewson.couchdb.lucene.Database.java

private synchronized String execute(final HttpMethodBase method) throws HttpException, IOException {
    try {/*w  w  w  .j ava  2s .  c o m*/

        final int sc = CLIENT.executeMethod(method);
        if (sc == 401) {
            throw new HttpException("Unauthorized.");
        }
        final InputStream in = method.getResponseBodyAsStream();
        try {
            final StringWriter writer = new StringWriter(2048);
            IOUtils.copy(in, writer, method.getResponseCharSet());
            return writer.toString();
        } finally {
            in.close();
        }
    } finally {
        method.releaseConnection();
    }
}

From source file:edu.indiana.d2i.registryext.RegistryExtAgent.java

/**
 * close connection/*from  w w  w.  j  a v  a 2 s  .c  o m*/
 * 
 * @param method
 *            http method type
 */
public void closeConnection(HttpMethodBase method) {
    if (method != null)
        method.releaseConnection();

}

From source file:com.cloud.network.nicira.NiciraNvpApi.java

private void executeMethod(HttpMethodBase method) throws NiciraNvpApiException {
    try {/*from w  w  w .  j  a va 2 s .c  o  m*/
        _client.executeMethod(method);
        if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            method.releaseConnection();
            // login and try again
            login();
            _client.executeMethod(method);
        }
    } catch (HttpException e) {
        s_logger.error("HttpException caught while trying to connect to the Nicira NVP Controller", e);
        throw new NiciraNvpApiException("API call to Nicira NVP Controller Failed", e);
    } catch (IOException e) {
        s_logger.error("IOException caught while trying to connect to the Nicira NVP Controller", e);
        throw new NiciraNvpApiException("API call to Nicira NVP Controller Failed", e);
    }
}

From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java

@Override
public OperatorDTO getOperatorByApiKey(String apiKey) {
    String url = String.format(baseUrl + OPERATOR_API_KEY, apiKey);
    HttpMethodBase method = createGetMethod(url);

    try {/* www  . ja va  2 s  . co  m*/
        // Execute the method.
        InputStream body = execute(method);

        return parseJson(body, OperatorDTO.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java

private boolean isOperatorEnabled(Long operatorId) {
    String url = String.format(baseUrl + OPERATOR_ENABLED, operatorId);
    HttpMethodBase method = createGetMethod(url);

    try {/*from   w ww  . j a  va 2s.  c om*/
        // Execute the method.
        InputStream body = execute(method);
        if (body == null) {
            return false;
        }
        return parseJson(body, Boolean.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        method.releaseConnection();
    }
}