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


Java RedirectException类代码示例

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


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

示例1: testMaxRedirectCheck

import org.apache.http.client.RedirectException; //导入依赖的package包/类
@Test(expected=ClientProtocolException.class)
public void testMaxRedirectCheck() throws Exception {
    this.serverBootstrap.registerHandler("*", new CircularRedirectService());

    final HttpHost target = start();

    final RequestConfig config = RequestConfig.custom()
        .setCircularRedirectsAllowed(true)
        .setMaxRedirects(5)
        .build();

    final HttpGet httpget = new HttpGet("/circular-oldlocation/");
    httpget.setConfig(config);
    try {
        this.httpclient.execute(target, httpget);
    } catch (final ClientProtocolException e) {
        Assert.assertTrue(e.getCause() instanceof RedirectException);
        throw e;
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestRedirects.java

示例2: testMaxRedirect

import org.apache.http.client.RedirectException; //导入依赖的package包/类
@Test(expected = RedirectException.class)
public void testMaxRedirect() throws Exception {
    final HttpRoute route = new HttpRoute(target);
    final HttpGet get = new HttpGet("/test");
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(get);
    final HttpClientContext context = HttpClientContext.create();
    final RequestConfig config = RequestConfig.custom()
            .setRedirectsEnabled(true)
            .setMaxRedirects(3)
            .build();
    context.setRequestConfig(config);

    final CloseableHttpResponse response1 = Mockito.mock(CloseableHttpResponse.class);
    final HttpGet redirect = new HttpGet("http://localhost:80/redirect");

    Mockito.when(requestExecutor.execute(
            Mockito.eq(route),
            Mockito.<HttpRequestWrapper>any(),
            Mockito.<HttpClientContext>any(),
            Mockito.<HttpExecutionAware>any())).thenReturn(response1);
    Mockito.when(redirectStrategy.isRedirected(
            Mockito.<HttpRequestWrapper>any(),
            Mockito.<HttpResponse>any(),
            Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
    Mockito.when(redirectStrategy.getRedirect(
            Mockito.<HttpRequestWrapper>any(),
            Mockito.<HttpResponse>any(),
            Mockito.<HttpClientContext>any())).thenReturn(redirect);
    Mockito.when(httpRoutePlanner.determineRoute(
            Mockito.eq(target),
            Mockito.<HttpRequestWrapper>any(),
            Mockito.<HttpClientContext>any())).thenReturn(route);

    redirectExec.execute(route, request, context, execAware);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:36,代码来源:TestRedirectExec.java

示例3: testRedirectSync

import org.apache.http.client.RedirectException; //导入依赖的package包/类
@Test
public void testRedirectSync() throws Exception {
	proxy = new SimpleFixedHttpProxy();
	URI robotsURL0 = URI.create("http://foo.bar/robots.txt");
	URI robotsURL1 = URI.create("http://foo.bar/fubar/robots.txt");

	proxy.addNon200(robotsURL0, "HTTP/1.1 301 Moved Permanently\nLocation: " + robotsURL1 + "\n", "");
	proxy.add200(robotsURL1, "",
			"# goodguy can do anything\n" +
			"User-agent: goodguy\n" +
			"Disallow:\n\n" +
			"# every other guy can do nothing\n" +
			"User-agent: *\n" +
			"Disallow: /\n"
	);
	URI url = URI.create("http://foo.bar/goo/zoo.html"); // Disallowed
	proxy.add200(url, "", "Should not be crawled...");

	proxy.addNon200(URI.create("http://too.many/robots.txt"), "HTTP/1.1 301 Moved Permanently\nLocation: http://too.many/0\n", "");
	for(int i = 0; i < 5; i++) proxy.addNon200(URI.create("http://too.many/" + i), "HTTP/1.1 301 Moved Permanently\nLocation: http://too.many/" + (i + 1) + "\n", "");

	proxy.start();

	HttpClient httpClient = FetchDataTest.getHttpClient(new HttpHost("localhost", proxy.port()), true);

	FetchData fetchData = new FetchData(Helpers.getTestConfiguration(this));

	fetchData.fetch(URI.create(BURL.schemeAndAuthority(url) + "/robots.txt"), httpClient, null, null, true);
	char[][] filter = URLRespectsRobots.parseRobotsResponse(fetchData, "goodGuy");
	assertTrue(URLRespectsRobots.apply(filter, url));
	filter = URLRespectsRobots.parseRobotsResponse(fetchData, "badGuy");
	assertFalse(URLRespectsRobots.apply(filter, url));

	filter = URLRespectsRobots.parseRobotsResponse(fetchData, "goodGuy foo");
	assertTrue(URLRespectsRobots.apply(filter, url));
	filter = URLRespectsRobots.parseRobotsResponse(fetchData, "badGuy foo");
	assertFalse(URLRespectsRobots.apply(filter, url));

	fetchData = new FetchData(Helpers.getTestConfiguration(this));
	fetchData.fetch(URI.create("http://too.many/robots.txt"), httpClient, null, null, true);
	assertTrue(fetchData.exception instanceof RedirectException);

	fetchData.close();
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:45,代码来源:URLRespectsRobotsTest.java


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