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.demo.workflow.integration.Helper.java

public String deleteProcess(String workflow_instance_id) throws HttpException, IOException {

    String connectionUrl = replaceTokensInURL(ALF_URL_SERV_WORK_DELETE[1], "host", host);
    connectionUrl = replaceTokensInURL(connectionUrl, "workflow_instance_id", workflow_instance_id);

    DeleteMethod method = new DeleteMethod(connectionUrl);

    client.executeMethod(method);/*  w  w  w . j a v  a2  s.c om*/

    String rt = method.getResponseBodyAsString();

    return rt;

}

From source file:org.eclipsecon.e4rover.client.production.ProductionServer.java

public void leavePlayerQueue(String playerKey) throws IOException {
    DeleteMethod delete = new DeleteMethod(IServerConstants.QUEUE_RESTLET + "/" + playerKey);
    try {//www. j a  v a2  s .c  o  m
        int resp = httpClient.executeMethod(delete);
        if (resp != HttpStatus.SC_OK) {
            throw new RobotServerException(resp, delete.getURI(), delete.getResponseBodyAsString());
        }
    } finally {
        delete.releaseConnection();
    }
}

From source file:org.jboss.seam.security.test.server.identity.LogoutTest.java

/**
 * Test for SEAMSECURITY-83/*  w  w w.j ava  2s  .  co  m*/
 */
@Test
public void assertLogoutInvalidatesSession(@ArquillianResource(LogoutServlet.class) URL baseUrl)
        throws IOException {
    final HttpClient client = new HttpClient();

    final PostMethod put = new PostMethod(baseUrl.toString() + "logout");
    client.executeMethod(put);

    assertThat(put.getResponseBodyAsString(), is("loggedIn"));

    final DeleteMethod delete = new DeleteMethod(baseUrl.toString() + "logout");
    client.executeMethod(delete);

    assertThat(delete.getResponseBodyAsString(), is("loggedOut and session invalidated"));
}

From source file:org.jboss.wise.core.client.jaxrs.impl.RSDynamicClientImpl.java

public InvocationResult invoke(RequestEntity requestEntity, WiseMapper mapper) {
    InvocationResult result = null;//from w w  w . jav  a2s  .c om
    Map<String, Object> responseHolder = new HashMap<String, Object>();

    if (HttpMethod.GET == httpMethod) {
        GetMethod get = new GetMethod(resourceURI);
        setRequestHeaders(get);

        try {
            int statusCode = httpClient.executeMethod(get);
            // TODO: Use InputStream
            String response = get.getResponseBodyAsString();
            responseHolder.put(InvocationResult.STATUS, Integer.valueOf(statusCode));

            result = new InvocationResultImpl(InvocationResult.RESPONSE, null, response, responseHolder);

            // System.out.print(response);
        } catch (IOException e) {
            // TODO:
        } finally {
            get.releaseConnection();
        }
    } else if (HttpMethod.POST == httpMethod) {
        PostMethod post = new PostMethod(resourceURI);
        setRequestHeaders(post);

        post.setRequestEntity(requestEntity);

        try {
            int statusCode = httpClient.executeMethod(post);
            String response = post.getResponseBodyAsString();
            responseHolder.put(InvocationResult.STATUS, Integer.valueOf(statusCode));

            result = new InvocationResultImpl(InvocationResult.RESPONSE, null, response, responseHolder);

            // System.out.print(response);
        } catch (IOException e) {
            // TODO:
        } finally {
            post.releaseConnection();
        }
    } else if (HttpMethod.PUT == httpMethod) {
        PutMethod put = new PutMethod(resourceURI);
        setRequestHeaders(put);

        put.setRequestEntity(requestEntity);

        try {
            int statusCode = httpClient.executeMethod(put);
            String response = put.getResponseBodyAsString();
            responseHolder.put(InvocationResult.STATUS, Integer.valueOf(statusCode));

            result = new InvocationResultImpl(InvocationResult.RESPONSE, null, response, responseHolder);

            // System.out.print(response);
        } catch (IOException e) {
            // TODO:
        } finally {
            put.releaseConnection();
        }
    } else if (HttpMethod.DELETE == httpMethod) {
        DeleteMethod delete = new DeleteMethod(resourceURI);
        setRequestHeaders(delete);

        try {
            int statusCode = httpClient.executeMethod(delete);
            String response = delete.getResponseBodyAsString();
            responseHolder.put(InvocationResult.STATUS, Integer.valueOf(statusCode));

            result = new InvocationResultImpl(InvocationResult.RESPONSE, null, response, responseHolder);

            // System.out.print(response);
        } catch (IOException e) {
            // TODO:
        } finally {
            delete.releaseConnection();
        }
    }

    return result;
}

From source file:org.nuxeo.ecm.core.storage.sql.ScalityBinaryManager.java

/**
 * Deletes an object using its digest string.
 *
 * @param objectID/*from   w  w w.j a va  2 s .c o  m*/
 */
protected void removeBinary(String objectID) {
    String url = PROTOCOL_PREFIX + this.bucketName + "." + this.hostBase;
    log.debug(url);
    DeleteMethod deleteMethod = new DeleteMethod(url);
    String contentMD5 = "";

    // date to be provided to the cloud server
    Date currentDate = new Date();

    String cloudDateString = StringGenerator.getCloudFormattedDateString(currentDate);

    String stringToSign = StringGenerator.getStringToSign(HTTPMethod.DELETE, contentMD5, DEFAULT_CONTENT_TYPE,
            this.bucketName, objectID, currentDate);
    try {
        deleteMethod.addRequestHeader("Authorization",
                StringGenerator.getAuthorizationString(stringToSign, awsID, awsSecret));
        deleteMethod.addRequestHeader("x-amz-date", cloudDateString);
        deleteMethod.setPath("/" + objectID);

        HttpClient client = new HttpClient();
        int returnCode = client.executeMethod(deleteMethod);
        log.debug(deleteMethod.getResponseBodyAsString());
        // only for logging
        if (returnCode == HttpStatus.SC_NO_CONTENT) {
            log.info("Object " + objectID + " deleted");
        } else if (returnCode == HttpStatus.SC_NOT_FOUND) {
            log.debug("Object " + objectID + " does not exist");
        } else {
            String connectionMsg = "Scality connection problem. Object could not be verified";
            log.debug(connectionMsg);
            throw new RuntimeException(connectionMsg);
        }
        deleteMethod.releaseConnection();
    } catch (SignatureException e) {
        throw new RuntimeException(e);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sharegov.cirm.utils.GenUtils.java

public static String httpDelete(String url, String... headers) {
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(url);
    if (headers != null) {
        if (headers.length % 2 != 0)
            throw new IllegalArgumentException(
                    "Odd number of headers argument, specify HTTP headers in pairs: name then value, etc.");
        for (int i = 0; i < headers.length; i++)
            method.addRequestHeader(headers[i], headers[++i]);
    }/*from   w  w w.  j  a  va  2 s  .  co m*/
    try {
        // disable retries from within the HTTP client          
        client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(0, false));
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK)
            throw new RuntimeException("HTTP Error " + statusCode + " while deleting " + url.toString());
        return method.getResponseBodyAsString();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:org.wso2.carbon.identity.scim.common.impl.ProvisioningClient.java

public void provisionDeleteUser() throws IdentitySCIMException {
    String userName = null;//w  ww  .  j  a va 2s.c om

    try {
        //get provider details
        String userEPURL = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_USER_ENDPOINT);
        userName = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_USERNAME);
        String password = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_PASSWORD);
        String contentType = provider.getProperty(SCIMConstants.CONTENT_TYPE_HEADER);

        if (contentType == null) {
            contentType = SCIMConstants.APPLICATION_JSON;
        }

        /*get the userId of the user being provisioned from the particular provider by filtering
          with user name*/
        GetMethod getMethod = new GetMethod(userEPURL);
        //add filter query parameter
        getMethod.setQueryString(USER_FILTER + ((User) scimObject).getUserName());
        //add authorization headers
        getMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER,
                BasicAuthUtil.getBase64EncodedBasicAuthHeader(userName, password));

        //create http client
        HttpClient httpFilterClient = new HttpClient();
        //send the request
        int responseStatus = httpFilterClient.executeMethod(getMethod);

        String response = getMethod.getResponseBodyAsString();
        if (logger.isDebugEnabled()) {
            logger.debug("SCIM - filter operation inside 'delete user' provisioning "
                    + "returned with response code: " + responseStatus);
            logger.debug("Filter User Response: " + response);
        }
        SCIMClient scimClient = new SCIMClient();
        if (scimClient.evaluateResponseStatus(responseStatus)) {
            //decode the response to extract the userId.
            ListedResource listedResource = scimClient.decodeSCIMResponseWithListedResource(response,
                    SCIMConstants.identifyFormat(contentType), objectType);
            List<SCIMObject> users = listedResource.getScimObjects();
            String userId = null;
            //we expect only one user in the list
            for (SCIMObject user : users) {
                userId = ((User) user).getId();
            }
            String url = userEPURL + "/" + userId;
            //now send the delete request.
            DeleteMethod deleteMethod = new DeleteMethod(url);
            deleteMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER,
                    BasicAuthUtil.getBase64EncodedBasicAuthHeader(userName, password));
            HttpClient httpDeleteClient = new HttpClient();
            int deleteResponseStatus = httpDeleteClient.executeMethod(deleteMethod);
            String deleteResponse = deleteMethod.getResponseBodyAsString();
            logger.info("SCIM - delete user operation returned with response code: " + deleteResponseStatus);
            if (!scimClient.evaluateResponseStatus(deleteResponseStatus)) {
                //decode scim exception and extract the specific error message.
                AbstractCharonException exception = scimClient.decodeSCIMException(deleteResponse,
                        SCIMConstants.identifyFormat(contentType));
                logger.error(exception.getDescription());
            }
        } else {
            //decode scim exception and extract the specific error message.
            AbstractCharonException exception = scimClient.decodeSCIMException(response,
                    SCIMConstants.identifyFormat(contentType));
            logger.error(exception.getDescription());
        }
    } catch (CharonException | IOException | BadRequestException e) {
        throw new IdentitySCIMException("Error in provisioning 'delete user' operation for user :" + userName,
                e);
    }
}

From source file:org.wso2.carbon.identity.scim.common.impl.ProvisioningClient.java

public void provisionDeleteGroup() throws IdentitySCIMException {
    String userName = null;//  ww w  . j a va  2 s  . com
    try {
        //get provider details
        String groupEPURL = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_GROUP_ENDPOINT);
        userName = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_USERNAME);
        String password = provider.getProperty(SCIMConfigConstants.ELEMENT_NAME_PASSWORD);
        String contentType = provider.getProperty(SCIMConstants.CONTENT_TYPE_HEADER);

        if (contentType == null) {
            contentType = SCIMConstants.APPLICATION_JSON;
        }

        /*get the groupId of the group being provisioned from the particular provider by filtering
          with display name*/
        GetMethod getMethod = new GetMethod(groupEPURL);
        //add filter query parameter
        getMethod.setQueryString(GROUP_FILTER + ((Group) scimObject).getDisplayName());
        //add authorization headers
        getMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER,
                BasicAuthUtil.getBase64EncodedBasicAuthHeader(userName, password));

        //create http client
        HttpClient httpFilterClient = new HttpClient();
        //send the request
        int responseStatus = httpFilterClient.executeMethod(getMethod);
        String response = getMethod.getResponseBodyAsString();

        if (logger.isDebugEnabled()) {
            logger.debug("SCIM - filter operation inside 'delete group' provisioning "
                    + "returned with response code: " + responseStatus);
            logger.debug("Filter Group Response: " + response);
        }
        SCIMClient scimClient = new SCIMClient();
        if (scimClient.evaluateResponseStatus(responseStatus)) {
            //decode the response to extract the groupId.
            ListedResource listedResource = scimClient.decodeSCIMResponseWithListedResource(response,
                    SCIMConstants.identifyFormat(contentType), objectType);
            List<SCIMObject> groups = listedResource.getScimObjects();
            String groupId = null;
            //we expect only one user in the list
            for (SCIMObject group : groups) {
                groupId = ((Group) group).getId();
            }
            String url = groupEPURL + "/" + groupId;
            //now send the delete request.
            DeleteMethod deleteMethod = new DeleteMethod(url);
            deleteMethod.addRequestHeader(SCIMConstants.AUTHORIZATION_HEADER,
                    BasicAuthUtil.getBase64EncodedBasicAuthHeader(userName, password));
            HttpClient httpDeleteClient = new HttpClient();
            int deleteResponseStatus = httpDeleteClient.executeMethod(deleteMethod);
            String deleteResponse = deleteMethod.getResponseBodyAsString();
            logger.info("SCIM - delete group operation returned with response code: " + deleteResponseStatus);
            if (!scimClient.evaluateResponseStatus(deleteResponseStatus)) {
                //decode scim exception and extract the specific error message.
                AbstractCharonException exception = scimClient.decodeSCIMException(deleteResponse,
                        SCIMConstants.identifyFormat(contentType));
                logger.error(exception.getDescription());
            }
        } else {
            //decode scim exception and extract the specific error message.
            AbstractCharonException exception = scimClient.decodeSCIMException(response,
                    SCIMConstants.identifyFormat(contentType));
            logger.error(exception.getDescription());
        }
    } catch (CharonException | IOException | BadRequestException e) {
        throw new IdentitySCIMException("Error in provisioning 'delete group' operation for user :" + userName,
                e);
    }
}

From source file:org.wso2.iot.integration.common.IOTHttpClient.java

public IOTResponse delete(String endpoint) {

    HttpClient client = new HttpClient();

    try {/*from   w w  w.j a va2  s.  c om*/
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();

        Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT);
        Protocol.registerProtocol(Constants.HTTPS, https);

        String url = backEndUrl + endpoint;

        DeleteMethod method = new DeleteMethod(url);
        method.setRequestHeader(AUTHORIZATION, authorizationString);
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));

        IOTResponse iotResponse = new IOTResponse();
        iotResponse.setStatus(client.executeMethod(method));
        iotResponse.setBody(method.getResponseBodyAsString());
        return iotResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at IOTResponse delete for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occurred at IOTResponse delete for IOException", e);
    }
    return null;
}

From source file:org.wso2.mdm.integration.common.MDMHttpClient.java

public MDMResponse delete(String endpoint) {

    HttpClient client = new HttpClient();

    try {// w  ww  . j  a  v a 2 s . c  om
        ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();

        Protocol https = new Protocol("https", socketFactory, 9443);
        Protocol.registerProtocol("https", https);

        String url = backEndUrl + endpoint;

        DeleteMethod method = new DeleteMethod(url);
        method.setRequestHeader(AUTHORIZATION, authrizationString);
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(3, false));

        MDMResponse mdmResponse = new MDMResponse();
        mdmResponse.setStatus(client.executeMethod(method));
        mdmResponse.setBody(method.getResponseBodyAsString());
        return mdmResponse;

    } catch (GeneralSecurityException e) {
        log.error("Failure occurred at MDMResponse delete for GeneralSecurityException", e);
    } catch (IOException e) {
        log.error("Failure occurred at MDMResponse delete for IOException", e);
    }
    return null;
}