当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponseInterceptor类代码示例

本文整理汇总了Java中org.apache.http.HttpResponseInterceptor的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseInterceptor类的具体用法?Java HttpResponseInterceptor怎么用?Java HttpResponseInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpResponseInterceptor类属于org.apache.http包,在下文中一共展示了HttpResponseInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHttpClient

import org.apache.http.HttpResponseInterceptor; //导入依赖的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: setupClient

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
/**
 * This method is used to capture Location headers after HttpClient redirect handling.
 */
private void setupClient(final AbstractHttpClient client) {
	this.client.addResponseInterceptor(new HttpResponseInterceptor() {
		@Override
		public void process(final HttpResponse response, final HttpContext context)
				throws HttpException, IOException {
			Header header = response.getFirstHeader("Location");
			if (header!=null) {
				String location = header.getValue();

				/*
				 * Append the base name to the Location header
				 */
				if (location.startsWith("/")) {
					String baseUrl = context.getAttribute(ExecutionContext.HTTP_TARGET_HOST).toString();
					location = baseUrl + location;
				}
				context.setAttribute("Location", location);
			}
		}
	});
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:25,代码来源:MechanizeAgent.java

示例3: testContentEncodingRequestParameter

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void testContentEncodingRequestParameter() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    final StringEntity original = new StringEntity("encoded stuff");
    original.setContentEncoding("GZip");
    response.setEntity(original);

    final RequestConfig config = RequestConfig.custom()
            .setDecompressionEnabled(false)
            .build();

    final HttpContext context = new BasicHttpContext();
    context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);

    final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
    interceptor.process(response, context);
    final HttpEntity entity = response.getEntity();
    Assert.assertNotNull(entity);
    Assert.assertFalse(entity instanceof GzipDecompressingEntity);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestResponseContentEncoding.java

示例4: testParseCookies

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void testParseCookies() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    response.addHeader(SM.SET_COOKIE, "name1=value1");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
    context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);

    final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
    interceptor.process(response, context);

    final List<Cookie> cookies = this.cookieStore.getCookies();
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());
    final Cookie cookie = cookies.get(0);
    Assert.assertEquals(0, cookie.getVersion());
    Assert.assertEquals("name1", cookie.getName());
    Assert.assertEquals("value1", cookie.getValue());
    Assert.assertEquals("localhost", cookie.getDomain());
    Assert.assertEquals("/", cookie.getPath());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestResponseProcessCookies.java

示例5: testNoCookieOrigin

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void testNoCookieOrigin() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    response.addHeader(SM.SET_COOKIE, "name1=value1");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.COOKIE_ORIGIN, null);
    context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);

    final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
    interceptor.process(response, context);

    final List<Cookie> cookies = this.cookieStore.getCookies();
    Assert.assertNotNull(cookies);
    Assert.assertEquals(0, cookies.size());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestResponseProcessCookies.java

示例6: testNoCookieSpec

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void testNoCookieSpec() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    response.addHeader(SM.SET_COOKIE, "name1=value1");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
    context.setAttribute(HttpClientContext.COOKIE_SPEC, null);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);

    final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
    interceptor.process(response, context);

    final List<Cookie> cookies = this.cookieStore.getCookies();
    Assert.assertNotNull(cookies);
    Assert.assertEquals(0, cookies.size());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestResponseProcessCookies.java

示例7: testNoCookieStore

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void testNoCookieStore() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    response.addHeader(SM.SET_COOKIE, "name1=value1");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
    context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
    context.setAttribute(HttpClientContext.COOKIE_STORE, null);

    final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
    interceptor.process(response, context);

    final List<Cookie> cookies = this.cookieStore.getCookies();
    Assert.assertNotNull(cookies);
    Assert.assertEquals(0, cookies.size());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestResponseProcessCookies.java

示例8: testSetCookie2OverrideSetCookie

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void testSetCookie2OverrideSetCookie() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    response.addHeader(SM.SET_COOKIE, "name1=value1");
    response.addHeader(SM.SET_COOKIE2, "name1=value2; Version=1");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
    context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);

    final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
    interceptor.process(response, context);

    final List<Cookie> cookies = this.cookieStore.getCookies();
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.size());
    final Cookie cookie = cookies.get(0);
    Assert.assertEquals(1, cookie.getVersion());
    Assert.assertEquals("name1", cookie.getName());
    Assert.assertEquals("value2", cookie.getValue());
    Assert.assertEquals("localhost.local", cookie.getDomain());
    Assert.assertEquals("/", cookie.getPath());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:25,代码来源:TestResponseProcessCookies.java

示例9: testInvalidHeader

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void testInvalidHeader() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    response.addHeader(SM.SET_COOKIE2, "name=value; Version=crap");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
    context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);

    final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
    interceptor.process(response, context);

    final List<Cookie> cookies = this.cookieStore.getCookies();
    Assert.assertNotNull(cookies);
    Assert.assertTrue(cookies.isEmpty());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestResponseProcessCookies.java

示例10: testCookieRejected

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void testCookieRejected() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    response.addHeader(SM.SET_COOKIE2, "name=value; Domain=www.somedomain.com; Version=1");

    final HttpClientContext context = HttpClientContext.create();
    context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
    context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
    context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);

    final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
    interceptor.process(response, context);

    final List<Cookie> cookies = this.cookieStore.getCookies();
    Assert.assertNotNull(cookies);
    Assert.assertTrue(cookies.isEmpty());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestResponseProcessCookies.java

示例11: RequestListenerThread

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
public RequestListenerThread(int port, final String docroot) throws IOException {
    this.serversocket = new ServerSocket(port);
    this.params = new SyncBasicHttpParams();
    this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[]{
        new ResponseDate(),
        new ResponseServer(),
        new ResponseContent(),
        new ResponseConnControl()
    });

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new HttpFileHandler());

    // Set up the HTTP service
    this.httpService = new HttpService(
            httpproc,
            new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory(),
            reqistry,
            this.params);
}
 
开发者ID:Torridity,项目名称:dsworkbench,代码行数:26,代码来源:ReportServer.java

示例12: RequestListenerThread

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
/**
 * Default constructor which specifies the <code>port</code> to listen to
 * for requests and the <code>handlers</code>, which specify how to handle
 * the request.
 * 
 * @param port
 *            the port to listen to
 * @param handlers
 *            the handlers, which specify how to handle the different
 *            requests
 * 
 * @throws IOException
 *             if some IO operation fails
 */
public RequestListenerThread(final int port,
		final Map<String, IHandler> handlers) throws IOException {
	super(port);

	// Set up the HTTP protocol processor
	final HttpProcessor httpproc = new ImmutableHttpProcessor(
			new HttpResponseInterceptor[] { new ResponseDate(),
					new ResponseServer(), new ResponseContent(),
					new ResponseConnControl() });

	// Set up request handlers
	UriHttpRequestHandlerMapper registry = new UriHttpRequestHandlerMapper();
	for (final Entry<String, IHandler> entry : handlers.entrySet()) {
		registry.register(entry.getKey(), entry.getValue());
	}

	// Set up the HTTP service
	httpService = new HttpService(httpproc, registry);
	connFactory = DefaultBHttpServerConnectionFactory.INSTANCE;
}
 
开发者ID:pmeisen,项目名称:gen-server-http-listener,代码行数:35,代码来源:RequestListenerThread.java

示例13: getGzipResponseInterceptor

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
/**
 * From apache examples
 *
 * @return
 *
 * @see <a
 * href="http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientGZipContentCompression.java">Apache
 * examples</a>
 */
private HttpResponseInterceptor getGzipResponseInterceptor() {
    return new HttpResponseInterceptor() {

        public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                Header ceheader = entity.getContentEncoding();
                if (ceheader != null) {
                    HeaderElement[] codecs = ceheader.getElements();
                    for (int i = 0; i < codecs.length; i++) {
                        if (codecs[i].getName().equalsIgnoreCase("gzip")) {
                            response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                            return;
                        }
                    }
                }
            }
        }
    };
}
 
开发者ID:antew,项目名称:RedditInPictures,代码行数:30,代码来源:RESTService.java

示例14: interceptResponse

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
/**
 * Tests if we can manipulate a response
 * @throws Exception if anything goes wrong
 */
@Test
public void interceptResponse() throws Exception {
    final AtomicBoolean interceptorCalled = new AtomicBoolean(false);

    Download t = makeProjectAndTask();
    t.src(makeSrc(INTERCEPTOR));
    File dst = folder.newFile();
    t.dest(dst);
    t.responseInterceptor(new HttpResponseInterceptor() {
        @Override
        public void process(HttpResponse response, HttpContext context)
                throws HttpException, IOException {
            assertFalse(interceptorCalled.get());
            interceptorCalled.set(true);
            response.setEntity(new StringEntity(INTERCEPTED));
        }
    });
    t.execute();
    
    assertTrue(interceptorCalled.get());
    
    String dstContents = FileUtils.readFileToString(dst);
    assertEquals(INTERCEPTED, dstContents);
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:29,代码来源:InterceptorTest.java

示例15: downloadingFiles

import org.apache.http.HttpResponseInterceptor; //导入依赖的package包/类
@Test
public void downloadingFiles() throws Exception {
  ProxyServer bmp = new ProxyServer(8071);
  bmp.start();

  HttpResponseInterceptor downloader = new FileDownloader()
      .addContentType("application/pdf");
  bmp.addResponseInterceptor(downloader);

  DesiredCapabilities caps = new DesiredCapabilities();
  caps.setCapability(CapabilityType.PROXY, bmp.seleniumProxy());

  WebDriver driver = new FirefoxDriver(caps);

  driver.get("http://localhost/test_download.html");
  driver.findElement(By.tagName("a")).click();

  String fileName = driver.findElement(By.tagName("body")).getText();
  assertTrue(new File(fileName).exists());

  Thread.sleep(30000);

  driver.quit();

  bmp.stop();
}
 
开发者ID:barancev,项目名称:selen-confetqa-2013,代码行数:27,代码来源:Sample8_DownloadingFiles.java


注:本文中的org.apache.http.HttpResponseInterceptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。