本文整理汇总了Java中org.apache.http.client.methods.HttpHead.setConfig方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHead.setConfig方法的具体用法?Java HttpHead.setConfig怎么用?Java HttpHead.setConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.methods.HttpHead
的用法示例。
在下文中一共展示了HttpHead.setConfig方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHeadExternalDatastream
import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Test
public void testHeadExternalDatastream() throws IOException, ParseException {
final String externalContentType = "message/external-body;access-type=URL;url=\"some:uri\"";
final String id = getRandomUniqueId();
final HttpPut put = putObjMethod(id);
put.addHeader(CONTENT_TYPE, externalContentType);
put.addHeader(LINK, NON_RDF_SOURCE_LINK_HEADER);
assertEquals(CREATED.getStatusCode(), getStatus(put));
// Configure HEAD request to NOT follow redirects
final HttpHead headObjMethod = headObjMethod(id);
final RequestConfig.Builder requestConfig = RequestConfig.custom();
requestConfig.setRedirectsEnabled(false);
headObjMethod.setConfig(requestConfig.build());
try (final CloseableHttpResponse response = execute(headObjMethod)) {
assertEquals(TEMPORARY_REDIRECT.getStatusCode(), response.getStatusLine().getStatusCode());
assertEquals(externalContentType, response.getFirstHeader(CONTENT_TYPE).getValue());
assertEquals("some:uri", response.getFirstHeader(CONTENT_LOCATION).getValue());
assertEquals("bytes", response.getFirstHeader("Accept-Ranges").getValue());
final ContentDisposition disposition =
new ContentDisposition(response.getFirstHeader(CONTENT_DISPOSITION).getValue());
assertEquals("attachment", disposition.getType());
}
}
示例2: makeHeadRequest
import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
public void makeHeadRequest(String alias, String uri, Map<String, String> headers, Boolean allowRedirects) {
logger.debug("Making HEAD request");
HttpHead headRequest = new HttpHead(this.buildUrl(alias, uri));
headRequest = this.setHeaders(headRequest, headers);
headRequest.setConfig(RequestConfig.custom().setRedirectsEnabled(allowRedirects).build());
Session session = this.getSession(alias);
this.makeRequest(headRequest, session);
}
示例3: doTestUrlExists
import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
private boolean doTestUrlExists(final URI requestUri) {
try {
final HttpHead request = new HttpHead(requestUri);
request.addHeader(new BasicScheme().authenticate(createCredentials(), request, new BasicHttpContext()));
request.setConfig(createRequestConfig());
return httpClient.execute(request).getStatusLine().getStatusCode() == HttpStatus.OK.value();
} catch (final Exception e) {
LOG.error("Exception, message: " + e.getMessage());
}
return false;
}
示例4: doHead
import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
public CloseableHttpResponse doHead(String url, int expectedStatusCode)
throws ClientProtocolException, IOException {
HttpHead head = new HttpHead(fullURL + url);
head.setConfig(requestConfig);
CloseableHttpResponse response = httpClient.execute(targetHost, head, httpClientContext);
assertStatusCode(expectedStatusCode, response);
return response;
}
示例5: doHead
import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
private CloseableHttpResponse doHead(final URL url, final int connectionTimeout, final int readTimeout) throws IOException {
final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(readTimeout)
.setConnectTimeout(connectionTimeout)
.setAuthenticationEnabled(hasCredentialsConfigured(url))
.setTargetPreferredAuthSchemes(getAuthSchemePreferredOrder())
.setProxyPreferredAuthSchemes(getAuthSchemePreferredOrder())
.build();
final HttpHead httpHead = new HttpHead(normalizeToString(url));
httpHead.setConfig(requestConfig);
return this.httpClient.execute(httpHead);
}
示例6: testHeadExternalDatastreamWithWantDigest
import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Test
public void testHeadExternalDatastreamWithWantDigest() throws IOException, ParseException {
final String dsId = getRandomUniqueId();
createDatastream(dsId, "x", "01234567890123456789012345678901234567890123456789");
final String dsUrl = serverAddress + dsId + "/x";
final String externalContentType = "message/external-body;access-type=URL;url=\"" + dsUrl + "\"";
final String id = getRandomUniqueId();
final HttpPut put = putObjMethod(id);
put.addHeader(CONTENT_TYPE, externalContentType);
assertEquals(CREATED.getStatusCode(), getStatus(put));
// Configure HEAD request to NOT follow redirects
final HttpHead headObjMethod = headObjMethod(id);
headObjMethod.addHeader(WANT_DIGEST, "sha");
final RequestConfig.Builder requestConfig = RequestConfig.custom();
requestConfig.setRedirectsEnabled(false);
headObjMethod.setConfig(requestConfig.build());
try (final CloseableHttpResponse response = execute(headObjMethod)) {
assertEquals(TEMPORARY_REDIRECT.getStatusCode(), response.getStatusLine().getStatusCode());
assertEquals(externalContentType, response.getFirstHeader(CONTENT_TYPE).getValue());
assertTrue(response.getHeaders(DIGEST).length > 0);
final String digesterHeaderValue = response.getHeaders(DIGEST)[0].getValue();
assertTrue("Fixity Checksum doesn't match",
digesterHeaderValue.equals("sha=9578f951955d37f20b601c26591e260c1e5389bf"));
}
}
示例7: testHeadExternalDatastreamWithWantDigestMultiple
import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Test
public void testHeadExternalDatastreamWithWantDigestMultiple() throws IOException, ParseException {
final String dsId = getRandomUniqueId();
createDatastream(dsId, "x", "01234567890123456789012345678901234567890123456789");
final String dsUrl = serverAddress + dsId + "/x";
final String externalContentType = "message/external-body;access-type=URL;url=\"" + dsUrl + "\"";
final String id = getRandomUniqueId();
final HttpPut put = putObjMethod(id);
put.addHeader(CONTENT_TYPE, externalContentType);
assertEquals(CREATED.getStatusCode(), getStatus(put));
// Configure HEAD request to NOT follow redirects
final HttpHead headObjMethod = headObjMethod(id);
headObjMethod.addHeader(WANT_DIGEST, "sha, md5;q=0.3");
final RequestConfig.Builder requestConfig = RequestConfig.custom();
requestConfig.setRedirectsEnabled(false);
headObjMethod.setConfig(requestConfig.build());
try (final CloseableHttpResponse response = execute(headObjMethod)) {
assertEquals(TEMPORARY_REDIRECT.getStatusCode(), response.getStatusLine().getStatusCode());
assertEquals(externalContentType, response.getFirstHeader(CONTENT_TYPE).getValue());
assertTrue(response.getHeaders(DIGEST).length > 0);
final String digesterHeaderValue = response.getHeaders(DIGEST)[0].getValue();
assertTrue("SHA-1 Fixity Checksum doesn't match",
digesterHeaderValue.indexOf("sha=9578f951955d37f20b601c26591e260c1e5389bf") >= 0);
assertTrue("MD5 fixity checksum doesn't match",
digesterHeaderValue.indexOf("md5=baed005300234f3d1503c50a48ce8e6f") >= 0);
}
}