当前位置: 首页>>代码示例>>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;未经允许,请勿转载。