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


Java HttpPatch.setHeader方法代码示例

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


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

示例1: register

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
@Override
public void register(final URI uri) {
    init.await();
    try {
        LOG.debug("Registering service {} ", uri);

        final HttpPatch patch = new HttpPatch(registryContainer);
        patch.setHeader(HttpHeaders.CONTENT_TYPE, SPARQL_UPDATE);
        patch.setEntity(new InputStreamEntity(patchAddService(uri)));

        try (CloseableHttpResponse resp = execute(patch)) {
            LOG.info("Adding service {} to registry {}", uri, registryContainer);
        }
    } catch (final Exception e) {
        throw new RuntimeException(String.format("Could not add <%s> to service registry <%s>", uri,
                registryContainer), e);
    }

    update(uri);
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-api-x,代码行数:21,代码来源:JenaServiceRegistry.java

示例2: sendPATCH

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
public static int sendPATCH(String endpoint, String content, Map<String, String> headers) throws IOException {
	HttpClient httpClient = new DefaultHttpClient();
	HttpPatch httpPatch = new HttpPatch(endpoint);
	for (String headerType : headers.keySet()) {
		httpPatch.setHeader(headerType, headers.get(headerType));
	}
	if (null != content) {
		HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
		if (headers.get("Content-Type") == null) {
			httpPatch.setHeader("Content-Type", "application/json");
		}
		httpPatch.setEntity(httpEntity);
	}
	HttpResponse httpResponse = httpClient.execute(httpPatch);
	return httpResponse.getStatusLine().getStatusCode();
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:17,代码来源:ODataTestUtils.java

示例3: setProperty

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
protected HttpResponse setProperty(final String pid, final String txId,
                                   final String propertyUri,
                                   final String value) throws IOException {
    final HttpPatch postProp = new HttpPatch(serverAddress
            + (txId != null ? txId + "/" : "") + pid);
    postProp.setHeader(CONTENT_TYPE, "application/sparql-update");
    final String updateString =
            "INSERT { <"
                    + serverAddress + pid
                    + "> <" + propertyUri + "> \"" + value + "\" } WHERE { }";
    postProp.setEntity(new StringEntity(updateString));
    final HttpResponse dcResp = execute(postProp);
    assertEquals(dcResp.getStatusLine().toString(),
            204, dcResp.getStatusLine().getStatusCode());
    postProp.releaseConnection();
    return dcResp;
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:18,代码来源:AbstractResourceIT.java

示例4: testGetObjectOmitContainment

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
@Test
public void testGetObjectOmitContainment() throws IOException {
    final String id = getRandomUniqueId();
    createObjectAndClose(id);
    final HttpPatch patch = patchObjMethod(id);
    patch.setHeader(CONTENT_TYPE, "application/sparql-update");
    final String updateString =
            "INSERT DATA { <> a <" + DIRECT_CONTAINER.getURI() + "> ; <" + MEMBERSHIP_RESOURCE.getURI() +
                    "> <> ; <" + HAS_MEMBER_RELATION + "> <" + LDP_NAMESPACE + "member> .}";
    patch.setEntity(new StringEntity(updateString));
    assertEquals(NO_CONTENT.getStatusCode(), getStatus(patch));

    createObjectAndClose(id + "/a");
    final HttpGet getObjMethod = getObjMethod(id);
    getObjMethod
            .addHeader("Prefer", "return=representation; omit=\"http://www.w3.org/ns/ldp#PreferContainment\"");
    try (final CloseableDataset dataset = getDataset(getObjMethod)) {
        final DatasetGraph graph = dataset.asDatasetGraph();
        final Node resource = createURI(serverAddress + id);
        assertTrue("Didn't find member resources", graph.find(ANY, resource, LDP_MEMBER.asNode(), ANY).hasNext());
        assertFalse("Expected nothing contained", graph.find(ANY, resource, CONTAINS.asNode(), ANY).hasNext());
    }
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:24,代码来源:FedoraLdpIT.java

示例5: createPatch

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
/**
 * Create Patch Request
 */
public HttpPatch createPatch(String url, JSON data) {
    HttpPatch patch = new HttpPatch(url);
    patch.setHeader("Content-Type", "application/json");

    String string = data.toString(1);
    try {
        patch.setEntity(new StringEntity(string, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return patch;
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:16,代码来源:HttpUtils.java

示例6: writeV2

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
public boolean writeV2(Map<String, String> map) {
    try {
        StringBuffer sb = new StringBuffer();
        sb.append("{");
        for (String key : map.keySet()) {
            sb.append(QUATA);
            sb.append(key);
            sb.append(QUATA);
            sb.append(" : ");
            sb.append(QUATA);
            sb.append(map.get(key));
            sb.append(QUATA);
            sb.append(",");
        }
        String data = sb.toString();
        data = data.substring(0, data.length() - 1);
        String node = data + "}";
        HttpClient httpclient = HttpClients.createDefault();
        HttpPatch httppost = new HttpPatch(getChannelUrl()); // Use PATCH updates things
        StringEntity entity = new StringEntity(node);
        httppost.setEntity(entity);
        httppost.setHeader("Accept", "application/json");
        httppost.setHeader("Content-type", "application/json");
        HttpResponse response = httpclient.execute(httppost);
        this.resetChannel();
        return response.getStatusLine().getStatusCode() == 200;
    } catch (Exception ex) {
        ex.printStackTrace();
        return false;
    }
}
 
开发者ID:Advait-M,项目名称:AttendanceTracker,代码行数:32,代码来源:Driver.java

示例7: setHeaders

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
/**
 * Set the header for request.
 * 
 * @param httpPatch HttpURLConnection
 * @param headers Map<String,String>
 */
private static void setHeaders(HttpPatch httpPatch, Map<String, String> headers) {
  Iterator<Entry<String, String>> itr = headers.entrySet().iterator();
  while (itr.hasNext()) {
    Entry<String, String> entry = itr.next();
    httpPatch.setHeader(entry.getKey(), entry.getValue());
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:14,代码来源:HttpUtil.java

示例8: sendPATCH

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
private static int sendPATCH(String endpoint, String content, String acceptType) throws IOException {
	HttpClient httpClient = new DefaultHttpClient();
	HttpPatch httpPatch = new HttpPatch(endpoint);
	httpPatch.setHeader("Accept", acceptType);
	if (null != content) {
		HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
		httpPatch.setHeader("Content-Type", "application/json");
		httpPatch.setEntity(httpEntity);
	}
	HttpResponse httpResponse = httpClient.execute(httpPatch);
	return httpResponse.getStatusLine().getStatusCode();
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:13,代码来源:ODataSuperTenantUserTestCase.java

示例9: unsupportedContentTypeParameter

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
@Test
public void unsupportedContentTypeParameter() throws Exception {
  HttpPatch patch = new HttpPatch(URI.create(getEndpoint().toString() + "Rooms('1')"));
  patch.setHeader(HttpHeaders.CONTENT_TYPE, HttpContentType.APPLICATION_JSON + ";illegal=wrong");
  final HttpResponse response = getHttpClient().execute(patch);
  assertEquals(HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE.getStatusCode(), response.getStatusLine().getStatusCode());
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:8,代码来源:RequestContentTypeTest.java

示例10: patch

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
/**
 * @see com.kixeye.relax.RestClient#patch(java.lang.String, java.lang.String, java.lang.String, I, java.lang.Object)
 */
@Override
public <I> HttpPromise<HttpResponse<Void>> patch(String path, String contentTypeHeader, String acceptHeader, I requestObject, Map<String, List<String>> additonalHeaders, Object... pathVariables) throws IOException {
	HttpPromise<HttpResponse<Void>> promise = new HttpPromise<>();
	
	HttpPatch request = new HttpPatch(UrlUtils.expand(uriPrefix + path, pathVariables));
	if (requestObject != null) {
		request.setEntity(new ByteArrayEntity(serDe.serialize(contentTypeHeader, requestObject)));
	}
	
	if (contentTypeHeader != null) {
		request.setHeader("Content-Type", contentTypeHeader);
	}
	
	if (acceptHeader != null) {
		request.setHeader("Accept", acceptHeader);
	}
	
	if (additonalHeaders != null && !additonalHeaders.isEmpty()) {
		for (Entry<String, List<String>> header : additonalHeaders.entrySet()) {
			for (String value : header.getValue()) {
				request.addHeader(header.getKey(), value);
			}
		}
	}

	httpClient.execute(request, new AsyncRestClientResponseCallback<>(null, promise));
	
	return promise;
}
 
开发者ID:Kixeye,项目名称:relax,代码行数:33,代码来源:AsyncRestClient.java

示例11: createPatchMethod

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
/**
 * Create a request to update triples with SPARQL Update.
 * @param path The datastream path.
 * @param sparqlUpdate SPARQL Update command.
 * @return created patch based on parameters
 * @throws FedoraException
**/
public HttpPatch createPatchMethod(final String path, final String sparqlUpdate) throws FedoraException {
    if ( isBlank(sparqlUpdate) ) {
        throw new FedoraException("SPARQL Update command must not be blank");
    }

    final HttpPatch patch = new HttpPatch(repositoryURL + path);
    patch.setEntity( new ByteArrayEntity(sparqlUpdate.getBytes()) );
    patch.setHeader("Content-Type", contentTypeSPARQLUpdate);
    return patch;
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo4-client,代码行数:18,代码来源:HttpHelper.java

示例12: executeUpdateObject

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
protected <T> boolean executeUpdateObject(T newObject, String uri) throws BrocadeVcsApiException {

        final boolean result = true;

        if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) {
            throw new BrocadeVcsApiException("Hostname/credentials are null or empty");
        }

        final HttpPatch pm = (HttpPatch)createMethod("patch", uri);
        pm.setHeader("Accept", "application/vnd.configuration.resource+xml");

        pm.setEntity(new StringEntity(convertToString(newObject), ContentType.APPLICATION_XML));

        final HttpResponse response = executeMethod(pm);

        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) {

            String errorMessage;
            try {
                errorMessage = responseToErrorMessage(response);
            } catch (final IOException e) {
                s_logger.error("Failed to update object : " + e.getMessage());
                throw new BrocadeVcsApiException("Failed to update object : " + e.getMessage());
            }

            pm.releaseConnection();
            s_logger.error("Failed to update object : " + errorMessage);
            throw new BrocadeVcsApiException("Failed to update object : " + errorMessage);
        }

        pm.releaseConnection();

        return result;
    }
 
开发者ID:apache,项目名称:cloudstack,代码行数:35,代码来源:BrocadeVcsApi.java

示例13: linkToAcl

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
/**
 * Convenience method to link a Resource to a WebACL resource
 *
 * @param protectedResource path of the resource to be protected by the
 * @param aclResource path of the Acl resource
 */
private void linkToAcl(final String protectedResource, final String aclResource)
        throws IOException {
    final HttpPatch request = patchObjMethod(protectedResource.replace(serverAddress, ""));
    setAuth(request, "fedoraAdmin");
    request.setHeader("Content-type", "application/sparql-update");
    request.setEntity(new StringEntity(
            "INSERT { <> <" + WEBAC_ACCESS_CONTROL_VALUE + "> <" + aclResource + "> . } WHERE {}"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(request));
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:16,代码来源:WebACRecipesIT.java

示例14: scenario2

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
@Test
public void scenario2() throws IOException {
    final String id = "/rest/box/bag/collection";
    final String testObj = ingestObj(id);
    final String acl2 = ingestAcl("fedoraAdmin", "/acls/02/acl.ttl", "/acls/02/authorization.ttl");
    linkToAcl(testObj, acl2);

    logger.debug("Anonymous can not read " + testObj);
    final HttpGet requestGet = getObjMethod(id);
    assertEquals(HttpStatus.SC_FORBIDDEN, getStatus(requestGet));

    logger.debug("GroupId 'Editors' can read " + testObj);
    final HttpGet requestGet2 = getObjMethod(id);
    setAuth(requestGet2, "jones");
    requestGet2.setHeader("some-header", "Editors");
    assertEquals(HttpStatus.SC_OK, getStatus(requestGet2));

    logger.debug("Anonymous cannot write " + testObj);
    final HttpPatch requestPatch = patchObjMethod(id);
    requestPatch.setEntity(new StringEntity("INSERT { <> <" + title.getURI() + "> \"Test title\" . } WHERE {}"));
    requestPatch.setHeader("Content-type", "application/sparql-update");
    assertEquals(HttpStatus.SC_FORBIDDEN, getStatus(requestPatch));

    logger.debug("Editors can write " + testObj);
    final HttpPatch requestPatch2 = patchObjMethod(id);
    setAuth(requestPatch2, "jones");
    requestPatch2.setHeader("some-header", "Editors");
    requestPatch2.setEntity(
            new StringEntity("INSERT { <> <" + title.getURI() + "> \"Different title\" . } WHERE {}"));
    requestPatch2.setHeader("Content-type", "application/sparql-update");
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(requestPatch2));
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:33,代码来源:WebACRecipesIT.java

示例15: scenario5

import org.apache.http.client.methods.HttpPatch; //导入方法依赖的package包/类
@Test
public void scenario5() throws IOException {
    final String idPublic = "/rest/mixedCollection/publicObj";
    final String idPrivate = "/rest/mixedCollection/privateObj";
    final String testObj = ingestObj("/rest/mixedCollection");
    final String publicObj = ingestObj(idPublic);
    final HttpPatch patch = patchObjMethod(idPublic);
    final String acl5 =
            ingestAcl("fedoraAdmin", "/acls/05/acl.ttl", "/acls/05/auth_open.ttl", "/acls/05/auth_restricted.ttl");
    linkToAcl(testObj, acl5);

    setAuth(patch, "fedoraAdmin");
    patch.setHeader("Content-type", "application/sparql-update");
    patch.setEntity(new StringEntity("INSERT { <> a <http://example.com/terms#publicImage> . } WHERE {}"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patch));

    final String privateObj = ingestObj(idPrivate);

    logger.debug("Anonymous can see eg:publicImage " + publicObj);
    final HttpGet requestGet = getObjMethod(idPublic);
    assertEquals(HttpStatus.SC_OK, getStatus(requestGet));

    logger.debug("Anonymous can't see other resource " + privateObj);
    final HttpGet requestGet2 = getObjMethod(idPrivate);
    assertEquals(HttpStatus.SC_FORBIDDEN, getStatus(requestGet2));

    logger.debug("Admins can see eg:publicImage " + publicObj);
    final HttpGet requestGet3 = getObjMethod(idPublic);
    setAuth(requestGet3, "jones");
    requestGet3.setHeader("some-header", "Admins");
    assertEquals(HttpStatus.SC_OK, getStatus(requestGet3));

    logger.debug("Admins can see others" + privateObj);
    final HttpGet requestGet4 = getObjMethod(idPrivate);
    setAuth(requestGet4, "jones");
    requestGet4.setHeader("some-header", "Admins");
    assertEquals(HttpStatus.SC_OK, getStatus(requestGet4));
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:39,代码来源:WebACRecipesIT.java


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