• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DefaultServiceUnavailableRetryStrategy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setUp

import org.apache.http.impl.client.DefaultServiceUnavailableRetryStrategy; //导入依赖的package包/类
@Before
    public void setUp() throws Exception {

        this.client = HttpClients.custom()
                .setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(3, 2000))
                .setDefaultRequestConfig(RequestConfig.custom()
                        .setSocketTimeout(10000)
                        .setConnectTimeout(10000)
                        .setConnectionRequestTimeout(10000)
                        .build()).build();
        this.om = new ObjectMapper();
        this.wsClient = ClientManager.createClient();
        wsClient.getProperties().put(ClientProperties.HANDSHAKE_TIMEOUT, 10000);        
            if (System.getProperty(TRAVIS_ENV) != null) {
                System.out.println("waiting for Travis machine");
                waitUrlAvailable(String.format("http://%s:%d/api?name=foo", LOCALHOST, PORT));
//                Thread.sleep(1); // Ugly sleep to debug travis            
            }
    }
 
开发者ID:LivePersonInc,项目名称:dropwizard-websockets,代码行数:20,代码来源:DropWizardWebsocketsTest.java


示例2: getHttpClientBuilder

import org.apache.http.impl.client.DefaultServiceUnavailableRetryStrategy; //导入依赖的package包/类
public static HttpClientBuilder getHttpClientBuilder(final String charset, String proxyIp,
        int proxyPort) {

    HttpClientBuilder builder = HttpClients.custom();

    Charset chartset = charset == null ? Charset.forName(CHARSET_UTF8)
            : Charset.forName(charset);
    ConnectionConfig.Builder connBuilder = ConnectionConfig.custom().setCharset(chartset);

    RequestConfig.Builder reqBuilder = RequestConfig.custom();
    reqBuilder.setExpectContinueEnabled(false);
    reqBuilder.setSocketTimeout(10 * 60 * 1000);
    reqBuilder.setConnectTimeout(10 * 60 * 1000);
    reqBuilder.setMaxRedirects(10);

    if (StringUtils.isNotBlank(proxyIp) && proxyPort > 0) {
        logger.info("using proxy {}:{} to request ", proxyIp, String.valueOf(proxyPort));
        HttpHost proxy = new HttpHost(proxyIp, proxyPort);
        reqBuilder.setProxy(proxy);
    }

    ServiceUnavailableRetryStrategy serviceUnavailableRetryStrategy = new DefaultServiceUnavailableRetryStrategy(
            3, 3000);
    builder.setServiceUnavailableRetryStrategy(serviceUnavailableRetryStrategy);
    // 模拟浏览器,解决一些服务器程序只允许浏览器访问的问题
    builder.setUserAgent(
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");

    builder.setDefaultRequestConfig(reqBuilder.build());
    builder.setDefaultConnectionConfig(connBuilder.build());
    builder.setConnectionManager(getConnectionManager());

    // HostnameVerifier allowAllHostnameVerifier =
    // NoopHostnameVerifier.INSTANCE;
    // builder.setSSLHostnameVerifier(allowAllHostnameVerifier);

    return builder;

}
 
开发者ID:jiucai,项目名称:appframework,代码行数:40,代码来源:HttpClientUtil.java


示例3: start

import org.apache.http.impl.client.DefaultServiceUnavailableRetryStrategy; //导入依赖的package包/类
public void start() {
	Runnable thread = new Runnable() {

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Thread#run()
		 */
		@Override
		public void run() {
			Tracker tracker = new Tracker(getUser(), getHostName(),
					getIp(), getOs(), System.currentTimeMillis(), getInitiator());

			AutoRetryHttpClient client = new AutoRetryHttpClient(
					new DefaultServiceUnavailableRetryStrategy(3, 3000));
			HttpPost request = createRequest(tracker);
			HttpHost httpHost = createHttpHost();

			try {
				HttpResponse resp = client.execute(httpHost, request);
				int code = resp.getStatusLine().getStatusCode();
				if (HttpResponseStatus.OK.code() == code) {
					InputStream is = null;
					try {
						is = resp.getEntity().getContent();
						is = new BufferedInputStream(is);
						InputStreamReader reader = new InputStreamReader(is);
						JsonStreamParser parser = new JsonStreamParser(
								reader);
						while (parser.hasNext()) {
							JsonElement json = parser.next();
							LOGGER.debug("Tracking data sent: " + json);
						}
					} finally {
						if (is != null) {
							is.close();
						}
					}

				} else {
					LOGGER.error(ERROR_FAILED_TO_SEND);
					LOGGER.debug("Response code: " + code);
				}
			} catch (IOException e) {
				LOGGER.warn(ERROR_FAILED_TO_SEND);
			}
		}

	};

	m_scheduledService.scheduleAtFixedRate(thread, 0, m_interval,
			TimeUnit.SECONDS);
}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:54,代码来源:TrackerClient.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IJIComObject类代码示例发布时间:2022-05-23
下一篇:
Java LexerGrammar类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap