Example usage for org.apache.http.client.fluent Request Delete

List of usage examples for org.apache.http.client.fluent Request Delete

Introduction

In this page you can find the example usage for org.apache.http.client.fluent Request Delete.

Prototype

public static Request Delete(final String uri) 

Source Link

Usage

From source file:org.ow2.proactive.addons.webhook.service.ApacheHttpClientRequestGetter.java

public Request getHttpRequestByString(String method, String url) {
    switch (method) {
    case "GET":
        return Request.Get(url);
    case "POST":
        return Request.Post(url);
    case "HEAD":
        return Request.Head(url);
    case "PUT":
        return Request.Put(url);
    case "DELETE":
        return Request.Delete(url);
    case "OPTIONS":
        return Request.Options(url);
    case "TRACE":
        return Request.Trace(url);
    default://from w  w w  .  j  ava2  s.  com
        throw new IllegalArgumentException(method + " is not supported as a rest method");
    }
}

From source file:org.debux.webmotion.server.tools.RequestBuilder.java

/**
 * @return a delete request/*from  w  ww  .  jav  a  2 s.  co  m*/
 */
public Request Delete() throws URISyntaxException {
    return Request.Delete(this.build());
}

From source file:org.mule.listener.HttpListenerMethodRoutingTestCase.java

@Test
public void allowedCustomMethodReturns200() throws Exception {
    final String url = String.format("http://localhost:%s/%s", listenPort2.getNumber(), path.getValue());

    final Response response = Request.Delete(url).connectTimeout(1000).execute();
    final HttpResponse httpResponse = response.returnResponse();

    assertThat(httpResponse.getStatusLine().getStatusCode(), is(200));
    assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is("CUSTOM-METHOD"));
}

From source file:org.restheart.test.integration.DeleteDBIT.java

@Test
public void testDeleteDB() throws Exception {
    try {//from  w w  w. j  av  a  2 s . c om
        Response resp;

        // *** PUT tmpdb
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put db", resp, HttpStatus.SC_CREATED);

        // try to delete without etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri));
        check("check delete tmp doc without etag", resp, HttpStatus.SC_CONFLICT);

        // try to delete with wrong etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri).addHeader(Headers.IF_MATCH_STRING, "pippoetag"));
        check("check delete tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        //check("getting etag of tmp doc", resp, HttpStatus.SC_OK);

        JsonObject content = JsonObject.readFrom(resp.returnContent().asString());

        String etag = content.get("_etag").asObject().get("$oid").asString();

        // try to delete with correct etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri).addHeader(Headers.IF_MATCH_STRING, etag));
        check("check delete tmp doc with correct etag", resp, HttpStatus.SC_NO_CONTENT);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        check("check get deleted tmp doc", resp, HttpStatus.SC_NOT_FOUND);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}

From source file:com.softinstigate.restheart.integrationtest.DeleteDBIT.java

@Test
public void testDeleteDB() throws Exception {
    try {//ww  w .  j ava2 s . c o  m
        Response resp;

        // *** PUT tmpdb
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put db", resp, HttpStatus.SC_CREATED);

        // try to delete without etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri));
        check("check delete tmp doc without etag", resp, HttpStatus.SC_CONFLICT);

        // try to delete with wrong etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri).addHeader(Headers.IF_MATCH_STRING, "pippoetag"));
        check("check delete tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        //check("getting etag of tmp doc", resp, HttpStatus.SC_OK);

        JsonObject content = JsonObject.readFrom(resp.returnContent().asString());

        String etag = content.get("_etag").asString();

        // try to delete with correct etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri).addHeader(Headers.IF_MATCH_STRING, etag));
        check("check delete tmp doc with correct etag", resp, HttpStatus.SC_NO_CONTENT);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        check("check get deleted tmp doc", resp, HttpStatus.SC_NOT_FOUND);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}

From source file:org.restheart.test.integration.DeleteCollectionIT.java

@Test
public void testDeleteCollection() throws Exception {
    try {//  w ww . j  av  a 2 s  .c om
        Response resp;

        // *** PUT tmpdb
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put db", resp, HttpStatus.SC_CREATED);

        // *** PUT tmpcoll
        resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put coll1", resp, HttpStatus.SC_CREATED);

        // try to delete without etag
        resp = adminExecutor.execute(Request.Delete(collectionTmpUri));
        check("check delete tmp doc without etag", resp, HttpStatus.SC_CONFLICT);

        // try to delete with wrong etag
        resp = adminExecutor
                .execute(Request.Delete(collectionTmpUri).addHeader(Headers.IF_MATCH_STRING, "pippoetag"));
        check("check delete tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED);

        resp = adminExecutor.execute(Request.Get(collectionTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        //check("getting etag of tmp doc", resp, HttpStatus.SC_OK);

        JsonObject content = JsonObject.readFrom(resp.returnContent().asString());

        String etag = content.get("_etag").asObject().get("$oid").asString();

        // try to delete with correct etag
        resp = adminExecutor.execute(Request.Delete(collectionTmpUri).addHeader(Headers.IF_MATCH_STRING, etag));
        check("check delete tmp doc with correct etag", resp, HttpStatus.SC_NO_CONTENT);

        resp = adminExecutor.execute(Request.Get(collectionTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        check("check get deleted tmp doc", resp, HttpStatus.SC_NOT_FOUND);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}

From source file:com.softinstigate.restheart.integrationtest.DeleteCollectionIT.java

@Test
public void testDeleteCollection() throws Exception {
    try {/*from   w ww.  j a  v  a2 s .c o m*/
        Response resp;

        // *** PUT tmpdb
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put db", resp, HttpStatus.SC_CREATED);

        // *** PUT tmpcoll
        resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put coll1", resp, HttpStatus.SC_CREATED);

        // try to delete without etag
        resp = adminExecutor.execute(Request.Delete(collectionTmpUri));
        check("check delete tmp doc without etag", resp, HttpStatus.SC_CONFLICT);

        // try to delete with wrong etag
        resp = adminExecutor
                .execute(Request.Delete(collectionTmpUri).addHeader(Headers.IF_MATCH_STRING, "pippoetag"));
        check("check delete tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED);

        resp = adminExecutor.execute(Request.Get(collectionTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        //check("getting etag of tmp doc", resp, HttpStatus.SC_OK);

        JsonObject content = JsonObject.readFrom(resp.returnContent().asString());

        String etag = content.get("_etag").asString();

        // try to delete with correct etag
        resp = adminExecutor.execute(Request.Delete(collectionTmpUri).addHeader(Headers.IF_MATCH_STRING, etag));
        check("check delete tmp doc with correct etag", resp, HttpStatus.SC_NO_CONTENT);

        resp = adminExecutor.execute(Request.Get(collectionTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        check("check get deleted tmp doc", resp, HttpStatus.SC_NOT_FOUND);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}

From source file:org.wildfly.swarm.servlet.jpa.jta.test.ServletJpaJtaTest.java

@Test
@RunAsClient/*from  w  w w.j a v a2 s . co  m*/
@InSequence(4)
public void delete() throws IOException {
    String result = Request.Delete("http://localhost:8080/?id=" + id).execute().returnContent().asString()
            .trim();
    assertThat(result).isEqualTo(id + " deleted");
}

From source file:org.mule.module.http.functional.listener.HttpListenerMethodRoutingTestCase.java

@Test
public void callWithMethod() throws Exception {
    final String url = String.format("http://localhost:%s/%s", listenPort.getNumber(), path.getValue());
    Request request = null;/*from w  ww.  j av a 2 s. co  m*/
    switch (method) {
    case "GET":
        request = Request.Get(url);
        break;
    case "POST":
        request = Request.Post(url);
        break;
    case "OPTIONS":
        request = Request.Options(url);
        break;
    case "DELETE":
        request = Request.Delete(url);
        break;
    case "PUT":
        request = Request.Put(url);
        break;
    }
    final Response response = request.connectTimeout(1000).execute();
    final HttpResponse httpResponse = response.returnResponse();
    assertThat(httpResponse.getStatusLine().getStatusCode(), is(200));
    assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(expectedContent));
}

From source file:org.restheart.test.integration.DeleteDocumentIT.java

@Test
public void testDeleteDocument() throws Exception {
    try {/*www . j  av  a 2s. c  om*/
        Response resp;

        // *** PUT tmpdb
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put db", resp, HttpStatus.SC_CREATED);

        // *** PUT tmpcoll
        resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put coll1", resp, HttpStatus.SC_CREATED);

        // *** PUT tmpdoc
        resp = adminExecutor.execute(Request.Put(documentTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put tmp doc", resp, HttpStatus.SC_CREATED);

        // try to delete without etag
        resp = adminExecutor.execute(Request.Delete(documentTmpUri));
        check("check delete tmp doc without etag", resp, HttpStatus.SC_CONFLICT);

        // try to delete with wrong etag
        resp = adminExecutor
                .execute(Request.Delete(documentTmpUri).addHeader(Headers.IF_MATCH_STRING, "pippoetag"));
        check("check delete tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED);

        resp = adminExecutor.execute(Request.Get(documentTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        //check("getting etag of tmp doc", resp, HttpStatus.SC_OK);

        JsonObject content = JsonObject.readFrom(resp.returnContent().asString());

        String etag = content.get("_etag").asObject().get("$oid").asString();

        // try to delete with correct etag
        resp = adminExecutor.execute(Request.Delete(documentTmpUri).addHeader(Headers.IF_MATCH_STRING, etag));
        check("check delete tmp doc with correct etag", resp, HttpStatus.SC_NO_CONTENT);

        resp = adminExecutor.execute(Request.Get(documentTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        check("check get deleted tmp doc", resp, HttpStatus.SC_NOT_FOUND);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}