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.iavante.sling.s3backend.S3BackendTestIT.java

private void deleteContent(String content) {

    // Delete the content
    DeleteMethod post_delete = new DeleteMethod(content);

    post_delete.setDoAuthentication(true);
    // post_delete.setRequestBody(data_delete);

    try {// w  w  w.  ja  va2  s  .  co  m
        client.executeMethod(post_delete);
    } catch (HttpException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    assertEquals(204, post_delete.getStatusCode());
    log.info("Borrado contenido: " + content);
    post_delete.releaseConnection();

}

From source file:org.infoscoop.request.ProxyRequest.java

public int executeDelete() throws Exception {
    DeleteMethod method = null;/*from  w  ww .ja  v  a 2s  .c o  m*/
    try {
        HttpClient client = this.newHttpClient();
        method = new DeleteMethod(this.getTargetURL());
        method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(1, false));
        ProxyFilterContainer filterContainer = (ProxyFilterContainer) SpringUtil.getBean(filterType);
        return filterContainer.invoke(client, method, this);
    } catch (ProxyAuthenticationException e) {
        if (e.isTraceOn()) {
            log.error(this.getTargetURL());
            log.error("", e);
        } else {
            log.warn(this.getTargetURL() + " : " + e.getMessage());
        }
        return 401;
    }
}

From source file:org.intalio.tempo.workflow.tas.core.WDSStorageStrategy.java

public void deleteAttachment(Property[] props, String url) throws UnavailableAttachmentException {
    _logger.debug("Requested to delete attachment: '" + url + "'");

    DeleteMethod deleteMethod = new DeleteMethod(url);
    setUpMethod(deleteMethod);//from   w w w. ja  v  a  2 s  .c o  m
    HttpClient httpClient = getClient();
    try {
        int code = httpClient.executeMethod(deleteMethod);
        if (code != 200) {
            throw new UnavailableAttachmentException(
                    "Error code: " + code + " when attempting to DELETE '" + url + "'");
        }
    } catch (Exception e) {
        throw new UnavailableAttachmentException(e);
    }
    _logger.debug("Deleted attachment: '" + url + "'");
}

From source file:org.intalio.tempo.workflow.tas.nuxeo.NuxeoStorageStrategy.java

/**
 * Implement the interface for deleting a file
 *///from  ww  w.  j ava 2s . c o m
public void deleteAttachment(Property[] props, String url) throws UnavailableAttachmentException {
    try {
        // if (!init)
        init();
        String fileUrl = url.substring(0, url.indexOf(this.REST_DOWNLOAD));
        String newUri = fileUrl + REST_DELETE;
        log.debug("NUXEO DELETE:" + newUri);
        DeleteMethod method = new DeleteMethod(newUri);
        httpclient.executeMethod(method);
        // needed for proper httpclient handling
        // but we do not return the value
        // method.getResponseBodyAsString();
        method.releaseConnection();
    } catch (Exception e) {
        throw new UnavailableAttachmentException(e);
    }
}

From source file:org.intalio.tempo.workflow.tas.sling.SlingStorageStrategy.java

public void deleteAttachment(Property[] arg0, String arg1) throws UnavailableAttachmentException {
    DeleteMethod delete = new DeleteMethod(arg1);
    try {//from   www  .  jav a2 s  .com
        httpclient.executeMethod(delete);
    } catch (Exception e) {
        throw new UnavailableAttachmentException(e);
    }
}

From source file:org.intermine.webservice.client.util.HttpConnection.java

private void executeMethod() {
    HttpClient client = new HttpClient();
    client.getParams().setConnectionManagerTimeout(timeout);
    String url = request.getEncodedUrl();
    if (request.getType() == RequestType.GET) {
        executedMethod = new GetMethod(url);
    } else if (request.getType() == RequestType.DELETE) {
        executedMethod = new DeleteMethod(url);
    } else {/*  w ww . j  a v  a2s  .com*/
        PostMethod postMethod;
        if (request.getContentType() == ContentType.MULTI_PART_FORM) {
            postMethod = new PostMethod(url);
            setMultiPartPostEntity(postMethod, ((MultiPartRequest) request));
        } else {
            url = request.getServiceUrl();
            postMethod = new PostMethod(url);
            setPostMethodParameters(postMethod, request.getParameterMap());
        }
        executedMethod = postMethod;
    }
    // Provide custom retry handler is necessary
    executedMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(retryCount, false));
    for (String name : request.getHeaders().keySet()) {
        executedMethod.setRequestHeader(name, request.getHeader(name));
    }
    try {
        // Execute the method.
        client.executeMethod(executedMethod);
        checkResponse();
    } catch (HttpException e) {
        throw new RuntimeException("Fatal protocol violation.", e);
    } catch (IOException e) {
        throw new RuntimeException("Fatal transport error connecting to " + url, e);
    }
}

From source file:org.jaggeryjs2.xhr.XMLHttpRequest.java

private void sendRequest(Object obj) throws Exception {
    final HttpMethodBase method;
    if ("GET".equalsIgnoreCase(methodName)) {
        method = new GetMethod(this.url);
    } else if ("HEAD".equalsIgnoreCase(methodName)) {
        method = new HeadMethod(this.url);
    } else if ("POST".equalsIgnoreCase(methodName)) {
        PostMethod post = new PostMethod(this.url);
        if (obj instanceof FormData) {
            FormData fd = ((FormData) obj);
            List<Part> parts = new ArrayList<Part>();
            for (Map.Entry<String, String> entry : fd) {
                parts.add(new StringPart(entry.getKey(), entry.getValue()));
            }/* w  ww. ja va 2 s .  co m*/
            post.setRequestEntity(
                    new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post.getParams()));
        } else {
            String content = getRequestContent(obj);
            if (content != null) {
                post.setRequestEntity(
                        new InputStreamRequestEntity(new ByteArrayInputStream(content.getBytes())));
            }
        }
        method = post;
    } else if ("PUT".equalsIgnoreCase(methodName)) {
        PutMethod put = new PutMethod(this.url);
        String content = getRequestContent(obj);
        if (content != null) {
            put.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(content.getBytes())));
        }
        method = put;
    } else if ("DELETE".equalsIgnoreCase(methodName)) {
        method = new DeleteMethod(this.url);
    } else if ("TRACE".equalsIgnoreCase(methodName)) {
        method = new TraceMethod(this.url);
    } else if ("OPTIONS".equalsIgnoreCase(methodName)) {
        method = new OptionsMethod(this.url);
    } else {
        throw new Exception("Unknown HTTP method : " + methodName);
    }
    for (Header header : requestHeaders) {
        method.addRequestHeader(header);
    }
    if (username != null) {
        httpClient.getState().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(username, password));
    }
    this.method = method;
    final XMLHttpRequest xhr = this;
    if (async) {
        updateReadyState(xhr, LOADING);
        final ExecutorService es = Executors.newSingleThreadExecutor();
        es.submit(new Callable() {
            public Object call() throws Exception {
                try {
                    executeRequest(xhr);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                } finally {
                    es.shutdown();
                }
                return null;
            }
        });
    } else {
        executeRequest(xhr);
    }
}

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

/**
 * Test for SEAMSECURITY-83//from  www.j ava 2 s .  c om
 */
@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.soa.esb.actions.http.HttpAction.java

public Message process(final Message msg) throws ActionProcessingException {

    try {/*  w ww  .  j ava2  s .  co  m*/
        final HttpClient client = new HttpClient();

        final Properties props = msg.getProperties();

        final String[] names = props.getNames();

        if (METHOD_DELETE.equals(method)) {
            final HttpMethodBase req = new DeleteMethod(uri);

            for (int i = 0; i < names.length; i++) {
                final Matcher headerMatcher = PATTERN_HEADER.matcher(names[i]);

                if (headerMatcher.find())
                    req.addRequestHeader(headerMatcher.group(1),
                            (String) props.getProperty(headerMatcher.group()));

            }

            client.executeMethod(req);

            final Header[] headers = req.getResponseHeaders();

            for (int i = 0; i < headers.length; i++)
                props.setProperty(PREFIX_HEADER + headers[i].getName(), headers[i].getValue());

            proxy.setPayload(msg, req.getResponseBodyAsString());
        } else if (METHOD_GET.equals(method)) {
            final HttpMethodBase req = new GetMethod(uri);

            final List<NameValuePair> paramList = new ArrayList<NameValuePair>();

            for (int i = 0; i < names.length; i++) {
                final Matcher headerMatcher = PATTERN_HEADER.matcher(names[i]);

                if (headerMatcher.find()) {
                    req.addRequestHeader(headerMatcher.group(1),
                            (String) props.getProperty(headerMatcher.group()));

                    continue;
                }

                final Matcher paramMatcher = PATTERN_PARAM.matcher(names[i]);

                if (paramMatcher.find())
                    paramList.add(new NameValuePair(paramMatcher.group(1),
                            (String) props.getProperty(paramMatcher.group())));

            }

            req.setQueryString(paramList.toArray(new NameValuePair[] {}));

            client.executeMethod(req);

            final Header[] headers = req.getResponseHeaders();

            for (int i = 0; i < headers.length; i++)
                props.setProperty(PREFIX_HEADER + headers[i].getName(), headers[i].getValue());

            proxy.setPayload(msg, req.getResponseBodyAsString());
        } else if (METHOD_POST.equals(method)) {
            final PostMethod req = new PostMethod(uri);

            for (int i = 0; i < names.length; i++) {
                final Matcher headerMatcher = PATTERN_HEADER.matcher(names[i]);

                if (headerMatcher.find()) {
                    req.addRequestHeader(headerMatcher.group(1),
                            (String) props.getProperty(headerMatcher.group()));

                    continue;
                }

                final Matcher paramMatcher = PATTERN_PARAM.matcher(names[i]);

                if (paramMatcher.find())
                    req.addParameter(new NameValuePair(paramMatcher.group(1),
                            (String) props.getProperty(paramMatcher.group())));

            }

            req.setRequestEntity(new StringRequestEntity((String) proxy.getPayload(msg), null, null));

            client.executeMethod(req);

            final Header[] headers = req.getResponseHeaders();

            for (int i = 0; i < headers.length; i++)
                props.setProperty(PREFIX_HEADER + headers[i].getName(), headers[i].getValue());

            proxy.setPayload(msg, req.getResponseBodyAsString());
        } else if (METHOD_PUT.equals(method)) {
            final EntityEnclosingMethod req = new PutMethod(uri);

            for (int i = 0; i < names.length; i++) {
                final Matcher headerMatcher = PATTERN_HEADER.matcher(names[i]);

                if (headerMatcher.find())
                    req.addRequestHeader(headerMatcher.group(1),
                            (String) props.getProperty(headerMatcher.group()));

            }

            req.setRequestEntity(new StringRequestEntity((String) proxy.getPayload(msg), null, null));

            client.executeMethod(req);

            final Header[] headers = req.getResponseHeaders();

            for (int i = 0; i < headers.length; i++)
                props.setProperty(PREFIX_HEADER + headers[i].getName(), headers[i].getValue());

            proxy.setPayload(msg, req.getResponseBodyAsString());
        }

    } catch (final Exception e) {
        throw new ActionProcessingException("Can't process message", e);
    }

    return msg;
}

From source file:org.jboss.web.loadbalancer.Loadbalancer.java

protected HttpMethod createMethod(HttpServletRequest request, HttpServletResponse response, int requestMethod)
        throws NoHostAvailableException {
    String url = null;//  w w  w. ja  v  a 2 s. c  o m
    HttpMethod method = null;

    // get target host from scheduler
    url = scheduler.getHost(request, response).toExternalForm();

    String path = url.substring(0, url.length() - 1) + request.getRequestURI();

    switch (requestMethod) {
    case Constants.HTTP_METHOD_GET:
        method = new GetMethod(path);
        break;
    case Constants.HTTP_METHOD_POST:
        method = new PostMethod(path);
        break;
    case Constants.HTTP_METHOD_DELETE:
        method = new DeleteMethod(path);
        break;
    case Constants.HTTP_METHOD_HEAD:
        method = new HeadMethod(path);
        break;
    case Constants.HTTP_METHOD_OPTIONS:
        method = new OptionsMethod(path);
        break;
    case Constants.HTTP_METHOD_PUT:
        method = new PutMethod(path);
        break;
    default:
        throw new IllegalStateException("Unknown Request Method " + request.getMethod());
    }

    return method;
}