當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicHttpEntityEnclosingRequest類代碼示例

本文整理匯總了Java中org.apache.http.message.BasicHttpEntityEnclosingRequest的典型用法代碼示例。如果您正苦於以下問題:Java BasicHttpEntityEnclosingRequest類的具體用法?Java BasicHttpEntityEnclosingRequest怎麽用?Java BasicHttpEntityEnclosingRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BasicHttpEntityEnclosingRequest類屬於org.apache.http.message包,在下文中一共展示了BasicHttpEntityEnclosingRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSimpleSigner

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testSimpleSigner() throws Exception {
    HttpEntityEnclosingRequest request =
            new BasicHttpEntityEnclosingRequest("GET", "/query?a=b");
    request.setEntity(new StringEntity("I'm an entity"));
    request.addHeader("foo", "bar");
    request.addHeader("content-length", "0");

    HttpCoreContext context = new HttpCoreContext();
    context.setTargetHost(HttpHost.create("localhost"));

    createInterceptor().process(request, context);

    assertEquals("bar", request.getFirstHeader("foo").getValue());
    assertEquals("wuzzle", request.getFirstHeader("Signature").getValue());
    assertNull(request.getFirstHeader("content-length"));
}
 
開發者ID:awslabs,項目名稱:aws-request-signing-apache-interceptor,代碼行數:18,代碼來源:AWSRequestSigningApacheInterceptorTest.java

示例2: testEncodedUriSigner

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testEncodedUriSigner() throws Exception {
    HttpEntityEnclosingRequest request =
            new BasicHttpEntityEnclosingRequest("GET", "/foo-2017-02-25%2Cfoo-2017-02-26/_search?a=b");
    request.setEntity(new StringEntity("I'm an entity"));
    request.addHeader("foo", "bar");
    request.addHeader("content-length", "0");

    HttpCoreContext context = new HttpCoreContext();
    context.setTargetHost(HttpHost.create("localhost"));

    createInterceptor().process(request, context);

    assertEquals("bar", request.getFirstHeader("foo").getValue());
    assertEquals("wuzzle", request.getFirstHeader("Signature").getValue());
    assertNull(request.getFirstHeader("content-length"));
    assertEquals("/foo-2017-02-25%2Cfoo-2017-02-26/_search", request.getFirstHeader("resourcePath").getValue());
}
 
開發者ID:awslabs,項目名稱:aws-request-signing-apache-interceptor,代碼行數:19,代碼來源:AWSRequestSigningApacheInterceptorTest.java

示例3: newHttpRequest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
public HttpRequest newHttpRequest(final RequestLine requestline)
        throws MethodNotSupportedException {
    if (requestline == null) {
        throw new IllegalArgumentException("Request line may not be null");
    }
    String method = requestline.getMethod();
    if (isOneOf(RFC2616_COMMON_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
        return new BasicHttpEntityEnclosingRequest(requestline);
    } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
        return new BasicHttpRequest(requestline);
    } else {
        throw new MethodNotSupportedException(method +  " method not supported");
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:DefaultHttpRequestFactory.java

示例4: getHostNameAndPort

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
public static String[] getHostNameAndPort(String hostName, int port, SessionId session) {
    String[] hostAndPort = new String[2];
    String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: \n";

    try {
        HttpHost host = new HttpHost(hostName, port);
        CloseableHttpClient client = HttpClients.createSystem();
        URL sessionURL = new URL("http://" + hostName + ":" + port + "/grid/api/testsession?session=" + session);
        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());
        HttpResponse response = client.execute(host, r);
        String url = extractUrlFromResponse(response);
        if (url != null) {
            URL myURL = new URL(url);
            if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
                hostAndPort[0] = myURL.getHost();
                hostAndPort[1] = Integer.toString(myURL.getPort());
            }
        }
    } catch (Exception e) {
        Logger.getLogger(GridInfoExtractor.class.getName()).log(Level.SEVERE, null, errorMsg + e);
    }
    return hostAndPort;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:24,代碼來源:GridInfoExtractor.java

示例5: consumesBodyOf100ContinueResponseIfItArrives

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@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);
    resp.setEntity(new InputStreamEntity(bais, -1));

    try {
        impl.ensureProtocolCompliance(wrapper, resp);
    } catch (final ClientProtocolException expected) {
    }
    assertTrue(closed.set || bais.read() == -1);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestResponseProtocolCompliance.java

示例6: testResponsesToPOSTWithoutCacheControlOrExpiresAreNotCached

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testResponsesToPOSTWithoutCacheControlOrExpiresAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setHeader("Content-Length", "128");
    post.setEntity(HttpTestUtils.makeBody(128));

    originResponse.removeHeaders("Cache-Control");
    originResponse.removeHeaders("Expires");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, HttpRequestWrapper.wrap(post), context, null);

    verifyMocks();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:26,代碼來源:TestProtocolRequirements.java

示例7: testResponsesToPUTsAreNotCached

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testResponsesToPUTsAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    final BasicHttpEntityEnclosingRequest put = new BasicHttpEntityEnclosingRequest("PUT", "/",
            HttpVersion.HTTP_1_1);
    put.setEntity(HttpTestUtils.makeBody(128));
    put.addHeader("Content-Length", "128");

    originResponse.setHeader("Cache-Control", "max-age=3600");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, HttpRequestWrapper.wrap(put), context, null);

    verifyMocks();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:25,代碼來源:TestProtocolRequirements.java

示例8: testDoesNotModifyHeaderOnRequest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
private void testDoesNotModifyHeaderOnRequest(final String header, final String value) throws Exception {
    final BasicHttpEntityEnclosingRequest req =
        new BasicHttpEntityEnclosingRequest("POST","/",HttpVersion.HTTP_1_1);
    req.setEntity(HttpTestUtils.makeBody(128));
    req.setHeader("Content-Length","128");
    req.setHeader(header,value);

    final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.eq(route),
                    EasyMock.capture(cap),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();
    impl.execute(route, HttpRequestWrapper.wrap(req), context, null);
    verifyMocks();

    final HttpRequest captured = cap.getValue();
    Assert.assertEquals(value, captured.getFirstHeader(header).getValue());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:TestProtocolRequirements.java

示例9: testDoesNotAddHeaderToRequestIfNotPresent

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
private void testDoesNotAddHeaderToRequestIfNotPresent(final String header) throws Exception {
    final BasicHttpEntityEnclosingRequest req =
        new BasicHttpEntityEnclosingRequest("POST","/",HttpVersion.HTTP_1_1);
    req.setEntity(HttpTestUtils.makeBody(128));
    req.setHeader("Content-Length","128");
    req.removeHeaders(header);

    final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.eq(route),
                    EasyMock.capture(cap),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();
    impl.execute(route, HttpRequestWrapper.wrap(req), context, null);
    verifyMocks();

    final HttpRequest captured = cap.getValue();
    Assert.assertNull(captured.getFirstHeader(header));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:TestProtocolRequirements.java

示例10: testInvalidatesUrisInContentLocationHeadersOnPUTs

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testInvalidatesUrisInContentLocationHeadersOnPUTs() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

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

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

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
    verify(mockStorage).removeEntry("http://foo.example.com:80/content");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestCacheInvalidator.java

示例11: testInvalidatesUrisInLocationHeadersOnPUTs

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testInvalidatesUrisInLocationHeadersOnPUTs() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

    final String contentLocation = "http://foo.example.com/content";
    putRequest.setHeader("Location",contentLocation);

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

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
    verify(mockStorage).removeEntry(cacheKeyGenerator.canonicalizeUri(contentLocation));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestCacheInvalidator.java

示例12: testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

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

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

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
    verify(mockStorage).removeEntry("http://foo.example.com:80/content");
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestCacheInvalidator.java

示例13: testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts() throws Exception {
    final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
    putRequest.setEntity(HttpTestUtils.makeBody(128));
    putRequest.setHeader("Content-Length","128");

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

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

    cacheReturnsEntryForUri(theUri);

    impl.flushInvalidatedCacheEntries(host, putRequest);

    verify(mockEntry).getVariantMap();
    verify(mockStorage).getEntry(theUri);
    verify(mockStorage).removeEntry(theUri);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:21,代碼來源:TestCacheInvalidator.java

示例14: testHTTP1_1RequestsWithBodiesOfKnownLengthMustHaveContentLength

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Ignore
public void testHTTP1_1RequestsWithBodiesOfKnownLengthMustHaveContentLength() throws Exception {
    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HTTP_1_1);
    post.setEntity(mockEntity);

    replayMocks();

    final HttpResponse response = impl.execute(route, HttpRequestWrapper.wrap(post), context, null);

    verifyMocks();

    Assert
            .assertEquals(HttpStatus.SC_LENGTH_REQUIRED, response.getStatusLine()
                    .getStatusCode());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:17,代碼來源:TestProtocolDeviations.java

示例15: testDigestAuthenticationQopAuthInt

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入依賴的package包/類
@Test
public void testDigestAuthenticationQopAuthInt() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
            "qop=\"auth,auth-int\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
    request.setEntity(new StringEntity("abc\u00e4\u00f6\u00fcabc", HTTP.DEF_CONTENT_CHARSET));
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final DigestScheme authscheme = new DigestScheme();
    final HttpContext context = new BasicHttpContext();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

    Assert.assertEquals("Post:/:acd2b59cd01c7737d8069015584c6cac", authscheme.getA2());

    final Map<String, String> table = parseAuthResponse(authResponse);
    Assert.assertEquals("username", table.get("username"));
    Assert.assertEquals("realm1", table.get("realm"));
    Assert.assertEquals("/", table.get("uri"));
    Assert.assertEquals("auth-int", table.get("qop"));
    Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:23,代碼來源:TestDigestScheme.java


注:本文中的org.apache.http.message.BasicHttpEntityEnclosingRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。