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:org.adridadou.ethereum.swarm.SwarmService.java

public SwarmHash publish(final String content) {
    try {/*from w ww. j  a v a  2s .c  om*/
        Response response = Request.Post(host + "/bzzr:/").bodyString(content, ContentType.TEXT_PLAIN)
                .execute();
        return SwarmHash.of(response.returnContent().asString());
    } catch (IOException e) {
        throw new EthereumApiException("error while publishing the smart contract metadata to Swarm", e);
    }
}

From source file:com.kalessil.phpStorm.phpInspectionsEA.utils.analytics.AnalyticsUtil.java

public static void registerPluginEvent(@NotNull EASettings source, @NotNull String action,
        @NotNull String eventValue) {
    new Thread() {
        public void run() {
            /* See https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event */
            final StringBuilder payload = new StringBuilder();
            payload.append("v=1") // Version.
                    .append("&tid=").append(COLLECTOR_ID) // Tracking ID / Property ID.
                    .append("&cid=").append(source.getUuid()) // Anonymous Client ID.
                    .append("&t=event") // Event hit type
                    .append("&ec=plugin") // Event Category. Required.
                    .append("&ea=").append(action) // Event Action. Required.
                    .append("&el=").append(source.getVersion()) // Event label - current version
                    .append("&ev=").append(eventValue.replaceAll("[^\\d]", "")) // Event value - oldest version as int
            ;//from  w ww  .j av  a 2s . c  om

            try {
                Request.Post(COLLECTOR_URL).bodyByteArray(payload.toString().getBytes()).connectTimeout(3000)
                        .execute();

                lastError = null;
            } catch (Exception failed) {
                lastError = failed.getClass().getName() + " - " + failed.getMessage();
            }
        }
    }.start();
}

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

@Test
public void handlesEmptyHeader() throws Exception {
    String url = String.format("http://localhost:%s/testHeaders", listenPort.getNumber());
    HttpResponse response = Request.Post(url).addHeader("Accept", null).execute().returnResponse();

    assertThat(response.getStatusLine().getStatusCode(), is(OK.getStatusCode()));
    assertThat(IOUtils.toString(response.getEntity().getContent()), is(EMPTY));
}

From source file:in.flipbrain.Utils.java

public static String httpPost(String uri, HashMap<String, String> params) {
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    for (Map.Entry<String, String> entrySet : params.entrySet()) {
        String key = entrySet.getKey();
        String value = entrySet.getValue();
        nvps.add(new BasicNameValuePair(key, value));
    }// w  ww  .  j  ava2  s  .c o m
    String res = null;
    try {
        res = Request.Post(uri).bodyForm(nvps).execute().returnContent().asString();
        logger.debug("Response: " + res);
    } catch (IOException e) {
        logger.fatal("Failed to process request. ", e);
    }
    return res;
}

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

private void assertResponse(int port, String path) throws Exception {
    final String url = String.format("http://localhost:%s/%s", port, path);
    final Response response = Request.Post(url).body(new StringEntity(TEST_MESSAGE)).connectTimeout(1000)
            .execute();/* ww  w . j  a v  a2s. c om*/
    assertThat(response.returnContent().asString(), equalTo(TEST_MESSAGE));

}

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

From source file:io.bitgrillr.gocddockerexecplugin.utils.GoTestUtils.java

/**
 * Schedules the named pipeline to run.//from  w  w  w  .j  a  v a  2 s  .  c o  m
 *
 * @param pipeline Name of the Pipeline to run.
 * @return Counter of the pipeline instance scheduled.
 * @throws GoError If Go.CD returns a non 2XX response.
 * @throws IOException If a communication error occurs.
 * @throws InterruptedException If something has gone horribly wrong.
 */
public static int runPipeline(String pipeline) throws GoError, IOException, InterruptedException {
    final Response scheduleResponse = executor
            .execute(Request.Post(PIPELINES + pipeline + "/schedule").addHeader("Confirm", "true"));
    final int scheduleStatus = scheduleResponse.returnResponse().getStatusLine().getStatusCode();
    if (scheduleStatus != HttpStatus.SC_ACCEPTED) {
        throw new GoError(scheduleStatus);
    }

    Thread.sleep(5 * 1000);

    final HttpResponse historyResponse = executor.execute(Request.Get(PIPELINES + pipeline + "/history"))
            .returnResponse();
    final int historyStatus = historyResponse.getStatusLine().getStatusCode();
    if (historyStatus != HttpStatus.SC_OK) {
        throw new GoError(historyStatus);
    }
    final JsonArray pipelineInstances = Json.createReader(historyResponse.getEntity().getContent()).readObject()
            .getJsonArray("pipelines");
    JsonObject lastPipelineInstance = pipelineInstances.getJsonObject(0);
    for (JsonValue pipelineInstance : pipelineInstances) {
        if (pipelineInstance.asJsonObject().getInt("counter") > lastPipelineInstance.getInt("counter")) {
            lastPipelineInstance = pipelineInstance.asJsonObject();
        }
    }

    return lastPipelineInstance.getInt("counter");
}

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

private void sendRequestAndAssertResponse(boolean filterExpression, String expectedBody) throws IOException {
    Request request = Request.Post(String.format("http://localhost:%s", listenPort.getValue()))
            .body(new StringEntity(TEST_MESSAGE))
            .addHeader("filterExpression", Boolean.toString(filterExpression));

    HttpResponse response = request.execute().returnResponse();

    assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
    assertThat(IOUtils.toString(response.getEntity().getContent()), equalTo(expectedBody));
}

From source file:org.wildfly.swarm.examples.camel.mail.CamelMailIT.java

@Test
public void testIt() throws Exception {

    Thread.sleep(5000);// w  w w  . j ava 2  s.  c  o m

    Log log = getStdOutLog();
    assertThatLog(log).hasLineContaining("Bound camel naming object: java:jboss/camel/context/mail-context");
    assertThatLog(log).hasLineContaining("Bound mail session [java:jboss/mail/greenmail]");

    String response = Request.Post("http://localhost:8080/mail")
            .bodyString("Hello from camel!", ContentType.APPLICATION_FORM_URLENCODED).execute().returnContent()
            .asString();

    Assert.assertEquals(response, "Email sent to user1@localhost");
}

From source file:io.gravitee.gateway.standalone.UnreachableTest.java

@Test
public void call_unreachable_api() throws Exception {
    Request request = Request.Post("http://localhost:8082/unreachable");
    Response response = request.execute();
    HttpResponse returnResponse = response.returnResponse();

    assertEquals(HttpStatus.SC_BAD_GATEWAY, returnResponse.getStatusLine().getStatusCode());
}