当前位置: 首页>>代码示例>>Java>>正文


Java HttpHead.releaseConnection方法代码示例

本文整理汇总了Java中org.apache.http.client.methods.HttpHead.releaseConnection方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHead.releaseConnection方法的具体用法?Java HttpHead.releaseConnection怎么用?Java HttpHead.releaseConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.methods.HttpHead的用法示例。


在下文中一共展示了HttpHead.releaseConnection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCsrfToken

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
public String getCsrfToken() throws IOException {
	HttpHead request = new HttpHead(queryUrl);
	HttpResponse response = httpClient.execute(request);
	try {
		int statusCode = response.getStatusLine().getStatusCode();
		if (statusCode == 200) {
			Header[] headers = response.getHeaders(SET_COOKIE);
			//CSRF-TOKEN
			for (Header header : headers) {
				if (header.getValue().startsWith(CSRF_COOKIE)) {
					String csrfToken = getCookieValue(header);
					return csrfToken;
				}
			}
			throw new IOException("Authentication service returned ok, but did not offer a CrossScripting token");
		} else {
			throw new IOException("Authentication service returned unexpected status while requesting CrossScripting Token value: " + statusCode);
		}
	} finally {
		request.releaseConnection();
	}
}
 
开发者ID:IHTSDO,项目名称:MLDS,代码行数:23,代码来源:HttpAuthAdaptor.java

示例2: testHeadToGetSwitch

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Test
public void testHeadToGetSwitch() throws Exception {
    HttpHead head = new HttpHead(getHttpURl("/hello/html"));
    // When checking the content length, we must disable the compression:
    head.setHeader(HeaderNames.ACCEPT_ENCODING, "identity");
    HttpResponse<String> response;
    try {
        org.apache.http.HttpResponse resp = ClientFactory.getHttpClient().execute(head);
        response = new HttpResponse<>(resp, String.class);
    } finally {
        head.releaseConnection();
    }

    assertThat(response.code()).isEqualTo(OK);
    assertThat(response.contentType()).isEqualTo(MimeTypes.HTML);
    System.out.println(response.headers());
    assertThat(Integer.valueOf(response.header(CONTENT_LENGTH))).isEqualTo(20);
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:19,代码来源:HeadIT.java

示例3: head

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
/**
 * Send a HEAD request
 * @param cluster the cluster definition
 * @param path the path or URI
 * @param headers the HTTP headers to include in the request
 * @return a Response object with response detail
 * @throws IOException
 */
public Response head(Cluster cluster, String path, Header[] headers)
    throws IOException {
  HttpHead method = new HttpHead(path);
  try {
    HttpResponse resp = execute(cluster, method, null, path);
    return new Response(resp.getStatusLine().getStatusCode(), resp.getAllHeaders(), null);
  } finally {
    method.releaseConnection();
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:19,代码来源:Client.java

示例4: exists

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Override
public boolean exists(final String path) throws FedoraException, ForbiddenException {
    final HttpHead head = httpHelper.createHeadMethod(prependTransactionId(path));
    try {
        final HttpResponse response = httpHelper.execute(head);
        final StatusLine status = response.getStatusLine();
        final int statusCode = status.getStatusCode();
        final String uri = head.getURI().toString();
        if (statusCode == SC_OK) {
            return true;
        } else if (statusCode == SC_NOT_FOUND) {
            return false;
        } else if (statusCode == SC_FORBIDDEN) {
            LOGGER.error("request for resource {} is not authorized.", uri);
            throw new ForbiddenException("request for resource " + uri + " is not authorized.");
        } else {
            LOGGER.error("error checking resource {}: {} {}", uri, statusCode, status.getReasonPhrase());
            throw new FedoraException("error checking resource " + uri + ": " + statusCode + " " +
                                      status.getReasonPhrase());
        }
    } catch (final Exception e) {
        LOGGER.error("Could not encode URI parameter: {}", e.getMessage());
        throw new FedoraException(e);
    } finally {
        head.releaseConnection();
    }
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo4-client,代码行数:28,代码来源:FedoraRepositoryImpl.java

示例5: getHttpStatus

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
public int getHttpStatus (String url) throws IOException {
    String encodedUrl = getEncodedUrl(url);
    CloseableHttpClient httpClient = getHttpClient(encodedUrl);
    HttpHead head = new HttpHead(encodedUrl);
    try {
        LOGGER.debug("executing head request to retrieve page status on " + head.getURI());
        HttpResponse response = httpClient.execute(head);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("received " + response.getStatusLine().getStatusCode() + " from head request");
            for (Header h : head.getAllHeaders()) {
                LOGGER.debug("header : " + h.getName() + " " + h.getValue());
            }
        }
        
        return response.getStatusLine().getStatusCode();
    } catch (UnknownHostException uhe) {
        LOGGER.warn("UnknownHostException on " + encodedUrl);
        return HttpStatus.SC_NOT_FOUND;
    } catch (IllegalArgumentException iae) {
        LOGGER.warn("IllegalArgumentException on " + encodedUrl);
        return HttpStatus.SC_NOT_FOUND;
    } catch (IOException ioe) {
        LOGGER.warn("IOException on " + encodedUrl);
        return HttpStatus.SC_NOT_FOUND;
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        head.releaseConnection();
        httpClient.close();
    }
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:33,代码来源:HttpRequestHandler.java

示例6: testHeadToGetSwitchOnMissingPage

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Test
public void testHeadToGetSwitchOnMissingPage() throws Exception {
    HttpHead head = new HttpHead(getHttpURl("/hello/missing"));

    HttpResponse<String> response;
    try {
        org.apache.http.HttpResponse resp = ClientFactory.getHttpClient().execute(head);
        response = new HttpResponse<>(resp, String.class);
    } finally {
        head.releaseConnection();
    }

    assertThat(response.code()).isEqualTo(NOT_FOUND);
    assertThat(response.body()).isNull();
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:16,代码来源:HeadIT.java


注:本文中的org.apache.http.client.methods.HttpHead.releaseConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。