Examples of HttpEntityEnclosingRequest


Examples of org.apache.http.HttpEntityEnclosingRequest

      setProxy(httpUriRequest.getParams());
      // statistics
      storeConnectionInfo(httpUriRequest);
      // execute the method; some asserts confirm that that the request can be send with Content-Length and is therefore not terminated by EOF
      if (httpUriRequest instanceof HttpEntityEnclosingRequest) {
          final HttpEntityEnclosingRequest hrequest = (HttpEntityEnclosingRequest) httpUriRequest;
          final HttpEntity entity = hrequest.getEntity();
          assert entity != null;
          //assert !entity.isChunked();
          //assert entity.getContentLength() >= 0;
          assert !hrequest.expectContinue();
      }

      try {
          final long time = System.currentTimeMillis();
            this.httpResponse = httpClient.execute(httpUriRequest, httpContext);
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

       * Spec: RFC 2616, sec 4.3: either of these two headers signal that there is a message body.
       */
      if (servletRequest.getHeader(HttpHeaders.CONTENT_LENGTH) != null ||
               servletRequest.getHeader(HttpHeaders.TRANSFER_ENCODING) != null)
      {
         HttpEntityEnclosingRequest eProxyRequest = new BasicHttpEntityEnclosingRequest(method, targetUri);
         /*
          * Add the input entity (streamed) note: we don't bother ensuring we close the servletInputStream since the
          * container handles it
          */
         eProxyRequest.setEntity(new InputStreamEntity(servletRequest.getInputStream(), servletRequest
                  .getContentLength()));
         proxyRequest = eProxyRequest;
      }
      else
         proxyRequest = new BasicHttpRequest(method, targetUri);
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

        verifyMocks();

        HttpRequest forwarded = reqCap.getValue();
        Assert.assertTrue(forwarded instanceof HttpEntityEnclosingRequest);
        HttpEntityEnclosingRequest reqWithBody = (HttpEntityEnclosingRequest) forwarded;
        HttpEntity reqBody = reqWithBody.getEntity();
        Assert.assertNotNull(reqBody);
        Assert.assertNotNull(reqBody.getContentType());
    }
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

        assertTrue(closed.set || bais.read() == -1);
    }
   
    @Test
    public void consumesBodyOf100ContinueResponseIfItArrives() throws Exception {
        HttpEntityEnclosingRequest req = new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
        int nbytes = 128;
        req.setHeader("Content-Length","" + nbytes);
        req.setHeader("Content-Type", "application/octet-stream");
        HttpEntity postBody = new ByteArrayEntity(HttpTestUtils.getRandomBytes(nbytes));
        req.setEntity(postBody);
       
        HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_CONTINUE, "Continue");
        final Flag closed = new Flag();
        ByteArrayInputStream bais = makeTrackableBody(nbytes, closed);
        resp.setEntity(new InputStreamEntity(bais, -1));
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

        }

        HttpResponse response = null;

        if (request instanceof HttpEntityEnclosingRequest) {
            HttpEntityEnclosingRequest eeRequest = (HttpEntityEnclosingRequest) request;
           
            if (eeRequest.expectContinue()) {
                response = this.responseFactory.newHttpResponse(
                        ver,
                        HttpStatus.SC_CONTINUE,
                        context);
                response.setParams(
                        new DefaultedHttpParams(response.getParams(), this.params));
                if (this.expectationVerifier != null) {
                    try {
                        this.expectationVerifier.verify(request, response, context);
                    } catch (HttpException ex) {
                        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0,
                                HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
                        response.setParams(
                                new DefaultedHttpParams(response.getParams(), this.params));
                        handleException(ex, response);
                    }
                }
           
                if (response.getStatusLine().getStatusCode() < 200) {
                   
                    // Send 1xx response indicating the server expections
                    // have been met
                    synchronized (connState) {
                        connState.setResponse(response);
                        conn.requestOutput();
                       
                        // Block until 1xx response is sent to the client
                        try {
                            for (;;) {
                                int currentState = connState.getOutputState();
                                if (currentState == ServerConnState.RESPONSE_SENT) {
                                    break;
                                }
                                if (currentState == ServerConnState.SHUTDOWN) {
                                    return;
                                }
                                connState.wait();
                            }
                        } catch (InterruptedException ex) {
                            connState.shutdown();
                            return;
                        }
                        connState.resetOutput();
                        response = null;
                    }
                } else {
                    // Discard request entity
                    conn.resetInput();
                    eeRequest.setEntity(null);
                }

            }

            // Create a wrapper entity instead of the original one
            if (eeRequest.getEntity() != null) {
                eeRequest.setEntity(new ContentBufferEntity(
                        eeRequest.getEntity(),
                        connState.getInbuffer()));
            }
           
        }
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

            try {
                connState.reset();

                if (request instanceof HttpEntityEnclosingRequest) {
                   
                    HttpEntityEnclosingRequest eeRequest = (HttpEntityEnclosingRequest) request;
                    if (eeRequest.expectContinue()) {
                        HttpResponse ack = this.responseFactory.newHttpResponse(
                                ver, 100, context);
                        conn.submitResponse(ack);
                    }
                    // Wait until the request content is fully received
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

            HttpRequest request = conn.getHttpRequest();
            request.setParams(
                    new DefaultedHttpParams(request.getParams(), this.params));

            if (request instanceof HttpEntityEnclosingRequest) {
                HttpEntityEnclosingRequest eeRequest = (HttpEntityEnclosingRequest) request;
                Header h = request.getFirstHeader(HTTP.CONTENT_TYPE);
                String contentType = null;
                if (h != null) {
                    contentType = h.getValue();
                }
                HttpNIOEntity entity = new FileNIOEntity(connState.getInputFile(), contentType);
                eeRequest.setEntity(entity);
            }
           
            ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
            HttpResponse response =  this.responseFactory.newHttpResponse(ver, 200, context);
            response.setParams(
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

            if (decoder.isCompleted()) {
                // Request entity has been fully received
                connState.setInputState(ServerConnState.REQUEST_BODY_DONE);

                // Create a wrapper entity instead of the original one
                HttpEntityEnclosingRequest entityReq = (HttpEntityEnclosingRequest) request;
                if (entityReq.getEntity() != null) {
                    entityReq.setEntity(new ContentBufferEntity(
                            entityReq.getEntity(),
                            connState.getInbuffer()));
                }
                conn.suspendInput();
                processRequest(conn, request);
            }
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

        HttpResponse response = null;
        context.setAttribute(HttpExecutionContext.HTTP_REQ_SENT, Boolean.FALSE);

        conn.sendRequestHeader(request);
        if (request instanceof HttpEntityEnclosingRequest) {
            HttpEntityEnclosingRequest entityEnclRequest =
                (HttpEntityEnclosingRequest) request;

            // Check for expect-continue handshake. We have to flush the
            // headers and wait for an 100-continue response to handle it.
            // If we get a different response, we must not send the entity.
            boolean sendentity = true;
            final HttpVersion ver = request.getRequestLine().getHttpVersion();
            if (entityEnclRequest.expectContinue() &&
                ver.greaterEquals(HttpVersion.HTTP_1_1)) {

                conn.flush();
                // As suggested by RFC 2616 section 8.2.3, we don't wait for a
                // 100-continue response forever. On timeout, send the entity.
View Full Code Here

Examples of org.apache.http.HttpEntityEnclosingRequest

      }
      pw.println("BODY: (below)");
      pw.flush();//done with pw now

      if (request instanceof HttpEntityEnclosingRequest) {
        HttpEntityEnclosingRequest enclosingRequest = (HttpEntityEnclosingRequest) request;
        HttpEntity entity = enclosingRequest.getEntity();
        byte[] body = EntityUtils.toByteArray(entity);
        baos.write(body);
      }

      response.setStatusCode(200);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.