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

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

Introduction

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

Prototype

public static Request Put(final String uri) 

Source Link

Usage

From source file:edu.xjtu.qxcamerabridge.JSONActionWrapper.java

public static Response httpPostTest(String content) throws IOException {
    Response reply = Request.Put("http://posttestserver.com/post.php").bodyByteArray(content.getBytes())
            .execute();//  w w  w  . ja v a  2s  .  c om
    System.out.println(reply.returnContent().asString());
    return reply;
}

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

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

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

    assertThat(httpResponse.getStatusLine().getStatusCode(), is(404));
}

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 ww  w . j a  v  a  2  s .  c o m*/
        throw new IllegalArgumentException(method + " is not supported as a rest method");
    }
}

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

@Test
public void testDeleteDB() throws Exception {
    try {//from  w  w  w. j a v  a2 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 a v a 2s.  co  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 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").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:org.restheart.test.integration.DeleteDocumentIT.java

@Test
public void testDeleteDocument() throws Exception {
    try {/* www . j  ava 2  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);

        // *** 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);
    }
}

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

@Test
public void testPutCollection() throws Exception {
    try {//  w  w w. jav a  2s.com
        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 put without etag
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put tmp db without etag", resp, HttpStatus.SC_CONFLICT);

        // try to put with wrong etag
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)
                .addHeader(Headers.IF_MATCH_STRING, "pippoetag"));
        check("check put tmp db with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));

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

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

        // try to put with correct etag
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{b:2}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)
                .addHeader(Headers.IF_MATCH_STRING, etag));
        check("check put tmp db with correct etag", resp, HttpStatus.SC_OK);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));

        content = JsonObject.readFrom(resp.returnContent().asString());
        assertNull("check put content", content.get("a"));
        assertNotNull("check put content", content.get("b"));
        assertTrue("check put content", content.get("b").asInt() == 2);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}

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

@Test
public void testDeleteCollection() throws Exception {
    try {// ww w  .  ja v 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);

        // 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:com.softinstigate.restheart.integrationtest.DeleteDocumentIT.java

@Test
public void testDeleteDocument() throws Exception {
    try {// w w  w. ja va2s  . com
        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").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);
    }
}