List of usage examples for org.apache.http.entity ContentType APPLICATION_JSON
ContentType APPLICATION_JSON
To view the source code for org.apache.http.entity ContentType APPLICATION_JSON.
Click Source Link
From source file:com.ibm.watson.app.common.util.rest.JSONEntity.java
private JSONEntity(Object object) throws UnsupportedEncodingException { super(gson.toJson(object), ContentType.APPLICATION_JSON); }
From source file:org.elasticsearch.upgrades.TokenBackwardsCompatibilityIT.java
public void testGeneratingTokenInOldCluster() throws Exception { assumeTrue("this test should only run against the old cluster", clusterType == CLUSTER_TYPE.OLD); final StringEntity tokenPostBody = new StringEntity("{\n" + " \"username\": \"test_user\",\n" + " \"password\": \"x-pack-test-password\",\n" + " \"grant_type\": \"password\"\n" + "}", ContentType.APPLICATION_JSON); Response response = client().performRequest("POST", "_xpack/security/oauth2/token", Collections.emptyMap(), tokenPostBody);/*from w ww . j ava2 s .com*/ assertOK(response); Map<String, Object> responseMap = entityAsMap(response); String token = (String) responseMap.get("access_token"); assertNotNull(token); assertTokenWorks(token); StringEntity oldClusterToken = new StringEntity("{\n" + " \"token\": \"" + token + "\"\n" + "}", ContentType.APPLICATION_JSON); Response indexResponse = client().performRequest("PUT", "token_backwards_compatibility_it/doc/old_cluster_token1", Collections.emptyMap(), oldClusterToken); assertOK(indexResponse); response = client().performRequest("POST", "_xpack/security/oauth2/token", Collections.emptyMap(), tokenPostBody); assertOK(response); responseMap = entityAsMap(response); token = (String) responseMap.get("access_token"); assertNotNull(token); assertTokenWorks(token); oldClusterToken = new StringEntity("{\n" + " \"token\": \"" + token + "\"\n" + "}", ContentType.APPLICATION_JSON); indexResponse = client().performRequest("PUT", "token_backwards_compatibility_it/doc/old_cluster_token2", Collections.emptyMap(), oldClusterToken); assertOK(indexResponse); }
From source file:org.arquillian.graphene.visual.testing.test.RestUtilsTest.java
@Test public void testResponse() { String token = "test-word"; CloseableHttpClient httpClient = RestUtils.getHTTPClient(conf.getJcrContextRootURL(), conf.getJcrUserName(), conf.getJcrPassword());// w w w. j a v a2 s . com HttpPost postCreateWords = new HttpPost( conf.getManagerContextRootURL() + "graphene-visual-testing-webapp/rest/words"); StringEntity wordEnity = new StringEntity("{\"value\": \"" + token + "\"}", ContentType.APPLICATION_JSON); postCreateWords.setHeader("Content-Type", "application/json"); postCreateWords.setEntity(wordEnity); String response = RestUtils.executePost(postCreateWords, httpClient, token + " created", "FAILED TO CREATE: " + token); }
From source file:com.messagemedia.restapi.client.v1.internal.http.interceptors.ContentTypeInterceptor.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { Args.notNull(request, "HTTP request"); if ((request instanceof HttpEntityEnclosingRequest) && !request.containsHeader(HTTP.CONTENT_TYPE)) { request.setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); }/*from w w w . java 2 s . co m*/ }
From source file:de.appsolve.padelcampus.external.cloudflare.CloudFlareApiRequestInterceptor.java
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpHeaders headers = request.getHeaders(); headers.add("X-Auth-Key", cloudFlareApiKey); headers.add("X-Auth-Email", cloudFlareApiEmail); headers.add("Content-Type", ContentType.APPLICATION_JSON.toString()); return execution.execute(request, body); }
From source file:com.jubination.io.chatbot.backend.service.core.DashBotUpdater.java
public String sendAutomatedUpdate(DashBot dashbot, String type) { String responseText = ""; try {/* w w w. j a va 2 s . c o m*/ String url = "https://tracker.dashbot.io/track?platform=generic&v=0.8.2-rest&type=" + type + "&apiKey=bJt7U0oEG79HSUm4nJWUQTPm1nhjKu3gieZ83M0O"; ObjectMapper mapper = new ObjectMapper(); //Object to JSON in String String jsonString = mapper.writeValueAsString(dashbot); HttpClient httpClient = HttpClientBuilder.create().build(); // System.out.println(jsonString+"STRING JSON TO DASH BOT"); StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); HttpPost postMethod = new HttpPost(url); postMethod.setEntity(requestEntity); HttpResponse response = httpClient.execute(postMethod); HttpEntity entity = response.getEntity(); responseText = EntityUtils.toString(entity, "UTF-8"); } catch (Exception ex) { Logger.getLogger(DashBotUpdater.class.getName()).log(Level.SEVERE, null, ex); } // System.out.println(responseText); return responseText; }
From source file:gobblin.writer.http.RestJsonWriter.java
@Override public Optional<HttpUriRequest> onNewRecord(RestEntry<JsonObject> record) { HttpUriRequest uriRequest = RequestBuilder.post() .addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()) .setUri(combineUrl(getCurServerHost(), record.getResourcePath())) .setEntity(new StringEntity(record.getRestEntryVal().toString(), ContentType.APPLICATION_JSON)) .build();//from w w w .j a v a2 s .c o m return Optional.of(uriRequest); }
From source file:org.jitsi.meet.test.util.JvbUtil.java
static private void triggerShutdown(HttpClient client, String jvbEndpoint, boolean force) throws IOException { String url = jvbEndpoint + "/colibri/shutdown"; HttpPost post = new HttpPost(url); StringEntity requestEntity = new StringEntity( force ? "{ \"force-shutdown\": \"true\" }" : "{ \"graceful-shutdown\": \"true\" }", ContentType.APPLICATION_JSON); post.setEntity(requestEntity);//from ww w . j av a 2 s . co m System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + post.getEntity()); HttpResponse response = client.execute(post); int responseCode = response.getStatusLine().getStatusCode(); if (200 != responseCode) { throw new RuntimeException( "Failed to trigger graceful shutdown on: " + jvbEndpoint + ", response code: " + responseCode); } }
From source file:juzu.plugin.jackson.AbstractJacksonRequestTestCase.java
@Test public void testRequest() throws Exception { HttpPost post = new HttpPost(applicationURL() + "/post"); post.setEntity(new StringEntity("{\"foo\":\"bar\"}", ContentType.APPLICATION_JSON)); HttpClient client = HttpClientBuilder.create().build(); payload = null;//from w ww.j a v a 2 s . c om client.execute(post); }
From source file:org.kitodo.data.index.elasticsearch.type.HistoryType.java
@SuppressWarnings("unchecked") @Override/* ww w . j av a 2 s. c om*/ public HttpEntity createDocument(History history) { LinkedHashMap<String, String> orderedHistoryMap = new LinkedHashMap<>(); orderedHistoryMap.put("numericValue", history.getNumericValue().toString()); orderedHistoryMap.put("stringValue", history.getStringValue()); orderedHistoryMap.put("type", history.getHistoryType().toString()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String date = history.getDate() != null ? dateFormat.format(history.getDate()) : null; orderedHistoryMap.put("date", date); orderedHistoryMap.put("process", history.getProcess().getId().toString()); JSONObject historyObject = new JSONObject(orderedHistoryMap); return new NStringEntity(historyObject.toJSONString(), ContentType.APPLICATION_JSON); }