List of usage examples for org.apache.http.client.methods HttpPatch HttpPatch
public HttpPatch(final String uri)
From source file:org.fcrepo.integration.http.api.AbstractResourceIT.java
protected static HttpPatch patchObjMethod(final String id) { return new HttpPatch(serverAddress + id); }
From source file:com.logsniffer.event.publisher.http.HttpPublisher.java
@Override public void publish(final Event event) throws PublishException { VelocityContext vCtx = velocityRenderer.getContext(event); String eventUrl = velocityRenderer.render(url, vCtx); HttpRequestBase request = null;/*w w w . j a v a2s .c om*/ switch (method) { case GET: request = new HttpGet(eventUrl); break; case POST: request = new HttpPost(eventUrl); addBody((HttpPost) request, vCtx); break; case PUT: request = new HttpPut(eventUrl); addBody((HttpPut) request, vCtx); break; case DELETE: request = new HttpDelete(eventUrl); break; case HEAD: request = new HttpHead(eventUrl); break; case OPTIONS: request = new HttpOptions(eventUrl); break; case PATCH: request = new HttpPatch(eventUrl); break; case TRACE: request = new HttpTrace(eventUrl); break; } httpAddons(request, event); try { logger.debug("Publishing event {} via HTTP '{}'", event.getId(), request); HttpResponse response = httpClient.execute(request, httpContext); if (response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() < 300) { logger.debug("Published event {} successfuly via HTTP '{}' with status: {}", event.getId(), request, response.getStatusLine().getStatusCode()); } else { logger.warn("Failed to publish event {} via HTTP '{}' due to status: {} - {}", event.getId(), request, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); throw new PublishException("Got errornuous HTTP status for pubslihed event: " + response.getStatusLine().getStatusCode()); } } catch (Exception e) { throw new PublishException("Failed to publish event " + event.getId() + " via HTTP", e); } }
From source file:org.fcrepo.integration.connector.file.FileConnectorIT.java
/** * I should be able to link to content on a federated filesystem. * * @throws IOException thrown during this function **//*from ww w .j a v a 2s . c o m*/ @Test public void testFederatedDatastream() throws IOException { final String federationAddress = serverAddress + "files/FileSystem1/ds1"; final String linkingAddress; try (final CloseableHttpResponse response = client.execute(new HttpPost(serverAddress))) { EntityUtils.consume(response.getEntity()); linkingAddress = response.getFirstHeader("Location").getValue(); } // link from the object to the content of the file on the federated filesystem final HttpPatch patch = new HttpPatch(linkingAddress); patch.addHeader("Content-Type", "application/sparql-update"); patch.setEntity(new ByteArrayEntity(("INSERT DATA { <> <http://some-vocabulary#hasExternalContent> " + "<" + federationAddress + "> . }").getBytes())); assertEquals("Couldn't link to external datastream!", NO_CONTENT.getStatusCode(), getStatus(patch)); }
From source file:com.blazemeter.bamboo.plugin.api.HttpUtility.java
public <V> HttpResponse httpResponse(String url, V data, Method method) throws IOException { if (StringUtils.isBlank(url)) return null; logger.info("Requesting : " + url.substring(0, url.indexOf("?") + 14)); HttpResponse response = null;// w w w. j a va2 s . c om HttpRequestBase request = null; try { if (method == Method.GET) { request = new HttpGet(url); } else if (method == Method.POST) { request = new HttpPost(url); if (data != null) { ((HttpPost) request).setEntity(new StringEntity(data.toString())); } } else if (method == Method.PUT) { request = new HttpPut(url); if (data != null) { ((HttpPut) request).setEntity(new StringEntity(data.toString())); } } else if (method == Method.PATCH) { request = new HttpPatch(url); if (data != null) { ((HttpPatch) request).setEntity(new StringEntity(data.toString())); } } else { throw new RuntimeException("Unsupported method: " + method.toString()); } request.setHeader("Accept", "application/json"); request.setHeader("Content-type", "application/json; charset=UTF-8"); if (proxy != null) { RequestConfig conf = RequestConfig.custom().setProxy(proxy).build(); request.setConfig(conf); } response = this.httpClient.execute(request); if (response == null || response.getStatusLine() == null) { logger.info("Erroneous response (Probably null) for url: \n" + url); response = null; } } catch (Exception e) { logger.error("Problems with creating and sending request: \n", e); } return response; }
From source file:com.ksc.http.apache.request.impl.ApacheHttpRequestFactory.java
private HttpRequestBase createApacheRequest(Request<?> request, String uri, String encodedParams) throws FakeIOException { switch (request.getHttpMethod()) { case HEAD:// w w w .j av a2s . c o m return new HttpHead(uri); case GET: return new HttpGet(uri); case DELETE: return new HttpDelete(uri); case PATCH: return wrapEntity(request, new HttpPatch(uri), encodedParams); case POST: return wrapEntity(request, new HttpPost(uri), encodedParams); case PUT: return wrapEntity(request, new HttpPut(uri), encodedParams); default: throw new KscClientException("Unknown HTTP method name: " + request.getHttpMethod()); } }
From source file:org.datagator.api.client.backend.DataGatorService.java
public CloseableHttpResponse patch(String endpoint, InputStream data, ContentType ctype) throws URISyntaxException, IOException { HttpPatch request = new HttpPatch(buildServiceURI(endpoint)); if (data != null) { HttpEntity entity = new InputStreamEntity(data, ctype); request.setEntity(entity);//from w ww. j a va 2 s. c o m } return http.execute(request, context); }
From source file:com.microsoft.services.odata.unittests.WireMockTestClient.java
public WireMockResponse patchWithBody(String url, String body, String contentType, TestHttpHeader... headers) throws UnsupportedEncodingException { HttpPatch httpPatch = new HttpPatch(mockServiceUrlFor(url)); return requestWithBody(httpPatch, body, contentType, headers); }
From source file:com.precioustech.fxtrading.oanda.restapi.order.OandaOrderManagementProvider.java
HttpPatch createPatchCommand(Order<String, Long> order, Long accountId) throws Exception { HttpPatch httpPatch = new HttpPatch(orderForAccountUrl(accountId, order.getOrderId())); httpPatch.setHeader(this.authHeader); List<NameValuePair> params = Lists.newArrayList(); params.add(new BasicNameValuePair(takeProfit, String.valueOf(order.getTakeProfit()))); params.add(new BasicNameValuePair(stopLoss, String.valueOf(order.getStopLoss()))); params.add(new BasicNameValuePair(units, String.valueOf(order.getUnits()))); params.add(new BasicNameValuePair(price, String.valueOf(order.getPrice()))); httpPatch.setEntity(new UrlEncodedFormEntity(params)); return httpPatch; }
From source file:org.fcrepo.client.impl.FedoraResourceImplTest.java
@Test public void testUpdatePropertiesSPARQL() throws Exception { final HttpResponse mockResponse = mock(HttpResponse.class); final StatusLine mockStatus = mock(StatusLine.class); final HttpPatch patch = new HttpPatch(repositoryURL); when(mockHelper.execute(any(HttpPatch.class))).thenReturn(mockResponse); when(mockResponse.getStatusLine()).thenReturn(mockStatus); when(mockStatus.getStatusCode()).thenReturn(204); when(mockHelper.createPatchMethod(anyString(), anyString())).thenReturn(patch); resource.updateProperties("test sparql update"); verify(mockHelper).execute(patch);/*from ww w . j ava 2 s. com*/ verify(mockHelper).loadProperties(resource); }