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

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

Introduction

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

Prototype

@Override
public String getResponseBodyAsString() throws IOException 

Source Link

Document

Returns the response body of the HTTP method, if any, as a String .

Usage

From source file:org.wso2.scim.sample.group.DeleteGroup.java

public static void main(String[] args) {

    try {//  w  w w. j  av  a  2  s. c om
        //load sample configuration
        SCIMSamplesUtils.loadConfiguration();
        //set the keystore
        SCIMSamplesUtils.setKeyStore();

        String groupId = getSCIMIdOfGroup(SCIMSamplesUtils.groupDisplayNameToDeleteGroup);

        String url = SCIMSamplesUtils.groupEndpointURL + "/" + groupId;
        //now send the delete request.
        DeleteMethod deleteMethod = new DeleteMethod(url);
        //add authorization header
        String authHeader = SCIMSamplesUtils.getAuthorizationHeader();
        deleteMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, authHeader);
        HttpClient httpDeleteClient = new HttpClient();
        int deleteResponseStatus = httpDeleteClient.executeMethod(deleteMethod);
        String deleteResponse = deleteMethod.getResponseBodyAsString();

        System.out.println("");
        System.out.println("");
        System.out.println("/******SCIM group delete response status: " + deleteResponseStatus);
        System.out.println("SCIM group delete response data: " + deleteResponse + "******/");
        System.out.println("");

    } catch (CharonException e) {
        e.printStackTrace();
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.wso2.scim.sample.user.DeleteUser.java

public static void main(String[] args) {

    try {//from ww w  .java 2s . c o  m
        //load sample configuration
        SCIMSamplesUtils.loadConfiguration();
        //set the keystore
        SCIMSamplesUtils.setKeyStore();

        String userId = getSCIMIdOfUser(SCIMSamplesUtils.userNameToDeleteUser);

        String url = SCIMSamplesUtils.userEndpointURL + "/" + userId;
        //now send the delete request.
        DeleteMethod deleteMethod = new DeleteMethod(url);
        //add authorization header
        String authHeader = SCIMSamplesUtils.getAuthorizationHeader();
        deleteMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER, authHeader);

        HttpClient httpDeleteClient = new HttpClient();
        int deleteResponseStatus = httpDeleteClient.executeMethod(deleteMethod);
        String deleteResponse = deleteMethod.getResponseBodyAsString();

        System.out.println("");
        System.out.println("");
        System.out.println("/******SCIM user delete response status: " + deleteResponseStatus);
        System.out.println("SCIM user delete response data: " + deleteResponse + "******/");
        System.out.println("");

    } catch (CharonException e) {
        e.printStackTrace();
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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);/*from   www . j a  v a2 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);
}