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


Java BasicHttpRequest類代碼示例

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


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

示例1: newHttpRequest

import org.apache.http.message.BasicHttpRequest; //導入依賴的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

示例2: logsRequestAndResponseFields

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void logsRequestAndResponseFields() {
    HttpContext context = new BasicHttpContext();
    context.setAttribute(HTTP_TARGET_HOST, "http://www.google.com");

    OutboundRequestLoggingInterceptor interceptor = new OutboundRequestLoggingInterceptor(new FakeClock(20));

    interceptor.process(new BasicHttpRequest("GET", "/something"), context);
    interceptor.process(new BasicHttpResponse(new BasicStatusLine(ANY_PROTOCOL, 200, "any")), context);

    Map<String, Object> fields = new ConcurrentHashMap<>();
    fields.put("requestMethod", "GET");
    fields.put("requestURI", "http://www.google.com/something");
    testAppender.assertEvent(0, INFO, "Outbound request start", appendEntries(fields));

    fields.put("responseTime", 20L);
    fields.put("responseCode", 200);
    testAppender.assertEvent(1, INFO, "Outbound request finish", appendEntries(fields));
}
 
開發者ID:hmcts,項目名稱:java-logging,代碼行數:20,代碼來源:OutboundRequestLoggingInterceptorTest.java

示例3: allowEmptyConstructorToBuildDefaultClock

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void allowEmptyConstructorToBuildDefaultClock() {
    testAppender.clearEvents();

    HttpContext context = new BasicHttpContext();
    context.setAttribute(HTTP_TARGET_HOST, "http://www.google.com");

    OutboundRequestLoggingInterceptor interceptor = new OutboundRequestLoggingInterceptor();

    interceptor.process(new BasicHttpRequest("GET", "/something"), context);
    interceptor.process(new BasicHttpResponse(new BasicStatusLine(ANY_PROTOCOL, 200, "any")), context);

    assertThat(testAppender.getEvents()).extracting("message")
        .contains("Outbound request start", Index.atIndex(0))
        .contains("Outbound request finish", Index.atIndex(1));
}
 
開發者ID:hmcts,項目名稱:java-logging,代碼行數:17,代碼來源:OutboundRequestLoggingInterceptorTest.java

示例4: testDigestAuthenticationWithQueryStringInDigestURI

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testDigestAuthenticationWithQueryStringInDigestURI() throws Exception {
    final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
    final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
    final HttpRequest request = new BasicHttpRequest("Simple", "/?param=value");
    final Credentials cred = new UsernamePasswordCredentials("username","password");
    final HttpContext context = new BasicHttpContext();
    final DigestScheme authscheme = new DigestScheme();
    authscheme.processChallenge(authChallenge);
    final Header authResponse = authscheme.authenticate(cred, request, context);

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

示例5: submitRequest

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
public HttpRequest submitRequest(final HttpContext context) {
    HttpHost targetHost = (HttpHost) context.getAttribute(
            ExecutionContext.HTTP_TARGET_HOST);
    Object flag = context.getAttribute(REQUEST_SENT);
    if (flag == null) {
        // Stick some object into the context
        context.setAttribute(REQUEST_SENT, Boolean.TRUE);

        System.out.println("--------------");
        System.out.println("Sending request to " + targetHost);
        System.out.println("--------------");
        
        return new BasicHttpRequest("GET", "/");
    } else {
        // No new request to submit
        return null;
    }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:19,代碼來源:NHttpClient.java

示例6: testAuthCacheEmpty

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testAuthCacheEmpty() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
    context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);

    final AuthCache authCache = new BasicAuthCache();
    context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);

    final HttpRequestInterceptor interceptor = new RequestAuthCache();
    interceptor.process(request, context);
    Assert.assertNull(this.targetState.getAuthScheme());
    Assert.assertNull(this.targetState.getCredentials());
    Assert.assertNull(this.proxyState.getAuthScheme());
    Assert.assertNull(this.proxyState.getCredentials());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:22,代碼來源:TestRequestAuthCache.java

示例7: testAddCookiesUsingExplicitCookieSpec

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testAddCookiesUsingExplicitCookieSpec() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");
    final RequestConfig config = RequestConfig.custom()
        .setCookieSpec(CookieSpecs.NETSCAPE).build();
    final HttpRoute route = new HttpRoute(this.target, null, false);

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

    final HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);

    final CookieSpec cookieSpec = context.getCookieSpec();
    Assert.assertTrue(cookieSpec instanceof NetscapeDraftSpec);

    final Header[] headers1 = request.getHeaders(SM.COOKIE);
    Assert.assertNotNull(headers1);
    Assert.assertEquals(1, headers1.length);
    Assert.assertEquals("name1=value1; name2=value2", headers1[0].getValue());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:26,代碼來源:TestRequestAddCookies.java

示例8: testExpiresHeaderMatchesDateIfAddedToCacheHit

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testExpiresHeaderMatchesDateIfAddedToCacheHit() throws Exception {
    final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
    final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));

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

    backendExpectsAnyRequest().andReturn(originResponse);

    replayMocks();
    impl.execute(route, req1, context, null);
    final HttpResponse result = impl.execute(route, req2, context, null);
    verifyMocks();

    final Header expHdr = result.getFirstHeader("Expires");
    if (expHdr != null) {
        Assert.assertEquals(result.getFirstHeader("Date").getValue(),
                            expHdr.getValue());
    }
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:TestProtocolRequirements.java

示例9: testNoTargetHost

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testNoTargetHost() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpRoute route = new HttpRoute(this.target, null, false);

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, null);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

    final HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);

    final Header[] headers1 = request.getHeaders(SM.COOKIE);
    Assert.assertNotNull(headers1);
    Assert.assertEquals(0, headers1.length);
    final Header[] headers2 = request.getHeaders(SM.COOKIE2);
    Assert.assertNotNull(headers2);
    Assert.assertEquals(0, headers2.length);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:23,代碼來源:TestRequestAddCookies.java

示例10: testMayReturnStaleResponseIfClientExplicitlySpecifiesAcceptableMaxStale

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testMayReturnStaleResponseIfClientExplicitlySpecifiesAcceptableMaxStale()
        throws Exception {
    final HttpRequestWrapper req1 = requestToPopulateStaleCacheEntry();
    final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
    req2.setHeader("Cache-Control","max-stale=20");

    backendExpectsAnyRequest().andThrow(new IOException()).times(0,1);

    replayMocks();
    impl.execute(route, req1, context, null);
    final HttpResponse result = impl.execute(route, req2, context, null);
    verifyMocks();

    assertEquals(HttpStatus.SC_OK, result.getStatusLine().getStatusCode());
    assertNotNull(result.getFirstHeader("Warning"));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:19,代碼來源:TestProtocolRecommendations.java

示例11: testPreemptiveTargetAndProxyAuth

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testPreemptiveTargetAndProxyAuth() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
    context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);

    final AuthCache authCache = new BasicAuthCache();
    authCache.put(this.target, this.authscheme1);
    authCache.put(this.proxy, this.authscheme2);

    context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);

    final HttpRequestInterceptor interceptor = new RequestAuthCache();
    interceptor.process(request, context);
    Assert.assertNotNull(this.targetState.getAuthScheme());
    Assert.assertSame(this.creds1, this.targetState.getCredentials());
    Assert.assertNotNull(this.proxyState.getAuthScheme());
    Assert.assertSame(this.creds2, this.proxyState.getCredentials());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:25,代碼來源:TestRequestAuthCache.java

示例12: testNoCacheCannotSatisfyASubsequentRequestWithoutRevalidationEvenWithContraryIndications

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testNoCacheCannotSatisfyASubsequentRequestWithoutRevalidationEvenWithContraryIndications()
throws Exception {
    final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
    final HttpResponse resp1 = HttpTestUtils.make200Response();
    resp1.setHeader("ETag","\"etag\"");
    resp1.setHeader("Cache-Control","no-cache,s-maxage=3600");

    backendExpectsAnyRequestAndReturn(resp1);

    final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
    req2.setHeader("Cache-Control","max-stale=7200");
    final HttpResponse resp2 = HttpTestUtils.make200Response();

    // this MUST happen
    backendExpectsAnyRequestAndReturn(resp2);

    replayMocks();
    impl.execute(route, req1, context, null);
    impl.execute(route, req2, context, null);
    verifyMocks();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:25,代碼來源:TestProtocolRequirements.java

示例13: testCacheControlPrivateIsNotCacheableBySharedCache

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testCacheControlPrivateIsNotCacheableBySharedCache()
throws Exception {
   if (config.isSharedCache()) {
           final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(
                   new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
           final HttpResponse resp1 = HttpTestUtils.make200Response();
           resp1.setHeader("Cache-Control","private,max-age=3600");

           backendExpectsAnyRequestAndReturn(resp1);

           final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
                   new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
           final HttpResponse resp2 = HttpTestUtils.make200Response();
           // this backend request MUST happen
           backendExpectsAnyRequestAndReturn(resp2);

           replayMocks();
           impl.execute(route, req1, context, null);
           impl.execute(route, req2, context, null);
           verifyMocks();
   }
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:TestProtocolRequirements.java

示例14: testCookiesForConnectRequest

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testCookiesForConnectRequest() throws Exception {
    final HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");

    final HttpRoute route = new HttpRoute(this.target, null, false);

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

    final HttpRequestInterceptor interceptor = new RequestAddCookies();
    interceptor.process(request, context);

    final Header[] headers1 = request.getHeaders(SM.COOKIE);
    Assert.assertNotNull(headers1);
    Assert.assertEquals(0, headers1.length);
    final Header[] headers2 = request.getHeaders(SM.COOKIE2);
    Assert.assertNotNull(headers2);
    Assert.assertEquals(0, headers2.length);
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:23,代碼來源:TestRequestAddCookies.java

示例15: testNoMatchingCredentials

import org.apache.http.message.BasicHttpRequest; //導入依賴的package包/類
@Test
public void testNoMatchingCredentials() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", "/");

    this.credProvider.clear();

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
    context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
    context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);

    final AuthCache authCache = new BasicAuthCache();
    authCache.put(this.target, this.authscheme1);
    authCache.put(this.proxy, this.authscheme2);

    context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);

    final HttpRequestInterceptor interceptor = new RequestAuthCache();
    interceptor.process(request, context);
    Assert.assertNull(this.targetState.getAuthScheme());
    Assert.assertNull(this.targetState.getCredentials());
    Assert.assertNull(this.proxyState.getAuthScheme());
    Assert.assertNull(this.proxyState.getCredentials());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:27,代碼來源:TestRequestAuthCache.java


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