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