本文整理汇总了Java中org.apache.http.HttpRequestInterceptor.process方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestInterceptor.process方法的具体用法?Java HttpRequestInterceptor.process怎么用?Java HttpRequestInterceptor.process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HttpRequestInterceptor
的用法示例。
在下文中一共展示了HttpRequestInterceptor.process方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAuthDefaultHttpPortWhenProxy
import org.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(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(80, cookieOrigin.getPort());
Assert.assertEquals("/stuff", cookieOrigin.getPath());
Assert.assertFalse(cookieOrigin.isSecure());
}
示例2: testPreserveCustomProxyConnectionHeader
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
@Test
public void testPreserveCustomProxyConnectionHeader() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
request.addHeader("Proxy-Connection", HTTP.CONN_CLOSE);
final HttpClientContext context = HttpClientContext.create();
final HttpHost target = new HttpHost("localhost", 80, "http");
final HttpHost proxy = new HttpHost("localhost", 8080);
final HttpRoute route = new HttpRoute(target, null, proxy, false,
TunnelType.PLAIN, LayerType.PLAIN);
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
final HttpRequestInterceptor interceptor = new RequestClientConnControl();
interceptor.process(request, context);
final Header header1 = request.getFirstHeader("Proxy-Connection");
Assert.assertNotNull(header1);
Assert.assertEquals(HTTP.CONN_CLOSE, header1.getValue());
}
示例3: 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());
}
示例4: 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);
}
示例5: 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);
}
示例6: testProxyConnectionKeepAliveForRequestsOverProxy
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
@Test
public void testProxyConnectionKeepAliveForRequestsOverProxy() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
final HttpClientContext context = HttpClientContext.create();
final HttpHost target = new HttpHost("localhost", 80, "http");
final HttpHost proxy = new HttpHost("localhost", 8080);
final HttpRoute route = new HttpRoute(target, null, proxy, false,
TunnelType.PLAIN, LayerType.PLAIN);
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
final HttpRequestInterceptor interceptor = new RequestClientConnControl();
interceptor.process(request, context);
final Header header1 = request.getFirstHeader("Proxy-Connection");
Assert.assertNotNull(header1);
Assert.assertEquals(HTTP.CONN_KEEP_ALIVE, header1.getValue());
final Header header2 = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
Assert.assertNull(header2);
}
示例7: 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());
}
示例8: process
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
String baseUrl = (String) context.getAttribute(BASE_URL);
String layerId = (String) context.getAttribute(LAYER_ID);
try {
if (interceptors != null && baseUrl != null) {
for (Entry<String, List<HttpRequestInterceptor>> entry : interceptors.getMap().entrySet()) {
String key = entry.getKey();
if ("".equals(key) || (layerId != null && layerId.equals(key)) || baseUrl.startsWith(key)) {
for (HttpRequestInterceptor inter : entry.getValue()) {
inter.process(request, context);
}
}
}
}
} catch (Exception e) {
log.warn("Error processing interceptors: " + e.getMessage());
}
}
示例9: process
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
public void process(
final HttpRequest request,
final HttpContext context)
throws IOException, HttpException {
for (int i = 0; i < this.requestInterceptors.size(); i++) {
HttpRequestInterceptor interceptor =
this.requestInterceptors.get(i);
interceptor.process(request, context);
}
}
示例10: process
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
public void process(
final HttpRequest request,
final HttpContext context) throws IOException, HttpException {
for (final HttpRequestInterceptor requestInterceptor : this.requestInterceptors) {
requestInterceptor.process(request, context);
}
}
示例11: testAcceptEncoding
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
@Test
public void testAcceptEncoding() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
final HttpContext context = new BasicHttpContext();
final HttpRequestInterceptor interceptor = new RequestAcceptEncoding();
interceptor.process(request, context);
final Header header = request.getFirstHeader("Accept-Encoding");
Assert.assertNotNull(header);
Assert.assertEquals("gzip,deflate", header.getValue());
}
示例12: testCookieOrder
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
@Test
// Test for ordering adapted from test in Commons HC 3.1
public void testCookieOrder() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/foobar/yada/yada");
this.cookieStore.clear();
cookieStore.addCookie(makeCookie("nomatch", "value", "localhost.local", "/noway"));
cookieStore.addCookie(makeCookie("name2", "value", "localhost.local", "/foobar/yada"));
cookieStore.addCookie(makeCookie("name3", "value", "localhost.local", "/foobar"));
cookieStore.addCookie(makeCookie("name1", "value", "localhost.local", "/foobar/yada/yada"));
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(1, headers1.length);
Assert.assertEquals("name1=value; name2=value; name3=value", headers1[0].getValue());
}
示例13: testConnectionKeepAliveForConnectRequest
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
@Test
public void testConnectionKeepAliveForConnectRequest() throws Exception {
final HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");
final HttpClientContext context = HttpClientContext.create();
final HttpRequestInterceptor interceptor = new RequestClientConnControl();
interceptor.process(request, context);
final Header header1 = request.getFirstHeader("Proxy-Connection");
Assert.assertNotNull(header1);
Assert.assertEquals(HTTP.CONN_KEEP_ALIVE, header1.getValue());
final Header header2 = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
Assert.assertNull(header2);
}
示例14: testAuthSchemeAlreadySet
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
@Test
public void testAuthSchemeAlreadySet() 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);
this.targetState.setState(AuthProtocolState.CHALLENGED);
this.targetState.update(new BasicScheme(), new UsernamePasswordCredentials("user3", "secret3"));
this.proxyState.setState(AuthProtocolState.CHALLENGED);
this.proxyState.update(new BasicScheme(), new UsernamePasswordCredentials("user4", "secret4"));
final HttpRequestInterceptor interceptor = new RequestAuthCache();
interceptor.process(request, context);
Assert.assertNotSame(this.authscheme1, this.targetState.getAuthScheme());
Assert.assertNotSame(this.creds1, this.targetState.getCredentials());
Assert.assertNotSame(this.authscheme2, this.proxyState.getAuthScheme());
Assert.assertNotSame(this.creds2, this.proxyState.getCredentials());
}
示例15: testNoDefaultHeadersForConnectRequest
import org.apache.http.HttpRequestInterceptor; //导入方法依赖的package包/类
@Test
public void testNoDefaultHeadersForConnectRequest() throws Exception {
final HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");
final List<Header> defheaders = new ArrayList<Header>();
defheaders.add(new BasicHeader("custom", "stuff"));
final HttpContext context = new BasicHttpContext();
final HttpRequestInterceptor interceptor = new RequestDefaultHeaders(defheaders);
interceptor.process(request, context);
final Header header1 = request.getFirstHeader("custom");
Assert.assertNull(header1);
}