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

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

Introduction

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

Prototype

@Override
public void releaseConnection() 

Source Link

Document

Releases the connection being used by this HTTP method.

Usage

From source file:org.apache.wink.itest.InheritanceTest.java

public void testSubResourceLocaterInheritance() throws Exception {
    DeleteMethod deleteMethod = new DeleteMethod(PARKING_LOT_URI + "/cars/remove/ParkingLot");
    GetMethod getMethod = new GetMethod(FRUIT_URI + "/fruit%20suffix");
    PostMethod postMethod = new PostMethod(FRUIT_URI + "/orange%20suffix");
    try {//from w  ww  .  jav a 2s .  c o  m
        // ParkingLot classes. Sub resource classes are potential root
        // resources
        httpClient.executeMethod(deleteMethod);
        Header header = deleteMethod.getResponseHeader("Invoked");
        assertNotNull(header);
        assertEquals("ParkingLot.removeCar", header.getValue());
        deleteMethod.releaseConnection();
        deleteMethod = new DeleteMethod(PARKING_LOT_URI + "/cars/remove/ParkingGarage");
        httpClient.executeMethod(deleteMethod);
        header = deleteMethod.getResponseHeader("Invoked");
        assertNotNull(header);
        assertEquals("ParkingGarage.removeCar", header.getValue());
        deleteMethod.releaseConnection();
        deleteMethod = new DeleteMethod(PARKING_LOT_URI + "/cars/remove/CarFerry");
        httpClient.executeMethod(deleteMethod);
        assertEquals(405, deleteMethod.getStatusCode());

        // Fruit classes. Sub resource classes are not potential root
        // resources
        httpClient.executeMethod(getMethod);
        String response = getMethod.getResponseBodyAsString();
        assertEquals("org.apache.wink.itest.fruits.Fruit;fruit%20suffix", response);
        getMethod.releaseConnection();
        getMethod = new GetMethod(FRUIT_URI + "/apple%20suffix");
        httpClient.executeMethod(getMethod);
        response = getMethod.getResponseBodyAsString();
        assertEquals("org.apache.wink.itest.fruits.Apple;apple suffix", // parameters
                // on
                // class
                // are
                // not
                // inherited
                response);
        getMethod.releaseConnection();
        getMethod = new GetMethod(FRUIT_URI + "/orange%20suffix");
        httpClient.executeMethod(getMethod);
        assertEquals(405, getMethod.getStatusCode());
        httpClient.executeMethod(postMethod);
        response = postMethod.getResponseBodyAsString();
        assertEquals("org.apache.wink.itest.fruits.Orange;orange suffix", response);
        assertEquals(200, postMethod.getStatusCode());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.toString());
    } finally {
        deleteMethod.releaseConnection();
        getMethod.releaseConnection();
    }
}

From source file:org.apache.wink.itest.sequence.SequenceTest.java

/**
 * Calls a resource (which is not a singleton) several times. Verifies that
 * the resource instance is created each time.
 * /*w  w w .java 2 s  . c  o m*/
 * @throws Exception
 */
public void testHit100TimesRegularResource() throws Exception {
    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/sequence/static");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(204, deleteMethod.getStatusCode());
    } finally {
        deleteMethod.releaseConnection();
    }

    deleteMethod = new DeleteMethod(getBaseURI() + "/sequence/constructor");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(204, deleteMethod.getStatusCode());
    } finally {
        deleteMethod.releaseConnection();
    }

    for (int c = 0; c < 10; ++c) {
        GetMethod getMethod = new GetMethod(getBaseURI() + "/sequence");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("0", new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/sequence/static");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + c, new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        PostMethod postMethod = new PostMethod(getBaseURI() + "/sequence");
        try {
            client.executeMethod(postMethod);
            assertEquals(200, postMethod.getStatusCode());
            assertEquals("1", new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(),
                    postMethod.getResponseCharSet())).readLine());
        } finally {
            postMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/sequence/static");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + (c + 1), new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/sequence/constructor");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + ((c + 1) * 5), new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }
    }
}

From source file:org.apache.wink.itest.sequence.SequenceTest.java

/**
 * Calls a singleton resource several times. Verifies that the resource
 * instance is re-used each time.//from   w w w . j  a v a 2  s  .com
 * 
 * @throws Exception
 */
public void testHit100TimesSingletonResource() throws Exception {
    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/singletonsequence/static");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(204, deleteMethod.getStatusCode());
    } finally {
        deleteMethod.releaseConnection();
    }

    deleteMethod = new DeleteMethod(getBaseURI() + "/singletonsequence/");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(204, deleteMethod.getStatusCode());
    } finally {
        deleteMethod.releaseConnection();
    }

    for (int c = 0; c < 10; ++c) {
        GetMethod getMethod = new GetMethod(getBaseURI() + "/singletonsequence");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + c, new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/singletonsequence/static");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + c, new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        PostMethod postMethod = new PostMethod(getBaseURI() + "/singletonsequence");
        try {
            client.executeMethod(postMethod);
            assertEquals(200, postMethod.getStatusCode());
            assertEquals("" + (c + 1),
                    new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(),
                            postMethod.getResponseCharSet())).readLine());
        } finally {
            postMethod.releaseConnection();
        }

        getMethod = new GetMethod(getBaseURI() + "/singletonsequence/static");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("" + (c + 1), new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }

        /*
         * the constructor for this resource should never be more than 1.
         * note the constructor hit count is never cleared.
         */
        getMethod = new GetMethod(getBaseURI() + "/singletonsequence/constructor");
        try {
            client.executeMethod(getMethod);
            assertEquals(200, getMethod.getStatusCode());
            assertEquals("1", new BufferedReader(
                    new InputStreamReader(getMethod.getResponseBodyAsStream(), getMethod.getResponseCharSet()))
                            .readLine());
        } finally {
            getMethod.releaseConnection();
        }
    }
}

From source file:org.apache.wink.itest.subresources.JAXRSExceptionsSubresourcesTest.java

/**
 * Test the positive workflow where a comment with a message and author is
 * successfully posted to the Guestbook.
 * //from  w  w  w . j a  v  a 2 s. co m
 * @throws Exception
 */
public void testRuntimeException() throws Exception {
    HttpClient client = new HttpClient();
    DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/commentdata/afdsfsdf");
    try {
        client.executeMethod(deleteMethod);
        assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), deleteMethod.getStatusCode());
        // assertLogContainsException("java.lang.NumberFormatException: For input string: \"afdsfsdf\"");
    } finally {
        deleteMethod.releaseConnection();
    }
}

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

@Test
public void deleteParticipant() {
    try {//  w w  w .j  a va 2  s  .  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=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 {/*from  w  w w .j  av  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_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  ww  . j  a v  a2  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=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 {//w w w  .j  a  va 2s .  co 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 {/*from   w ww  .  j  a  v  a2 s  .com*/
        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 {/* ww w .  ja  v  a 2s.  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");
    }
}