Example usage for org.apache.http.client.methods HttpDelete HttpDelete

List of usage examples for org.apache.http.client.methods HttpDelete HttpDelete

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpDelete HttpDelete.

Prototype

public HttpDelete(final String uri) 

Source Link

Usage

From source file:com.urbancode.ud.client.VersionClient.java

public void deleteVersion(UUID versionId) throws IOException {
    String uri = url + "/rest/deploy/version/" + versionId.toString();

    HttpDelete method = new HttpDelete(uri);
    try {/*from w  w  w. ja  v a 2  s. c  om*/
        invokeMethod(method);
    } finally {
        releaseConnection(method);
    }
}

From source file:com.hoccer.api.RESTfulApiTest.java

@Test(timeout = 4000)
public void testSigningOffJustCreatedClient() throws Exception {

    String client = ClientConfig.getLinccerBaseUri() + "/clients/" + UUID.randomUUID().toString();

    publishPosition(client + "/environment");

    HttpResponse response = receiveOneToOne(client);
    // response.getEntity().consumeContent();

    HttpDelete request = new HttpDelete(client + "/environment");
    response = mHttpClient.execute(request);
    response.getEntity().consumeContent();
    assertEquals("should be able to sign off client", 200, response.getStatusLine().getStatusCode());
}

From source file:com.adobe.ags.curly.controller.ActionRunner.java

@Override
public void run() {
    if (!ApplicationState.getInstance().runningProperty().get()) {
        response.setException(new Exception(ApplicationState.getMessage(ACTIVITY_TERMINATED)));
        return;/*  w  w w.  j a v  a  2  s.  co  m*/
    }
    response.started().set(true);
    response.updateProgress(0.5);

    if (action.getDelay() > 0) {
        try {
            Thread.sleep(action.getDelay());
        } catch (InterruptedException ex) {
            response.setException(ex);
            return;
        }
    }

    HttpUriRequest request;
    try {
        switch (httpMethod) {
        case GET:
            request = new HttpGet(getURL());
            break;
        case HEAD:
            request = new HttpHead(getURL());
            break;
        case DELETE:
            request = new HttpDelete(getURL());
            break;
        case POST:
            request = new HttpPost(getURL());
            addPostParams((HttpPost) request);
            break;
        case PUT:
            request = new HttpPut(getURL());
            ((HttpPut) request).setEntity(new FileEntity(new File(putFile)));
            break;
        default:
            throw new UnsupportedOperationException(
                    ApplicationState.getMessage(UNSUPPORTED_METHOD_ERROR) + ": " + httpMethod.name());
        }

        addHeaders(request);
        Optional<Exception> ex = processor.apply((CloseableHttpClient client) -> {
            try (CloseableHttpResponse httpResponse = client.execute(request, ConnectionManager.getContext())) {
                response.processHttpResponse(httpResponse, action.getResultType());
                EntityUtils.consume(httpResponse.getEntity());
                return Optional.empty();
            } catch (Exception e) {
                return Optional.of(e);
            }
        });
        if (ex.isPresent()) {
            throw ex.get();
        }
    } catch (Exception ex) {
        Logger.getLogger(ActionRunner.class.getName()).log(Level.SEVERE, null, ex);
        response.setException(ex);
    } finally {
        response.updateProgress(1);
    }
}

From source file:com.google.dataconnector.client.fetchrequest.HttpFetchStrategy.java

/**
 * Based on the inbound request type header, determine the correct http
 * method to use.  If a method cannot be determined (or not specified),
 * HTTP GET is attempted.//  w w  w . ja va 2 s  . c  o  m
 */
HttpRequestBase getMethod(FetchRequest request) {
    String method = null;
    for (MessageHeader h : request.getHeadersList()) {
        if ("x-sdc-http-method".equalsIgnoreCase(h.getKey())) {
            method = h.getValue().toUpperCase();
        }
    }

    LOG.info(request.getId() + ": method=" + method + ", resource=" + request.getResource()
            + ((request.hasContents()) ? ", payload_size=" + request.getContents().size() : ""));

    if (method == null) {
        LOG.info(request.getId() + ": No http method specified. Default to GET.");
        method = "GET";
    }

    if ("GET".equals(method)) {
        return new HttpGet(request.getResource());
    }
    if ("POST".equals(method)) {
        HttpPost httpPost = new HttpPost(request.getResource());
        if (request.hasContents()) {
            LOG.debug(request.getId() + ": Content = " + new String(request.getContents().toByteArray()));
            httpPost.setEntity(new ByteArrayEntity(request.getContents().toByteArray()));
        }
        return httpPost;
    }
    if ("PUT".equals(method)) {
        HttpPut httpPut = new HttpPut(request.getResource());
        if (request.hasContents()) {
            LOG.debug(request.getId() + ": Content = " + new String(request.getContents().toByteArray()));
            httpPut.setEntity(new ByteArrayEntity(request.getContents().toByteArray()));
        }
        return httpPut;
    }
    if ("DELETE".equals(method)) {
        return new HttpDelete(request.getResource());
    }
    if ("HEAD".equals(method)) {
        return new HttpHead(request.getResource());
    }
    LOG.info(request.getId() + ": Unknown method " + method);
    return null;
}

From source file:org.dasein.cloud.ibm.sce.SCEMethod.java

public void delete(@Nonnull String resource) throws CloudException, InternalException {
    Logger std = SCE.getLogger(SCEMethod.class, "std");
    Logger wire = SCE.getLogger(SCEMethod.class, "wire");

    if (std.isTraceEnabled()) {
        std.trace("enter - " + SCEMethod.class.getName() + ".post(" + resource + ")");
    }/*from   w w w  .  j  a v a 2 s  . com*/
    if (wire.isDebugEnabled()) {
        wire.debug("POST --------------------------------------------------------> " + endpoint + resource);
        wire.debug("");
    }
    try {
        HttpClient client = getClient();
        HttpDelete method = new HttpDelete(endpoint + resource);

        method.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        if (wire.isDebugEnabled()) {
            wire.debug(method.getRequestLine().toString());
            for (Header header : method.getAllHeaders()) {
                wire.debug(header.getName() + ": " + header.getValue());
            }
            wire.debug("");
        }
        HttpResponse response;
        StatusLine status;

        try {
            APITrace.trace(provider, resource);
            response = client.execute(method);
            status = response.getStatusLine();
        } catch (IOException e) {
            std.error("post(): Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage());
            if (std.isTraceEnabled()) {
                e.printStackTrace();
            }
            throw new CloudException(e);
        }
        if (std.isDebugEnabled()) {
            std.debug("post(): HTTP Status " + status);
        }
        Header[] headers = response.getAllHeaders();

        if (wire.isDebugEnabled()) {
            wire.debug(status.toString());
            for (Header h : headers) {
                if (h.getValue() != null) {
                    wire.debug(h.getName() + ": " + h.getValue().trim());
                } else {
                    wire.debug(h.getName() + ":");
                }
            }
            wire.debug("");
        }
        if (status.getStatusCode() != HttpServletResponse.SC_OK
                && status.getStatusCode() != HttpServletResponse.SC_CREATED
                && status.getStatusCode() != HttpServletResponse.SC_ACCEPTED) {
            std.error("post(): Expected OK for GET request, got " + status.getStatusCode());

            HttpEntity entity = response.getEntity();

            if (entity == null) {
                throw new SCEException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(),
                        "An error was returned without explanation");
            }
            String body;

            try {
                body = EntityUtils.toString(entity);
            } catch (IOException e) {
                throw new SCEException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(),
                        e.getMessage());
            }
            if (wire.isDebugEnabled()) {
                wire.debug(body);
            }
            wire.debug("");
            throw new SCEException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(),
                    body);
        }
    } finally {
        if (std.isTraceEnabled()) {
            std.trace("exit - " + SCEMethod.class.getName() + ".post()");
        }
        if (wire.isDebugEnabled()) {
            wire.debug("");
            wire.debug("POST --------------------------------------------------------> " + endpoint + resource);
        }
    }
}

From source file:org.deviceconnect.android.profile.restful.test.NormalVibrationProfileTestCase.java

/**
 * Vibration?????./*from w  w w .ja  v a2s.  c  om*/
 * <pre>
 * ?HTTP
 * Method: DELETE
 * Path: /vibration/vibrate?deviceid=xxxx
 * </pre>
 * <pre>
 * ??
 * result?0???????
 * </pre>
 */
public void testDeleteVibrate() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + VibrationProfileConstants.PROFILE_NAME);
    builder.append("/" + VibrationProfileConstants.ATTRIBUTE_VIBRATE);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpUriRequest request = new HttpDelete(builder.toString());
        JSONObject root = sendRequest(request);
        assertResultOK(root);
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:com.aperigeek.dropvault.dav.DAVClient.java

public void delete(String uri) throws DAVException {
    try {//from www  .ja v  a 2  s.co  m
        HttpDelete delete = new HttpDelete(uri);

        HttpResponse response = client.execute(delete);
        response.getEntity().consumeContent();
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new DAVException("Invalid status code:" + response.getStatusLine().getStatusCode() + " "
                    + response.getStatusLine().getReasonPhrase());
        }
    } catch (IOException ex) {
        throw new DAVException(ex);
    }
}

From source file:org.codehaus.httpcache4j.resolver.HTTPClientResponseResolver.java

/**
 * Determines the HttpClient's request method from the HTTPMethod enum.
 *
 * @param method     the HTTPCache enum that determines
 * @param requestURI the request URI./*w  ww .j av a  2  s  . com*/
 * @return a new HttpMethod subclass.
 */
protected HttpUriRequest getMethod(HTTPMethod method, URI requestURI) {

    if (DELETE.equals(method)) {
        return new HttpDelete(requestURI);
    } else if (GET.equals(method)) {
        return new HttpGet(requestURI);
    } else if (HEAD.equals(method)) {
        return new HttpHead(requestURI);
    } else if (OPTIONS.equals(method)) {
        return new HttpOptions(requestURI);
    } else if (POST.equals(method)) {
        return new HttpPost(requestURI);
    } else if (PUT.equals(method)) {
        return new HttpPut(requestURI);
    } else if (TRACE.equals(method)) {
        return new HttpTrace(requestURI);
    } else {
        throw new IllegalArgumentException("Cannot handle method: " + method);
    }
}

From source file:com.eTilbudsavis.etasdk.network.impl.DefaultHttpNetwork.java

private HttpRequestBase createRequest(Request<?> request) {

    String url = Utils.requestToUrlAndQueryString(request);

    switch (request.getMethod()) {
    case POST:/*from   w  w w  .  ja  va2  s .c  om*/
        HttpPost post = new HttpPost(url);
        setEntity(post, request);
        return post;

    case GET:
        HttpGet get = new HttpGet(url);
        return get;

    case PUT:
        HttpPut put = new HttpPut(url);
        setEntity(put, request);
        return put;

    case DELETE:
        HttpDelete delete = new HttpDelete(url);
        return delete;

    default:
        return null;
    }

}

From source file:xyz.cloudbans.client.DefaultClient.java

@Override
public Future<BanResponse> deleteBan(UUID banId) {
    HttpDelete httpRequest = new HttpDelete(buildSafe(createUri("/ban/" + banId)));
    initHeaders(httpRequest);// w w  w  .jav  a 2 s  .c  o  m

    return client.execute(new BasicAsyncRequestProducer(URIUtils.extractHost(config.getBaseUri()), httpRequest),
            SerializerConsumer.create(config.getSerializer(), BanResponse.class),
            DeafFutureCallback.<BanResponse>instance());
}