Example usage for org.apache.http.entity ContentType APPLICATION_JSON

List of usage examples for org.apache.http.entity ContentType APPLICATION_JSON

Introduction

In this page you can find the example usage for org.apache.http.entity ContentType APPLICATION_JSON.

Prototype

ContentType APPLICATION_JSON

To view the source code for org.apache.http.entity ContentType APPLICATION_JSON.

Click Source Link

Usage

From source file:org.kitodo.data.index.elasticsearch.type.WorkpieceType.java

@SuppressWarnings("unchecked")
@Override// ww  w.j a  v  a 2s  . c om
public HttpEntity createDocument(Workpiece workpiece) {

    LinkedHashMap<String, String> orderedWorkpieceMap = new LinkedHashMap<>();
    String process = workpiece.getProcess() != null ? workpiece.getProcess().getId().toString() : "null";
    orderedWorkpieceMap.put("process", process);

    JSONObject processObject = new JSONObject(orderedWorkpieceMap);

    JSONArray properties = new JSONArray();
    List<WorkpieceProperty> workpieceProperties = workpiece.getProperties();
    for (WorkpieceProperty property : workpieceProperties) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("title", property.getTitle());
        propertyObject.put("value", property.getValue());
        properties.add(propertyObject);
    }
    processObject.put("properties", properties);

    return new NStringEntity(processObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:onl.area51.httpd.rest.JsonEntity.java

public JsonEntity(JsonStructure json) {
    super(encode(json), ContentType.APPLICATION_JSON);
}

From source file:org.elasticsearch.smoketest.ReindexFromOldRemoteIT.java

private void oldEsTestCase(String portPropertyName, String requestsPerSecond) throws IOException {
    int oldEsPort = Integer.parseInt(System.getProperty(portPropertyName));
    try (RestClient oldEs = RestClient.builder(new HttpHost("127.0.0.1", oldEsPort)).build()) {
        try {/*from   w w w . j  a v  a2 s . c om*/
            HttpEntity entity = new StringEntity("{\"settings\":{\"number_of_shards\": 1}}",
                    ContentType.APPLICATION_JSON);
            oldEs.performRequest("PUT", "/test", singletonMap("refresh", "true"), entity);

            entity = new StringEntity("{\"test\":\"test\"}", ContentType.APPLICATION_JSON);
            oldEs.performRequest("PUT", "/test/doc/testdoc1", singletonMap("refresh", "true"), entity);
            oldEs.performRequest("PUT", "/test/doc/testdoc2", singletonMap("refresh", "true"), entity);
            oldEs.performRequest("PUT", "/test/doc/testdoc3", singletonMap("refresh", "true"), entity);
            oldEs.performRequest("PUT", "/test/doc/testdoc4", singletonMap("refresh", "true"), entity);
            oldEs.performRequest("PUT", "/test/doc/testdoc5", singletonMap("refresh", "true"), entity);

            entity = new StringEntity("{\n" + "  \"source\":{\n" + "    \"index\": \"test\",\n"
                    + "    \"size\": 1,\n" + "    \"remote\": {\n" + "      \"host\": \"http://127.0.0.1:"
                    + oldEsPort + "\"\n" + "    }\n" + "  },\n" + "  \"dest\": {\n"
                    + "    \"index\": \"test\"\n" + "  }\n" + "}", ContentType.APPLICATION_JSON);
            Map<String, String> params = new TreeMap<>();
            params.put("refresh", "true");
            params.put("pretty", "true");
            if (requestsPerSecond != null) {
                params.put("requests_per_second", requestsPerSecond);
            }
            client().performRequest("POST", "/_reindex", params, entity);

            Response response = client().performRequest("POST", "test/_search", singletonMap("pretty", "true"));
            String result = EntityUtils.toString(response.getEntity());
            assertThat(result, containsString("\"_id\" : \"testdoc1\""));
        } finally {
            oldEs.performRequest("DELETE", "/test");
        }
    }
}

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.camunda.connect.plugin.MockHttpConnectorConfigurator.java

public void configure(HttpConnector connecor) {
    connecor.addRequestInterceptor(new ConnectorRequestInterceptor() {

        public Object handleInvocation(ConnectorInvocation invocation) throws Exception {

            // intercept the call. => do not call invocation.proceed()

            // Could do validation on the invocation here:
            // invocation.getRequest() ....

            // build response using http client api...
            TestHttpResonse testHttpResonse = new TestHttpResonse();
            testHttpResonse.setEntity(new StringEntity("{...}", ContentType.APPLICATION_JSON));

            // return the response
            return new HttpResponseImpl(testHttpResonse);
        }//from ww w.j a  va  2 s  . c  o m
    });
}

From source file:com.redhat.refarch.microservices.warehouse.service.WarehouseService.java

public void fulfillOrder(Result result) throws Exception {

    HttpClient client = new DefaultHttpClient();
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("status", "Shipped");

    URIBuilder uriBuilder = new URIBuilder("http://gateway-service:9091/customers/" + result.getCustomerId()
            + "/orders/" + result.getOrderNumber());
    HttpPatch patch = new HttpPatch(uriBuilder.build());
    patch.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON));
    logInfo("Executing " + patch);
    HttpResponse response = client.execute(patch);
    String responseString = EntityUtils.toString(response.getEntity());
    logInfo("Got response " + responseString);
}

From source file:com.seleritycorp.common.base.http.client.HttpRequestFactory.java

/**
 * Creates a POST request for plain Json data.
 *
 * @param url The URL to request./*  w  w  w.  j  a va 2 s  . c  o m*/
 * @param json The json object to post to the url.
 * @return The created request.
 */
public HttpRequest createPostJson(String url, JsonObject json) {
    return create(url).setMethodPost().setContentType(ContentType.APPLICATION_JSON).addData(json.toString());
}

From source file:ijfx.service.remote.DefaultLoginService.java

@Override
public Task<Boolean> login(final String email, final String password) {

    Task<Boolean> task = new Task() {

        @Override/*from   ww  w .jav a 2  s .  co m*/
        protected Boolean call() throws Exception {

            int response = Request.Get(server + API_USER)
                    .bodyString(JSONUtils.generateJSON(EMAIL, email, PASSWORD, password),
                            ContentType.APPLICATION_JSON)
                    .execute().returnResponse().getStatusLine().getStatusCode();

            return response == 200;
        }

    };

    ImageJFX.getThreadPool().submit(task);
    return task;

}

From source file:com.enitalk.configs.BotConfig.java

@Bean
@Primary/*from   w  ww  .  j  a  v  a 2 s . co  m*/
public LoadingCache<String, String> tokenCache() {
    LoadingCache<String, String> cache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS)
            .build(new CacheLoader<String, String>() {

                @Override
                public String load(String key) throws Exception {
                    String id = jackson.createObjectNode().put("login", env.getProperty("bot.login"))
                            .put("password", env.getProperty("bot.pass")).toString();
                    byte[] auth = Request.Post(env.getProperty("bot.auth"))
                            .bodyString(id, ContentType.APPLICATION_JSON).execute().returnContent().asBytes();
                    JsonNode tree = jackson.readTree(auth);
                    logger.info("Bot token came {}", tree);
                    String authToken = tree.path("token").asText();
                    return authToken;
                }

            });
    return cache;
}