Package org.apache.http.entity

Examples of org.apache.http.entity.ContentType


            if (i < 0) {
                i = 4096;
            }
            Charset charset = null;
            try {
                ContentType contentType = ContentType.getOrDefault(entity);
                charset = contentType.getCharset();
            } catch (UnsupportedCharsetException ex) {
                throw new UnsupportedEncodingException(ex.getMessage());
            }
            if (charset == null) {
                charset = defaultCharset;
View Full Code Here


                        }
                    }

                    HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
                    String line = EntityUtils.toString(incoming);
                    ContentType contentType = ContentType.getOrDefault(incoming);
                    Charset charset = contentType.getCharset();
                    if (charset == null) {
                        charset = HTTP.DEF_CONTENT_CHARSET;
                    }
                    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();
        DefaultBHttpClientConnection conn = client.createConnection();
        HttpHost host = new HttpHost("localhost", this.server.getPort());

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

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

                    HttpResponse response = this.client.execute(post, host, conn);
                    HttpEntity incoming = response.getEntity();
                    Assert.assertNotNull(incoming);
                    InputStream instream = incoming.getContent();
                    ContentType contentType = ContentType.getOrDefault(incoming);
                    Charset charset = contentType.getCharset();
                    if (charset == null) {
                        charset = HTTP.DEF_CONTENT_CHARSET;
                    }
                    Assert.assertNotNull(instream);
                    BufferedReader reader = new BufferedReader(new InputStreamReader(instream, charset));
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);
                        Charset charset = contentType.getCharset();
                        if (charset == null) {
                            charset = HTTP.DEF_CONTENT_CHARSET;
                        }
                        content = new String(outstream.toByteArray(), charset.name());
                    } catch (InterruptedException ex) {
View Full Code Here

        if (ResourceResponse.HTTP_STATUS_CODE.equals(key)) {
            this.portletResourceOutputHandler.setStatus(Integer.parseInt(value));
            return true;
        }
        if ("Content-Type".equals(key)) {
            final ContentType contentType = ContentType.parse(value);
            final Charset charset = contentType.getCharset();
            if (charset != null) {
                this.portletResourceOutputHandler.setCharacterEncoding(charset.name());
            }
            this.portletResourceOutputHandler.setContentType(contentType.getMimeType());
            return true;
        }
        if ("Content-Length".equals(key)) {
            this.portletResourceOutputHandler.setContentLength(Integer.parseInt(value));
            return true;
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

      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

                        }
                    }

                    HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
                    String line = EntityUtils.toString(incoming);
                    ContentType contentType = ContentType.getOrDefault(incoming);
                    String charset = contentType.getCharset();
                    if (charset == null) {
                        charset = HTTP.DEFAULT_CONTENT_CHARSET;
                    }
                    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();
        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        HttpHost host = new HttpHost("localhost", this.server.getPort());

        try {
            for (int i = 0; i < patterns.length; i++) {
                String pattern = patterns[i];
                for (int n = 1000; n < 1020; n++) {
                    if (!conn.isOpen()) {
                        Socket socket = new Socket(host.getHostName(), host.getPort());
                        conn.bind(socket, this.client.getParams());
                    }

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

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

  private static Charset getCharSet(HttpEntity entity)
  {
    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

  private static Charset getCharSet(HttpEntity entity)
  {
    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

      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

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.