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.vmware.photon.controller.client.RestClient.java

private HttpUriRequest createHttpRequest(final Method method, final String path, final HttpEntity payload)
        throws IOException {
    String uri = target + path;/*from  w  w w  .j a va2 s  .c o  m*/
    HttpUriRequest request = null;

    switch (method.name().toLowerCase()) {
    case "get":
        request = new HttpGet(uri);
        break;

    case "put":
        request = new HttpPut(uri);
        ((HttpPut) request).setEntity(payload);
        break;

    case "post":
        request = new HttpPost(uri);
        ((HttpPost) request).setEntity(payload);
        break;

    case "delete":
        request = new HttpDelete(uri);
        break;

    default:
        throw new RuntimeException("Unknown method: " + method);
    }

    request = addAuthHeader(request);
    return request;
}

From source file:magicware.scm.redmine.tools.RedmineClient.java

public boolean deleteIssue(String issueId) throws ClientProtocolException, IOException {
    HttpDelete httpDelete = null;/*from w w  w . jav  a 2  s  .  c  o  m*/
    try {
        httpDelete = new HttpDelete(this.context + "/issues/" + issueId + ".json");
        log.debug("executing request delete " + httpDelete.getURI());
        RdeminResponse rdeminResponse = getRdeminResponse(httpDelete);
        return rdeminResponse.isResponseOK();
    } finally {
        if (httpDelete != null)
            httpDelete.abort();
    }
}

From source file:com.meltmedia.cadmium.blackbox.test.ApiRequest.java

private HttpDelete setupDeleteRequest() {
    return new HttpDelete(url);
}

From source file:com.overture.questdroid.utility.ExtHttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *//*ww w . ja v  a 2  s.c  o m*/
@SuppressWarnings("deprecation")
/* protected */static HttpUriRequest createHttpRequest(Request<?> request,
        Map<String, String> additionalHeaders) throws AuthFailureError {
    switch (request.getMethod()) {
    case Method.DEPRECATED_GET_OR_POST: {
        // This is the deprecated way that needs to be handled for backwards compatibility.
        // If the request's post body is null, then the assumption is that the request is
        // GET.  Otherwise, it is assumed that the request is a POST.
        byte[] postBody = request.getPostBody();
        if (postBody != null) {
            HttpPost postRequest = new HttpPost(request.getUrl());
            postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType());
            HttpEntity entity;
            entity = new ByteArrayEntity(postBody);
            postRequest.setEntity(entity);
            return postRequest;
        } else {
            return new HttpGet(request.getUrl());
        }
    }
    case Method.GET:
        return new HttpGet(request.getUrl());
    case Method.DELETE:
        return new HttpDelete(request.getUrl());
    case Method.POST: {
        HttpPost postRequest = new HttpPost(request.getUrl());
        postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(postRequest, request);
        return postRequest;
    }
    case Method.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(putRequest, request);
        return putRequest;
    }
    default:
        throw new IllegalStateException("Unknown request method.");
    }
}

From source file:code.google.restclient.core.Hitter.java

/**
 * Method to make POST or PUT request by sending http entity (as body)
 *//*  ww  w .  ja v a 2  s .c o m*/
public void hit(String url, String methodName, HttpHandler handler, Map<String, String> requestHeaders)
        throws Exception {

    if (DEBUG_ENABLED)
        LOG.debug("hit() - method => " + methodName + ", url => " + url);

    if (HttpGet.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> GET " + url);
        hit(url, new HttpGet(url), handler, requestHeaders);
    } else if (HttpHead.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> HEAD " + url);
        hit(url, new HttpHead(url), handler, requestHeaders);
    } else if (HttpDelete.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> DELETE " + url);
        hit(url, new HttpDelete(url), handler, requestHeaders);
    } else if (HttpOptions.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> OPTIONS " + url);
        hit(url, new HttpOptions(url), handler, requestHeaders);
    } else if (HttpTrace.METHOD_NAME.equals(methodName)) {
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> TRACE " + url);
        hit(url, new HttpTrace(url), handler, requestHeaders);
    } else if (HttpPost.METHOD_NAME.equals(methodName)) { // POST
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> POST " + url);
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(handler.getReqBodyEntity());
        hit(url, httpPost, handler, requestHeaders);
    } else if (HttpPut.METHOD_NAME.equals(methodName)) { // PUT
        if (DEBUG_ENABLED)
            LOG.debug("hit() - ===> PUT " + url);
        HttpPut httpPut = new HttpPut(url);
        httpPut.setEntity(handler.getReqBodyEntity());
        hit(url, httpPut, handler, requestHeaders);
    } else {
        throw new IllegalArgumentException("hit(): Unsupported method => " + methodName);
    }
}

From source file:ca.sqlpower.enterprise.DataSourceCollectionUpdater.java

/**
 * Handles deleting of a database entry by requesting that the server
 * deletes it. Also unlistens to the data source to prevent memory
 * leaks./*from w  ww  .ja  v a2  s.  c  o  m*/
 */
@Override
public void databaseRemoved(DatabaseListChangeEvent e) {
    HttpClient httpClient = getHttpClient();
    try {
        SPDataSource removedDS = e.getDataSource();
        HttpDelete request = new HttpDelete(jdbcDataSourceURI(removedDS));
        httpClient.execute(request, responseHandler);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:org.activiti.rest.service.api.repository.ModelResourceTest.java

public void testDeleteModel() throws Exception {
    Model model = null;//from  www . j  a  v  a  2s . c o  m
    try {
        Calendar now = Calendar.getInstance();
        now.set(Calendar.MILLISECOND, 0);
        processEngineConfiguration.getClock().setCurrentTime(now.getTime());

        model = repositoryService.newModel();
        model.setCategory("Model category");
        model.setKey("Model key");
        model.setMetaInfo("Model metainfo");
        model.setName("Model name");
        model.setVersion(2);
        repositoryService.saveModel(model);

        HttpDelete httpDelete = new HttpDelete(
                SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
        closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));

        // Check if the model is really gone
        assertNull(repositoryService.createModelQuery().modelId(model.getId()).singleResult());

        model = null;
    } finally {
        if (model != null) {
            try {
                repositoryService.deleteModel(model.getId());
            } catch (Throwable ignore) {
                // Ignore, model might not be created
            }
        }
    }
}

From source file:org.restexpress.RestExpressTest.java

@Test
public void shouldCallDefaultMethods() throws ClientProtocolException, IOException {
    RestExpressService restExpress = RestExpressService.newBuilder();
    NoopController controller = new NoopController();
    restExpress.uri(TEST_PATH, controller);
    try {/* w  w w .ja  va2 s . com*/
        restExpress.bind(TEST_PORT);

        HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(TEST_URL);
        HttpResponse response = (HttpResponse) client.execute(get);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals(1, controller.read);
        assertEquals(0, controller.create);
        assertEquals(0, controller.update);
        assertEquals(0, controller.delete);
        get.releaseConnection();

        HttpPost post = new HttpPost(TEST_URL);
        response = (HttpResponse) client.execute(post);
        assertEquals(201, response.getStatusLine().getStatusCode());
        assertEquals(1, controller.create);
        assertEquals(1, controller.read);
        assertEquals(0, controller.update);
        assertEquals(0, controller.delete);
        post.releaseConnection();

        HttpPut put = new HttpPut(TEST_URL);
        response = (HttpResponse) client.execute(put);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals(1, controller.update);
        assertEquals(1, controller.read);
        assertEquals(1, controller.create);
        assertEquals(0, controller.delete);
        put.releaseConnection();

        HttpDelete delete = new HttpDelete(TEST_URL);
        response = (HttpResponse) client.execute(delete);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals(1, controller.delete);
        assertEquals(1, controller.read);
        assertEquals(1, controller.create);
        assertEquals(1, controller.update);
        delete.releaseConnection();
    } finally {
        restExpress.shutdown();
    }
}

From source file:org.droidparts.http.RESTClient.java

public void delete(String uri) throws HTTPException {
    L.d("DELETE on " + uri);
    // TODO useHttpURLConnection()
    DefaultHttpClientWrapper wrapper = getLegacy();
    HttpDelete req = new HttpDelete(uri);
    HttpResponse resp = wrapper.getResponse(req);
    DefaultHttpClientWrapper.consumeResponse(resp);
}

From source file:org.activiti.rest.service.api.identity.GroupMembershipResourceTest.java

public void testDeleteMembership() throws Exception {
    try {//from  w ww. ja v a 2  s . c  o  m
        Group testGroup = identityService.newGroup("testgroup");
        testGroup.setName("Test group");
        testGroup.setType("Test type");
        identityService.saveGroup(testGroup);

        User testUser = identityService.newUser("testuser");
        identityService.saveUser(testUser);

        identityService.createMembership("testuser", "testgroup");

        HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX
                + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_MEMBERSHIP, "testgroup", "testuser"));
        CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
        closeResponse(response);

        // Check if membership is actually deleted
        assertNull(identityService.createUserQuery().memberOfGroup("testgroup").singleResult());
    } finally {
        try {
            identityService.deleteGroup("testgroup");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }

        try {
            identityService.deleteUser("testuser");
        } catch (Throwable ignore) {
            // Ignore, since the group may not have been created in the test
            // or already deleted
        }
    }
}