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

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

Introduction

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

Prototype

@Override
public void setQueryString(String queryString) 

Source Link

Document

Sets the query string of this HTTP method.

Usage

From source file:com.clarkparsia.sbol.editor.sparql.StardogEndpoint.java

@Override
public void clear(String namedGraph) throws HttpException, IOException, QueryEvaluationException {
    DeleteMethod delete = new DeleteMethod(url);
    delete.setQueryString(new NameValuePair[] { graphParam(namedGraph) });
    execute(delete);/* w  w  w  .j ava  2  s .  c  om*/
}

From source file:com.funambol.json.dao.JsonDAOImpl.java

public JsonResponse removeAllItems(String token, long since) throws HttpException, IOException {

    String request = Utility.getUrl(jsonServerUrl, resourceType, REMOVE_ITEM_URL);

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: start removeAllItems");
    }//from w w  w  .ja  v  a 2  s  .c o  m

    DeleteMethod remove = new DeleteMethod(request);

    if (since != 0) {
        NameValuePair nvp_since = new NameValuePair();
        nvp_since.setName("since");
        nvp_since.setValue("" + since);
        NameValuePair[] nvp = { nvp_since };
        remove.setQueryString(nvp);
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: removeAllItem request:" + request);
    }
    remove.setRequestHeader(Utility.TOKEN_HEADER_NAME, token);

    int statusCode = 0;
    String responseBody = null;
    try {
        statusCode = httpClient.executeMethod(remove);
        responseBody = remove.getResponseBodyAsString();
    } finally {
        remove.releaseConnection();
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: deleteAllItem response " + responseBody);
    }

    JsonResponse response = new JsonResponse(statusCode, responseBody);

    return response;
}

From source file:com.funambol.json.dao.JsonDAOImpl.java

public JsonResponse removeItem(String token, String id, long since) throws HttpException, IOException {

    String request = Utility.getUrl(jsonServerUrl, resourceType, REMOVE_ITEM_URL) + Utility.URL_SEP + id;

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: start removeItem with id:" + id + "and since=" + since);
    }//from  w  ww. j a  v a  2 s  . c om

    DeleteMethod remove = new DeleteMethod(request);

    if (since != 0) {
        NameValuePair nvp_since = new NameValuePair();
        nvp_since.setName("since");
        nvp_since.setValue("" + since);
        NameValuePair[] nvp = { nvp_since };
        remove.setQueryString(nvp);
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: removeItem request:" + request);
    }
    remove.setRequestHeader(Utility.TOKEN_HEADER_NAME, token);

    int statusCode = 0;
    String responseBody = null;
    try {
        statusCode = httpClient.executeMethod(remove);
        responseBody = remove.getResponseBodyAsString();
    } finally {
        remove.releaseConnection();
    }

    if (log.isTraceEnabled()) {
        log.trace("JsonDAOImpl: deleteItem response " + responseBody);
        log.trace("JsonDAOImpl: item with id:" + id + " removed");
    }

    JsonResponse response = new JsonResponse(statusCode, responseBody);

    return response;
}

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

@Test
public void deleteParticipant() {
    try {/*from w  ww .  j  a v  a  2 s  .  c o m*/
        HttpClient client = new HttpClient();
        DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
        post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=participantstest&participant_id=1");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(200, code);
        post.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("delete failed");
    }
    // Now lets GET it to make sure it was deleted
    try {
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
        get.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=participantstest");
        client.executeMethod(get);
        int code = get.getStatusCode();
        assertEquals(200, code);
        String response = get.getResponseBodyAsString();
        assertFalse(response.contains(
                "<participant id=\"1\" display_name=\"bob\" thumbnail_url=\"http://www.test.org\" />"));
        get.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("get failed");
    }
}

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

@Test
public void deleteParticipant_InvalidAPIKey() {
    try {// w  w  w  .  j  av  a  2 s .  c om
        HttpClient client = new HttpClient();
        DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
        post.setQueryString("api_key=" + API_KEY_INVALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=participantstest");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(401, code);
        post.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("post failed");
    }
}

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

@Test
public void deleteParticipant_InvalidParticipant() {
    try {//from  w w  w .  ja v  a2s.  c  om
        HttpClient client = new HttpClient();
        DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
        post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=participantstest&participant_id=99");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(404, code);
        post.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("post failed");
    }
}

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

@Test
public void deleteParticipant_InvalidInstance() {
    try {//from  w  w w  . j a v a2s .  c  o  m
        HttpClient client = new HttpClient();
        DeleteMethod post = new DeleteMethod(TEST_PARTICIPANTS_SERVICE_URL_VALID);
        post.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&shareddatakey=participantstestinvalidkey&participant_id=1");
        client.executeMethod(post);
        int code = post.getStatusCode();
        assertEquals(400, code);
        post.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("post failed");
    }
}

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

@Test
public void removeProperty() {
    try {//ww  w.j a v a 2 s .  c  om
        HttpClient client = new HttpClient();
        DeleteMethod delete = new DeleteMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        delete.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&is_public=true&shareddatakey=propstest&propertyname=cat");
        client.executeMethod(delete);
        int code = delete.getStatusCode();
        assertEquals(200, code);
        delete.releaseConnection();
    } catch (Exception e) {
        fail("delete failed");
    }
}

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

@Test
public void removePropertyNonExisting() {
    try {/*from  www. j  a v  a 2  s.  c  o m*/
        HttpClient client = new HttpClient();
        DeleteMethod delete = new DeleteMethod(TEST_PROPERTIES_SERVICE_URL_VALID);
        delete.setQueryString("api_key=" + API_KEY_VALID + "&widgetid=" + WIDGET_ID_VALID
                + "&userid=test&is_public=true&shareddatakey=propstest&propertyname=bogus");
        client.executeMethod(delete);
        int code = delete.getStatusCode();
        assertEquals(404, code);
        delete.releaseConnection();
    } catch (Exception e) {
        fail("delete failed");
    }
}

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

@Test
public void deleteServiceNoAuth() {
    try {//  w w  w .  j a va  2s .c  o m
        HttpClient client = new HttpClient();
        DeleteMethod del = new DeleteMethod(TEST_SERVICES_SERVICE_URL_VALID + "/test2");
        del.setQueryString("name=test2");
        client.executeMethod(del);
        int code = del.getStatusCode();
        assertEquals(401, code);
        del.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
        fail("put failed");
    }
}