當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpPatch.addHeader方法代碼示例

本文整理匯總了Java中org.apache.http.client.methods.HttpPatch.addHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpPatch.addHeader方法的具體用法?Java HttpPatch.addHeader怎麽用?Java HttpPatch.addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.methods.HttpPatch的用法示例。


在下文中一共展示了HttpPatch.addHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: modifyAccount

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
/**
 * Given an Account object, modifies an account.
 * This can only be used when a child account is specified by email, id or creatorRef.
 *
 * @param accountInfo account object. Requires atleast one value set.
 * Having id set will throw an exception, unless set to -1.
 * @return Whoami object of the modified account.
 * @throws IOException if HTTP client is given bad values
 * @see Account
 * @see Whoami
 * */
public final Whoami modifyAccount(final Account accountInfo) throws IOException {
    CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credentials).build();
    Whoami account;
    try {
        HttpPatch httppost = new HttpPatch(apiUrl + "/account/");
        httppost.addHeader(childHeaders[0], childHeaders[1]);
        httppost.addHeader("Content-Type", "application/json");
        Gson gson = gsonWithAdapters();
        String json = gson.toJson(accountInfo);
        StringEntity jsonEntity = new StringEntity(json);
        httppost.setEntity(jsonEntity);
        CloseableHttpResponse response = client.execute(httppost);
        try {
            JsonObject responseParse = responseToJsonElement(response).getAsJsonObject();
            account = new Whoami(responseParse);
        } finally {
            response.close();
        }
    } finally {
        client.close();
    }
    return account;
}
 
開發者ID:PrintNode,項目名稱:PrintNode-Java,代碼行數:35,代碼來源:APIClient.java

示例2: casePatchFromConnect

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
private HttpResponse casePatchFromConnect(List<NameValuePair> queryParameters, String url, String method, StringEntity input, String encodedString) throws URISyntaxException, IOException {
	URIBuilder putBuilder = new URIBuilder(url);
	if(queryParameters != null) {
		putBuilder.setParameters(queryParameters);
	}
	HttpPatch patch = new HttpPatch(putBuilder.build());
	patch.setEntity(input);
	patch.addHeader("Content-Type", "application/json");
	patch.addHeader("Accept", "application/json");
	patch.addHeader("Authorization", "Basic " + encodedString);
	try {
		HttpClient client = HttpClientBuilder.create().useSystemProperties().setSslcontext(sslContext).build();
		return client.execute(patch);
	} catch (IOException e) {
		LoggerUtility.warn(CLASS_NAME, method, e.getMessage());
		throw e;
	} 

}
 
開發者ID:ibm-watson-iot,項目名稱:iot-java,代碼行數:20,代碼來源:APIClient.java

示例3: doPatchRequest

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
/**
 * Calls a http Patch with given {@link URI} and returns the response.
 * 
 * @param uri
 * @return
 */
@VisibleForTesting
String doPatchRequest(URI uri) {
   CloseableHttpClient httpclient = null;
   CloseableHttpResponse response = null;
   String responseAsString = "";
   try {
      httpclient = HttpClients.createDefault();
      HttpPatch httpPatch = new HttpPatch(uri);
      httpPatch.addHeader("Content-type", "application/json");
      httpPatch.addHeader("Authorization", statuspageApiKey);
      response = httpclient.execute(httpPatch);
      responseAsString = IOUtils.toString(response.getEntity().getContent());
   } catch (Exception e) {
      logger.error(e.getMessage(), e);
   } finally {
      IOUtils.closeQuietly(httpclient);
      IOUtils.closeQuietly(response);
   }

   return responseAsString;
}
 
開發者ID:shopping24,項目名稱:pagerDutySynchronizer,代碼行數:28,代碼來源:DefaultStatusPageIODao.java

示例4: testInvalidAccessControlLink

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testInvalidAccessControlLink() throws IOException {
    final String id = "/rest/" + getRandomUniqueId();
    ingestObj(id);

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "fedoraAdmin");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity(
            "INSERT { <> <" + WEBAC_ACCESS_CONTROL_VALUE + "> \"/rest/acl/badAclLink\" . } WHERE {}"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));

    final HttpGet getReq = getObjMethod(id);
    setAuth(getReq, "fedoraAdmin");
    assertEquals("Non-URI accessControl property did not throw Exception", HttpStatus.SC_BAD_REQUEST,
            getStatus(getReq));
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:18,代碼來源:WebACRecipesIT.java

示例5: testEmbeddedChildResources

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testEmbeddedChildResources() throws IOException {
    final String id = getRandomUniqueId();
    final String binaryId = "binary0";

    assertEquals(CREATED.getStatusCode(), getStatus(putObjMethod(id)));
    assertEquals(CREATED.getStatusCode(), getStatus(putDSMethod(id, binaryId, "some test content")));

    final HttpPatch httpPatch = patchObjMethod(id + "/" + binaryId + "/fcr:metadata");
    httpPatch.addHeader(CONTENT_TYPE, "application/sparql-update");
    httpPatch.setEntity(new StringEntity(
            "INSERT { <> <http://purl.org/dc/elements/1.1/title> 'this is a title' } WHERE {}"));
    assertEquals(NO_CONTENT.getStatusCode(), getStatus(httpPatch));

    final HttpGet httpGet = getObjMethod(id);
    httpGet.setHeader("Prefer",
            "return=representation; include=\"http://fedora.info/definitions/v4/repository#EmbedResources\"");
    try (final CloseableDataset dataset = getDataset(httpGet)) {
        final DatasetGraph graphStore = dataset.asDatasetGraph();
        assertTrue("Property on child binary should be found!" + graphStore, graphStore.contains(ANY,
                createURI(serverAddress + id + "/" + binaryId),
                createURI("http://purl.org/dc/elements/1.1/title"), createLiteral("this is a title")));
    }
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:25,代碼來源:FedoraLdpIT.java

示例6: testRegisterNodeType

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testRegisterNodeType() throws IOException {
    final String testObj = ingestObj("/rest/test_nodetype");
    final String acl1 = ingestAcl("fedoraAdmin", "/acls/14/acl.ttl", "/acls/14/authorization.ttl");
    linkToAcl(testObj, acl1);

    final String id = "/rest/test_nodetype/" + getRandomUniqueId();
    ingestObj(id);

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "user14");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity("PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "INSERT DATA { <> rdf:type dc:type }"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:18,代碼來源:WebACRecipesIT.java

示例7: testLinkedDeletion

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testLinkedDeletion() {
    final String linkedFrom = getRandomUniqueId();
    final String linkedTo = getRandomUniqueId();
    createObjectAndClose(linkedFrom);
    createObjectAndClose(linkedTo);

    final String sparql =
            "INSERT DATA { <" + serverAddress + linkedFrom + "> " +
                    "<http://some-vocabulary#isMemberOfCollection> <" + serverAddress + linkedTo + "> . }";
    final HttpPatch patch = patchObjMethod(linkedFrom);
    patch.addHeader(CONTENT_TYPE, "application/sparql-update");
    patch.setEntity(new ByteArrayEntity(sparql.getBytes(UTF_8)));
    assertEquals("Couldn't link resources!", NO_CONTENT.getStatusCode(), getStatus(patch));
    assertEquals("Error deleting linked-to!", NO_CONTENT.getStatusCode(), getStatus(deleteObjMethod(linkedTo)));
    assertEquals("Linked to should still exist!", OK.getStatusCode(), getStatus(getObjMethod(linkedFrom)));
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:18,代碼來源:FedoraLdpIT.java

示例8: testUpdateObjectGraphWithNonLocalTriples

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testUpdateObjectGraphWithNonLocalTriples() throws IOException {
    final String pid = getRandomUniqueId();
    createObject(pid);
    final String otherPid = getRandomUniqueId();
    createObject(otherPid);
    final String location = serverAddress + pid;
    final String otherLocation = serverAddress + otherPid;
    final HttpPatch updateObjectGraphMethod = new HttpPatch(location);
    updateObjectGraphMethod.addHeader(CONTENT_TYPE, "application/sparql-update");
    updateObjectGraphMethod.setEntity(new StringEntity("INSERT { <" + location +
            "> <http://purl.org/dc/elements/1.1/identifier> \"this is an identifier\". " + "<" + otherLocation +
            "> <http://purl.org/dc/elements/1.1/identifier> \"this is an identifier\"" + " } WHERE {}"));
    assertEquals("It ought not be possible to use PATCH to create non-local triples!",
            FORBIDDEN.getStatusCode(),getStatus(updateObjectGraphMethod));
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:17,代碼來源:FedoraLdpIT.java

示例9: testPatchBinaryDescriptionWithBinaryProperties

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
/**
 * Descriptions of bitstreams contain only triples about the described thing, so only triples with the described
 * thing as their subject are legal.
 *
 * @throws IOException on error
 */
@Test
public void testPatchBinaryDescriptionWithBinaryProperties() throws IOException {
    final String id = getRandomUniqueId();
    createDatastream(id, "x", "some content");
    final String resource = serverAddress + id;
    final String location = resource + "/x/fcr:metadata";

    final HttpPatch patch = new HttpPatch(location);
    patch.addHeader(CONTENT_TYPE, "application/sparql-update");
    patch.setEntity(new StringEntity("INSERT { <" +
            resource + "/x>" + " <" + DC_IDENTIFIER + "> \"identifier\" } WHERE {}"));
    try (final CloseableHttpResponse response = execute(patch)) {
        assertEquals(NO_CONTENT.getStatusCode(), getStatus(response));
        try (final CloseableDataset dataset = getDataset(new HttpGet(location))) {
            final DatasetGraph graph = dataset.asDatasetGraph();
            assertTrue(graph.contains(ANY,
                    createURI(resource + "/x"), DC_IDENTIFIER, createLiteral("identifier")));
        }
    }
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:27,代碼來源:FedoraLdpIT.java

示例10: testPatchWithBlankNode

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testPatchWithBlankNode() throws Exception {
    final String id = getRandomUniqueId();
    createObjectAndClose(id);

    final String location = serverAddress + id;
    final HttpPatch updateObjectGraphMethod = patchObjMethod(id);
    updateObjectGraphMethod.addHeader(CONTENT_TYPE, "application/sparql-update");
    updateObjectGraphMethod.setEntity(new StringEntity("INSERT { <" +
            location + "> <info:some-predicate> _:a .\n " +
            "_:a <http://purl.org/dc/elements/1.1/title> \"this is a title\"\n" + " } WHERE {}"));
    assertEquals(NO_CONTENT.getStatusCode(), getStatus(updateObjectGraphMethod));

    try (final CloseableDataset dataset = getDataset(new HttpGet(location))) {
        final DatasetGraph graphStore = dataset.asDatasetGraph();
        assertTrue(graphStore.contains(ANY, createURI(location), createURI("info:some-predicate"), ANY));
        final Node bnode = graphStore.find(ANY,
                createURI(location), createURI("info:some-predicate"), ANY).next().getObject();
        try (final CloseableDataset dataset2 = getDataset(new HttpGet(bnode.getURI()))) {
            assertTrue(dataset2.asDatasetGraph().contains(ANY, bnode, DCTITLE, createLiteral("this is a title")));
        }
    }
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:24,代碼來源:FedoraLdpIT.java

示例11: patch

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Override
public boolean patch(DeviceId device, String request, InputStream payload, String mediaType) {
    try {
        log.debug("Url request {} ", getUrlString(device, request));
        HttpPatch httprequest = new HttpPatch(getUrlString(device, request));
        if (deviceMap.get(device).username() != null) {
            String pwd = deviceMap.get(device).password() == null ? "" : COLON + deviceMap.get(device).password();
            String userPassword = deviceMap.get(device).username() + pwd;
            String base64string = Base64.getEncoder().encodeToString(userPassword.getBytes(StandardCharsets.UTF_8));
            httprequest.addHeader(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + base64string);
        }
        if (payload != null) {
            StringEntity input = new StringEntity(IOUtils.toString(payload, StandardCharsets.UTF_8));
            input.setContentType(mediaType);
            httprequest.setEntity(input);
        }
        CloseableHttpClient httpClient;
        if (deviceMap.containsKey(device) && deviceMap.get(device).protocol().equals(HTTPS)) {
            httpClient = getApacheSslBypassClient();
        } else {
            httpClient = HttpClients.createDefault();
        }
        int responseStatusCode = httpClient
                .execute(httprequest)
                .getStatusLine()
                .getStatusCode();
        return checkStatusCode(responseStatusCode);
    } catch (IOException | NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
        log.error("Cannot do PATCH {} request on device {}",
                  request, device, e);
    }
    return false;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:34,代碼來源:RestSBControllerImpl.java

示例12: modifyClientDownloads

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
/**
 * Given a set of clients, such as "10-15" or "10,11,13" or just "10",
 * will set whether clients in the set are enabled.
 * If you are unsure what is possible for clientSet, check the PrintNode API docs on printnode.com.
 *
 * @param clientSet set of clients as a string.
 * @param enabled whether you are disabling or enabling the clients.
 * @return An array of ids relative to clients with changed values.
 * @throws IOException if HTTP client is given bad values
 * */
public final int[] modifyClientDownloads(final String clientSet, final boolean enabled) throws IOException {
    CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credentials).build();
    int[] results;
    try {
        HttpPatch httppost = new HttpPatch(apiUrl + "/download/clients/" + clientSet);
        httppost.addHeader(childHeaders[0], childHeaders[1]);
        httppost.addHeader("Content-Type", "application/json");
        Gson gson = gsonWithAdapters();
        JsonObject jObject = new JsonObject();
        jObject.addProperty("enabled", enabled);
        String json = gson.toJson(jObject);
        StringEntity jsonEntity = new StringEntity(json);
        httppost.setEntity(jsonEntity);
        CloseableHttpResponse response = client.execute(httppost);
        try {
            JsonArray responseParse = responseToJsonElement(response).getAsJsonArray();
            results = new int[responseParse.size()];
            for (int i = 0; i < responseParse.size(); i++) {
                results[i] = responseParse.get(i).getAsInt();
            }
        } finally {
            response.close();
        }
    } finally {
        client.close();
    }
    return results;
}
 
開發者ID:PrintNode,項目名稱:PrintNode-Java,代碼行數:39,代碼來源:APIClient.java

示例13: 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

示例14: patch

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
public static TransportResponse patch(TransportTools nuts)
		throws ClientProtocolException, IOException {

	DefaultHttpClient httpclient = new DefaultHttpClient();
	HttpPatch httppatch = new HttpPatch(nuts.urlString());

	if (nuts.headers() != null) {
		for (Map.Entry<String, String> headerEntry : nuts.headers().entrySet()) {
			httppatch.addHeader(headerEntry.getKey(), headerEntry.getValue());
		}
	}
	
	if (nuts.pairs() != null && (nuts.contentType() ==null)) {
		httppatch.setEntity(new UrlEncodedFormEntity(nuts.pairs()));
	}
	
	if (nuts.contentType() !=null) {
		httppatch.setEntity(new StringEntity(nuts.contentString(),nuts.contentType()));
	}

	TransportResponse transportResp = null;
	try {
		  httpclient.execute(httppatch);
		//transportResp = new TransportResponse(httpResp.getStatusLine(), httpResp.getEntity(), httpResp.getLocale());
	} finally {
		httppatch.releaseConnection();
	}
	return transportResp;

}
 
開發者ID:megamsys,項目名稱:megam_api_jvm,代碼行數:31,代碼來源:TransportMachinery.java

示例15: patch

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Override
public JsonObject patch(String path, JsonObject body) throws HttpResponseException, IOException {
    HttpPatch request = new HttpPatch(url(path));

    // see
    // https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#patch-operations
    request.addHeader(HttpHeaders.CONTENT_TYPE, "application/merge-patch+json");
    request.setEntity(new StringEntity(JsonUtils.toString(body)));
    HttpRequestResponse response = client().execute(request);
    return bodyAsJsonObjectOrNull(response);

}
 
開發者ID:elastisys,項目名稱:scale.cloudpool,代碼行數:13,代碼來源:StandardApiServerClient.java


注:本文中的org.apache.http.client.methods.HttpPatch.addHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。