Package org.apache.http.entity

Examples of org.apache.http.entity.ContentType


            final HttpRequest request) throws HttpException, IOException {
        onRequestReceived(request);
        if (request instanceof HttpEntityEnclosingRequest) {
            final HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
            if (entity != null) {
                final ContentType contentType = ContentType.getOrDefault(entity);
                onEntityEnclosed(entity, contentType);
            }
        }
    }
View Full Code Here


                    final HttpResponse response,
                    final HttpContext context) throws HttpException, IOException {
                final HttpEntity responseEntity;
                if (request instanceof HttpEntityEnclosingRequest) {
                    final HttpEntity requestEntity = ((HttpEntityEnclosingRequest) request).getEntity();
                    final ContentType contentType = ContentType.getOrDefault(requestEntity);
                    responseEntity = new NByteArrayEntity(
                            EntityUtils.toByteArray(requestEntity), contentType);
                } else {
                    responseEntity = new NStringEntity("Say what?", ContentType.DEFAULT_TEXT);
                }
View Full Code Here

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

    public final synchronized void responseReceived(
            final HttpResponse response) throws IOException, HttpException {
        onResponseReceived(response);
        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            final ContentType contentType = ContentType.getOrDefault(entity);
            onEntityEnclosed(entity, contentType);
        }
    }
View Full Code Here

            final HttpRequest request) throws HttpException, IOException {
        onRequestReceived(request);
        if (request instanceof HttpEntityEnclosingRequest) {
            final HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
            if (entity != null) {
                final ContentType contentType = ContentType.getOrDefault(entity);
                onEntityEnclosed(entity, contentType);
            }
        }
    }
View Full Code Here

                        int l;
                        while((l = instream.read(tmp)) != -1) {
                            Thread.sleep(1);
                            outstream.write(tmp, 0, l);
                        }
                        final 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 (final InterruptedException ex) {
View Full Code Here

                    stats.incFailureCount();
                }

                final HttpEntity entity = response.getEntity();
                if (entity != null) {
                    final ContentType ct = ContentType.getOrDefault(entity);
                    Charset charset = ct.getCharset();
                    if (charset == null) {
                        charset = HTTP.DEF_CONTENT_CHARSET;
                    }
                    long contentlen = 0;
                    final InputStream instream = entity.getContent();
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

                    stats.incFailureCount();
                }

                final HttpEntity entity = response.getEntity();
                if (entity != null) {
                    final ContentType ct = ContentType.getOrDefault(entity);
                    Charset charset = ct.getCharset();
                    if (charset == null) {
                        charset = HTTP.DEF_CONTENT_CHARSET;
                    }
                    long contentlen = 0;
                    final InputStream instream = entity.getContent();
View Full Code Here

      try
      {
        Charset charSet;
        try
        {
          ContentType ct = ContentType.get(entity);
          if (ct == null)
            charSet = StandardCharsets.UTF_8;
          else
            charSet = ct.getCharset();
        }
        catch (ParseException e)
        {
          charSet = StandardCharsets.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.