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.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 av a 2s .  c om*/

    String rt = method.getResponseBodyAsString();

    return rt;

}

From source file:org.eclipse.ecf.remoteservice.rest.client.RestClientService.java

/**
 * @throws RestException  /*from  www  .ja v  a  2  s.c o  m*/
 */
protected HttpMethod prepareDeleteMethod(String uri, IRemoteCall call, IRemoteCallable callable)
        throws RestException {
    return new DeleteMethod(uri);
}

From source file:org.eclipse.om2m.comm.http.RestHttpClient.java

/**
* Converts a protocol-independent {@link RequestIndication} object into a standard HTTP request and sends a standard HTTP request.
* Converts the received standard HTTP request into {@link ResponseConfirm} object and returns it back.
* @param requestIndication - protocol independent request.
* @return protocol independent response.
*///from  w w w.  j a v a2 s.c  om
public ResponseConfirm sendRequest(RequestIndication requestIndication) {

    logServiceTracker = new ServiceTracker(FrameworkUtil.getBundle(RestHttpClient.class).getBundleContext(),
            org.osgi.service.log.LogService.class.getName(), null);
    logServiceTracker.open();
    logservice = (LogService) logServiceTracker.getService();
    LOGGER.debug("Http Client > " + requestIndication);
    logservice.log(LogService.LOG_ERROR, "Http Client > " + requestIndication);

    HttpClient httpclient = new HttpClient();

    ResponseConfirm responseConfirm = new ResponseConfirm();
    HttpMethod httpMethod = null;
    String url = requestIndication.getUrl();
    if (!url.startsWith(protocol + "://")) {
        url = protocol + "://" + url;
    }
    try {
        switch (requestIndication.getMethod()) {
        case "RETRIEVE":
            httpMethod = new GetMethod(url);
            break;
        case "CREATE":
            httpMethod = new PostMethod(url);

            ((PostMethod) httpMethod).setRequestEntity(
                    new StringRequestEntity(requestIndication.getRepresentation(), "application/xml", "UTF8"));
            break;
        case "UPDATE":
            httpMethod = new PutMethod(url);
            ((PutMethod) httpMethod).setRequestEntity(
                    new StringRequestEntity(requestIndication.getRepresentation(), "application/xml", "UTF8"));
            break;
        case "DELETE":
            httpMethod = new DeleteMethod(url);
            break;
        case "EXECUTE":
            httpMethod = new PostMethod(url);
            break;
        default:
            return new ResponseConfirm();
        }
        httpMethod.addRequestHeader("Authorization",
                "Basic " + new String(Base64.encodeBase64(requestIndication.getRequestingEntity().getBytes())));
        httpMethod.setQueryString(getQueryFromParams(requestIndication.getParameters()));

        int statusCode = httpclient.executeMethod(httpMethod);
        responseConfirm.setStatusCode(getRestStatusCode(statusCode));

        if (statusCode != 204) {
            if (httpMethod.getResponseBody() != null) {
                responseConfirm.setRepresentation(new String(httpMethod.getResponseBody()));
            }
        }
        if (statusCode == 201) {
            if (httpMethod.getResponseHeader("Location").getValue() != null) {
                responseConfirm.setResourceURI(httpMethod.getResponseHeader("Location").getValue());
            }
        }
        //LOGGER.debug("Http Client > "+responseConfirm);
        LOGGER.debug("Http Client > " + responseConfirm);
        logservice.log(LogService.LOG_ERROR, "Http Client > " + responseConfirm);

    } catch (IOException e) {
        LOGGER.error(url + " Not Found" + responseConfirm, e);
        logservice.log(LogService.LOG_ERROR, url + " Not Found" + responseConfirm);

    } finally {
        httpMethod.releaseConnection();
    }

    return responseConfirm;
}

From source file:org.eclipse.orion.server.cf.commands.DeleteApplicationCommand.java

@Override
protected ServerStatus _doIt() {
    try {// w  ww.j  a v  a 2s  . c  om

        /* read deploy parameters */
        JSONObject appMetadata = null;
        JSONObject appEntity = null;

        URI targetURI = URIUtil.toURI(target.getUrl());

        /* get application details */
        String appsUrl = target.getSpace().getCFJSON().getJSONObject("entity").getString("apps_url"); //$NON-NLS-1$//$NON-NLS-2$
        URI appsURI = targetURI.resolve(appsUrl);
        GetMethod getAppsMethod = new GetMethod(appsURI.toString());
        HttpUtil.configureHttpMethod(getAppsMethod, target);
        getAppsMethod.setQueryString("q=name:" + appName + "&inline-relations-depth=1"); //$NON-NLS-1$ //$NON-NLS-2$

        ServerStatus appsStatus = HttpUtil.executeMethod(getAppsMethod);
        if (!appsStatus.isOK())
            return appsStatus;

        JSONObject apps = appsStatus.getJsonData();
        if (!apps.has("resources") || apps.getJSONArray("resources").length() == 0) //$NON-NLS-1$//$NON-NLS-2$
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Application not found",
                    null);

        appMetadata = apps.getJSONArray("resources").getJSONObject(0).getJSONObject("metadata"); //$NON-NLS-1$ //$NON-NLS-2$
        appEntity = apps.getJSONArray("resources").getJSONObject(0).getJSONObject("entity"); //$NON-NLS-1$ //$NON-NLS-2$

        if (application.getGuid() == null) {

            String summaryAppUrl = appMetadata.getString("url") + "/summary"; //$NON-NLS-1$ //$NON-NLS-2$
            URI summaryAppURI = targetURI.resolve(summaryAppUrl);

            GetMethod getSummaryMethod = new GetMethod(summaryAppURI.toString());
            HttpUtil.configureHttpMethod(getSummaryMethod, target);

            ServerStatus getStatus = HttpUtil.executeMethod(getSummaryMethod);
            if (!getStatus.isOK())
                return getStatus;

            JSONObject summaryJSON = getStatus.getJsonData();

            /* set known application GUID */
            application.setGuid(summaryJSON.getString(CFProtocolConstants.V2_KEY_GUID));
        }

        /* gather application service bindings */
        ArrayList<String> serviceInstances = new ArrayList<String>();
        JSONArray appServiceBindings = appEntity.getJSONArray("service_bindings"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        for (int i = 0; i < appServiceBindings.length(); ++i) {
            JSONObject binding = appServiceBindings.getJSONObject(i).getJSONObject("entity"); //$NON-NLS-1$
            serviceInstances.add(binding.getString("service_instance_url")); //$NON-NLS-1$
        }

        /* delete the application */
        URI appURI = targetURI.resolve("/v2/apps/" + application.getGuid()); //$NON-NLS-1$

        DeleteMethod deleteAppMethod = new DeleteMethod(appURI.toString());
        HttpUtil.configureHttpMethod(deleteAppMethod, target);
        deleteAppMethod.setQueryString("recursive=true"); //$NON-NLS-1$

        ServerStatus status = HttpUtil.executeMethod(deleteAppMethod);
        return status;

    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName);
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:org.eclipse.orion.server.cf.commands.DeleteApplicationRoutesCommand.java

@Override
protected ServerStatus _doIt() {
    MultiServerStatus status = new MultiServerStatus();

    try {/*from   w  w  w.j ava2  s.  co m*/
        URI targetURI = URIUtil.toURI(target.getUrl());

        // get app details
        // TODO: it should be passed along with App object
        String appsUrl = target.getSpace().getCFJSON().getJSONObject("entity").getString("apps_url"); //$NON-NLS-1$//$NON-NLS-2$
        URI appsURI = targetURI.resolve(appsUrl);
        GetMethod getAppsMethod = new GetMethod(appsURI.toString());
        HttpUtil.configureHttpMethod(getAppsMethod, target);
        getAppsMethod.setQueryString("q=name:" + appName + "&inline-relations-depth=1"); //$NON-NLS-1$ //$NON-NLS-2$

        ServerStatus appsStatus = HttpUtil.executeMethod(getAppsMethod);
        status.add(appsStatus);
        if (!status.isOK())
            return status;

        JSONObject jsonData = appsStatus.getJsonData();
        if (!jsonData.has("resources") || jsonData.getJSONArray("resources").length() == 0) //$NON-NLS-1$//$NON-NLS-2$
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Application not found",
                    null);
        JSONArray apps = jsonData.getJSONArray("resources");

        // get app routes
        String routesUrl = apps.getJSONObject(0).getJSONObject("entity").getString("routes_url");
        URI routesURI = targetURI.resolve(routesUrl);
        GetMethod getRoutesMethod = new GetMethod(routesURI.toString());
        HttpUtil.configureHttpMethod(getRoutesMethod, target);

        ServerStatus routesStatus = HttpUtil.executeMethod(getRoutesMethod);
        status.add(routesStatus);
        if (!status.isOK())
            return status;

        jsonData = routesStatus.getJsonData();
        if (!jsonData.has("resources") || jsonData.getJSONArray("resources").length() == 0) //$NON-NLS-1$//$NON-NLS-2$
            return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, "No routes for the app", null);
        JSONArray routes = jsonData.getJSONArray("resources");

        for (int i = 0; i < routes.length(); ++i) {
            JSONObject route = routes.getJSONObject(i);

            // delete route
            String routeUrl = route.getJSONObject(CFProtocolConstants.V2_KEY_METADATA)
                    .getString(CFProtocolConstants.V2_KEY_URL);
            URI routeURI = targetURI.resolve(routeUrl); //$NON-NLS-1$
            DeleteMethod deleteRouteMethod = new DeleteMethod(routeURI.toString());
            HttpUtil.configureHttpMethod(deleteRouteMethod, target);

            ServerStatus deleteStatus = HttpUtil.executeMethod(deleteRouteMethod);
            status.add(deleteStatus);
            if (!status.isOK())
                return status;
        }

        return status;

    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName);
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:org.eclipse.orion.server.cf.commands.DeleteRouteCommand.java

@Override
protected ServerStatus _doIt() {
    try {/*w ww.ja va2s.c o m*/
        URI targetURI = URIUtil.toURI(target.getUrl());

        /* delete the route */
        URI routeURI = targetURI.resolve("/v2/routes/" + route.getGuid()); //$NON-NLS-1$

        DeleteMethod deleteRouteMethod = new DeleteMethod(routeURI.toString());
        HttpUtil.configureHttpMethod(deleteRouteMethod, target);
        deleteRouteMethod.setQueryString("recursive=true"); //$NON-NLS-1$

        ServerStatus status = HttpUtil.executeMethod(deleteRouteMethod);
        return status;

    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName);
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:org.eclipse.orion.server.cf.commands.UnmapRouteCommand.java

@Override
protected ServerStatus _doIt() {
    try {// w ww .  ja  v  a2s . c  o m

        /* unmap route from application */
        URI targetURI = URIUtil.toURI(target.getUrl());
        DeleteMethod unmapRouteMethod = new DeleteMethod(
                targetURI.resolve("/v2/apps/" + app.getGuid() + "/routes/" + route.getGuid()).toString()); //$NON-NLS-1$//$NON-NLS-2$
        HttpUtil.configureHttpMethod(unmapRouteMethod, target);
        return HttpUtil.executeMethod(unmapRouteMethod);

    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:org.eclipse.orion.server.cf.live.cflauncher.commands.DeleteFileCommand.java

@Override
public IStatus doIt() {
    try {//from ww  w . jav a  2  s.  c  om
        /* Construct WebDAV request to update the file. */
        String path = CFLauncherConstants.cfLauncherPrefix + DAV_PATH + this.path; // launcher/dav/whatever.txt
        URI fileUpdateURI = new URI("https", null, this.uri, 443, path, null, null);

        DeleteMethod deleteFileMethod = new DeleteMethod(fileUpdateURI.toString());
        configureHttpMethod(deleteFileMethod);

        ServerStatus status = executeMethod(deleteFileMethod);
        if (!status.isOK())
            return status;

        return status;

    } catch (Exception e) {
        String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
        logger.error(msg, e);
        return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
}

From source file:org.eclipse.rtp.configurator.rest.RestTemplate.java

public void delete(String string) {
    DeleteMethod method = new DeleteMethod(urlBase + string);
    executeMethod(method);
}

From source file:org.eclipse.smarthome.io.net.http.HttpUtil.java

/**
 * Factory method to create a {@link HttpMethod}-object according to the 
 * given String <code>httpMethod</codde>
 * /*ww  w . ja va  2  s.  c  o m*/
 * @param httpMethodString the name of the {@link HttpMethod} to create
 * @param url
 * 
 * @return an object of type {@link GetMethod}, {@link PutMethod}, 
 * {@link PostMethod} or {@link DeleteMethod}
 * @throws IllegalArgumentException if <code>httpMethod</code> is none of
 * <code>GET</code>, <code>PUT</code>, <code>POST</POST> or <code>DELETE</code>
 */
public static HttpMethod createHttpMethod(String httpMethodString, String url) {

    if ("GET".equals(httpMethodString)) {
        return new GetMethod(url);
    } else if ("PUT".equals(httpMethodString)) {
        return new PutMethod(url);
    } else if ("POST".equals(httpMethodString)) {
        return new PostMethod(url);
    } else if ("DELETE".equals(httpMethodString)) {
        return new DeleteMethod(url);
    } else {
        throw new IllegalArgumentException("given httpMethod '" + httpMethodString + "' is unknown");
    }
}