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:hulop.cm.util.LogHelper.java

public boolean saveLog(String clientId, JSONObject log) throws Exception {
    if (mApiKey == null) {
        return false;
    }//from w ww.  jav  a  2s  .c o  m
    JSONObject data = new JSONObject();
    data.put("event", "conversation");
    data.put("client", clientId);
    data.put("timestamp", System.currentTimeMillis());
    data.put("log", log);
    Request request = Request.Post(new URI(mEndpoint)).bodyForm(Form.form().add("action", "insert")
            .add("auditor_api_key", mApiKey).add("data", new JSONArray().put(data).toString()).build());
    HttpResponse response = request.execute().returnResponse();
    return response.getStatusLine().getStatusCode() == 200;
}

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

protected void testResponseIsChunkedEncoding(String url, HttpVersion httpVersion) throws IOException {
    final Response response = Request.Post(url).version(httpVersion).connectTimeout(1000).socketTimeout(1000)
            .bodyByteArray(TEST_BODY.getBytes()).execute();
    final HttpResponse httpResponse = response.returnResponse();
    final Header transferEncodingHeader = httpResponse.getFirstHeader(TRANSFER_ENCODING);
    final Header contentLengthHeader = httpResponse.getFirstHeader(CONTENT_LENGTH);
    assertThat(contentLengthHeader, nullValue());
    assertThat(transferEncodingHeader, notNullValue());
    assertThat(transferEncodingHeader.getValue(), is(CHUNKED));
    assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(TEST_BODY));
}

From source file:com.qwazr.search.index.IndexSingleClient.java

@Override
public SchemaSettingsDefinition createUpdateSchema(String schema_name, SchemaSettingsDefinition settings) {
    UBuilder uriBuilder = new UBuilder("/indexes/", schema_name);
    Request request = Request.Post(uriBuilder.build());
    return commonServiceRequest(request, settings, null, SchemaSettingsDefinition.class, 200);
}

From source file:de.elomagic.carafile.server.bl.RegistryClientBean.java

/**
 *
 * @param metaData/*from w  ww . j  a v a2  s  .  c o m*/
 * @throws IOException Thrown when unable to call REST service at the registry
 * @throws java.net.URISyntaxException
 */
public void registerMetaData(final MetaData metaData) throws IOException, URISyntaxException {
    LOG.debug("Registering meta data at registry: " + metaData);

    if (ownPeerURI.equals(registryURI)) {
        registryBean.registerFile(metaData);
    } else {
        URI restURI = UriBuilder.fromUri(registryURI).path(REGISTRY).path("register").build();
        Request.Post(restURI).addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
                .bodyStream(JsonUtil.write(metaData, Charset.forName("utf-8")), ContentType.APPLICATION_JSON)
                .execute();
    }
}

From source file:org.metaservice.demo.securityalert.NotificationBackend.java

public void send(String api, String s, String cve) {
    LOGGER.info("Sending {} {}", s, cve);
    URIBuilder uriBuilder = new URIBuilder();

    uriBuilder.setScheme("http").setHost("www.notifymyandroid.com").setPort(80).setPath("/publicapi/notify");

    try {//from w  ww . j a va 2s.c  o m
        String result = Request.Post(uriBuilder.build())
                .bodyForm(Form.form().add("apikey", api).add("event", s).add("application", "metaservice.org")
                        .add("priority", "2").add("description", s).add("url", cve).build())
                .connectTimeout(1000).socketTimeout(30000)
                // .setHeader("Accept", mimeType)
                .execute().returnContent().asString();
        LOGGER.info(result);
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:com.jaspersoft.studio.server.utils.HttpUtils.java

public static Request post(String url, Form form, ServerProfile sp) throws HttpException, IOException {
    System.out.println(url);//from   ww w.j a v a2  s.com
    return HttpUtils.setRequest(Request.Post(url).bodyForm(form.build()), sp);
}

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

@Test
public void call_case1_raw() throws Exception {
    String testCase = "case1";

    InputStream is = this.getClass().getClassLoader().getResourceAsStream(testCase + "/request_content.json");
    String content = StringUtils.copy(is);

    Request request = Request.Post("http://localhost:8082/test/my_team?case=" + testCase).bodyString(content,
            ContentType.APPLICATION_JSON);
    Response response = request.execute();

    HttpResponse returnResponse = response.returnResponse();
    assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode());

    String responseContent = StringUtils.copy(returnResponse.getEntity().getContent());
    assertEquals(content, responseContent);
}

From source file:com.qwazr.database.TableSingleClient.java

@Override
public TableDefinition createTable(String table_name) {
    UBuilder uriBuilder = new UBuilder("/table/", table_name);
    Request request = Request.Post(uriBuilder.build());
    return commonServiceRequest(request, null, null, TableDefinition.class, 200);
}

From source file:rxweb.RxJavaServerTests.java

public void echoCapitalizedStream() throws IOException {
    server.post("/test",
            (request,/* ww  w .ja  v  a 2s.c  o m*/
                    response) -> response.content(request.getContent()
                            .map(data -> ByteBuffer.wrap(new String(data.array(), StandardCharsets.UTF_8)
                                    .toUpperCase().getBytes(StandardCharsets.UTF_8)))));
    String content = Request.Post("http://localhost:8080/test")
            .bodyString("This is a test!", ContentType.TEXT_PLAIN).execute().returnContent().asString();
    Assert.assertEquals("THIS IS A TEST!", content);
}

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

@Override
protected void postPayload(String requestBody) {
    try {// w w w  . j a va  2s  .c om

        Request postReq = Request.Post(extension.getSplunkUri());
        postReq.bodyString(requestBody, ContentType.APPLICATION_JSON);
        addHeaders(postReq);
        StatusLine status = postReq.execute().returnResponse().getStatusLine();

        if (SC_OK != status.getStatusCode()) {
            error = String.format("%s (status code: %s)", status.getReasonPhrase(), status.getStatusCode());
        }
    } catch (IOException e) {
        error = e.getMessage();
    }
}