Package org.apache.http.entity

Examples of org.apache.http.entity.StringEntity


                            Charset cs = contentType.getCharset();
                            if (cs != null) {
                                charset = cs.name();
                            }
                        }
                        StringEntity entity = new StringEntity((String) data, charset);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }

                    // fallback as input stream
                    if (answer == null) {
                        // force the body as an input stream since this is the fallback
                        InputStream is = in.getMandatoryBody(InputStream.class);
                        InputStreamEntity entity = new InputStreamEntity(is, -1);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }
                }
            } catch (UnsupportedEncodingException e) {
View Full Code Here


    }
   
    @Test
    public void testPutConsumer() throws Exception {
        HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
        StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        put.addHeader("test", "header1;header2");
        put.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
View Full Code Here

                            Charset cs = contentType.getCharset();
                            if (cs != null) {
                                charset = cs.name();
                            }
                        }
                        StringEntity entity = new StringEntity((String) data, charset);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }

                    // fallback as input stream
                    if (answer == null) {
                        // force the body as an input stream since this is the fallback
                        InputStream is = in.getMandatoryBody(InputStream.class);
                        InputStreamEntity entity = new InputStreamEntity(is, -1);
                        if (contentType != null) {
                            entity.setContentType(contentType.toString());
                        }
                        answer = entity;
                    }
                }
            } catch (UnsupportedEncodingException e) {
View Full Code Here

     */
    @Test
    public void testMediaTypesRequestTextPlain() throws IOException {
        HttpPost post = new HttpPost(uri("/context/httpheaders/requestmediatype"));
        post.setHeader("Content-Type", "text/plain");
        post.setEntity(new StringEntity("Hello world!", "UTF-8"));

        final HttpResponse response = client.execute(post);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
        assertEquals("mediatype:text/plain:", responseBody);
View Full Code Here

     */
    @Test
    public void testMediaTypesRequestCustomContentType() throws IOException {
        HttpPost post = new HttpPost(uri("/context/httpheaders/requestmediatype"));
        post.setHeader("Content-Type", "defg/abcd");
        post.setEntity(new StringEntity("Hello world!", "UTF-8"));

        final HttpResponse response = client.execute(post);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
        assertEquals("mediatype:defg/abcd:", responseBody);
View Full Code Here

     */
    @Test
    public void testLanguageNoneGiven() throws IOException {
        HttpPost post = new HttpPost(uri("/context/httpheaders/language"));
        post.setHeader("Content-Type", "text/plain");
        post.setEntity(new StringEntity("Hello world!", "UTF-8"));

        final HttpResponse response = client.execute(post);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
        assertEquals("language:null:", responseBody);
View Full Code Here

     */
    @Test
    public void testLanguageEnglishGiven() throws IOException {
        HttpPost post = new HttpPost(uri("/context/httpheaders/language"));
        post.setHeader("Content-Type", "text/plain");
        post.setEntity(new StringEntity("Hello world!", "UTF-8"));
        post.addHeader("Content-Language", "en");

        final HttpResponse response = client.execute(post);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
View Full Code Here

     */
    @Test
    public void testLanguageChineseGiven() throws IOException {
        HttpPost post = new HttpPost(uri("/context/httpheaders/language"));
        post.setHeader("Content-Type", "text/plain");
        post.setEntity(new StringEntity("Hello world!", "UTF-8"));
        post.addHeader("Content-Language", "zh");

        final HttpResponse response = client.execute(post);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
View Full Code Here

        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);

        try {
           
            HttpEntity[] requestBodies = {
                    new StringEntity(
                            "This is the first test request", "UTF-8"),
                    new ByteArrayEntity(
                            "This is the second test request".getBytes("UTF-8")),
                    new InputStreamEntity(
                            new ByteArrayInputStream(
View Full Code Here

  {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPut method = new HttpPut(apiURL);
    try
    {
      method.setEntity(new StringEntity(input,ContentType.create("text/plain","UTF-8")));
      HttpResponse response = client.execute(method);
      int responseCode = response.getStatusLine().getStatusCode();
      String responseString = convertToString(response);
      if (responseCode != expectedResponse)
        throw new Exception("API http error; expected "+Integer.toString(expectedResponse)+", saw "+Integer.toString(responseCode)+": "+responseString);
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.