List of usage examples for org.apache.http.client.methods HttpPatch setEntity
public void setEntity(final HttpEntity entity)
From source file:org.fcrepo.it.BasicIT.java
private static void updateProperties(final String pid, final String sparql) throws IOException { final HttpPatch patch = new HttpPatch(getURIForPid(pid)); patch.setHeader("Content-type", "application/sparql-update"); patch.setEntity(new StringEntity(sparql)); Assert.assertEquals(204, getStatusCode(patch)); }
From source file:com.ecofactor.qa.automation.consumerapi.dr.HTTPSClient.java
/** * Patch response.//from w ww . j ava 2s . c om * * @param url the url * @param json the json * @param httpClient the http client * @return the http response */ public static synchronized HttpResponse patchResponse(final String url, final String json, final CloseableHttpClient httpClient) { try { checkHTTPClient(httpClient); final HttpPatch httpPatch = new HttpPatch(url); httpPatch.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); httpPatch.setHeader(HttpHeaders.ACCEPT, "application/json"); final StringEntity params = new StringEntity(json); httpPatch.setEntity(params); final CloseableHttpResponse response = httpClient.execute(httpPatch); setLogString("Status == " + response.getStatusLine(), true); return response; } catch (IOException | HTTPClientException e) { setLogString("Error executing HTTPS method. Reason ::: " + e, true); return null; } }
From source file:org.wso2.dss.integration.test.odata.ODataSuperTenantUserTestCase.java
private static int sendPATCH(String endpoint, String content, String acceptType) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpPatch httpPatch = new HttpPatch(endpoint); httpPatch.setHeader("Accept", acceptType); if (null != content) { HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8")); httpPatch.setHeader("Content-Type", "application/json"); httpPatch.setEntity(httpEntity); }//ww w . j av a 2 s . c o m HttpResponse httpResponse = httpClient.execute(httpPatch); return httpResponse.getStatusLine().getStatusCode(); }
From source file:org.megam.api.http.TransportMachinery.java
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()); }//from ww w . ja va2 s . c om } 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; }
From source file:org.wso2.dss.integration.test.odata.ODataTestUtils.java
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)); }/*from w w w . j a va 2 s . c o m*/ 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(); }
From source file:org.fcrepo.auth.xacml.XACMLTestUtil.java
/** * Removes the policy link from an object. * * @param client/*from w w w . j a v a 2 s. c o m*/ * @param serverAddress * @param objectPath * @throws Exception */ public static void unlinkPolicies(final HttpClient client, final String serverAddress, final String objectPath) throws Exception { final String subjectURI = serverAddress + objectPath; final HttpPatch patch = new HttpPatch(subjectURI); // setAuth(patch, "fedoraAdmin"); patch.addHeader("Content-Type", "application/sparql-update"); final BasicHttpEntity e = new BasicHttpEntity(); e.setContent(new ByteArrayInputStream(("DELETE { <" + subjectURI + "> <http://fedora.info/definitions/v4/authorization#policy> ?o } " + "WHERE { <" + subjectURI + "> <http://fedora.info/definitions/v4/authorization#policy> ?o }").getBytes())); patch.setEntity(e); LOGGER.debug("PATCH: {}", patch.getURI()); final HttpResponse response = client.execute(patch); assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine().getStatusCode()); }
From source file:org.fcrepo.integration.FedoraHtmlResponsesIT.java
License:asdf
private static void postSparqlUpdateUsingHttpClient(final String sparql, final String pid) throws IOException { final HttpPatch method = new HttpPatch(serverAddress + pid); method.addHeader(CONTENT_TYPE, "application/sparql-update"); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(sparql.getBytes())); method.setEntity(entity); final HttpResponse response = client.execute(method); assertEquals("Expected successful response.", 204, response.getStatusLine().getStatusCode()); }
From source file:org.fcrepo.integration.AbstractResourceIT.java
protected static void addMixin(final String pid, final String mixinUrl) throws IOException { final HttpPatch updateObjectGraphMethod = new HttpPatch(serverAddress + pid); updateObjectGraphMethod.addHeader(CONTENT_TYPE, "application/sparql-update"); final BasicHttpEntity e = new BasicHttpEntity(); e.setContent(new ByteArrayInputStream( ("INSERT DATA { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + mixinUrl + "> . } ") .getBytes()));//w w w. ja va 2 s . co m updateObjectGraphMethod.setEntity(e); final HttpResponse response = client.execute(updateObjectGraphMethod); assertEquals(NO_CONTENT.getStatusCode(), response.getStatusLine().getStatusCode()); }
From source file:com.redhat.refarch.microservices.warehouse.service.WarehouseService.java
public void fulfillOrder(Result result) throws Exception { HttpClient client = new DefaultHttpClient(); JSONObject jsonObject = new JSONObject(); jsonObject.put("status", "Shipped"); URIBuilder uriBuilder = new URIBuilder("http://gateway-service:9091/customers/" + result.getCustomerId() + "/orders/" + result.getOrderNumber()); HttpPatch patch = new HttpPatch(uriBuilder.build()); patch.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON)); logInfo("Executing " + patch); HttpResponse response = client.execute(patch); String responseString = EntityUtils.toString(response.getEntity()); logInfo("Got response " + responseString); }
From source file:de.devbliss.apitester.factory.impl.DefaultPatchFactory.java
public HttpPatch createPatchRequest(URI uri, Object payload) throws IOException { HttpPatch request = new HttpPatch(uri); if (payload != null) { request.setEntity(entityBuilder.buildEntity(payload)); }/*from w ww .j a va 2 s. c om*/ return request; }