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


Java HttpRequestInterceptor類代碼示例

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


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

示例1: getHttpClient

import org.apache.http.HttpRequestInterceptor; //導入依賴的package包/類
private CloseableHttpClient getHttpClient() {
    int timeout = 10000;
    RequestConfig config = RequestConfig.custom()
        .setConnectTimeout(timeout)
        .setConnectionRequestTimeout(timeout)
        .setSocketTimeout(timeout)
        .build();

    return HttpClientBuilder
        .create()
        .useSystemProperties()
        .addInterceptorFirst(new OutboundRequestIdSettingInterceptor())
        .addInterceptorFirst((HttpRequestInterceptor) new OutboundRequestLoggingInterceptor())
        .addInterceptorLast((HttpResponseInterceptor) new OutboundRequestLoggingInterceptor())
        .setDefaultRequestConfig(config)
        .build();
}
 
開發者ID:hmcts,項目名稱:cmc-claim-store,代碼行數:18,代碼來源:HttpClientConfiguration.java

示例2: ProxyClient

import org.apache.http.HttpRequestInterceptor; //導入依賴的package包/類
public ProxyClient(final HttpParams params) {
    super();
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
            new RequestContent(),
            new RequestTargetHost(),
            new RequestClientConnControl(),
            new RequestUserAgent(),
            new RequestProxyAuthentication()
    } );
    this.requestExec = new HttpRequestExecutor();
    this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
    this.authenticator = new HttpAuthenticator();
    this.proxyAuthState = new AuthState();
    this.authSchemeRegistry = new AuthSchemeRegistry();
    this.authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
    this.authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
    this.reuseStrategy = new DefaultConnectionReuseStrategy();
    this.params = params;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:ProxyClient.java

示例3: _getApacheKissHttpClientBuilder

import org.apache.http.HttpRequestInterceptor; //導入依賴的package包/類
private static HttpClientBuilder _getApacheKissHttpClientBuilder() {

        return HttpClients.custom()
                .addInterceptorFirst(new RequestDefaultHeaders())
                .addInterceptorFirst(new RequestContent())
                .addInterceptorFirst(new RequestTargetHost())
                .addInterceptorFirst(new RequestClientConnControl())
                .addInterceptorFirst(new RequestAddCookies())
                .addInterceptorFirst(new ResponseProcessCookies())
                .addInterceptorFirst(new RequestAuthCache())
                .addInterceptorLast(new HttpRequestInterceptor() {

                    @Override
                    public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {

                        if (request.containsHeader("User-Agent")) {

                            request.removeHeaders("User-Agent");

                        }

                        if (request.containsHeader("Custom-User-Agent")) {

                            request.addHeader("User-Agent", request.getFirstHeader("Custom-User-Agent").getValue());

                            request.removeHeaders("Custom-User-Agent");
                        }
                    }

                });
    }
 
開發者ID:tonikelope,項目名稱:megabasterd,代碼行數:32,代碼來源:MiscTools.java

示例4: testPreemptiveTargetAndProxyAuth

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

示例5: testCredentialsProviderNotSet

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

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.CREDS_PROVIDER, null);
    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,代碼行數:25,代碼來源:TestRequestAuthCache.java

示例6: testAuthCacheNotSet

import org.apache.http.HttpRequestInterceptor; //導入依賴的package包/類
@Test
public void testAuthCacheNotSet() 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);
    context.setAttribute(HttpClientContext.AUTH_CACHE, null);

    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,代碼行數:20,代碼來源:TestRequestAuthCache.java

示例7: testAuthCacheEmpty

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

示例8: testNoMatchingCredentials

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

示例9: testCookiesForConnectRequest

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

示例10: testNoCookieStore

import org.apache.http.HttpRequestInterceptor; //導入依賴的package包/類
@Test
public void testNoCookieStore() 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, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, null);
    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

示例11: testNoCookieSpecRegistry

import org.apache.http.HttpRequestInterceptor; //導入依賴的package包/類
@Test
public void testNoCookieSpecRegistry() 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, this.target);
    context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
    context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, null);

    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

示例12: testNoTargetHost

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

示例13: testNoHttpConnection

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

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
    context.setAttribute(HttpCoreContext.HTTP_CONNECTION, null);
    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,代碼行數:21,代碼來源:TestRequestAddCookies.java

示例14: testAddCookiesUsingExplicitCookieSpec

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

示例15: testAuthScopeRemotePortWhenDirect

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

    this.target = new HttpHost("localhost.local");
    final HttpRoute route = new HttpRoute(new HttpHost("localhost.local", 1234), 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 CookieOrigin cookieOrigin = context.getCookieOrigin();
    Assert.assertNotNull(cookieOrigin);
    Assert.assertEquals(this.target.getHostName(), cookieOrigin.getHost());
    Assert.assertEquals(1234, cookieOrigin.getPort());
    Assert.assertEquals("/stuff", cookieOrigin.getPath());
    Assert.assertFalse(cookieOrigin.isSecure());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:24,代碼來源:TestRequestAddCookies.java


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