Example usage for org.apache.http.client.methods HttpRequestBase releaseConnection

List of usage examples for org.apache.http.client.methods HttpRequestBase releaseConnection

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpRequestBase releaseConnection.

Prototype

public void releaseConnection() 

Source Link

Document

A convenience method to simplify migration from HttpClient 3.1 API.

Usage

From source file:com.urbancode.ud.client.UDRestClient.java

/**
 * @param request
 */
protected void releaseConnection(HttpRequestBase request) {
    request.releaseConnection();
}

From source file:org.apache.solr.client.solrj.embedded.JettyWebappTest.java

public void testAdminUI() throws Exception {
    // Currently not an extensive test, but it does fire up the JSP pages and make 
    // sure they compile ok

    String adminPath = "http://127.0.0.1:" + port + context + "/";
    byte[] bytes = IOUtils.toByteArray(new URL(adminPath).openStream());
    assertNotNull(bytes); // real error will be an exception

    HttpClient client = HttpClients.createDefault();
    HttpRequestBase m = new HttpGet(adminPath);
    HttpResponse response = client.execute(m, HttpClientUtil.createNewHttpClientRequestContext());
    assertEquals(200, response.getStatusLine().getStatusCode());
    Header header = response.getFirstHeader("X-Frame-Options");
    assertEquals("DENY", header.getValue().toUpperCase(Locale.ROOT));
    m.releaseConnection();
}

From source file:com.offbytwo.jenkins.client.JenkinsHttpClient.java

private void releaseConnection(HttpRequestBase httpRequestBase) {
    httpRequestBase.releaseConnection();
}

From source file:net.ychron.unirestinst.http.HttpClientHelper.java

public <T> HttpResponse<T> request(HttpRequest request, Class<T> responseClass) throws UnirestException {
    HttpRequestBase requestObj = prepareRequest(request, false);
    HttpClient client = options.getHttpClient(); // The
    // DefaultHttpClient
    // is thread-safe

    org.apache.http.HttpResponse response;
    try {/*from   w w w .  ja  v  a 2s  .c om*/
        response = client.execute(requestObj);
        HttpResponse<T> httpResponse = new HttpResponse<T>(options, response, responseClass);
        requestObj.releaseConnection();
        return httpResponse;
    } catch (Exception e) {
        throw new UnirestException(e);
    } finally {
        requestObj.releaseConnection();
    }
}

From source file:io.cloudslang.content.httpclient.CSHttpClient.java

private void checkKeepAlive(HttpRequestBase httpRequestBase, PoolingHttpClientConnectionManager connManager,
        String keepAliveInput, CloseableHttpResponse httpResponse) {
    boolean keepAlive = StringUtils.isBlank(keepAliveInput) || Boolean.parseBoolean(keepAliveInput);
    if (keepAlive) {
        httpRequestBase.releaseConnection();
    } else {/*from  w  ww .ja  va  2 s . c  o  m*/
        try {
            httpResponse.close();
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        httpRequestBase.releaseConnection();
        connManager.closeExpiredConnections();
    }
}

From source file:org.jtalks.poulpe.service.JcommuneHttpNotifier.java

/**
 * Creates the HTTP request from specified data, adds admin password to the URL and sends to JCommune. The password
 * is required to be set in order to secure this invocation, otherwise anyway would be able to send such request to
 * JCommune.//  w ww . ja  va 2s .  co  m
 *
 * @param url        an address to send the request to
 * @param httpMethod delete or post request, see {@link HttpDelete}, {@link HttpPost}
 * @throws JcommuneRespondedWithErrorException
 *          if HTTP request reached JCommune, but JCommune responded with error code, such situation may happen for
 *          instance when we're deleting some branch, but it was already deleted, or JCommune has troubles removing
 *          that branch (database connection lost). Note that if we reach some other site and it responds with 404
 *          for example, this will be still this error.
 * @throws NoConnectionToJcommuneException
 *          if nothing was found at the specified URL, note that if URL was set incorrectly to point to another
 *          site, this can't be figured out by us, we just operate with HTTP codes, which means that either the
 *          request will be fine or {@link JcommuneRespondedWithErrorException} might be thrown in case if some
 *          other site was specified and it returned 404
 */
private void createAndSendRequest(String url, String httpMethod)
        throws JcommuneRespondedWithErrorException, NoConnectionToJcommuneException {
    logger.info("Sending [{}] request to JCommune: [{}]", httpMethod, url);
    String adminPassword = userDao.getByUsername("admin").getPassword();
    HttpRequestBase request = createWithHttpMethod(httpMethod, url + "?password=" + adminPassword);
    try {
        HttpResponse response = doSendRequest(request);
        assertStatusSuccessful(response);
    } catch (IOException e) {
        logger.info("Was not possible to send request since [{}] does not respond", url);
        throw new NoConnectionToJcommuneException(e);
    } finally {
        request.releaseConnection();
    }
}

From source file:org.apache.directory.fortress.core.rest.RestUtils.java

/**
 * Process the HTTP method request.//from w ww  .  j  a va 2  s  .  co  m
 *
 * @param httpGetRequest
 * @return String containing response
 * @throws Exception
 */
private static String handleHttpMethod(HttpRequestBase httpGetRequest, org.apache.http.client.HttpClient client)
        throws RestException {
    String szResponse = null;
    try {
        HttpResponse response = client.execute(httpGetRequest);
        LOG.debug("handleHttpMethod Response status : {}", response.getStatusLine().getStatusCode());

        Response.Status status = Response.Status.fromStatusCode(response.getStatusLine().getStatusCode());

        if (status == Response.Status.OK) {
            szResponse = IOUtils.toString(response.getEntity().getContent());
            LOG.debug(szResponse);
        } else if (status == Response.Status.FORBIDDEN) {
            LOG.debug("handleHttpMethod Authorization failure");
        } else if (status == Response.Status.UNAUTHORIZED) {
            LOG.debug("handleHttpMethod Authentication failure");
        } else {
            LOG.debug("handleHttpMethod Unknown error");
        }
    } catch (IOException ioe) {
        String error = "handleHttpMethod caught IOException=" + ioe;
        LOG.error(error);
        throw new RestException(GlobalErrIds.REST_IO_ERR, error, ioe);
    } finally {
        // Release current connection to the connection pool.
        httpGetRequest.releaseConnection();
    }
    return szResponse;
}

From source file:org.openscore.content.httpclient.ScoreHttpClient.java

private void checkKeepAlive(HttpRequestBase httpRequestBase, PoolingHttpClientConnectionManager connManager,
        String keepAliveInput, CloseableHttpResponse httpResponse) {
    boolean keepAlive = StringUtils.isBlank(keepAliveInput) || Boolean.parseBoolean(keepAliveInput);
    if (!keepAlive) {
        try {/*from   w  w w .  j a v  a2  s .c  o  m*/
            httpResponse.close();
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        httpRequestBase.releaseConnection();
        connManager.closeExpiredConnections();
    }
}

From source file:com.cloud.network.brocade.BrocadeVcsApi.java

protected HttpResponse executeMethod(HttpRequestBase method) throws BrocadeVcsApiException {
    HttpResponse response = null;//  w ww  . ja v a  2s .c o  m
    try {
        response = _client.execute(method);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            method.releaseConnection();
            response = _client.execute(method);
        }
    } catch (HttpException e) {
        s_logger.error("HttpException caught while trying to connect to the Brocade Switch", e);
        method.releaseConnection();
        throw new BrocadeVcsApiException("API call to Brocade Switch Failed", e);
    } catch (IOException e) {
        s_logger.error("IOException caught while trying to connect to the Brocade Switch", e);
        method.releaseConnection();
        throw new BrocadeVcsApiException("API call to Brocade Switch Failed", e);
    }

    return response;
}

From source file:com.sap.core.odata.testutil.tool.core.AbstractTestClient.java

private void call(final URI baseUri, final TestRequest testPath) {
    HttpRequestBase request = null;
    try {/*from  w w  w.  j a  v a2 s . c  om*/
        request = createRequest(baseUri, testPath);
        testPath.applyHeaders(request);

        LOG.debug("Call for request line '{}'", request.getRequestLine());

        final HttpHost targetHost = new HttpHost(baseUri.getHost(), baseUri.getPort());
        final HttpResponse response = httpClient.execute(targetHost, request);

        //
        handleSuccessCall(baseUri, testPath, request, response);
    } catch (Exception e) {
        handleFailureCall(testPath, request, e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}