本文整理汇总了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();
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}