Package org.apache.http

Examples of org.apache.http.HttpEntityEnclosingRequest


        verifyMocks();
    }

    @Test
    public void testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs() throws Exception {
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
        request.setEntity(HttpTestUtils.makeBody(128));
        request.setHeader("Content-Length","128");

        final String relativePath = "/content";
        request.setHeader("Content-Location",relativePath);

        final String theUri = "http://foo.example.com:80/";
        cacheEntryHasVariantMap(new HashMap<String,String>());

        cacheReturnsEntryForUri(theUri);
View Full Code Here


        verifyMocks();
    }

    @Test
    public void testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts() throws Exception {
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
        request.setEntity(HttpTestUtils.makeBody(128));
        request.setHeader("Content-Length","128");

        final String contentLocation = "http://bar.example.com/content";
        request.setHeader("Content-Location",contentLocation);

        final String theUri = "http://foo.example.com:80/";
        cacheEntryHasVariantMap(new HashMap<String,String>());

        cacheReturnsEntryForUri(theUri);
View Full Code Here

        assertTrue(closed.set || bais.read() == -1);
    }

    @Test
    public void consumesBodyOf100ContinueResponseIfItArrives() throws Exception {
        final HttpEntityEnclosingRequest req = new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
        final int nbytes = 128;
        req.setHeader("Content-Length","" + nbytes);
        req.setHeader("Content-Type", "application/octet-stream");
        final HttpEntity postBody = new ByteArrayEntity(HttpTestUtils.getRandomBytes(nbytes));
        req.setEntity(postBody);
        final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);

        final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_CONTINUE, "Continue");
        final Flag closed = new Flag();
        final ByteArrayInputStream bais = makeTrackableBody(nbytes, closed);
View Full Code Here

        verifyMocks();

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

    }

    @Test
    public void testDoesNotModifyContentLengthOnRequests()
            throws Exception {
        final HttpEntityEnclosingRequest post =
            new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
        post.setEntity(HttpTestUtils.makeBody(128));
        post.setHeader("Content-Length","128");
        request = HttpRequestWrapper.wrap(post);
        testDoesNotModifyHeaderOnRequests("Content-Length");
    }
View Full Code Here

    }

    @Test
    public void testDoesNotModifyContentMD5OnRequests()
            throws Exception {
        final HttpEntityEnclosingRequest post =
            new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
        post.setEntity(HttpTestUtils.makeBody(128));
        post.setHeader("Content-Length","128");
        post.setHeader("Content-MD5","Q2hlY2sgSW50ZWdyaXR5IQ==");
        request = HttpRequestWrapper.wrap(post);
        testDoesNotModifyHeaderOnRequests("Content-MD5");
    }
View Full Code Here

    }

    @Test
    public void testDoesNotModifyContentRangeOnRequests()
            throws Exception {
        final HttpEntityEnclosingRequest put =
            new BasicHttpEntityEnclosingRequest("PUT", "/", HttpVersion.HTTP_1_1);
        put.setEntity(HttpTestUtils.makeBody(128));
        put.setHeader("Content-Length","128");
        put.setHeader("Content-Range","bytes 0-127/256");
        request = HttpRequestWrapper.wrap(put);
        testDoesNotModifyHeaderOnRequests("Content-Range");
    }
View Full Code Here

    }

    @Test
    public void testDoesNotModifyContentTypeOnRequests()
            throws Exception {
        final HttpEntityEnclosingRequest post =
            new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
        post.setEntity(HttpTestUtils.makeBody(128));
        post.setHeader("Content-Length","128");
        post.setHeader("Content-Type","application/octet-stream");
        request = HttpRequestWrapper.wrap(post);
        testDoesNotModifyHeaderOnRequests("Content-Type");
    }
View Full Code Here

    /**
     * Create and return a new HttpPost request to the destination EPR
     * @return the HttpRequest to be sent out
     */
    public HttpRequest getRequest() throws IOException {
        HttpEntityEnclosingRequest httpRequest = new BasicHttpEntityEnclosingRequest(
                "POST",
                epr.getAddress());       
        httpRequest.setEntity(new BasicHttpEntity());

        // set any transport headers
        Object o = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
        if (o != null && o instanceof Map) {
            Map headers = (Map) o;
            Iterator iter = headers.keySet().iterator();
            while (iter.hasNext()) {
                Object header = iter.next();
                Object value = headers.get(header);
                if (header instanceof String && value != null && value instanceof String) {
                    httpRequest.setHeader((String) header, (String) value);
                }
            }
        }

        // if the message is SOAP 11 (for which a SOAPAction is *required*), and
        // the msg context has a SOAPAction or a WSA-Action (give pref to SOAPAction)
        // use that over any transport header that may be available
        String soapAction = msgContext.getSoapAction();
        if (soapAction == null) {
            soapAction = msgContext.getWSAAction();
        }
        if (soapAction == null) {
            msgContext.getAxisOperation().getSoapAction();
        }

        if (msgContext.isSOAP11() && soapAction != null &&
            soapAction.length() > 0) {
            Header existingHeader =
                httpRequest.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION);
            if (existingHeader != null) {
                httpRequest.removeHeader(existingHeader);
            }
            httpRequest.setHeader(HTTPConstants.HEADER_SOAP_ACTION,
                soapAction);
        }


        httpRequest.setHeader(
            HTTP.CONTENT_TYPE,
            messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction()));

        return httpRequest;
    }
View Full Code Here

          this.httpRequest.addHeader(headerName, headerValue);
        }
      }
    }
    if (this.httpRequest instanceof HttpEntityEnclosingRequest) {
      HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest;
      HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput);
      entityEnclosingRequest.setEntity(requestEntity);
    }
    HttpResponse httpResponse = this.httpClient.execute(this.httpRequest, this.httpContext);
    return new HttpComponentsClientHttpResponse(httpResponse);
  }
View Full Code Here

TOP

Related Classes of org.apache.http.HttpEntityEnclosingRequest

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.