Package org.apache.http.entity

Examples of org.apache.http.entity.ContentType


            }
            int i = (int)entity.getContentLength();
            if (i < 0) {
                i = 4096;
            }
            ContentType contentType = ContentType.getOrDefault(entity);
            String charset = contentType.getCharset();
            if (charset == null) {
                charset = defaultCharset;
            }
            if (charset == null) {
                charset = HTTP.DEFAULT_CONTENT_CHARSET;
View Full Code Here


      try
      {
        Charset charSet;
        try
        {
          ContentType ct = ContentType.get(entity);
          if (ct == null)
            charSet = UTF_8;
          else
            charSet = ct.getCharset();
        }
        catch (ParseException e)
        {
          charSet = UTF_8;
        }
View Full Code Here

                  if (bodyStream != null)
                  {
                    threadStream = new XThreadInputStream(bodyStream);
                    try
                    {
                      ContentType ct = ContentType.get(entity);
                      if (ct == null)
                        charSet = null;
                      else
                        charSet = ct.getCharset();
                    }
                    catch (ParseException e)
                    {
                      charSet = null;
                    }
View Full Code Here

                  if (bodyStream != null)
                  {
                    threadStream = new XThreadInputStream(bodyStream);
                    try
                    {
                      ContentType ct = ContentType.get(entity);
                      if (ct == null)
                        charSet = null;
                      else
                        charSet = ct.getCharset();
                    }
                    catch (ParseException e)
                    {
                      charSet = null;
                    }
View Full Code Here

                        int l;
                        while((l = instream.read(tmp)) != -1) {
                            Thread.sleep(1);
                            outstream.write(tmp, 0, l);
                        }
                        ContentType contentType = ContentType.getOrDefault(entity);
                        String charset = contentType.getCharset();
                        if (charset == null) {
                            charset = HTTP.DEFAULT_CONTENT_CHARSET;
                        }
                        content = new String(outstream.toByteArray(), charset);
                    } catch (InterruptedException ex) {
View Full Code Here

      try
      {
        Charset charSet;
        try
        {
          ContentType ct = ContentType.get(entity);
          if (ct == null)
            charSet = UTF_8;
          else
            charSet = ct.getCharset();
        }
        catch (ParseException e)
        {
          charSet = UTF_8;
        }
View Full Code Here

                    "POST", requestLineUri, httpVersion);
            this.request = postRequest;
            String submitData = (String) curi.getData().get(CoreAttributeConstants.A_SUBMIT_DATA);
            if (submitData != null) {
                // XXX brittle, doesn't support multipart form data etc
                ContentType contentType = ContentType.create(URLEncodedUtils.CONTENT_TYPE, "UTF-8");
                StringEntity formEntity = new StringEntity(submitData, contentType);
                postRequest.setEntity(formEntity);
            }
        } else {
            this.request = new BasicExecutionAwareRequest("GET",
View Full Code Here

  @Test
  public void testWithCharsetOnContentType() throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(applicationURL().toString() + "/foo");
    ContentType content = ContentType.create("application/x-www-form-urlencoded", "UTF-8");
    HttpEntity entity = new StringEntity("param=" + "test" + EURO, content);
    httpPost.setEntity(entity);
    client.execute(httpPost);
    assertEquals("test" + EURO, param);
  }
View Full Code Here

  @Test
  public void testWithoutCharsetOnContentType() throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(applicationURL().toString() + "/foo");
    ContentType content = ContentType.create("application/x-www-form-urlencoded");
    HttpEntity entity = new StringEntity("param=" + "test", content);
    httpPost.setEntity(entity);
    client.execute(httpPost);
    assertEquals("test", param);
  }
View Full Code Here

                        }
                    }

                    final HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
                    final String line = EntityUtils.toString(incoming);
                    final ContentType contentType = ContentType.getOrDefault(incoming);
                    Charset charset = contentType.getCharset();
                    if (charset == null) {
                        charset = HTTP.DEF_CONTENT_CHARSET;
                    }
                    final RepeatingEntity outgoing = new RepeatingEntity(line, charset, n);
                    outgoing.setChunked(n % 2 == 0);
                    response.setEntity(outgoing);
                } else {
                    throw new HttpException("Invalid request: POST request expected");
                }
            }

        });

        this.server.start();
        final DefaultBHttpClientConnection conn = client.createConnection();
        final HttpHost host = new HttpHost("localhost", this.server.getPort());

        try {
            for (final String pattern : patterns) {
                for (int n = 1000; n < 1020; n++) {
                    if (!conn.isOpen()) {
                        client.connect(host, conn);
                    }

                    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest(
                            "POST", "/?n=" + n);
                    final StringEntity outgoing = new StringEntity(pattern);
                    outgoing.setChunked(n % 2 == 0);
                    post.setEntity(outgoing);

                    final HttpResponse response = this.client.execute(post, host, conn);
                    final HttpEntity incoming = response.getEntity();
                    Assert.assertNotNull(incoming);
                    final InputStream instream = incoming.getContent();
                    final ContentType contentType = ContentType.getOrDefault(incoming);
                    Charset charset = contentType.getCharset();
                    if (charset == null) {
                        charset = HTTP.DEF_CONTENT_CHARSET;
                    }
                    Assert.assertNotNull(instream);
                    final BufferedReader reader = new BufferedReader(new InputStreamReader(instream, charset));
View Full Code Here

TOP

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

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.