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


Java HttpPatch.setEntity方法代碼示例

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


在下文中一共展示了HttpPatch.setEntity方法的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: 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

示例4: testPatchValidJson

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testPatchValidJson() throws Exception {
	String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
	HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
	httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_JSON_PATCH)));
	CloseableHttpResponse status = ourClient.execute(httpPatch);

	try {
		String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
		ourLog.info(responseContent);
		assertEquals(200, status.getStatusLine().getStatusCode());
		assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">OK</div></text></OperationOutcome>", responseContent);
	} finally {
		IOUtils.closeQuietly(status.getEntity().getContent());
	}

	assertEquals("patientPatch", ourLastMethod);
	assertEquals("Patient/123", ourLastId.getValue());
	assertEquals(requestContents, ourLastBody);
	assertEquals(PatchTypeEnum.JSON_PATCH, ourLastPatchType);
}
 
開發者ID:jamesagnew,項目名稱:hapi-fhir,代碼行數:22,代碼來源:PatchDstu3Test.java

示例5: testPatchValidXml

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testPatchValidXml() throws Exception {
	String requestContents = "<root/>";
	HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
	httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_XML_PATCH)));
	CloseableHttpResponse status = ourClient.execute(httpPatch);

	try {
		String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
		ourLog.info(responseContent);
		assertEquals(200, status.getStatusLine().getStatusCode());
		assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">OK</div></text></OperationOutcome>", responseContent);
	} finally {
		IOUtils.closeQuietly(status.getEntity().getContent());
	}

	assertEquals("patientPatch", ourLastMethod);
	assertEquals("Patient/123", ourLastId.getValue());
	assertEquals(requestContents, ourLastBody);
	assertEquals(PatchTypeEnum.XML_PATCH, ourLastPatchType);
}
 
開發者ID:jamesagnew,項目名稱:hapi-fhir,代碼行數:22,代碼來源:PatchDstu3Test.java

示例6: testPatchValidJsonWithCharset

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testPatchValidJsonWithCharset() throws Exception {
	String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
	HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
	httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_JSON_PATCH + Constants.CHARSET_UTF8_CTSUFFIX)));
	CloseableHttpResponse status = ourClient.execute(httpPatch);

	try {
		String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
		ourLog.info(responseContent);
		assertEquals(200, status.getStatusLine().getStatusCode());
	} finally {
		IOUtils.closeQuietly(status.getEntity().getContent());
	}

	assertEquals("patientPatch", ourLastMethod);
	assertEquals("Patient/123", ourLastId.getValue());
	assertEquals(requestContents, ourLastBody);
}
 
開發者ID:jamesagnew,項目名稱:hapi-fhir,代碼行數:20,代碼來源:PatchDstu3Test.java

示例7: testPatchInvalidMimeType

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testPatchInvalidMimeType() throws Exception {
	String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
	HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
	httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse("text/plain; charset=UTF-8")));
	CloseableHttpResponse status = ourClient.execute(httpPatch);

	try {
		String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
		ourLog.info(responseContent);
		assertEquals(400, status.getStatusLine().getStatusCode());
		assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><issue><severity value=\"error\"/><code value=\"processing\"/><diagnostics value=\"Invalid Content-Type for PATCH operation: text/plain; charset=UTF-8\"/></issue></OperationOutcome>", responseContent);
	} finally {
		IOUtils.closeQuietly(status.getEntity().getContent());
	}

}
 
開發者ID:jamesagnew,項目名稱:hapi-fhir,代碼行數:18,代碼來源:PatchDstu3Test.java

示例8: testUpdateEntity

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
public void testUpdateEntity() throws Exception {
  String payload = "{" + 
      "  \"Emails\":[" + 
      "     \"[email protected]\"," +
      "     \"[email protected]\"" +        
      "         ]" + 
      "}";
  HttpPatch updateRequest = new HttpPatch(baseURL+"/People('kristakemp')");
  updateRequest.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
  httpSend(updateRequest, 204);
  
  HttpResponse response = httpGET(baseURL + "/People('kristakemp')", 200);
  JsonNode node = getJSONNode(response);
  assertEquals("$metadata#People/$entity", node.get("@odata.context").asText());
  assertEquals("[email protected]", node.get("Emails").get(0).asText());
  assertEquals("[email protected]", node.get("Emails").get(1).asText());
}
 
開發者ID:apache,項目名稱:olingo-odata4,代碼行數:19,代碼來源:TripPinServiceTest.java

示例9: testNoPatchSupport

import org.apache.http.client.methods.HttpPatch; //導入方法依賴的package包/類
@Test
@Category({
	ExceptionPath.class
})
@OperateOnDeployment(DEPLOYMENT)
public void testNoPatchSupport(@ArquillianResource final URL url) throws Exception {
	LOGGER.info("Started {}",testName.getMethodName());
	HELPER.base(url);
	HELPER.setLegacy(false);

	HttpPatch patch = HELPER.newRequest(MyApplication.ROOT_PERSON_CONTAINER_PATH,HttpPatch.class);
	patch.setEntity(
		new StringEntity(
			TEST_SUITE_BODY,
			ContentType.create("text/turtle", "UTF-8"))
	);
	Metadata patchResponse=HELPER.httpRequest(patch);
	assertThat(patchResponse.status,equalTo(HttpStatus.SC_METHOD_NOT_ALLOWED));
	assertThat(patchResponse.body,notNullValue());
	assertThat(patchResponse.contentType,startsWith("text/plain"));
	assertThat(patchResponse.language,equalTo(Locale.ENGLISH));
}
 
開發者ID:ldp4j,項目名稱:ldp4j,代碼行數:23,代碼來源:ServerFrontendITest.java

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

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

示例12: testRegisterNamespace

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

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

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "user13");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity("PREFIX novel: <info://" + getRandomUniqueId() + ">\n"
            + "INSERT DATA { <> novel:value 'test' }"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));
}
 
開發者ID:fcrepo4,項目名稱:fcrepo4,代碼行數:17,代碼來源:WebACRecipesIT.java

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

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

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


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