List of usage examples for org.apache.commons.httpclient.methods DeleteMethod setRequestHeader
@Override public void setRequestHeader(String headerName, String headerValue)
From source file:org.apache.cloudstack.network.opendaylight.api.resources.Action.java
protected void executeDelete(final String uri) throws NeutronRestApiException { try {//from ww w . j ava2 s . c om validateCredentials(); } catch (NeutronInvalidCredentialsException e) { throw new NeutronRestApiException("Invalid credentials!", e); } NeutronRestFactory factory = NeutronRestFactory.getInstance(); NeutronRestApi neutronRestApi = factory.getNeutronApi(DeleteMethod.class); DeleteMethod deleteMethod = (DeleteMethod) neutronRestApi.createMethod(url, uri); try { deleteMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE); String encodedCredentials = encodeCredentials(); deleteMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials); neutronRestApi.executeMethod(deleteMethod); if (deleteMethod.getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage = responseToErrorMessage(deleteMethod); deleteMethod.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new NeutronRestApiException("Failed to create object : " + errorMessage); } } catch (NeutronRestApiException e) { s_logger.error( "NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } finally { deleteMethod.releaseConnection(); } }
From source file:org.collectionspace.services.IntegrationTests.xmlreplay.XmlReplayTransport.java
public static ServiceResult doDELETE(String urlString, String authForTest, String testID, String fromTestID) throws Exception { ServiceResult pr = new ServiceResult(); pr.failureReason = ""; pr.method = "DELETE"; pr.fullURL = urlString;//from www . jav a 2 s . c om pr.fromTestID = fromTestID; if (Tools.isEmpty(urlString)) { pr.error = "url was empty. Check the result for fromTestID: " + fromTestID + ". currentTest: " + testID; return pr; } HttpClient client = new HttpClient(); DeleteMethod deleteMethod = new DeleteMethod(urlString); deleteMethod.setRequestHeader("Accept", "multipart/mixed"); deleteMethod.addRequestHeader("Accept", "application/xml"); deleteMethod.setRequestHeader("Authorization", "Basic " + authForTest); deleteMethod.setRequestHeader("X-XmlReplay-fromTestID", fromTestID); int statusCode1 = 0; String res = ""; try { statusCode1 = client.executeMethod(deleteMethod); pr.responseCode = statusCode1; //System.out.println("statusCode: "+statusCode1+" statusLine ==>" + deleteMethod.getStatusLine()); pr.responseMessage = deleteMethod.getStatusText(); res = deleteMethod.getResponseBodyAsString(); deleteMethod.releaseConnection(); } catch (Throwable t) { pr.error = t.toString(); } pr.result = res; pr.responseCode = statusCode1; return pr; }
From source file:org.panlab.software.fci.uop.UoPGWClient.java
/** * It makes a DELETE towards the gateway * @author ctranoris//from ww w . ja v a 2s. c o m * @param resourceInstance sets the name of the resource Instance, e.g.: uop.rubis_db-27 * @param ptmAlias sets the name of the provider URI, e.g.: uop * @param content sets the name of the content; send in utf8 */ public void DELETEexecute(String resourceInstance, String ptmAlias, String content) { System.out.println("content body=" + "\n" + content); HttpClient client = new HttpClient(); String tgwcontent = content; // resource instance is like uop.rubis_db-6 so we need to make it like // this /uop/uop.rubis_db-6 String ptm = ptmAlias; String url = uopGWAddress + "/" + ptm + "/" + resourceInstance; System.out.println("Request: " + url); // Create a method instance. DeleteMethod delMethod = new DeleteMethod(url); delMethod.setRequestHeader("User-Agent", userAgent); delMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // Provide custom retry handler is necessary // delMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, // new DefaultHttpMethodRetryHandler(3, false)); // RequestEntity requestEntity = null; // try { // requestEntity = new StringRequestEntity(tgwcontent, // "application/x-www-form-urlencoded", "utf-8"); // } catch (UnsupportedEncodingException e1) { // e1.printStackTrace(); // } //delMethod.setRequestEntity(requestEntity); try { // Execute the method. int statusCode = client.executeMethod(delMethod); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + delMethod.getStatusLine()); } // Deal with the response. // Use caution: ensure correct character encoding and is not binary // data // print the status and response InputStream responseBody = delMethod.getResponseBodyAsStream(); CopyInputStream cis = new CopyInputStream(responseBody); response_stream = cis.getCopy(); System.out.println("Response body=" + "\n" + convertStreamToString(response_stream)); response_stream.reset(); // System.out.println("for address: " + url + " the response is:\n " // + post.getResponseBodyAsString()); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. delMethod.releaseConnection(); } }
From source file:org.wso2.carbon.appfactory.common.util.MutualAuthHttpClient.java
/** * Send REST DELETE request to stratos SM. * * @param endPointUrl end point to send the message * @throws org.wso2.carbon.appfactory.common.AppFactoryException *///from w w w.ja v a2s.c o m public static ServerResponse sendDeleteRequest(String endPointUrl, String username) throws AppFactoryException { HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); DeleteMethod deleteMethod = new DeleteMethod(endPointUrl); deleteMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue(username)); return send(httpClient, deleteMethod); }
From source file:org.wso2.carbon.appfactory.s4.integration.utils.DomainMappingUtils.java
/** * Send REST DELETE request to stratos SM. * * @param stage the stage of the Stratos SM * @param removeSubscriptionDomainEndPoint end point to send the message * @throws AppFactoryException/*from w w w . ja v a2 s .co m*/ */ public static DomainMappingResponse sendDeleteRequest(String stage, String removeSubscriptionDomainEndPoint) throws AppFactoryException { HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); String endPointUrl = getSMUrl(stage) + removeSubscriptionDomainEndPoint; DeleteMethod deleteMethod = new DeleteMethod(endPointUrl); deleteMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue()); return send(httpClient, deleteMethod); }
From source file:org.wso2.iot.integration.common.IOTHttpClient.java
public IOTResponse delete(String endpoint) { HttpClient client = new HttpClient(); try {// w ww .j av a2 s .co m ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT); Protocol.registerProtocol(Constants.HTTPS, https); String url = backEndUrl + endpoint; DeleteMethod method = new DeleteMethod(url); method.setRequestHeader(AUTHORIZATION, authorizationString); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); IOTResponse iotResponse = new IOTResponse(); iotResponse.setStatus(client.executeMethod(method)); iotResponse.setBody(method.getResponseBodyAsString()); return iotResponse; } catch (GeneralSecurityException e) { log.error("Failure occurred at IOTResponse delete for GeneralSecurityException", e); } catch (IOException e) { log.error("Failure occurred at IOTResponse delete for IOException", e); } return null; }
From source file:org.wso2.mdm.integration.common.MDMHttpClient.java
public MDMResponse delete(String endpoint) { HttpClient client = new HttpClient(); try {// w w w . j av a 2 s .c om ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); Protocol https = new Protocol("https", socketFactory, 9443); Protocol.registerProtocol("https", https); String url = backEndUrl + endpoint; DeleteMethod method = new DeleteMethod(url); method.setRequestHeader(AUTHORIZATION, authrizationString); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); MDMResponse mdmResponse = new MDMResponse(); mdmResponse.setStatus(client.executeMethod(method)); mdmResponse.setBody(method.getResponseBodyAsString()); return mdmResponse; } catch (GeneralSecurityException e) { log.error("Failure occurred at MDMResponse delete for GeneralSecurityException", e); } catch (IOException e) { log.error("Failure occurred at MDMResponse delete for IOException", e); } return null; }
From source file:terrastore.integration.IntegrationTest.java
private DeleteMethod makeDeleteMethod(int nodePort, String path) { DeleteMethod method = new DeleteMethod("http://" + HOST + ":" + nodePort + "/" + path); method.setRequestHeader("Content-Type", "application/json"); return method; }
From source file:terrastore.server.impl.JsonHttpServerTest.java
@Test public void testJsonErrorMessageOnInternalFail() throws Exception { UpdateService updateService = createMock(UpdateService.class); QueryService queryService = createMock(QueryService.class); BackupService backupService = createMock(BackupService.class); StatsService statsService = createMock(StatsService.class); updateService.removeBucket("bucket"); expectLastCall().andThrow(new UpdateOperationException(new ErrorMessage(500, "error"))).once(); replay(updateService, queryService, backupService, statsService); JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService); HttpClient client = new HttpClient(); DeleteMethod method = new DeleteMethod("http://localhost:8080/bucket"); method.setRequestHeader("Content-Type", "application/json"); client.executeMethod(method);/* w ww .ja v a 2 s . c o m*/ assertEquals(500, method.getStatusCode()); assertEquals(toJson(new ErrorMessage(500, "error")), method.getResponseBodyAsString()); method.releaseConnection(); stopServer(server); verify(updateService, queryService, backupService, statsService); }