Package org.apache.http.entity

Examples of org.apache.http.entity.StringEntity


    HttpClient httpclient = ogpHttpClient.getHttpClient();
    InputStream replyStream = null;
    try {
      HttpPost httppost = new HttpPost(serviceURL);
      logger.debug(requestBody);
      StringEntity postEntity = new StringEntity(requestBody, ContentType.create(contentType, "UTF-8"));
      httppost.setEntity(postEntity);
      logger.info("executing POST request to " + httppost.getURI());
      HttpResponse response = httpclient.execute(httppost);
      this.setStatus(response.getStatusLine().getStatusCode());
      this.setHeaders(response.getAllHeaders());
View Full Code Here


  }

  @Test
  public void testSimple() throws IOException, InterruptedException {

    StringEntity input = new StringEntity("[{\"headers\":{\"a\": \"b\"},\"body\": \"random_body\"},"
            + "{\"headers\":{\"e\": \"f\"},\"body\": \"random_body2\"}]");
    //if we do not set the content type to JSON, the client will use
    //ISO-8859-1 as the charset. JSON standard does not support this.
    input.setContentType("application/json");
    postRequest.setEntity(input);

    HttpResponse response = httpClient.execute(postRequest);

    Assert.assertEquals(HttpServletResponse.SC_OK,
View Full Code Here

  }

  @Test
  public void testSimpleUTF16() throws IOException, InterruptedException {

    StringEntity input = new StringEntity("[{\"headers\":{\"a\": \"b\"},\"body\": \"random_body\"},"
            + "{\"headers\":{\"e\": \"f\"},\"body\": \"random_body2\"}]", "UTF-16");
    input.setContentType("application/json; charset=utf-16");
    postRequest.setEntity(input);

    HttpResponse response = httpClient.execute(postRequest);

    Assert.assertEquals(HttpServletResponse.SC_OK,
View Full Code Here

    tx.close();
  }

  @Test
  public void testInvalid() throws Exception {
    StringEntity input = new StringEntity("[{\"a\": \"b\",[\"d\":\"e\"],\"body\": \"random_body\"},"
            + "{\"e\": \"f\",\"body\": \"random_body2\"}]");
    input.setContentType("application/json");
    postRequest.setEntity(input);
    HttpResponse response = httpClient.execute(postRequest);

    Assert.assertEquals(HttpServletResponse.SC_BAD_REQUEST,
            response.getStatusLine().getStatusCode());
View Full Code Here

  public void testBigBatchDeserializarionUTF32() throws Exception {
    testBatchWithVariousEncoding("UTF-32");
  }
  @Test
  public void testSingleEvent() throws Exception {
    StringEntity input = new StringEntity("[{\"headers\" : {\"a\": \"b\"},\"body\":"
            + " \"random_body\"}]");
    input.setContentType("application/json");
    postRequest.setEntity(input);

    httpClient.execute(postRequest);
    Transaction tx = channel.getTransaction();
    tx.begin();
View Full Code Here

      e.setBody(String.valueOf(rand.nextGaussian()).getBytes(encoding));
      events.add(e);
    }
    Gson gson = new Gson();
    String json = gson.toJson(events, listType);
    StringEntity input = new StringEntity(json);
    input.setContentType("application/json; charset=" + encoding);
    postRequest.setEntity(input);
    HttpResponse resp = httpClient.execute(postRequest);
    return new ResultWrapper(resp, events);
  }
View Full Code Here

    while (statusCode != HttpStatus.SC_OK && triesCount < serversList.size()) {
      triesCount++;
      String host = serversList.get();
      String url = host + "/" + BULK_ENDPOINT;
      HttpPost httpRequest = new HttpPost(url);
      httpRequest.setEntity(new StringEntity(entity));
      response = httpClient.execute(httpRequest);
      statusCode = response.getStatusLine().getStatusCode();
      logger.info("Status code from elasticsearch: " + statusCode);
      if (response.getEntity() != null)
        logger.debug("Status message from elasticsearch: " + EntityUtils.toString(response.getEntity(), "UTF-8"));
View Full Code Here

    {
      HttpPost httppost = new HttpPost(url);
      if (body != null)
      {
        httppost.setHeader("Content-Type", "application/json;charset=UTF-8");
        httppost.setEntity(new StringEntity(body, "UTF-8"));
      }
      map = executeMethod(httppost, url, body, connectionTimeout, soTimeout);
    }
    catch (UnsupportedEncodingException e)
    {
View Full Code Here

    {
      HttpPut httpput = new HttpPut(url);
      if (body != null)
      {
        httpput.setHeader("Content-Type", "application/json;charset=UTF-8");
        httpput.setEntity(new StringEntity(body, "UTF-8"));
      }
      map = executeMethod(httpput, url, body, connectionTimeout, soTimeout);
    }
    catch (UnsupportedEncodingException e)
    {
View Full Code Here

    {
      HttpPost httppost = new HttpPost(url);
      if (body != null)
      {
        httppost.setHeader("Content-Type", "application/json;charset=UTF-8");
        httppost.setEntity(new StringEntity(body, "UTF-8"));
      }
      map = executeMethod(httppost, url, body, connectionTimeout, soTimeout);
    }
    catch (UnsupportedEncodingException e)
    {
View Full Code Here

TOP

Related Classes of org.apache.http.entity.StringEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.