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:io.gravitee.gateway.standalone.ConnectionTimeoutTest.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();

    assertTrue(returnResponse.getStatusLine().getStatusCode() == HttpStatus.SC_GATEWAY_TIMEOUT
            || returnResponse.getStatusLine().getStatusCode() == HttpStatus.SC_BAD_GATEWAY);
}

From source file:ADP_Streamline.CURL.java

public void UploadFiles() throws ClientProtocolException, IOException {

    String filePath = "file_path";
    String url = "http://localhost/files";
    File file = new File(filePath);
    MultipartEntity entity = new MultipartEntity();
    entity.addPart("file", new FileBody(file));
    HttpResponse returnResponse = Request.Post(url).body(entity).execute().returnResponse();
    System.out.println("Response status: " + returnResponse.getStatusLine().getStatusCode());
    System.out.println(EntityUtils.toString(returnResponse.getEntity()));
}

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

/**
 * @return a post request
 */
public Request Post() throws URISyntaxException {
    return Request.Post(this.build());
}

From source file:org.apache.james.jmap.HttpJmapAuthentication.java

private static String getContinuationToken(URIBuilder uriBuilder, String username)
        throws ClientProtocolException, IOException, URISyntaxException {
    Response response = Request.Post(uriBuilder.setPath("/authentication").build())
            .bodyString("{\"username\": \"" + username
                    + "\", \"clientName\": \"Mozilla Thunderbird\", \"clientVersion\": \"42.0\", \"deviceName\": \"Joe Bloggs iPhone\"}",
                    ContentType.APPLICATION_JSON)
            .setHeader("Accept", ContentType.APPLICATION_JSON.getMimeType()).execute();
    return JsonPath.parse(response.returnContent().asString()).read("continuationToken");
}

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

@Test
@RunAsClient//from   w  w w.  j  a  v a 2  s.  c  o  m
@InSequence(2)
public void create() throws IOException {
    String result = Request.Post("http://localhost:8080/")
            .bodyForm(new BasicNameValuePair("title", "Title"), new BasicNameValuePair("author", "Author"))
            .execute().returnContent().asString().trim();

    assertThat(result).isNotEmpty();
    id = Integer.parseInt(result);
}

From source file:com.enitalk.controllers.paypal.BasicPaypal.java

public String authPaypal() {
    String tt = null;//from   w ww .  jav a2s  .  c o  m
    try {
        tt = redis.opsForValue().get("paypal");
        if (StringUtils.isNotBlank(tt)) {
            return tt;
        }

        String url = env.getProperty("paypal.auth");
        String auth = env.getProperty("paypal.client") + ":" + env.getProperty("paypal.secret");
        String encoded = java.util.Base64.getEncoder().encodeToString(auth.getBytes());

        logger.info("Posting paypal auth to {} client {}", url, encoded);
        byte[] json = Request.Post(url).addHeader("Authorization", "Basic " + encoded)
                .bodyForm(Form.form().add("grant_type", "client_credentials").build()).execute().returnContent()
                .asBytes();

        JsonNode tree = jackson.readTree(json);
        tt = tree.path("access_token").asText();
        long duration = tree.path("expires_in").asLong();

        redis.opsForValue().set("paypal", tt, duration - 5, TimeUnit.SECONDS);

    } catch (Exception ex) {
        logger.info("Error auth Paypal {}", ExceptionUtils.getFullStackTrace(ex));
    }
    return tt;
}

From source file:es.upm.oeg.examples.watson.service.PersonalityInsightsService.java

public String analyse(String text) throws IOException, URISyntaxException {

    logger.info("Analyzing the text: \n" + text);

    URI profileURI = new URI(baseURL + "/v2/profile").normalize();
    logger.info("Profile URI: " + profileURI.toString());

    Request profileRequest = Request.Post(profileURI).addHeader("Accept", "application/json").bodyString(text,
            ContentType.TEXT_PLAIN);// w  w w .  ja  va2  s .  com

    Executor executor = Executor.newInstance().auth(username, password);
    Response response = executor.execute(profileRequest);
    HttpResponse httpResponse = response.returnResponse();
    StatusLine statusLine = httpResponse.getStatusLine();

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    httpResponse.getEntity().writeTo(os);
    String responseBody = new String(os.toByteArray());

    if (statusLine.getStatusCode() == HttpStatus.SC_OK) {

        return responseBody;

    } else {

        String msg = String.format("Personality Insights Service failed - %d %s \n %s",
                statusLine.getStatusCode(), statusLine.getReasonPhrase(), response);
        logger.severe(msg);
        throw new RuntimeException(msg);
    }
}

From source file:nl.mawoo.wcmscript.modules.webrequest.WebRequest.java

/**
 * POST webrequest using the apache library
 *
 * NOTE: this method starts with a capital because end-users can use the libraries documentation.
 * Documentation can be found at: https://hc.apache.org/httpcomponents-client-ga/tutorial/html/fluent.html
 * @param request url you want to send a get request to
 * @return REQUEST object//  w  ww.ja v  a  2  s  .co m
 */
public Request post(String request) {
    return Request.Post(request);
}

From source file:org.mule.module.http.functional.proxy.HttpProxyExpectHeaderTestCase.java

private Response sendRequest() throws IOException {
    return Request.Post(String.format("http://localhost:%s", proxyPort.getNumber())).useExpectContinue()
            .bodyString(TEST_MESSAGE, DEFAULT_TEXT).connectTimeout(RECEIVE_TIMEOUT).execute();
}

From source file:com.qwazr.graph.GraphSingleClient.java

@Override
public GraphResult createUpdateGraph(String graphName, GraphDefinition graphDef) {
    UBuilder uBuilder = new UBuilder(GRAPH_PREFIX, graphName);
    Request request = Request.Post(uBuilder.build());
    return commonServiceRequest(request, graphDef, null, GraphResult.class, 200);
}