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:com.dtolabs.client.utils.HttpClientChannel.java

/**
 * Create new HttpMethod objects for the requestUrl, and set any request headers specified previously
 *//*ww  w  .java  2 s.  c  o m*/
private HttpMethod initMethod() {
    if ("GET".equalsIgnoreCase(getMethodType())) {
        httpMethod = new GetMethod(requestUrl);
    } else if ("POST".equalsIgnoreCase(getMethodType())) {
        httpMethod = new PostMethod(requestUrl);
    } else if ("PUT".equalsIgnoreCase(getMethodType())) {
        httpMethod = new PutMethod(requestUrl);
    } else if ("DELETE".equalsIgnoreCase(getMethodType())) {
        httpMethod = new DeleteMethod(requestUrl);
    } else {
        throw new IllegalArgumentException("Unknown method type: " + getMethodType());
    }
    if (reqHeaders.size() > 0) {
        for (Iterator i = reqHeaders.keySet().iterator(); i.hasNext();) {
            String s = (String) i.next();
            String v = (String) reqHeaders.get(s);
            httpMethod.setRequestHeader(s, v);
        }
    }
    return httpMethod;
}

From source file:com.intuit.tank.httpclient3.TankHttpClient3.java

@Override
public void doDelete(BaseRequest request) {
    DeleteMethod httpdelete = new DeleteMethod(request.getRequestUrl());
    // Multiple calls can be expensive, so get it once
    String requestBody = request.getBody();
    String type = request.getHeaderInformation().get("Content-Type");
    if (StringUtils.isBlank(type)) {
        request.getHeaderInformation().put("Content-Type", "application/x-www-form-urlencoded");
    }//from   www .j a  v a2s. co  m
    sendRequest(request, httpdelete, requestBody);
}

From source file:net.bioclipse.opentox.api.Dataset.java

public static void deleteDataset(String datasetURI) throws Exception {
    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(datasetURI);
    HttpMethodHelper.addMethodHeaders(method, null);
    client.executeMethod(method);//  w  ww . ja  v a  2s. c o m
    int status = method.getStatusCode();
    method.releaseConnection();
    if (status == 404)
        throw new IllegalArgumentException("Dataset does not exist.");
    if (status == 503)
        throw new IllegalStateException("Service error: " + status);
}

From source file:com.utest.webservice.client.rest.RestClient.java

public HttpMethod createDelete(String service, String path, Map<String, Object> parameters) {
    DeleteMethod delete = new DeleteMethod(
            baseUrl + servicePath + service + "/" + path + paramsToString(parameters));
    setHeader(delete);// w w w  .ja  v a2s.c  o m
    return delete;
}

From source file:com.mercatis.lighthouse3.commons.commons.HttpRequest.java

/**
 * This method performs an HTTP request against an URL.
 *
 * @param url         the URL to call//from w w  w  .j  a  v a2  s .co m
 * @param method      the HTTP method to execute
 * @param body        the body of a POST or PUT request, can be <code>null</code>
 * @param queryParams a Hash with the query parameter, can be <code>null</code>
 * @return the data returned by the web server
 * @throws HttpException in case a communication error occurred.
 */
@SuppressWarnings("deprecation")
public String execute(String url, HttpRequest.HttpMethod method, String body, Map<String, String> queryParams) {

    NameValuePair[] query = null;

    if (queryParams != null) {
        query = new NameValuePair[queryParams.size()];

        int counter = 0;
        for (Entry<String, String> queryParam : queryParams.entrySet()) {
            query[counter] = new NameValuePair(queryParam.getKey(), queryParam.getValue());
            counter++;
        }
    }

    org.apache.commons.httpclient.HttpMethod request = null;

    if (method == HttpMethod.GET) {
        request = new GetMethod(url);
    } else if (method == HttpMethod.POST) {
        PostMethod postRequest = new PostMethod(url);
        if (body != null) {
            postRequest.setRequestBody(body);
        }
        request = postRequest;
    } else if (method == HttpMethod.PUT) {
        PutMethod putRequest = new PutMethod(url);
        if (body != null) {
            putRequest.setRequestBody(body);
        }
        request = putRequest;
    } else if (method == HttpMethod.DELETE) {
        request = new DeleteMethod(url);
    }

    request.setRequestHeader("Content-type", "application/xml;charset=utf-8");
    if (query != null) {
        request.setQueryString(query);
    }

    int resultCode = 0;
    StringBuilder resultBodyBuilder = new StringBuilder();

    try {
        resultCode = this.httpClient.executeMethod(request);
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(request.getResponseBodyAsStream(), Charset.forName("UTF-8")));
        String line = null;
        while ((line = reader.readLine()) != null) {
            resultBodyBuilder.append(line);
        }

        if (resultCode != 200) {
            throw new HttpException(resultBodyBuilder.toString(), null);
        }
    } catch (HttpException httpException) {
        throw new HttpException("HTTP request failed", httpException);
    } catch (IOException ioException) {
        throw new HttpException("HTTP request failed", ioException);
    } catch (NullPointerException npe) {
        throw new HttpException("HTTP request failed", npe);
    } finally {
        request.releaseConnection();
    }

    return resultBodyBuilder.toString();
}

From source file:flex.messaging.services.http.proxy.RequestFilter.java

/**
 * Setup the request./*ww w.  j  av a2s . c  om*/
 *
 * @param context the context
 */
protected void setupRequest(ProxyContext context) {
    // set the proxy to send requests through
    ExternalProxySettings externalProxy = context.getExternalProxySettings();
    if (externalProxy != null) {
        String proxyServer = externalProxy.getProxyServer();

        if (proxyServer != null) {
            context.getTarget().getHostConfig().setProxy(proxyServer, externalProxy.getProxyPort());
            if (context.getProxyCredentials() != null) {
                context.getHttpClient().getState().setProxyCredentials(ProxyUtil.getDefaultAuthScope(),
                        context.getProxyCredentials());
            }
        }
    }

    String method = context.getMethod();
    String encodedPath = context.getTarget().getEncodedPath();
    if (MessageIOConstants.METHOD_POST.equals(method)) {
        FlexPostMethod postMethod = new FlexPostMethod(encodedPath);
        context.setHttpMethod(postMethod);
        if (context.hasAuthorization()) {
            postMethod.setConnectionForced(true);
        }
    } else if (ProxyConstants.METHOD_GET.equals(method)) {
        FlexGetMethod getMethod = new FlexGetMethod(context.getTarget().getEncodedPath());
        context.setHttpMethod(getMethod);
        if (context.hasAuthorization()) {
            getMethod.setConnectionForced(true);
        }
    } else if (ProxyConstants.METHOD_HEAD.equals(method)) {
        HeadMethod headMethod = new HeadMethod(encodedPath);
        context.setHttpMethod(headMethod);
    } else if (ProxyConstants.METHOD_PUT.equals(method)) {
        PutMethod putMethod = new PutMethod(encodedPath);
        context.setHttpMethod(putMethod);
    } else if (ProxyConstants.METHOD_OPTIONS.equals(method)) {
        OptionsMethod optionsMethod = new OptionsMethod(encodedPath);
        context.setHttpMethod(optionsMethod);
    } else if (ProxyConstants.METHOD_DELETE.equals(method)) {
        DeleteMethod deleteMethod = new DeleteMethod(encodedPath);
        context.setHttpMethod(deleteMethod);
    } else if (ProxyConstants.METHOD_TRACE.equals(method)) {
        TraceMethod traceMethod = new TraceMethod(encodedPath);
        context.setHttpMethod(traceMethod);
    } else {
        ProxyException pe = new ProxyException(INVALID_METHOD);
        pe.setDetails(INVALID_METHOD, "1", new Object[] { method });
        throw pe;
    }

    HttpMethodBase httpMethod = context.getHttpMethod();
    if (httpMethod instanceof EntityEnclosingMethod) {
        ((EntityEnclosingMethod) httpMethod).setContentChunked(context.getContentChunked());
    }
}

From source file:com.manning.blogapps.chapter10.atomclient.AtomBlog.java

public void deleteEntry(BlogEntry entry) throws BlogClientException {
    DeleteMethod method = new DeleteMethod(entry.getToken());
    AtomBlogConnection.addAuthentication(method, username, password);
    try {/*from w  ww . j ava2 s. c o m*/
        httpClient.executeMethod(method);
    } catch (IOException ex) {
        throw new BlogClientException("ERROR: deleting entry", ex);
    }
}

From source file:com.sun.syndication.propono.atom.client.ClientEntry.java

/**
 * Remove entry from server./*from  w w  w  . j a v  a 2s  . c o m*/
 */
public void remove() throws ProponoException {
    if (getEditURI() == null) {
        throw new ProponoException("ERROR: cannot delete unsaved entry");
    }
    DeleteMethod method = new DeleteMethod(getEditURI());
    addAuthentication(method);
    try {
        getHttpClient().executeMethod(method);
    } catch (IOException ex) {
        throw new ProponoException("ERROR: removing entry, HTTP code", ex);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.ideabase.repository.webservice.client.impl.HttpWebServiceControllerImpl.java

private HttpMethod prepareMethod(final String pMethod, final String pServiceUri,
        final NameValuePair[] pParameters) {
    LOG.debug("Prepare appropriate http method.");

    final String baseUrl;
    if (mBaseUrl.endsWith("/")) {
        baseUrl = mBaseUrl.substring(0, mBaseUrl.length() - 1);
    } else {/*ww w. j a  va 2  s. c o  m*/
        baseUrl = mBaseUrl;
    }
    final String fullQualifiedUri = baseUrl + pServiceUri;
    final HttpMethod httpMethod;
    // GET method
    if (GET.equalsIgnoreCase(pMethod)) {
        httpMethod = new GetMethod(fullQualifiedUri);
        if (pParameters != null) {
            httpMethod.setQueryString(pParameters);
        }
    }
    // POST method
    else if (POST.equalsIgnoreCase(pMethod)) {
        httpMethod = new PostMethod(fullQualifiedUri);
        if (pParameters != null) {
            ((PostMethod) httpMethod).addParameters(pParameters);
        }
    }
    // DELETE method
    else if (DELETE.equalsIgnoreCase(pMethod)) {
        httpMethod = new DeleteMethod(fullQualifiedUri);
        if (pParameters != null) {
            httpMethod.setQueryString(pParameters);
        }
    }
    // If no such known method.
    else {
        throw new UnsupportedOperationException("Unknown method type - " + pMethod);
    }
    return httpMethod;
}

From source file:eu.eco2clouds.api.bonfire.client.rest.RestClient.java

/**
 * @param url //from w  ww.  ja  v  a2s  .co m
 * @param id of the resource to be deleted
 * @return Response object encapsulation all the HTTP information, it returns <code>null</code> if there was an error.
 */
public static Response executeDeleteMethod(String url, String username, String password) {

    DeleteMethod delete = new DeleteMethod(url);

    return executeMethod(delete, BONFIRE_XML, username, password, url);
}