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


Java HttpHead.addHeader方法代码示例

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


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

示例1: testHeadDefaultContentType

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
private void testHeadDefaultContentType(final String mimeType) throws IOException {
    final String id = getRandomUniqueId();
    createObjectAndClose(id);
    addMixin(id, CONTAINER.getURI());

    final HttpHead headObjMethod = headObjMethod(id);
    String mt = mimeType;
    if (mt != null) {
        headObjMethod.addHeader("Accept", mt);
    } else {
        mt = RDFMediaType.TURTLE_WITH_CHARSET;
    }
    try (final CloseableHttpResponse response = execute(headObjMethod)) {
        final Collection<String> contentTypes = getHeader(response, CONTENT_TYPE);
        final String contentType = contentTypes.iterator().next();
        assertTrue("Didn't find LDP valid content-type header: " + contentType +
                "; expected result: " + mt, contentType.contains(mt));
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:20,代码来源:FedoraLdpIT.java

示例2: testHeadDatastreamWithWantDigest

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Test
public void testHeadDatastreamWithWantDigest() throws IOException, ParseException {
    final String id = getRandomUniqueId();
    createDatastream(id, "x", "01234567890123456789012345678901234567890123456789");

    final HttpHead headObjMethod = headObjMethod(id + "/x");
    headObjMethod.addHeader(WANT_DIGEST, "SHA");
    try (final CloseableHttpResponse response = execute(headObjMethod)) {
        assertEquals(OK.getStatusCode(), response.getStatusLine().getStatusCode());
        assertEquals(TEXT_PLAIN, 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"));
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:17,代码来源:FedoraLdpIT.java

示例3: testHeadDatastreamWithWantDigestMultiple

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Test
public void testHeadDatastreamWithWantDigestMultiple() throws IOException, ParseException {
    final String id = getRandomUniqueId();
    createDatastream(id, "x", "01234567890123456789012345678901234567890123456789");

    final HttpHead headObjMethod = headObjMethod(id + "/x");
    headObjMethod.addHeader(WANT_DIGEST, "SHA, md5;q=0.3");
    try (final CloseableHttpResponse response = execute(headObjMethod)) {
        assertEquals(OK.getStatusCode(), response.getStatusLine().getStatusCode());
        assertEquals(TEXT_PLAIN, 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);
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:20,代码来源:FedoraLdpIT.java

示例4: testDigestConsistency

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
@Test
public void testDigestConsistency() throws IOException {
    final String id = getRandomUniqueId();
    executeAndClose(putDSMethod(id, "binary1", "some test content"));

    final String headDigestValue;
    final HttpHead headObjMethod = headObjMethod(id + "/binary1");
    headObjMethod.addHeader(WANT_DIGEST, "sha, md5");
    try (final CloseableHttpResponse response = execute(headObjMethod)) {
        assertTrue(response.getHeaders(DIGEST).length > 0);
        headDigestValue = response.getHeaders(DIGEST)[0].getValue();
    }

    final HttpGet getObjMethod = getObjMethod(id + "/binary1");
    getObjMethod.addHeader(WANT_DIGEST, "sha, md5");
    try (final CloseableHttpResponse response = execute(getObjMethod)) {
        assertTrue(response.getHeaders(DIGEST).length > 0);
        assertEquals(headDigestValue, response.getHeaders(DIGEST)[0].getValue());
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:21,代码来源:FedoraLdpIT.java

示例5: getCsrfToken

import org.apache.http.client.methods.HttpHead; //导入方法依赖的package包/类
private String getCsrfToken(CloseableHttpClient client) throws ClientProtocolException, IOException {
	String url = getMarketplaceUrl();

	HttpHead head = new HttpHead(url + "token");
	head.addHeader(X_CSRF_TOKEN, "fetch");
	CloseableHttpResponse response = client.execute(head);

	EntityUtils.consume(response.getEntity());
	String token = null;
	Header[] headers = response.getHeaders(X_CSRF_TOKEN);
	for (Header header : headers) {
		token = header.getValue();
	}
	return token;
}
 
开发者ID:Itema-as,项目名称:dawn-marketplace-server,代码行数:16,代码来源:OverviewPage.java

示例6: 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;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:12,代码来源:LukeReportFeature.java

示例7: 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"));
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:31,代码来源:FedoraLdpIT.java

示例8: 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);
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:34,代码来源:FedoraLdpIT.java


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