Example usage for org.apache.commons.httpclient.methods DeleteMethod setDoAuthentication

List of usage examples for org.apache.commons.httpclient.methods DeleteMethod setDoAuthentication

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods DeleteMethod setDoAuthentication.

Prototype

@Override
public void setDoAuthentication(boolean doAuthentication) 

Source Link

Document

Sets whether or not the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.)

Usage

From source file:edu.northwestern.jcr.adapter.fedora.persistence.FedoraConnectorREST.java

/**
 * Sends an HTTP DELETE request and returns the status code.
 *
 * @param url URL of the resource/*from  w w w . j  av  a 2 s  . co m*/
 * @return status code
 */
private int httpDelete(String url) {
    DeleteMethod deleteMethod = null;

    try {
        deleteMethod = new DeleteMethod(url);
        deleteMethod.setDoAuthentication(true);
        deleteMethod.getParams().setParameter("Connection", "Keep-Alive");
        fc.getHttpClient().executeMethod(deleteMethod);

        return deleteMethod.getStatusCode();
    } catch (Exception e) {
        e.printStackTrace();
        log.warn("failed to delete!");

        return -1;
    } finally {
        if (deleteMethod != null) {
            deleteMethod.releaseConnection();
        }
    }
}

From source file:org.apache.wookie.tests.functional.WidgetAccessRequestPolicyControllerTest.java

@Test
public void deletePolicy() {
    try {/*ww  w. ja v  a 2s.  c  o m*/
        HttpClient client = new HttpClient();
        setAuthenticationCredentials(client);
        DeleteMethod del = new DeleteMethod(TEST_WARP_SERVICE_URL_VALID + "/" + id);
        del.setDoAuthentication(true);
        client.executeMethod(del);
        int code = del.getStatusCode();
        assertEquals(200, code);
        del.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("put failed");
    }
    // Now lets make sure it was deleted OK
    Element[] policies = getPolicies();
    for (Element policy : policies) {
        if (policy.getAttribute("id").getValue().equals(id)) {
            fail("Policy was not deleted");
        }
    }
}

From source file:org.apache.wookie.tests.functional.WidgetServicesControllerTest.java

@Test
public void deleteService() {
    try {/* www . ja  va  2 s .  c o  m*/
        HttpClient client = new HttpClient();
        setAuthenticationCredentials(client);
        DeleteMethod del = new DeleteMethod(TEST_SERVICES_SERVICE_URL_VALID + "/test2");
        del.setDoAuthentication(true);
        client.executeMethod(del);
        int code = del.getStatusCode();
        assertEquals(200, code);
        del.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("put failed");
    }
    // Now lets GET it to make sure it was deleted OK
    try {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_SERVICES_SERVICE_URL_VALID + "/test2");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(404, code);
        get.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("get failed");
    }
}

From source file:org.apache.wookie.tests.functional.WidgetServicesControllerTest.java

@Test
public void addServiceAlreadyExists() {
    try {//from ww w .ja  v  a2s .  c o m
        HttpClient client = new HttpClient();
        setAuthenticationCredentials(client);
        PostMethod post = new PostMethod(TEST_SERVICES_SERVICE_URL_VALID + "/test_add2");
        post.setDoAuthentication(true);
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(201, code);
        post.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("post failed");
    }
    try {
        HttpClient client = new HttpClient();
        setAuthenticationCredentials(client);
        PostMethod post = new PostMethod(TEST_SERVICES_SERVICE_URL_VALID + "/test_add2");
        post.setDoAuthentication(true);
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(409, code);
        post.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("post failed");
    }
    // clean up
    try {
        HttpClient client = new HttpClient();
        setAuthenticationCredentials(client);
        DeleteMethod del = new DeleteMethod(TEST_SERVICES_SERVICE_URL_VALID + "/test_add2");
        del.setDoAuthentication(true);
        client.executeMethod(del);
        int code = del.getStatusCode();
        assertEquals(200, code);
        del.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("put failed");
    }
}

From source file:org.apache.wookie.tests.functional.WidgetServicesControllerTest.java

@Test
public void deleteServiceNonExists() {
    try {//w w  w .  j a v a2s.c o m
        HttpClient client = new HttpClient();
        setAuthenticationCredentials(client);
        DeleteMethod del = new DeleteMethod(TEST_SERVICES_SERVICE_URL_VALID + "/test999");
        del.setDoAuthentication(true);
        client.executeMethod(del);
        int code = del.getStatusCode();
        assertEquals(404, code);
        del.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("put failed");
    }
}

From source file:org.iavante.sling.commons.services.DistributionServerTestIT.java

private void deleteContent(String content) {

    // Delete the content
    DeleteMethod post_delete = new DeleteMethod(content);

    post_delete.setDoAuthentication(true);
    // post_delete.setRequestBody(data_delete);

    try {/*from   ww w .j  a va2  s.  c  om*/
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    System.out.println(post_delete.getStatusCode());
    assert 204 == post_delete.getStatusCode();
    System.out.println("Borrado contenido: " + content);
    post_delete.releaseConnection();

}

From source file:org.iavante.sling.s3backend.S3BackendTestIT.java

private void deleteContent(String content) {

    // Delete the content
    DeleteMethod post_delete = new DeleteMethod(content);

    post_delete.setDoAuthentication(true);
    // post_delete.setRequestBody(data_delete);

    try {/*from  w w  w.j  a v  a2s .  co  m*/
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(204, post_delete.getStatusCode());
    log.info("Borrado contenido: " + content);
    post_delete.releaseConnection();

}

From source file:org.xwiki.test.webdav.AbstractWebDAVTest.java

/**
 * Tests the DELETE method on the given url.
 * // w  ww. j  av a  2s . com
 * @param url the target url.
 * @param expect the return status expected.
 * @return the {@link HttpMethod} which contains the response.
 */
protected HttpMethod delete(String url, int expect) {
    DeleteMethod deleteMethod = new DeleteMethod();
    deleteMethod.setDoAuthentication(true);
    deleteMethod.setPath(url);
    testMethod(deleteMethod, expect);
    return deleteMethod;
}

From source file:org.xwiki.webdav.test.AbstractWebDAVTest.java

/**
 * Tests the DELETE method on the given url.
 * //w  w  w .ja  v a 2s.co  m
 * @param url the target url.
 * @param expect the return status expected.
 * @return the {@link HttpMethod} which contains the response.
 */
protected HttpMethod delete(String url, int expect) throws Exception {
    DeleteMethod deleteMethod = new DeleteMethod();
    deleteMethod.setDoAuthentication(true);
    deleteMethod.setPath(url);
    testMethod(deleteMethod, expect);
    return deleteMethod;
}