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

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

Introduction

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

Prototype

public DeleteMethod(String paramString) 

Source Link

Usage

From source file:org.wso2.carbon.appfactory.issuetracking.IssueTrackerConnector.java

public void deleteProjectVersions(String projectId, String tenantDomain) throws AppFactoryException {
    String postUrl = issueTrackerUrl + "services/tenant/" + tenantDomain + "/project/" + projectId + "/version";
    DeleteMethod deleteVersion = new DeleteMethod(postUrl);
    int result = -1;
    try {/*ww w  .  ja v a  2  s .  c om*/
        HttpClient httpclient = new HttpClient();
        result = httpclient.executeMethod(deleteVersion);
    } catch (Exception e) {
        String msg = "Error while  creating project in issue repository for " + projectId;
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
    } finally {
        // Release current connection to the connection pool once you are done
        deleteVersion.releaseConnection();
    }
}

From source file:org.wso2.carbon.appfactory.issuetracking.IssueTrackerConnector.java

public boolean deleteProjectVersion(String projectId, String version, String tenantDomain)
        throws AppFactoryException {
    String postUrl = issueTrackerUrl + "services/tenant/" + tenantDomain + "/project/" + projectId + "/"
            + version;//from  w w w  .  j a v a 2s .c om
    DeleteMethod deleteVersion = new DeleteMethod(postUrl);
    int result = -1;
    try {
        HttpClient httpclient = new HttpClient();
        result = httpclient.executeMethod(deleteVersion);
    } catch (Exception e) {
        String msg = "Error while  creating project in issue repository for " + projectId;
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
    } finally {
        // Release current connection to the connection pool once you are done
        deleteVersion.releaseConnection();
    }
    return result == 200;
}

From source file:org.wso2.carbon.appfactory.s4.integration.utils.DomainMappingUtils.java

/**
 * Send REST DELETE request to stratos SM.
 *
 * @param stage                            the stage of the Stratos SM
 * @param removeSubscriptionDomainEndPoint end point to send the message
 * @throws AppFactoryException//from w w w .j  a  v a 2s.  c o  m
 */
public static DomainMappingResponse sendDeleteRequest(String stage, String removeSubscriptionDomainEndPoint)
        throws AppFactoryException {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    String endPointUrl = getSMUrl(stage) + removeSubscriptionDomainEndPoint;
    DeleteMethod deleteMethod = new DeleteMethod(endPointUrl);
    deleteMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue());
    return send(httpClient, deleteMethod);
}

From source file:org.wso2.carbon.esb.rest.test.api.ESBJAVA4852URITemplateWithCompleteURLTestCase.java

@Test(groups = { "wso2.esb" }, description = "Sending complete URL to API and for dispatching")
public void testCompleteURLWithHTTPMethod() throws Exception {

    DeleteMethod delete = new DeleteMethod(getApiInvocationURL(
            "myApi1/order/21441/item/17440079" + "?message_id=41ec2ec4-e629-4e04-9fdf-c32e97b35bd1"));
    HttpClient httpClient = new HttpClient();
    LogViewerClient logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(), getSessionCookie());
    logViewerClient.clearLogs();/*from   w  w w  . j  ava  2s  .  c  o m*/

    try {
        httpClient.executeMethod(delete);
        Assert.assertEquals(delete.getStatusLine().getStatusCode(), 202, "Response code mismatched");
    } finally {
        delete.releaseConnection();
    }

    LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs();
    boolean isLogMessageFound = false;

    for (LogEvent log : logEvents) {
        if (log != null && log.getMessage().contains("order API INVOKED")) {
            isLogMessageFound = true;
            break;
        }
    }
    Assert.assertTrue(isLogMessageFound, "Request Not Dispatched to API when HTTP method having full url");

}

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

public void provisionDeleteUser() throws IdentitySCIMException {
    String userName = null;//from   w  w  w.ja  v  a  2  s . co m

    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;/*  www. jav a 2s. 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.carbon.mashup.javascript.hostobjects.pooledhttpclient.PooledHttpClientHostObject.java

/**
 * <p/>//from  w  ww.  j  a va  2s .c  o  m
 * This method executes the given HTTP method with user configured
 * details.ject to invoke a Web service. This method corresponds to the
 * following function of the HttpClient java script object.
 * </p>
 * <p/>
 * 
 * <pre>
 *    int executeMethod (
 *          in String method | in String url [, in String/Object content [, in Object params [,
 * Object headers]]]);
 */
public static Scriptable jsFunction_executeMethod(Context cx, Scriptable thisObj, Object[] args,
        Function funObj) {

    HttpMethod method = null;
    PooledHttpClientHostObject httpClientHostObject = (PooledHttpClientHostObject) thisObj;

    List<String> authSchemes = new ArrayList<String>();

    String contentType = PooledHttpClientHostObject.DEFAULT_CONTENT_TYPE;
    String charset = PooledHttpClientHostObject.DEFAULT_CHARSET;

    /*
     * we check weather authSchemes Priority has been set and put them into
     * a List
     */
    if (httpClientHostObject.authSchemePriority != null) {
        setAuthSchemes(httpClientHostObject, authSchemes);
    }

    if (httpClientHostObject.credentials != null) {
        setCredentials(httpClientHostObject, authSchemes);
    }

    if (httpClientHostObject.proxyCredentials != null) {
        setProxyCredentials(httpClientHostObject, authSchemes);
    }

    // checks whether cookies have been set
    if (httpClientHostObject.cookies != null) {
        setCookies(httpClientHostObject);
    }

    String methodName = null;
    // String url = null;
    NativeArray urls = null;
    Object content = null;
    NativeObject params = null;
    NativeArray headers = null;

    if (args[0] instanceof String) {
        methodName = (String) args[0];
    } else {
        throw new RuntimeException("HTTP method should be a String value");
    }

    if (args[1] instanceof String) {
        Object[] tmp = { args[1] };
        urls = (NativeArray) cx.newArray(thisObj, tmp);
    } else if (args[1] instanceof NativeArray) {
        urls = (NativeArray) args[1];
    } else {
        throw new RuntimeException("Url should be a String value or Array of Strings");
    }

    if (args.length > 2) {
        if (args[2] instanceof String) {
            content = (String) args[2];
        } else if (args[2] instanceof NativeArray) {
            content = (NativeArray) args[2];
        } else if (args[2] != null) {
            throw new RuntimeException("Content should be a String value or Array of Name-value pairs");
        }
    }

    if (args.length > 3) {
        if (args[3] instanceof NativeObject) {
            params = (NativeObject) args[3];
        } else if (args[3] != null) {
            throw new RuntimeException("Params argument should be an Object");
        }
    }

    if (args.length > 4) {
        if (args[4] instanceof NativeArray) {
            headers = (NativeArray) args[4];
        } else if (args[4] != null) {
            throw new RuntimeException("Headers argument should be an Object");
        }
    }

    Hashtable<String, SimpleHttpResponse> result = new Hashtable<String, SimpleHttpResponse>();
    int i = 0;
    for (i = 0; i < urls.getLength(); i++) {
        String url = urls.get(i, urls).toString();

        if (url != null) {
            if (methodName.equals("GET")) {
                method = new GetMethod(url);
            } else if (methodName.equals("POST")) {
                method = new PostMethod(url);
            } else if (methodName.equals("PUT")) {
                method = new PutMethod(url);
            } else if (methodName.equals("DELETE")) {
                method = new DeleteMethod(url);
            } else {
                throw new RuntimeException("HTTP method you specified is not supported");
            }
        } else {
            throw new RuntimeException("A url should be specified");
        }

        if (headers != null) {
            setHeaders(method, headers);
        }

        if (params != null) {
            setParams(httpClientHostObject, method, contentType, charset, methodName, content, params);
        } else if (content != null) {
            setContent(method, contentType, charset, methodName, content);
        }

        // check whether host configuration details has been set
        if (httpClientHostObject.host != null) {
            setHostConfig(httpClientHostObject);
        }

        pool.execute(new HttpCommand(httpClientHostObject.httpClient, method, result, i));
    }

    // wait for the result.
    int total = i;
    do {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    } while (result.size() < total);

    if (result.size() == 1) {
        return Context.toObject(result.get("0"), thisObj);
    } else {
        // order matters
        Object[] res = new Object[result.size()];
        for (i = 0; i < result.size(); i++) {
            res[i] = result.get(i + "");
        }
        return Context.toObject(res, thisObj);
    }
}

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 av  a 2  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 {//from  w  w w  .  jav  a 2 s  .c  o m
        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;
}

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

public static void main(String[] args) {

    try {/*from w  ww .  java2  s .co m*/
        //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();
    }
}