本文整理汇总了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);
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
}
示例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());
}
示例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));
}
示例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;
}
}
示例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)));
}
示例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));
}
示例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;
}
示例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")));
}
}
示例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;
}