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:fr.eurecom.nerd.core.proxy.ExtractivClient.java

/**
 * Get the output from the REST server/* w  ww.j av  a  2 s  .  c om*/
 */
private static InputStream fetchHttpRequest(final HttpMethodBase method) throws BadInputException {
    try {

        final int statusCode = getClient().executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            throw new BadInputException(
                    "webpage status " + HttpStatus.getStatusText(statusCode) + "(" + statusCode + ")");
        }

        final InputStream is = new ByteArrayInputStream(method.getResponseBody());
        final GZIPInputStream zippedInputStream = new GZIPInputStream(is);
        return zippedInputStream;
    } catch (HttpException e) {
        throw new BadInputException("Fatal protocol violation " + e.getMessage(), e);
    } catch (IOException e) {
        //e.g. www.google.assadsaddsa
        throw new BadInputException("Fatal transport error " + e.getMessage(), e);
    } finally {
        method.releaseConnection();
    }
}

From source file:cz.muni.fi.pa165.creatures.rest.client.services.utils.CRUDServiceHelper.java

/**
 * Helper methods which executes an HTTP {@code method} and writes the
 * output to the standard output (e.g. console). Return codes of the HTTP
 * responses are present so we can verify what happened at the server side.
 *
 * @param method method to send to the server side
 *//*from  w  ww .j a va  2  s .  c  om*/
public static void send(HttpMethodBase method) {
    HttpClient httpClient = new HttpClient();
    try {

        int result = httpClient.executeMethod(method);
        System.out.println(RESPONSE_STATUS_CODE + result);
        ResponseCode response = ResponseCode.fromInt(result);
        if (response != ResponseCode.NOT_FOUND && response != ResponseCode.SERVER_ERROR
                && response != ResponseCode.FORBIDDEN) {
            System.out.println(RESPONSE_HEADER);

            Header[] headers = method.getResponseHeaders();
            for (Header h : headers) {
                System.out.println(h.toString());
            }

            InputStreamReader isr = new InputStreamReader(method.getResponseBodyAsStream());
            BufferedReader br = new BufferedReader(isr);

            String line;

            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        }
    } catch (ConnectException ex) {
        logger.log(Level.WARNING, CONNECTION_EXCEPTION_MSG);
    } catch (IOException ex) {
        logger.log(Level.INFO, ex.getMessage());
    } finally {
        method.releaseConnection();
    }
}

From source file:de.juwimm.cms.common.http.HttpClientWrapper.java

public synchronized String getString(String destUrl, String userName, String password) throws IOException {
    HttpMethodBase method = invoke(destUrl, userName, password);
    String retString = method.getResponseBodyAsString();
    method.releaseConnection();
    return retString;
}

From source file:de.juwimm.cms.common.http.HttpClientWrapper.java

public synchronized byte[] getByte(String destUrl, String userName, String password) throws IOException {
    HttpMethodBase method = invoke(destUrl, userName, password);
    byte[] retArr;
    retArr = method.getResponseBody();//from   w  w w.  jav a2 s .c om
    method.releaseConnection();
    return retArr;
}

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

protected void executeMethod(HttpMethodBase method) throws BigSwitchVnsApiException {
    try {//w w  w . ja  v a  2  s .  com
        _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 BigSwitch Controller", e);
        method.releaseConnection();
        throw new BigSwitchVnsApiException("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 BigSwitchVnsApiException("API call to BigSwitch Controller Failed", e);
    }
}

From source file:edu.ucsb.eucalyptus.cloud.ws.tests.CreateSnapshotTest.java

public void testSendDummy() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty(WalrusProperties.URL_PROPERTY) + "/meh/ttt.wsl?gg=vol&hh=snap";

    HttpMethodBase method = new PutMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");

    httpClient.executeMethod(method);/*w  ww . j  av  a 2  s. c o  m*/
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

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

@Test
public void testSendDummy() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty("euca.objectstorage.url") + "/meh/ttt.wsl?gg=vol&hh=snap";

    HttpMethodBase method = new PutMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");

    httpClient.executeMethod(method);//  ww w  .ja  v  a2 s  . c  o  m
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

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

@Test
public void testSendDummy() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty(WalrusProperties.URL_PROPERTY) + "/meh/ttt.wsl?gg=vol&hh=snap";

    HttpMethodBase method = new PutMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");

    httpClient.executeMethod(method);//from  ww w  . j a  va 2s. c om
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

From source file:de.juwimm.cms.common.http.HttpClientWrapper.java

public synchronized String getString(URL destUrl, String userName, String password) throws IOException {
    HttpMethodBase method = invoke(destUrl, userName, password);
    String charSet = method.getRequestCharSet();
    String retString = new String(method.getResponseBodyAsString().getBytes(charSet));
    method.releaseConnection();
    return retString;
}

From source file:edu.ucsb.eucalyptus.cloud.ws.tests.CreateSnapshotTest.java

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);/*from   w  w  w  .  j ava2s. c o  m*/
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}