本文整理汇总了Java中com.epam.reportportal.apache.http.HttpRequestInterceptor类的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestInterceptor类的具体用法?Java HttpRequestInterceptor怎么用?Java HttpRequestInterceptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRequestInterceptor类属于com.epam.reportportal.apache.http包,在下文中一共展示了HttpRequestInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDefaultBuilder
import com.epam.reportportal.apache.http.HttpRequestInterceptor; //导入依赖的package包/类
/**
* Initializes default http client builder instance
*
* @return
*/
protected HttpClientBuilder initDefaultBuilder() {
HttpClientBuilder builder = HttpClientBuilder.create();
if (null != credentials) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentials);
builder.setDefaultCredentialsProvider(credentialsProvider);
}
builder.setMaxConnPerRoute(5);
builder.setMaxConnTotal(20);
// dirty hack to avoid npe in soapui client, soapui client sets default
// proxy selector to null
ProxySelector proxySelector = ProxySelector.getDefault();
if (proxySelector != null)
builder.setRoutePlanner(new SystemDefaultRoutePlanner(proxySelector));
if (null != interceptors && !interceptors.isEmpty()) {
for (HttpRequestInterceptor interceptor : interceptors) {
builder.addInterceptorFirst(interceptor);
}
}
return builder;
}
示例2: testPreemptiveTargetAndProxyAuth
import com.epam.reportportal.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(HttpClientContext.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.assertSame(this.authscheme1, this.targetState.getAuthScheme());
Assert.assertSame(this.creds1, this.targetState.getCredentials());
Assert.assertSame(this.authscheme2, this.proxyState.getAuthScheme());
Assert.assertSame(this.creds2, this.proxyState.getCredentials());
}
示例3: testCredentialsProviderNotSet
import com.epam.reportportal.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(HttpClientContext.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());
}
示例4: testAuthCacheNotSet
import com.epam.reportportal.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(HttpClientContext.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());
}
示例5: testAuthCacheEmpty
import com.epam.reportportal.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(HttpClientContext.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());
}
示例6: testNoMatchingCredentials
import com.epam.reportportal.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(HttpClientContext.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());
}
示例7: testCookiesForConnectRequest
import com.epam.reportportal.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(HttpClientContext.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);
}
示例8: testNoCookieStore
import com.epam.reportportal.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(HttpClientContext.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);
}
示例9: testNoCookieSpecRegistry
import com.epam.reportportal.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(HttpClientContext.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);
}
示例10: testNoTargetHost
import com.epam.reportportal.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(HttpClientContext.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);
}
示例11: testNoHttpConnection
import com.epam.reportportal.apache.http.HttpRequestInterceptor; //导入依赖的package包/类
@Test
public void testNoHttpConnection() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.HTTP_TARGET_HOST, this.target);
context.setAttribute(HttpClientContext.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);
}
示例12: testAddCookiesUsingExplicitCookieSpec
import com.epam.reportportal.apache.http.HttpRequestInterceptor; //导入依赖的package包/类
@Test
public void testAddCookiesUsingExplicitCookieSpec() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
final RequestConfig config = RequestConfig.custom()
.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
final HttpRoute route = new HttpRoute(this.target, null, false);
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.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 BrowserCompatSpec);
final Header[] headers1 = request.getHeaders(SM.COOKIE);
Assert.assertNotNull(headers1);
Assert.assertEquals(1, headers1.length);
Assert.assertEquals("name1=value1; name2=value2", headers1[0].getValue());
}
示例13: testAuthScopeRemotePortWhenDirect
import com.epam.reportportal.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(HttpClientContext.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());
}
示例14: testAuthDefaultHttpPortWhenProxy
import com.epam.reportportal.apache.http.HttpRequestInterceptor; //导入依赖的package包/类
@Test
public void testAuthDefaultHttpPortWhenProxy() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/stuff");
this.target = new HttpHost("localhost.local");
final HttpRoute route = new HttpRoute(
new HttpHost("localhost.local", 80), null, new HttpHost("localhost", 8888), false);
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.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(80, cookieOrigin.getPort());
Assert.assertEquals("/stuff", cookieOrigin.getPath());
Assert.assertFalse(cookieOrigin.isSecure());
}
示例15: testAuthDefaultHttpsPortWhenProxy
import com.epam.reportportal.apache.http.HttpRequestInterceptor; //导入依赖的package包/类
@Test
public void testAuthDefaultHttpsPortWhenProxy() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/stuff");
this.target = new HttpHost("localhost", -1, "https");
final HttpRoute route = new HttpRoute(
new HttpHost("localhost", 443, "https"), null,
new HttpHost("localhost", 8888), true, TunnelType.TUNNELLED, LayerType.LAYERED);
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.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(443, cookieOrigin.getPort());
Assert.assertEquals("/stuff", cookieOrigin.getPath());
Assert.assertTrue(cookieOrigin.isSecure());
}