Package org.apache.http.nio.entity

Examples of org.apache.http.nio.entity.BufferingNHttpEntity


    }

    @Override
    public ConsumingNHttpEntity responseEntity(HttpResponse response,
        HttpContext context) throws IOException {
      return new BufferingNHttpEntity(response.getEntity(),
          new HeapByteBufferAllocator());
    }
View Full Code Here


        }

        public ConsumingNHttpEntity entityRequest(
                final HttpEntityEnclosingRequest request,
                final HttpContext context) throws HttpException, IOException {
            return new BufferingNHttpEntity(
                    request.getEntity(),
                    new HeapByteBufferAllocator());
        }
View Full Code Here

        }
       
        public ConsumingNHttpEntity responseEntity(
                final HttpResponse response,
                final HttpContext context) throws IOException {
            return new BufferingNHttpEntity(
                    response.getEntity(),
                    new HeapByteBufferAllocator());
        }
View Full Code Here

            }

            public ConsumingNHttpEntity responseEntity(
                    final HttpResponse response,
                    final HttpContext context) throws IOException {
                return new BufferingNHttpEntity(response.getEntity(),
                        new HeapByteBufferAllocator());
            }

            public void handleResponse(final HttpResponse response, final HttpContext context) {
                NHttpConnection conn = (NHttpConnection) context.getAttribute(
View Full Code Here

        NHttpRequestHandler requestHandler = new SimpleNHttpRequestHandler() {

            public ConsumingNHttpEntity entityRequest(
                    final HttpEntityEnclosingRequest request,
                    final HttpContext context) throws HttpException, IOException {
                return new BufferingNHttpEntity(
                        request.getEntity(),
                        new HeapByteBufferAllocator());
            }

            @Override
            public void handle(
                    final HttpRequest request,
                    final HttpResponse response,
                    final HttpContext context) throws HttpException, IOException {
                if (request instanceof HttpEntityEnclosingRequest) {
                    HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
                    byte[] b = EntityUtils.toByteArray(entity);
                    response.setEntity(new NByteArrayEntity(b));
                } else {
                    NStringEntity outgoing = new NStringEntity("No content");
                    response.setEntity(outgoing);
                }
            }
        };

        NHttpRequestExecutionHandler requestExecutionHandler = new NHttpRequestExecutionHandler() {

            public void initalizeContext(final HttpContext context, final Object attachment) {
                context.setAttribute("LIST", attachment);
                context.setAttribute("REQ-COUNT", Integer.valueOf(0));
                context.setAttribute("RES-COUNT", Integer.valueOf(0));
            }

            public void finalizeContext(final HttpContext context) {
            }

            public ConsumingNHttpEntity responseEntity(
                    final HttpResponse response,
                    final HttpContext context) throws IOException {
                return new BufferingNHttpEntity(response.getEntity(),
                        new HeapByteBufferAllocator());
            }

            public HttpRequest submitRequest(final HttpContext context) {
                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
View Full Code Here

        NHttpRequestHandler requestHandler = new SimpleNHttpRequestHandler() {

            public ConsumingNHttpEntity entityRequest(
                    final HttpEntityEnclosingRequest request,
                    final HttpContext context) throws HttpException, IOException {
                return new BufferingNHttpEntity(
                        request.getEntity(),
                        new HeapByteBufferAllocator());
            }

            @Override
            public void handle(
                    final HttpRequest request,
                    final HttpResponse response,
                    final HttpContext context) throws HttpException, IOException {
                if (request instanceof HttpEntityEnclosingRequest) {
                    HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
                    byte[] b = EntityUtils.toByteArray(entity);
                    NByteArrayEntity outgoing = new NByteArrayEntity(b);
                    outgoing.setChunked(true);
                    response.setEntity(outgoing);
                } else {
                    NStringEntity outgoing = new NStringEntity("No content");
                    response.setEntity(outgoing);
                }
            }
        };

        NHttpRequestExecutionHandler requestExecutionHandler = new NHttpRequestExecutionHandler() {

            public void initalizeContext(final HttpContext context, final Object attachment) {
                context.setAttribute("LIST", attachment);
                context.setAttribute("REQ-COUNT", Integer.valueOf(0));
                context.setAttribute("RES-COUNT", Integer.valueOf(0));
            }

            public void finalizeContext(final HttpContext context) {
            }

            public ConsumingNHttpEntity responseEntity(
                    final HttpResponse response,
                    final HttpContext context) throws IOException {
                return new BufferingNHttpEntity(response.getEntity(),
                        new HeapByteBufferAllocator());
            }

            public HttpRequest submitRequest(final HttpContext context) {
                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
View Full Code Here

        NHttpRequestHandler requestHandler = new SimpleNHttpRequestHandler() {

            public ConsumingNHttpEntity entityRequest(
                    final HttpEntityEnclosingRequest request,
                    final HttpContext context) throws HttpException, IOException {
                return new BufferingNHttpEntity(
                        request.getEntity(),
                        new HeapByteBufferAllocator());
            }

            @Override
            public void handle(
                    final HttpRequest request,
                    final HttpResponse response,
                    final HttpContext context) throws HttpException, IOException {
                if (request instanceof HttpEntityEnclosingRequest) {
                    HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
                    byte[] b = EntityUtils.toByteArray(entity);
                    NByteArrayEntity outgoing = new NByteArrayEntity(b);
                    outgoing.setChunked(false);
                    response.setEntity(outgoing);
                } else {
                    NStringEntity outgoing = new NStringEntity("No content");
                    response.setEntity(outgoing);
                }
            }
        };

        // Set protocol level to HTTP/1.0
        this.client.getParams().setParameter(
                CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);

        NHttpRequestExecutionHandler requestExecutionHandler = new NHttpRequestExecutionHandler() {

            public void initalizeContext(final HttpContext context, final Object attachment) {
                context.setAttribute("LIST", attachment);
                context.setAttribute("REQ-COUNT", Integer.valueOf(0));
                context.setAttribute("RES-COUNT", Integer.valueOf(0));
            }

            public void finalizeContext(final HttpContext context) {
            }

            public ConsumingNHttpEntity responseEntity(
                    final HttpResponse response,
                    final HttpContext context) throws IOException {
                return new BufferingNHttpEntity(response.getEntity(),
                        new HeapByteBufferAllocator());
            }

            public HttpRequest submitRequest(final HttpContext context) {
                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
View Full Code Here

        NHttpRequestHandler requestHandler = new SimpleNHttpRequestHandler() {

            public ConsumingNHttpEntity entityRequest(
                    final HttpEntityEnclosingRequest request,
                    final HttpContext context) throws HttpException, IOException {
                return new BufferingNHttpEntity(
                        request.getEntity(),
                        new HeapByteBufferAllocator());
            }

            @Override
            public void handle(
                    final HttpRequest request,
                    final HttpResponse response,
                    final HttpContext context) throws HttpException, IOException {
                if (request instanceof HttpEntityEnclosingRequest) {
                    HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
                    byte[] b = EntityUtils.toByteArray(entity);
                    NByteArrayEntity outgoing = new NByteArrayEntity(b);
                    outgoing.setChunked(true);
                    response.setEntity(outgoing);
                } else {
                    NStringEntity outgoing = new NStringEntity("No content");
                    response.setEntity(outgoing);
                }
            }
        };

        // Activate 'expect: continue' handshake
        this.client.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);

        NHttpRequestExecutionHandler requestExecutionHandler = new NHttpRequestExecutionHandler() {

            public void initalizeContext(final HttpContext context, final Object attachment) {
                context.setAttribute("LIST", attachment);
                context.setAttribute("REQ-COUNT", Integer.valueOf(0));
                context.setAttribute("RES-COUNT", Integer.valueOf(0));
            }

            public void finalizeContext(final HttpContext context) {
            }

            public ConsumingNHttpEntity responseEntity(
                    final HttpResponse response,
                    final HttpContext context) throws IOException {
                return new BufferingNHttpEntity(response.getEntity(),
                        new HeapByteBufferAllocator());
            }

            public HttpRequest submitRequest(final HttpContext context) {
                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
View Full Code Here

        NHttpRequestHandler requestHandler = new SimpleNHttpRequestHandler() {

            public ConsumingNHttpEntity entityRequest(
                    final HttpEntityEnclosingRequest request,
                    final HttpContext context) throws HttpException, IOException {
                return new BufferingNHttpEntity(
                        request.getEntity(),
                        new HeapByteBufferAllocator());
            }

            @Override
            public void handle(
                    final HttpRequest request,
                    final HttpResponse response,
                    final HttpContext context) throws HttpException, IOException {
                NStringEntity outgoing = new NStringEntity("No content");
                response.setEntity(outgoing);
            }
        };

        HttpExpectationVerifier expectationVerifier = new HttpExpectationVerifier() {

            public void verify(
                    final HttpRequest request,
                    final HttpResponse response,
                    final HttpContext context) throws HttpException {
                Header someheader = request.getFirstHeader("Secret");
                if (someheader != null) {
                    int secretNumber;
                    try {
                        secretNumber = Integer.parseInt(someheader.getValue());
                    } catch (NumberFormatException ex) {
                        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
                        return;
                    }
                    if (secretNumber < 2) {
                        response.setStatusCode(HttpStatus.SC_EXPECTATION_FAILED);
                        NByteArrayEntity outgoing = new NByteArrayEntity(
                                EncodingUtils.getAsciiBytes("Wrong secret number"));
                        response.setEntity(outgoing);
                    }
                }
            }

        };

        // Activate 'expect: continue' handshake
        this.client.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);

        NHttpRequestExecutionHandler requestExecutionHandler = new NHttpRequestExecutionHandler() {

            public void initalizeContext(final HttpContext context, final Object attachment) {
                context.setAttribute("LIST", attachment);
                context.setAttribute("REQ-COUNT", Integer.valueOf(0));
                context.setAttribute("RES-COUNT", Integer.valueOf(0));
            }

            public void finalizeContext(final HttpContext context) {
            }

            public ConsumingNHttpEntity responseEntity(
                    final HttpResponse response,
                    final HttpContext context) throws IOException {
                return new BufferingNHttpEntity(response.getEntity(),
                        new HeapByteBufferAllocator());
            }

            public HttpRequest submitRequest(final HttpContext context) {
                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
View Full Code Here

        NHttpRequestHandler requestHandler = new SimpleNHttpRequestHandler() {

            public ConsumingNHttpEntity entityRequest(
                    final HttpEntityEnclosingRequest request,
                    final HttpContext context) throws HttpException, IOException {
                return new BufferingNHttpEntity(
                        request.getEntity(),
                        new HeapByteBufferAllocator());
            }

            @Override
            public void handle(
                    final HttpRequest request,
                    final HttpResponse response,
                    final HttpContext context) throws HttpException, IOException {
                String s = request.getRequestLine().getUri();
                URI uri;
                try {
                    uri = new URI(s);
                } catch (URISyntaxException ex) {
                    throw new HttpException("Invalid request URI: " + s);
                }
                int index = Integer.parseInt(uri.getQuery());
                byte[] bytes = requestData.getBytes(index);
                NByteArrayEntity entity = new NByteArrayEntity(bytes);
                response.setEntity(entity);
            }

        };

        NHttpRequestExecutionHandler requestExecutionHandler = new NHttpRequestExecutionHandler() {

            public void initalizeContext(final HttpContext context, final Object attachment) {
                context.setAttribute("LIST", attachment);
                context.setAttribute("REQ-COUNT", Integer.valueOf(0));
                context.setAttribute("RES-COUNT", Integer.valueOf(0));
            }

            public void finalizeContext(final HttpContext context) {
            }

            public ConsumingNHttpEntity responseEntity(
                    final HttpResponse response,
                    final HttpContext context) throws IOException {
                return new BufferingNHttpEntity(response.getEntity(),
                        new HeapByteBufferAllocator());
            }

            public HttpRequest submitRequest(final HttpContext context) {
                int i = ((Integer) context.getAttribute("REQ-COUNT")).intValue();
View Full Code Here

TOP

Related Classes of org.apache.http.nio.entity.BufferingNHttpEntity

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.