List of usage examples for org.apache.http.client.fluent Request Delete
public static Request Delete(final String uri)
From source file:org.elasticstore.server.integration.ItemIT.java
@Test public void testCreateRetrieveAndDeleteItem() throws Exception { final Item item = Fixtures.randomItem(); // create the item HttpResponse resp = executor//from w w w. j ava 2 s . com .execute(Request.Post(serverUrl + "/item").useExpectContinue() .bodyString(mapper.writeValueAsString(item), ContentType.APPLICATION_JSON)) .returnResponse(); assertEquals(201, resp.getStatusLine().getStatusCode()); // retrieve the item resp = executor.execute(Request.Get(serverUrl + "/item/" + item.getId()).useExpectContinue()) .returnResponse(); assertEquals(200, resp.getStatusLine().getStatusCode()); final Item fetched = mapper.readValue(resp.getEntity().getContent(), Item.class); assertEquals(item.getId(), fetched.getId()); assertEquals(item.getLabel(), fetched.getLabel()); assertNotNull(fetched.getCreated()); assertNotNull(fetched.getLastModified()); // delete the item resp = executor.execute(Request.Delete(serverUrl + "/item/" + item.getId()).useExpectContinue()) .returnResponse(); Assert.assertEquals(200, resp.getStatusLine().getStatusCode()); //retrieve the item again and assert a 404 resp = executor.execute(Request.Get(serverUrl + "/item/" + item.getId()).useExpectContinue()) .returnResponse(); assertEquals(404, resp.getStatusLine().getStatusCode()); }
From source file:org.springframework.ide.eclipse.boot.dash.ngrok.NGROKClient.java
private void shutdownTunnel(NGROKTunnel ngrokTunnel) { try {//from www. jav a 2 s . c om String deleteURL = process.getApiURL() + "/api/tunnels/" + URLEncoder.encode(ngrokTunnel.getName(), "UTF-8"); HttpResponse response = Request.Delete(deleteURL).execute().returnResponse(); if (response.getStatusLine().getStatusCode() != 204) { System.err.println("errro closing tunnel"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.ow2.proactive.procci.service.CloudAutomationVariablesClient.java
public void delete(String key) { logger.debug("delete " + key + " on " + requestUtils.getProperty(VARIABLES_ENDPOINT)); String url = getResourceUrl(key); try {/* ww w .j a va 2 s . c o m*/ HttpResponse response = Request.Delete(url).version(HttpVersion.HTTP_1_1).execute().returnResponse(); requestUtils.readHttpResponse(response, url, "DELETE"); } catch (IOException ex) { logger.error("Unable to delete on " + getQueryUrl(key) + ", exception : " + ex.getMessage()); throw new ServerException(); } }
From source file:io.coala.capability.online.FluentHCOnlineCapability.java
/** * @param method//from w w w . j av a 2s. c o m * @param uri * @return */ @SuppressWarnings("rawtypes") public static Request getFluentRequest(final HttpMethod method, final URI uri, final Map.Entry... formData) { final Request request; switch (method) { case GET: request = Request.Get(toFormDataURI(uri, formData)); break; case HEAD: request = Request.Head(toFormDataURI(uri, formData)); break; case POST: request = Request.Post(uri); break; case PUT: request = Request.Put(uri); break; case DELETE: request = Request.Delete(toFormDataURI(uri, formData)); break; case OPTIONS: request = Request.Options(toFormDataURI(uri, formData)); break; case TRACE: request = Request.Trace(toFormDataURI(uri, formData)); break; default: throw new IllegalStateException("UNSUPPORTED: " + method); } return request.useExpectContinue().version(HttpVersion.HTTP_1_1); }
From source file:org.schedulesdirect.api.json.DefaultJsonRequest.java
private Request initRequest() { Request r = null;//www . j a va 2 s . co m switch (action) { case GET: r = Request.Get(baseUrl); break; case PUT: r = Request.Put(baseUrl); break; case POST: r = Request.Post(baseUrl); break; case DELETE: r = Request.Delete(baseUrl); break; case OPTIONS: r = Request.Options(baseUrl); break; case HEAD: r = Request.Head(baseUrl); break; } return r.userAgent(userAgent); }
From source file:com.github.piotrkot.resources.CompilerResourceTest.java
/** * Appending logs should add them on the server. * @throws Exception If something fails. *//*from ww w . ja va 2s. c om*/ @Test public void testAppendLogs() throws Exception { final String req = "log"; final String mesg = "message"; final String uri = String.format("http://localhost:%d/compiler/logs/0", CompilerResourceTest.APP_RULE.getLocalPort()); Assert.assertTrue(HTTP_RESP_OK.contains( Request.Delete(uri).setHeader(OK_AUTH).execute().returnResponse().getStatusLine().getStatusCode())); Assert.assertTrue(HTTP_RESP_OK .contains(Request.Post(uri).setHeader(OK_AUTH).bodyForm(Form.form().add(req, mesg).build()) .execute().returnResponse().getStatusLine().getStatusCode())); Assert.assertTrue(HTTP_RESP_OK .contains(Request.Post(uri).setHeader(OK_AUTH).bodyForm(Form.form().add(req, mesg).build()) .execute().returnResponse().getStatusLine().getStatusCode())); Assert.assertEquals(Joiner.on(System.lineSeparator()).join(mesg, mesg), Request.Get(uri).setHeader(OK_AUTH).execute().returnContent().asString()); }
From source file:com.qwazr.database.TableSingleClient.java
@Override public Boolean removeColumn(String table_name, String column_name) { UBuilder uriBuilder = new UBuilder("/table/", table_name, "/column/", column_name); Request request = Request.Delete(uriBuilder.build()); return commonServiceRequest(request, null, null, Boolean.class, 200); }
From source file:edu.jhuapl.dorset.http.apache.ApacheHttpClient.java
private Response delete(HttpRequest request) throws IOException { Request apacheRequest = Request.Delete(request.getUrl()); prepareRequest(apacheRequest);/*from ww w . jav a2 s . c o m*/ return apacheRequest.execute(); }
From source file:com.ibm.streamsx.rest.StreamingAnalyticsConnection.java
/** * Cancels a job that has been submitted to IBM Streaming Analytcis service * * @param jobId/*from ww w .j a va2 s. c om*/ * string indicating the job id to be canceled * @return boolean indicating * <ul> * <li>true - if job is cancelled</li> * <li>false - if the job still exists</li> * </ul> * @throws IOException */ public boolean cancelJob(String jobId) throws IOException { boolean rc = false; String sReturn = ""; String deleteJob = jobsPath + "?job_id=" + jobId; Request request = Request.Delete(deleteJob).addHeader(AUTH.WWW_AUTH_RESP, apiKey).useExpectContinue(); Response response = executor.execute(request); HttpResponse hResponse = response.returnResponse(); int rcResponse = hResponse.getStatusLine().getStatusCode(); if (HttpStatus.SC_OK == rcResponse) { sReturn = EntityUtils.toString(hResponse.getEntity()); rc = true; } else { rc = false; } traceLog.finest("Request: [" + deleteJob + "]"); traceLog.finest(rcResponse + ": " + sReturn); return rc; }
From source file:es.uvigo.esei.dai.hybridserver.utils.TestUtils.java
/** * Realiza una peticin por DELETE y devuelve el cdigo de la respuesta HTTP. * /*from w w w .j ava2s . com*/ * La peticin se hace en UTF-8 y solicitando el cierre de la conexin. * * Este mtodo comprueba que el cdigo de respuesta HTTP sea 200 OK. * * @param url URL de la pgina solicitada. * @return cdigo de la respuesta HTTP. * @throws IOException en el caso de que se produzca un error de conexin. */ public static int deleteStatus(String url) throws IOException { return Request.Delete(url).addHeader("Connection", "close").addHeader("Content-encoding", "UTF-8").execute() .returnResponse().getStatusLine().getStatusCode(); }