Search in sources :

Example 96 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project sling by apache.

the class AbstractHtmlClientImpl method delete.

@Override
public <T extends Document> T delete(String url) throws ClientException {
    try {
        URI absoluteUri = absoluteUri(url);
        LOG.info("DELETE " + absoluteUri);
        HttpResponse response = this.execute(new HttpDelete(absoluteUri));
        return newDocument(response.getEntity().toString());
    } catch (URISyntaxException e) {
        throw new ClientException("Invalid post url " + url, e);
    } catch (Exception e) {
        throw new ClientException("Could not execute DELETE request", e);
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) URISyntaxException(java.net.URISyntaxException) ClientException(org.apache.sling.hapi.client.ClientException) URI(java.net.URI) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) ClientException(org.apache.sling.hapi.client.ClientException) IOException(java.io.IOException)

Example 97 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project cdap by caskdata.

the class AppFabricTestBase method doDelete.

protected static HttpResponse doDelete(String resource) throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpDelete delete = new HttpDelete(getEndPoint(resource));
    delete.setHeader(AUTH_HEADER);
    return client.execute(delete);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 98 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project iTest by e-government-ua.

the class DeleteTask method methodDelete.

public void methodDelete(String ID) throws Exception {
    if (configVariables.baseUrl.contains("alpha.test.igov.org.ua")) {
        Url = "https://alpha.test.region.igov.org.ua";
    } else if (configVariables.baseUrl.contains("beta.test.igov.org.ua")) {
        Url = "https://beta.test.region.igov.org.ua";
    } else if (configVariables.baseUrl.contains("beta-old.test.igov.org.ua")) {
        Url = "https://beta-old.test.region.igov.org.ua";
    } else if (configVariables.baseUrl.contains("delta.test.igov.org.ua")) {
        Url = "https://delta.test.region.igov.org.ua";
    } else {
        throw new Exception("ERROR URL ");
    }
    /*
        switch (configVariables.baseUrl) {
            case "https://alpha.test.igov.org.ua":
                Url ="https://alpha.test.region.igov.org.ua";
                break;

            case "https://beta.test.igov.org.ua":
                Url ="https://beta.test.region.igov.org.ua";
                break;

        case "https://beta-old.test.igov.org.ua":
                Url ="https://beta-old.test.region.igov.org.ua";
                break;

        case "https://delta.test.igov.org.ua":
                Url ="https://delta.test.region.igov.org.ua";
                break;

            default:
                throw new Exception("ERROR URL ");
    }
        */
    String patch = "/wf/service/action/task/delete-process?nID_Order=";
    String IdOrder = ID;
    String urlDelete = Url + patch + IdOrder;
    System.out.println("\nSending 'delete' request to URL : " + urlDelete);
    HttpResponse response = null;
    try {
        HttpClient client = createHttpClient_AcceptsUntrustedCerts();
        HttpDelete httpDelete = new HttpDelete(urlDelete);
        httpDelete.addHeader("Content-Type", "application/json");
        httpDelete.addHeader("Authorization", "Basic a2VybWl0Omtlcm1pdA==");
        response = client.execute(httpDelete);
        System.out.println("response: " + response);
    } catch (Exception oException) {
        System.err.println("Cant 'delete' " + urlDelete + "):" + oException.getMessage());
        throw new Exception("Cant 'delete' " + urlDelete + "):" + oException.getMessage());
    //throw oException;
    }
    //        HttpResponse response = Request.Post(url).stringBody("request_body","content_type").execute().returnResponse();
    //        JSONObject jsonResponse = new JSONObject(IOUtils.toString(response.getEntity().getContent()));
    //        JSONArray jsonResponse = new JSONArray(IOUtils.toString(response.getEntity().getContent()));
    //        JSONObject jsonResponse = new JSONObject(IOUtils.toString(response.getEntity().getContent()));
    //
    //        System.out.println("Response Code : " +
    //                response.getStatusLine().getStatusCode());
    //
    //        System.out.print("RESP Body :"+ jsonResponse);
    System.out.println("\nSending 'delete' request to URL : " + urlDelete);
    System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    System.out.println("rd: " + rd);
    StringBuffer result = new StringBuffer();
    System.out.println("result: " + result);
    String line = "";
    while ((line = rd.readLine()) != null) {
        System.out.println("line = rd.readLine(): " + rd.readLine());
        result.append(line);
        System.out.println("result.append(line): " + result.append(line));
    }
    System.out.println("result.toString(): " + result.toString());
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) InputStreamReader(java.io.InputStreamReader) HttpClient(org.apache.http.client.HttpClient) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) KeyManagementException(java.security.KeyManagementException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 99 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project dhis2-core by dhis2.

the class HttpUtils method httpDELETE.

/**
     * <pre>
     * <b>Description : </b>
     * Method to make an http DELETE call to a given URL with/without authentication.
     *
     * @param requestURL
     * @param authorize
     * @param username
     * @param password
     * @param headers
     * @param timeout
     * @return
     * @throws Exception </pre>
     */
public static DhisHttpResponse httpDELETE(String requestURL, boolean authorize, String username, String password, Map<String, String> headers, int timeout) throws Exception {
    DefaultHttpClient httpclient = null;
    DhisHttpResponse dhisHttpResponse = null;
    try {
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, timeout);
        HttpConnectionParams.setSoTimeout(params, timeout);
        httpclient = new DefaultHttpClient(params);
        HttpDelete httpDelete = new HttpDelete(requestURL);
        if (headers instanceof Map) {
            for (Map.Entry<String, String> e : headers.entrySet()) {
                httpDelete.addHeader(e.getKey(), e.getValue());
            }
        }
        if (authorize) {
            httpDelete.setHeader("Authorization", CodecUtils.getBasicAuthString(username, password));
        }
        HttpResponse response = httpclient.execute(httpDelete);
        dhisHttpResponse = processResponse(requestURL, username, response);
        return dhisHttpResponse;
    } catch (Exception e) {
        log.error("exception occurred in httpDELETE call with username " + username, e);
        throw e;
    } finally {
        if (httpclient != null) {
            httpclient.getConnectionManager().shutdown();
        }
    }
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) BasicHttpParams(org.apache.http.params.BasicHttpParams) Map(java.util.Map) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) IOException(java.io.IOException)

Example 100 with HttpDelete

use of org.apache.http.client.methods.HttpDelete in project cxf by apache.

the class Client method deleteCustomerInfo.

public void deleteCustomerInfo(String name, String password, int id) throws Exception {
    System.out.println("HTTP DELETE to update customer info, user : " + name + ", password : " + password);
    System.out.println("Confirming a customer with id " + id + " exists first");
    getCustomerInfo(name, password, id);
    System.out.println("Deleting now...");
    HttpDelete del = new HttpDelete("http://localhost:9002/customerservice/customers/" + id);
    setMethodHeaders(del, name, password);
    handleHttpMethod(del);
    System.out.println("Confirming a customer with id " + id + " does not exist anymore");
    getCustomerInfo(name, password, id);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete)

Aggregations

HttpDelete (org.apache.http.client.methods.HttpDelete)108 HttpResponse (org.apache.http.HttpResponse)25 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)22 Test (org.junit.Test)21 HttpGet (org.apache.http.client.methods.HttpGet)16 HttpPut (org.apache.http.client.methods.HttpPut)16 HttpPost (org.apache.http.client.methods.HttpPost)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)14 IOException (java.io.IOException)12 Deployment (org.activiti.engine.test.Deployment)12 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)11 Task (org.activiti.engine.task.Task)9 StringEntity (org.apache.http.entity.StringEntity)9 URI (java.net.URI)7 RequestExecutor (org.apache.stanbol.commons.testing.http.RequestExecutor)7 URISyntaxException (java.net.URISyntaxException)6 Header (org.apache.http.Header)6 HttpEntity (org.apache.http.HttpEntity)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 User (org.activiti.engine.identity.User)5