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

Java AsyncHttpClientConfig类代码示例

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

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



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

示例1: createConfig

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
/**
 * 生成默认的httpclient config
 *
 * @return the config
 */
public static AsyncHttpClientConfig createConfig(int connectTimeout, int requestTimeout) {
    HashedWheelTimer timer = new HashedWheelTimer();
    timer.start();
    DefaultChannelPool channelPool = new DefaultChannelPool(60000,
            -1,
            DefaultChannelPool.PoolLeaseStrategy.LIFO,
            timer,
            3000);

    return new DefaultAsyncHttpClientConfig.Builder()
            .setConnectTimeout(connectTimeout)
            .setRequestTimeout(requestTimeout)
            .setMaxConnectionsPerHost(10000)
            .setValidateResponseHeaders(false)
            .setMaxRequestRetry(0)
            .setChannelPool(channelPool)
            .build();
}
 
开发者ID:darren-fu,项目名称:RestyPass,代码行数:24,代码来源:AsyncHttpConfigFactory.java


示例2: TimeoutsHolder

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
public TimeoutsHolder(Timer nettyTimer, NettyResponseFuture<?> nettyResponseFuture, NettyRequestSender requestSender, AsyncHttpClientConfig config) {
    this.nettyTimer = nettyTimer;
    this.nettyResponseFuture = nettyResponseFuture;
    this.requestSender = requestSender;
    this.readTimeoutValue = config.getReadTimeout();

    int requestTimeoutInMs = nettyResponseFuture.getTargetRequest().getRequestTimeout();
    if (requestTimeoutInMs == 0) {
        requestTimeoutInMs = config.getRequestTimeout();
    }

    if (requestTimeoutInMs != -1) {
        requestTimeoutMillisTime = millisTime() + requestTimeoutInMs;
        requestTimeout = newTimeout(new RequestTimeoutTimerTask(nettyResponseFuture, requestSender, this, requestTimeoutInMs), requestTimeoutInMs);
    } else {
        requestTimeoutMillisTime = -1L;
        requestTimeout = null;
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:20,代码来源:TimeoutsHolder.java


示例3: negativeContentTypeTest

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
@Test(groups = "standalone")
public void negativeContentTypeTest() throws Exception {

    AsyncHttpClientConfig config = config()//
            .setConnectTimeout(100)//
            .setMaxConnections(50)//
            .setRequestTimeout(5 * 60 * 1000) // 5 minutes
            .build();

    try (AsyncHttpClient client = asyncHttpClient(config)) {
        RequestBuilder requestBuilder = post(getTargetUrl())//
                .setHeader("Content-Type", "message/rfc822")//
                .setBody(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())));

        Future<Response> future = client.executeRequest(requestBuilder.build());

        System.out.println("waiting for response");
        Response response = future.get();
        assertEquals(response.getStatusCode(), 200);
        assertEquals(response.getResponseBody(), MY_MESSAGE);
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:23,代码来源:BodyChunkTest.java


示例4: DRPCQueryResultPubscriber

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
/**
 * Create an instance from a given {@link BulletConfig}. Requires {@link DRPCConfig#DRPC_HTTP_CONNECT_TIMEOUT_MS},
 * {@link DRPCConfig#DRPC_HTTP_CONNECT_RETRY_LIMIT}, {@link DRPCConfig#DRPC_SERVERS}, {@link DRPCConfig#DRPC_HTTP_PORT},
 * and {@link DRPCConfig#DRPC_HTTP_PATH} to be set. To be used in PubSub.Context#QUERY_SUBMISSION mode.
 *
 * @param config A non-null config that contains the required settings.
 */
public DRPCQueryResultPubscriber(BulletConfig config) {
    Objects.requireNonNull(config);

    Number connectTimeout = config.getRequiredConfigAs(DRPCConfig.DRPC_HTTP_CONNECT_TIMEOUT_MS, Number.class);
    Number retryLimit = config.getRequiredConfigAs(DRPCConfig.DRPC_HTTP_CONNECT_RETRY_LIMIT, Number.class);
    List<String> servers = (List<String>) config.getRequiredConfigAs(DRPCConfig.DRPC_SERVERS, List.class);
    String protocol = config.getRequiredConfigAs(DRPCConfig.DRPC_HTTP_PROTOCOL, String.class);
    String port = config.getRequiredConfigAs(DRPCConfig.DRPC_HTTP_PORT, String.class);
    String path = config.getRequiredConfigAs(DRPCConfig.DRPC_HTTP_PATH, String.class);
    String function = config.getRequiredConfigAs(DRPCConfig.DRPC_FUNCTION, String.class);

    List<String> endpoints = servers.stream()
                                    .map(url -> String.format(URL_TEMPLATE, protocol, url, port, path, function))
                                    .collect(Collectors.toList());
    this.urls = new RandomPool<>(endpoints);
    AsyncHttpClientConfig clientConfig = new DefaultAsyncHttpClientConfig.Builder()
                                                .setConnectTimeout(connectTimeout.intValue())
                                                .setMaxRequestRetry(retryLimit.intValue())
                                                .setReadTimeout(NO_TIMEOUT)
                                                .setRequestTimeout(NO_TIMEOUT)
                                                .build();
    // This is thread safe
    client = new DefaultAsyncHttpClient(clientConfig);
    responses = new ConcurrentLinkedQueue<>();
}
 
开发者ID:yahoo,项目名称:bullet-storm,代码行数:33,代码来源:DRPCQueryResultPubscriber.java


示例5: initializeWebClient

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
/**
 * Initialize the client config.
 *
 * @param requestTimeout  Timeout to use for the client configuration.
 *
 * @return the set up client
 */
private static AsyncHttpClient initializeWebClient(int requestTimeout) {

    LOG.debug("Druid request timeout: {}ms", requestTimeout);

    // Build the configuration
    AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder()
            .setReadTimeout(requestTimeout)
            .setRequestTimeout(requestTimeout)
            .setConnectTimeout(requestTimeout)
            .setConnectionTtl(requestTimeout)
            .setPooledConnectionIdleTimeout(requestTimeout)
            .setFollowRedirect(true)
            .build();

    return new DefaultAsyncHttpClient(config);
}
 
开发者ID:yahoo,项目名称:fili,代码行数:24,代码来源:AsyncDruidWebServiceImpl.java


示例6: testAcceptWebSocket

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
@Test
public void testAcceptWebSocket() {
    TestServer server = testServer(19001);
    running(server, () -> {
        try {
            AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder().setMaxRequestRetry(0).build();
            AsyncHttpClient client = new DefaultAsyncHttpClient(config);
            WebSocketClient webSocketClient = new WebSocketClient(client);

            try {
                String serverURL = "ws://localhost:19001/ws";
                WebSocketClient.LoggingListener listener = new WebSocketClient.LoggingListener();
                CompletableFuture<WebSocket> completionStage = webSocketClient.call(serverURL, listener);

                await().until(() -> {
                    assertThat(completionStage).isDone();
                });
            } finally {
                //noinspection ThrowFromFinallyBlock
                client.close();
            }
        } catch (Exception e) {
            fail("Unexpected exception", e);
        }
    });
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:27,代码来源:FunctionalTest.java


示例7: initContextForService

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
/**
 * 为service创建Resty配置
 *
 * @param serviceClz the service clz
 */
public void initContextForService(Class serviceClz) {
    RestyService restyService = (RestyService) serviceClz.getDeclaredAnnotation(RestyService.class);
    if (restyService == null) {
        return;
    }
    String serviceName = restyService.serviceName();

    // class->@RestyService
    this.storeRestyService(serviceClz, restyService);
    AsyncHttpClientConfig httpClientConfig = AsyncHttpConfigFactory.createConfig(restyService.connectTimeout(), restyService.requestTimeout());
    HttpClientWrapper clientHolder = new HttpClientWrapper(httpClientConfig);
    httpClientPool.putIfAbsent(serviceName, clientHolder);


    SpringAnnotationWrapper wrapper = new SpringAnnotationWrapper();

    RestyCommandConfig commandProperties = new RestyCommandConfig.DefaultRestyCommandConfig();
    processRestyServiceAnnotation(restyService, commandProperties);


    for (Method method : serviceClz.getMethods()) {
        //存储 httpMethod 和 restyCommandConfig
        RestyMethod restyMethod = method.getDeclaredAnnotation(RestyMethod.class);
        if (restyMethod != null) {
            storeRestyMethod(method, restyMethod);
            processRestyMethodAnnotation(restyMethod, commandProperties);
        }
        commandPropertiesMap.putIfAbsent(method, commandProperties);

        // 存储 httpMethod 和 requestTemplate
        RestyRequestTemplate restyRequestTemplate = wrapper.processAnnotation(serviceClz, method);
        requestTemplateMap.putIfAbsent(method, restyRequestTemplate);

        serviceMethodTable.put(serviceName, restyRequestTemplate.getPath(), method);
    }
    log.info("RestyCommandContext初始化成功!");
}
 
开发者ID:darren-fu,项目名称:RestyPass,代码行数:43,代码来源:RestyCommandContext.java


示例8: newBootstrap

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
private Bootstrap newBootstrap(Class<? extends Channel> socketChannelClass, EventLoopGroup eventLoopGroup, AsyncHttpClientConfig config) {
    @SuppressWarnings("deprecation")
    Bootstrap bootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup)//
            // default to PooledByteBufAllocator
            .option(ChannelOption.ALLOCATOR, config.isUsePooledMemory() ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT)//
            .option(ChannelOption.TCP_NODELAY, config.isTcpNoDelay())//
            .option(ChannelOption.SO_REUSEADDR, config.isSoReuseAddress())//
            .option(ChannelOption.AUTO_CLOSE, false);

    if (config.getConnectTimeout() > 0) {
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout());
    }

    if (config.getSoLinger() >= 0) {
        bootstrap.option(ChannelOption.SO_LINGER, config.getSoLinger());
    }

    if (config.getSoSndBuf() >= 0) {
        bootstrap.option(ChannelOption.SO_SNDBUF, config.getSoSndBuf());
    }

    if (config.getSoRcvBuf() >= 0) {
        bootstrap.option(ChannelOption.SO_RCVBUF, config.getSoRcvBuf());
    }

    for (Entry<ChannelOption<Object>, Object> entry : config.getChannelOptions().entrySet()) {
        bootstrap.option(entry.getKey(), entry.getValue());
    }

    return bootstrap;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:32,代码来源:ChannelManager.java


示例9: NettyFileBody

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
public NettyFileBody(File file, long offset, long length, AsyncHttpClientConfig config) {
    if (!file.isFile()) {
        throw new IllegalArgumentException(String.format("File %s is not a file or doesn't exist", file.getAbsolutePath()));
    }
    this.file = file;
    this.offset = offset;
    this.length = length;
    this.config = config;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:10,代码来源:NettyFileBody.java


示例10: NettyChannelConnector

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
public NettyChannelConnector(InetAddress localAddress,//
        List<InetSocketAddress> remoteAddresses,//
        AsyncHandler<?> asyncHandler,//
        TimeoutsHolder timeoutsHolder,//
        AtomicBoolean closed,//
        AsyncHttpClientConfig config) {
    this.localAddress = localAddress != null ? new InetSocketAddress(localAddress, 0) : null;
    this.remoteAddresses = remoteAddresses;
    this.asyncHandlerExtensions = toAsyncHandlerExtensions(asyncHandler);
    this.timeoutsHolder = assertNotNull(timeoutsHolder, "timeoutsHolder");
    this.closed = closed;
    this.connectionTtlEnabled = config.getConnectionTtl() > 0;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:14,代码来源:NettyChannelConnector.java


示例11: NettyRequestSender

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
public NettyRequestSender(AsyncHttpClientConfig config,//
        ChannelManager channelManager,//
        Timer nettyTimer,//
        AtomicBoolean closed) {
    this.config = config;
    this.channelManager = channelManager;
    this.nettyTimer = nettyTimer;
    this.closed = closed;
    requestFactory = new NettyRequestFactory(config);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:11,代码来源:NettyRequestSender.java


示例12: NettyResponseStatus

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
public NettyResponseStatus(Uri uri, AsyncHttpClientConfig config, HttpResponse response, Channel channel) {
    super(uri, config);
    this.response = response;
    if (channel != null) {
        remoteAddress = channel.remoteAddress();
        localAddress = channel.localAddress();
    } else {
        remoteAddress = null;
        localAddress = null;
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:12,代码来源:NettyResponseStatus.java


示例13: Interceptors

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
public Interceptors(//
        AsyncHttpClientConfig config,//
        ChannelManager channelManager,//
        NettyRequestSender requestSender) {
    this.config = config;
    unauthorized401Interceptor = new Unauthorized401Interceptor(channelManager, requestSender);
    proxyUnauthorized407Interceptor = new ProxyUnauthorized407Interceptor(channelManager, requestSender);
    continue100Interceptor = new Continue100Interceptor(requestSender);
    redirect30xInterceptor = new Redirect30xInterceptor(channelManager, config, requestSender);
    connectSuccessInterceptor = new ConnectSuccessInterceptor(channelManager, requestSender);
    responseFiltersInterceptor = new ResponseFiltersInterceptor(config, requestSender);
    hasResponseFilters = !config.getResponseFilters().isEmpty();
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:14,代码来源:Interceptors.java


示例14: AsyncHttpClientHandler

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
public AsyncHttpClientHandler(AsyncHttpClientConfig config,//
        ChannelManager channelManager,//
        NettyRequestSender requestSender) {
    this.config = config;
    this.channelManager = channelManager;
    this.requestSender = requestSender;
    interceptors = new Interceptors(config, channelManager, requestSender);
    hasIOExceptionFilters = !config.getIoExceptionFilters().isEmpty();
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:10,代码来源:AsyncHttpClientHandler.java


示例15: configureSslEngine

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
protected void configureSslEngine(SSLEngine sslEngine, AsyncHttpClientConfig config) {
    sslEngine.setUseClientMode(true);
    if (!config.isAcceptAnyCertificate()) {
        SSLParameters params = sslEngine.getSSLParameters();
        params.setEndpointIdentificationAlgorithm("HTTPS");
        sslEngine.setSSLParameters(params);
    }

    if (isNonEmpty(config.getEnabledProtocols()))
        sslEngine.setEnabledProtocols(config.getEnabledProtocols());

    if (isNonEmpty(config.getEnabledCipherSuites()))
        sslEngine.setEnabledCipherSuites(config.getEnabledCipherSuites());
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:15,代码来源:SslEngineFactoryBase.java


示例16: getSslContext

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
private SslContext getSslContext(AsyncHttpClientConfig config) throws SSLException {
    if (config.getSslContext() != null)
        return config.getSslContext();

    SslContextBuilder sslContextBuilder = SslContextBuilder.forClient()//
            .sslProvider(config.isUseOpenSsl() ? SslProvider.OPENSSL : SslProvider.JDK)//
            .sessionCacheSize(config.getSslSessionCacheSize())//
            .sessionTimeout(config.getSslSessionTimeout());

    if (config.isAcceptAnyCertificate())
        sslContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE);

    return sslContextBuilder.build();
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:15,代码来源:DefaultSslEngineFactory.java


示例17: newSslEngine

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
@Override
public SSLEngine newSslEngine(AsyncHttpClientConfig config, String peerHost, int peerPort) {
    // FIXME should be using ctx allocator
    SSLEngine sslEngine = sslContext.newEngine(ByteBufAllocator.DEFAULT, peerHost, peerPort);
    configureSslEngine(sslEngine, config);
    return sslEngine;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:8,代码来源:DefaultSslEngineFactory.java


示例18: getProxyServer

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
/**
 * @param config the global config
 * @param request the request
 * @return the proxy server to be used for this request (can be null)
 */
public static ProxyServer getProxyServer(AsyncHttpClientConfig config, Request request) {
    ProxyServer proxyServer = request.getProxyServer();
    if (proxyServer == null) {
        ProxyServerSelector selector = config.getProxyServerSelector();
        if (selector != null) {
            proxyServer = selector.select(request.getUri());
        }
    }
    return proxyServer != null && !proxyServer.isIgnoredForHost(request.getUri().getHost()) ? proxyServer : null;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:16,代码来源:ProxyUtils.java


示例19: testRetryNonBlocking

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
/**
 * Tests that a head request can be made
 * 
 * @throws IOException
 * @throws ExecutionException
 * @throws InterruptedException
 */
@Test(groups = "standalone")
public void testRetryNonBlocking() throws IOException, InterruptedException, ExecutionException {

    AsyncHttpClientConfig config = config()//
            .setKeepAlive(true)//
            .setMaxConnections(100)//
            .setConnectTimeout(60000)//
            .setRequestTimeout(30000)//
            .build();

    try (AsyncHttpClient client = asyncHttpClient(config)) {
        List<ListenableFuture<Response>> res = new ArrayList<>();
        for (int i = 0; i < 32; i++) {
            res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString()));
        }

        StringBuilder b = new StringBuilder();
        for (ListenableFuture<Response> r : res) {
            Response theres = r.get();
            assertEquals(200, theres.getStatusCode());
            b.append("==============\r\n");
            b.append("Response Headers\r\n");
            HttpHeaders heads = theres.getHeaders();
            b.append(heads + "\r\n");
            b.append("==============\r\n");
        }
        System.out.println(b.toString());
        System.out.flush();
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:38,代码来源:RetryNonBlockingIssue.java


示例20: testRetryNonBlockingAsyncConnect

import org.asynchttpclient.AsyncHttpClientConfig; //导入依赖的package包/类
@Test(groups = "standalone")
public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, ExecutionException {

    AsyncHttpClientConfig config = config()//
            .setKeepAlive(true)//
            .setMaxConnections(100)//
            .setConnectTimeout(60000)//
            .setRequestTimeout(30000)//
            .build();

    try (AsyncHttpClient client = asyncHttpClient(config)) {
        List<ListenableFuture<Response>> res = new ArrayList<>();
        for (int i = 0; i < 32; i++) {
            res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString()));
        }

        StringBuilder b = new StringBuilder();
        for (ListenableFuture<Response> r : res) {
            Response theres = r.get();
            assertEquals(theres.getStatusCode(), 200);
            b.append("==============\r\n");
            b.append("Response Headers\r\n");
            HttpHeaders heads = theres.getHeaders();
            b.append(heads + "\r\n");
            b.append("==============\r\n");
        }
        System.out.println(b.toString());
        System.out.flush();
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:31,代码来源:RetryNonBlockingIssue.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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