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

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

Introduction

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

Prototype

public static Request Post(final String uri) 

Source Link

Usage

From source file:com.qwazr.scripts.ScriptSingleClient.java

@Override
public List<ScriptRunStatus> runScriptVariables(String scriptPath, Boolean local, String group,
        Integer msTimeout, TargetRuleEnum rule, Map<String, String> variables) {
    if (variables == null)
        return runScript(scriptPath, local, group, msTimeout, rule);
    UBuilder uriBuilder = new UBuilder(SCRIPT_PREFIX_RUN, scriptPath).setParameters(local, group, msTimeout)
            .setParameter("rule", rule);
    Request request = Request.Post(uriBuilder.build());
    return commonServiceRequest(request, variables, null, ListRunStatusTypeRef, 200, 202);
}

From source file:org.wildfly.swarm.microprofile.jwtauth.providers.ProvidersMergingTest.java

@RunAsClient
@Test/*from  ww w .j  av  a2 s  . co m*/
public void shouldRejectPostWithRBACFilter() throws Exception {
    HttpResponse response = Request.Post("http://localhost:8080/mpjwt/providers")
            .setHeader("Accept", MediaType.TEXT_PLAIN).execute().returnResponse();
    Assert.assertEquals(401, response.getStatusLine().getStatusCode());
}

From source file:com.m3958.apps.anonymousupload.integration.java.FileUploadTest.java

@Test
public void testPostRename() throws ClientProtocolException, IOException, URISyntaxException {

    File f = new File("README.md");

    Assert.assertTrue(f.exists());/* ww  w .j a  v  a2s. c o  m*/

    String c = Request.Post(new URIBuilder().setScheme("http").setHost("localhost").setPort(8080).build())
            .body(MultipartEntityBuilder.create()
                    .addBinaryBody("afile", f, ContentType.MULTIPART_FORM_DATA, f.getName())
                    .addTextBody("fn", "abcfn.md").build())
            .execute().returnContent().asString();

    String url = c.trim();
    Assert.assertTrue(url.endsWith("abcfn.md"));

    testComplete();
}

From source file:org.elasticstore.server.integration.ItemIT.java

@Test
public void testCreateRetrieveAndDeleteItem() throws Exception {
    final Item item = Fixtures.randomItem();
    // create the item
    HttpResponse resp = executor/*from w w  w .j a va2 s .c om*/
            .execute(Request.Post(serverUrl + "/item").useExpectContinue()
                    .bodyString(mapper.writeValueAsString(item), ContentType.APPLICATION_JSON))
            .returnResponse();

    assertEquals(201, resp.getStatusLine().getStatusCode());

    // retrieve the item
    resp = executor.execute(Request.Get(serverUrl + "/item/" + item.getId()).useExpectContinue())
            .returnResponse();
    assertEquals(200, resp.getStatusLine().getStatusCode());
    final Item fetched = mapper.readValue(resp.getEntity().getContent(), Item.class);
    assertEquals(item.getId(), fetched.getId());
    assertEquals(item.getLabel(), fetched.getLabel());
    assertNotNull(fetched.getCreated());
    assertNotNull(fetched.getLastModified());

    // delete the item
    resp = executor.execute(Request.Delete(serverUrl + "/item/" + item.getId()).useExpectContinue())
            .returnResponse();
    Assert.assertEquals(200, resp.getStatusLine().getStatusCode());

    //retrieve the item again and assert a 404
    resp = executor.execute(Request.Get(serverUrl + "/item/" + item.getId()).useExpectContinue())
            .returnResponse();
    assertEquals(404, resp.getStatusLine().getStatusCode());
}

From source file:org.ow2.proactive.procci.service.CloudAutomationVariablesClient.java

public void post(String key, String value) {

    logger.debug("post " + key + " on " + requestUtils.getProperty(VARIABLES_ENDPOINT));
    String url = getQueryUrl(key);
    try {/*from   www .  j av  a2s  .c o  m*/
        HttpResponse response = Request.Post(url)

                .useExpectContinue().version(HttpVersion.HTTP_1_1)
                .bodyString(value, ContentType.APPLICATION_JSON).execute().returnResponse();

        requestUtils.readHttpResponse(response, url, "POST " + value);

    } catch (IOException ex) {
        logger.error("Unable to post on " + getQueryUrl(key) + ", exception : " + ex.getMessage());
        throw new ServerException();
    }

}

From source file:org.obm.sync.push.client.commands.SmartEmailCommand.java

@Override
public Boolean run(AccountInfos ai, OPClient opc, HttpClient hc) throws Exception {
    return Request
            .Post(opc.buildUrl(ai.getUrl(), ai.getLogin(), ai.getDevId(), ai.getDevType(), getCommandName(),
                    commandParams()))/*w  w  w .ja  v a2 s .co m*/
            .addHeader("User-Agent", ai.getUserAgent()).addHeader("Authorization", ai.authValue())
            .addHeader("Ms-Asprotocolversion", ProtocolVersion.V121.asSpecificationValue())
            .addHeader("Accept", "*/*").addHeader("Accept-Language", "fr-fr")
            .addHeader("Connection", "keep-alive").body(new ByteArrayEntity(emailData)).execute()
            .returnResponse().getStatusLine().getStatusCode() == HttpStatus.SC_OK;
}

From source file:com.difference.historybook.importer.indexer.Indexer.java

/**
 * Uploads the given HistoryRecord to the search index service
 * /*from  w  w w . ja  v  a2 s .  co  m*/
 * @param record HistoryRecord to send to index. Should have a body.
 */
public void index(HistoryRecord record) {
    try {
        if (record.getBody() != null) {
            String url = baseUrl + "/collections/" + collection + "/"
                    + URLEncoder.encode(record.getUrl(), Charsets.UTF_8.name());
            if (record.getTimestamp() != null) {
                url = url + "/" + URLEncoder.encode(record.getTimestamp(), Charsets.UTF_8.name());
            }
            Request.Post(url).bodyString(record.getBody(), ContentType.TEXT_HTML).execute();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.elasticsearch.packaging.util.ServerUtils.java

public static void runElasticsearchTests() throws IOException {
    makeRequest(Request.Post("http://localhost:9200/library/book/1?refresh=true&pretty")
            .bodyString("{ \"title\": \"Book #1\", \"pages\": 123 }", ContentType.APPLICATION_JSON));

    makeRequest(Request.Post("http://localhost:9200/library/book/2?refresh=true&pretty")
            .bodyString("{ \"title\": \"Book #2\", \"pages\": 456 }", ContentType.APPLICATION_JSON));

    String count = makeRequest(Request.Get("http://localhost:9200/_count?pretty"));
    assertThat(count, containsString("\"count\" : 2"));

    makeRequest(Request.Delete("http://localhost:9200/_all"));
}

From source file:nebula.plugin.metrics.dispatcher.RestMetricsDispatcher.java

protected void postPayload(String payload) {
    checkNotNull(payload);/*from w  w  w .  j  a  v a 2s  .  co m*/

    try {
        Request postReq = Request.Post(extension.getRestUri());
        postReq.bodyString(payload, ContentType.APPLICATION_JSON);
        addHeaders(postReq);
        postReq.execute();
    } catch (IOException e) {
        throw new RuntimeException("Unable to POST to " + extension.getRestUri(), e);
    }
}

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

@Test
public void testPostCollectionInt() throws Exception {
    try {/*from w ww  .j  a v a2s .  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);

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

        URI collectionTmpUriInt = buildURI("/" + dbTmpName + "/" + collectionTmpName,
                new NameValuePair[] { new BasicNameValuePair(DOC_ID_TYPE_KEY, DOC_ID_TYPE.NUMBER.name()) });

        // *** POST tmpcoll
        resp = adminExecutor.execute(Request.Post(collectionTmpUriInt).bodyString("{_id:100, a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        HttpResponse httpResp = check("check post coll1 again", resp, HttpStatus.SC_CREATED);

        Header[] headers = httpResp.getHeaders(Headers.LOCATION_STRING);

        assertNotNull("check loocation header", headers);
        assertTrue("check loocation header", headers.length > 0);

        Header locationH = headers[0];
        String location = locationH.getValue();

        //assertTrue("check location header value", location.endsWith("/100?id_type=NUMBER"));
        URI createdDocUri = URI.create(location);

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

        JsonObject content = JsonObject.readFrom(resp.returnContent().asString());
        assertTrue("check created doc content", content.get("_id").asInt() == 100);
        assertNotNull("check created doc content", content.get("_etag"));
        assertNotNull("check created doc content", content.get("a"));
        assertTrue("check created doc content", content.get("a").asInt() == 1);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}