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


Java HttpClient类代码示例

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


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

示例1: emmit

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
private void emmit(FlowableEmitter<Message> emitter, String roomId) throws Exception {
    SSLContext sslCtx = SSLContext.getDefault();
    SSLEngine sslEngine = sslCtx.createSSLEngine("stream.gitter.im", 443);
    sslEngine.setUseClientMode(true);

    HttpClient
            .newClient("stream.gitter.im", 443)
            .secure(sslEngine)
            .createGet("/v1/rooms/" + roomId + "/chatMessages")
            .addHeader("Authorization", "Bearer 3cd4820adf59b6a7116f99d92f68a1b786895ce7")
            .flatMap(HttpClientResponse::getContent)
            .filter(bb -> bb.capacity() > 2)
            .map(MessageEncoder::mapToMessage)
            .doOnNext(m -> System.out.println("Log Emit: " + m))
            .subscribe(emitter::onNext, emitter::onError, emitter::onComplete);
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:17,代码来源:RxGitterClient.java

示例2: create

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
public static HttpClient<ByteBuf, ByteBuf> create(String server, final String portStr) {
    int port = 0;

    try {

        URL url = new URL(defaultToHttps(server));
        if (portStr == null) {
            port = url.getDefaultPort();
        } else if (Integer.parseInt(portStr) > 0){
            port = Integer.parseInt(portStr);
        }
        final HttpClient<ByteBuf, ByteBuf> httpClient = HttpClient.newClient(new InetSocketAddress(
                url.getHost(), port));
        if(url.getProtocol().equals("https")) {
            return httpClient.unsafeSecure();
        } else if (url.getProtocol().equals("http")) {
            return httpClient;
        } else {
            throw new RuntimeException("Unsuported protocol");
        }
    }

    catch(MalformedURLException e){
        throw new RuntimeException(e);
    }
}
 
开发者ID:gradle,项目名称:ge-export,代码行数:27,代码来源:HttpClientFactory.java

示例3: newHttpClient

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
@Override
public HttpClient<ByteBuf, ByteBuf> newHttpClient(final IClientConfig config) {
    final List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = new ArrayList<>();
    listeners.add(createBearerHeaderAdder());
    final PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>> pipelineConfigurator = new PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>,
            HttpClientRequest<ByteBuf>>(new HttpClientPipelineConfigurator<ByteBuf, ByteBuf>(),
                                        new HttpObjectAggregationConfigurator(maxChunkSize));
    final LoadBalancingHttpClient<ByteBuf, ByteBuf> client = LoadBalancingHttpClient.<ByteBuf, ByteBuf>builder()
            .withClientConfig(config)
            .withExecutorListeners(listeners)
            .withRetryHandler(getDefaultHttpRetryHandlerWithConfig(config))
            .withPipelineConfigurator(pipelineConfigurator)
            .withPoolCleanerScheduler(RibbonTransport.poolCleanerScheduler)
            .build();

    return client;
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:18,代码来源:SecuredTransportFactory.java

示例4: newHttpClient

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
@Override
public HttpClient<ByteBuf, ByteBuf> newHttpClient(final IClientConfig config) {
    final List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = new ArrayList<>();
    listeners.add(createBearerHeaderAdder());
    final PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>> pipelineConfigurator = new PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>, 
            HttpClientRequest<ByteBuf>>(new HttpClientPipelineConfigurator<ByteBuf, ByteBuf>(),
            new HttpObjectAggregationConfigurator(maxChunkSize));
    final LoadBalancingHttpClient<ByteBuf, ByteBuf> client = LoadBalancingHttpClient.<ByteBuf, ByteBuf>builder()
            .withClientConfig(config)
            .withExecutorListeners(listeners)
            .withRetryHandler(getDefaultHttpRetryHandlerWithConfig(config))
            .withPipelineConfigurator(pipelineConfigurator)
            .withPoolCleanerScheduler(RibbonTransport.poolCleanerScheduler)
            .build();

    return client;
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:18,代码来源:SecuredTransportFactory.java

示例5: getResponse

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
private Observable<HttpClientResponse<ByteBuf>> getResponse(String externalHealthCheckURL) {
    String host = "localhost";
    int port = DEFAULT_APPLICATION_PORT;
    String path = "/healthcheck";
    try {
        URL url = new URL(externalHealthCheckURL);
        host = url.getHost();
        port = url.getPort();
        path = url.getPath();
    } catch (MalformedURLException e) {
        //continue
    }
    Integer timeout = DynamicProperty.getInstance("prana.host.healthcheck.timeout").getInteger(DEFAULT_CONNECTION_TIMEOUT);
    HttpClient<ByteBuf, ByteBuf> httpClient = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(host, port)
            .pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator())
            .channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout)
            .build();
    return httpClient.submit(HttpClientRequest.createGet(path));

}
 
开发者ID:Netflix,项目名称:Prana,代码行数:21,代码来源:HealthCheckHandler.java

示例6: getResponse

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
public static String getResponse(HttpClientRequest<ByteBuf> request, HttpClient<ByteBuf, ByteBuf> client) {
    return client.submit(request).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<String>>() {
        @Override
        public Observable<String> call(HttpClientResponse<ByteBuf> response) {
            return response.getContent().map(new Func1<ByteBuf, String>() {
                @Override
                public String call(ByteBuf byteBuf) {
                    return byteBuf.toString(Charset.defaultCharset());
                }
            });
        }
    }).onErrorFlatMap(new Func1<OnErrorThrowable, Observable<String>>() {
        @Override
        public Observable<String> call(OnErrorThrowable onErrorThrowable) {
            throw onErrorThrowable;
        }
    }).toBlocking().first();
}
 
开发者ID:Netflix,项目名称:Prana,代码行数:19,代码来源:TestUtils.java

示例7: testTransportFactoryWithInjection

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
@Test
public void testTransportFactoryWithInjection() {
    Injector injector = Guice.createInjector(
            new AbstractModule() {
                @Override
                protected void configure() {
                    bind(ClientConfigFactory.class).to(MyClientConfigFactory.class).in(Scopes.SINGLETON);
                    bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
                }
            }
    );

    RibbonTransportFactory transportFactory = injector.getInstance(RibbonTransportFactory.class);
    HttpClient<ByteBuf, ByteBuf> client = transportFactory.newHttpClient("myClient");
    IClientConfig config = ((LoadBalancingHttpClient) client).getClientConfig();
    assertEquals("MyConfig", config.getNameSpace());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:18,代码来源:RxMovieProxyExampleTest.java

示例8: HttpResourceObservableCommand

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
public HttpResourceObservableCommand(HttpClient<ByteBuf, ByteBuf> httpClient,
                                     HttpClientRequest<ByteBuf> httpRequest, String hystrixCacheKey,
                                     Map<String, Object> requestProperties,
                                     FallbackHandler<T> fallbackHandler,
                                     ResponseValidator<HttpClientResponse<ByteBuf>> validator,
                                     Class<? extends T> classType,
                                     HystrixObservableCommand.Setter setter) {
    super(setter);
    this.httpClient = httpClient;
    this.fallbackHandler = fallbackHandler;
    this.validator = validator;
    this.httpRequest = httpRequest;
    this.hystrixCacheKey = hystrixCacheKey;
    this.classType = classType;
    this.requestProperties = requestProperties;
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:17,代码来源:HttpResourceObservableCommand.java

示例9: RxGatewayStoreModel

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
public RxGatewayStoreModel(ConnectionPolicy connectionPolicy,
        ConsistencyLevel consistencyLevel,
        QueryCompatibilityMode queryCompatibilityMode,
        String masterKey,
        Map<String, String> resourceTokens,
        UserAgentContainer userAgentContainer,
        EndpointManager globalEndpointManager,
        HttpClient<ByteBuf, ByteBuf> httpClient) {
    this.defaultHeaders = new HashMap<String, String>();
    this.defaultHeaders.put(HttpConstants.HttpHeaders.CACHE_CONTROL,
            "no-cache");
    this.defaultHeaders.put(HttpConstants.HttpHeaders.VERSION,
            HttpConstants.Versions.CURRENT_VERSION);

    if (userAgentContainer == null) {
        userAgentContainer = new UserAgentContainer();
    }

    this.defaultHeaders.put(HttpConstants.HttpHeaders.USER_AGENT, userAgentContainer.getUserAgent());

    if (consistencyLevel != null) {
        this.defaultHeaders.put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL,
                consistencyLevel.toString());
    }

    this.globalEndpointManager = globalEndpointManager;
    this.queryCompatibilityMode = queryCompatibilityMode;

    this.httpClient = httpClient;
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:31,代码来源:RxGatewayStoreModel.java

示例10: main

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
public static void main(String[] args) {

        HttpClient.newClient("localhost", 8080)
                  .enableWireLogging("hello-client", LogLevel.ERROR)
                  .createOptions("/files")
                  .doOnNext(resp -> logger.info(resp.toString()))
                  .flatMap(resp -> resp.getContent()
                                       .map(bb -> bb.toString(Charset.defaultCharset())))
                  .toBlocking()
                  .forEach(logger::info);
	}
 
开发者ID:jerbome,项目名称:tusRx,代码行数:12,代码来源:TestClient.java

示例11: getHttpClient

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
public HttpClient<ByteBuf, ByteBuf> getHttpClient () {
    if (client == null) {
        HttpClient<ByteBuf, ByteBuf> _client = embedded ? HttpClient.newClient(getServerAddress()) :  HttpClient.newClient(new InetSocketAddress("localhost", 8080));
        client = _client;
    }
    return client;
}
 
开发者ID:jerbome,项目名称:tusRx,代码行数:8,代码来源:TestServerRule.java

示例12: initializeStream

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
private Observable<String> initializeStream() {
    HttpClient<ByteBuf, ServerSentEvent> client =
            RxNetty.createHttpClient("localhost", port, PipelineConfigurators.<ByteBuf>clientSseConfigurator());

    return client.submit(HttpClientRequest.createGet("/hello")).
            flatMap(response -> {
                printResponseHeader(response);
                return response.getContent();
            }).map(serverSentEvent -> serverSentEvent.contentAsString());
}
 
开发者ID:RxHandsOn,项目名称:MarketData,代码行数:11,代码来源:RxNettyEventEventStreamClient.java

示例13: nioTest

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
@Test
public void nioTest() throws Exception {
  HttpServer<ByteBuf, ByteBuf> server = getServer();

  TestSubscriber<String> ts = new TestSubscriber<>();

  long start = System.currentTimeMillis();

  // we use 10 since the default rxnetty thread pool size is 8
  // you could also shrink the pool down for the same effect
  // but I couldn't be bothered finding the settings
  Observable.range(1, 10)
    // flatMap runs async Observables concurrently
    .flatMap(i ->
      HttpClient.newClient(server.getServerAddress())
        .createGet("/" + i)
        .flatMap(response ->
          response.getContent()
            .map(bytes ->
              bytes.toString(Charset.defaultCharset()) + " " +
                "[response received on " + Thread.currentThread().getName() +
                " at " + (System.currentTimeMillis() - start) + "]"
            )
        )
    )
    .doOnNext(System.out::println)
    .subscribe(ts);

  ts.awaitTerminalEvent();

  server.shutdown();
}
 
开发者ID:jamesgorman2,项目名称:rxnetty-nio-test,代码行数:33,代码来源:RxJavaNioTest.java

示例14: testGET

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
@Test
public void testGET() throws InterruptedException, ExecutionException, TimeoutException {
    SocketAddress serverAddress = new InetSocketAddress("127.0.0.1", server.getServerPort());

    /*Create a new client for the server address*/
    HttpClient<ByteBuf, ByteBuf> client = HttpClient.newClient(serverAddress);
    HttpClientRequest<ByteBuf, ByteBuf> req1 = client.createGet(PATH_1 + "?" + QUERY_1);

    Object result1 = req1
            .flatMap((HttpClientResponse<ByteBuf> resp) -> resp.getContent()
                    .map(bb -> bb.toString(Charset.defaultCharset())))
            .singleOrDefault(null).toBlocking().toFuture().get(5, TimeUnit.SECONDS);

    assertNull(result1);

    Wait.until(() -> getApmMockServer().getTraces().size() == 1);

    // Check stored traces (including 1 for the test client)
    assertEquals(1, getApmMockServer().getTraces().size());

    List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class);

    assertEquals("Expecting 1 producers", 1, producers.size());

    Producer testProducer = producers.get(0);

    assertEquals(PATH_1, testProducer.getUri());
    assertEquals(QUERY_1, testProducer.getProperties(Constants.PROP_HTTP_QUERY).iterator().next().getValue());
    assertEquals("GET", testProducer.getOperation());
    assertEquals("GET", testProducer.getProperties("http_method").iterator().next().getValue());
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:32,代码来源:NettyNoResponseHttpITest.java

示例15: testPOST

import io.reactivex.netty.protocol.http.client.HttpClient; //导入依赖的package包/类
@Test
public void testPOST() throws InterruptedException, ExecutionException, TimeoutException {
    SocketAddress serverAddress = new InetSocketAddress("127.0.0.1", server.getServerPort());

    /*Create a new client for the server address*/
    HttpClient<ByteBuf, ByteBuf> client = HttpClient.newClient(serverAddress);
    HttpClientRequest<ByteBuf, ByteBuf> req1 = client.createPost(PATH_2);
    req1.writeStringContent(Observable.just(HELLO_THERE));

    Object result1 = req1
            .flatMap((HttpClientResponse<ByteBuf> resp) -> resp.getContent()
                    .map(bb -> bb.toString(Charset.defaultCharset())))
            .singleOrDefault(null).toBlocking().toFuture().get(5, TimeUnit.SECONDS);

    assertNull(result1);

    Wait.until(() -> getApmMockServer().getTraces().size() == 1);

    // Check stored traces (including 1 for the test client)
    assertEquals(1, getApmMockServer().getTraces().size());

    List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class);

    assertEquals("Expecting 1 producers", 1, producers.size());

    Producer testProducer = producers.get(0);

    assertEquals(PATH_2, testProducer.getUri());
    assertTrue(testProducer.getProperties(Constants.PROP_HTTP_QUERY).isEmpty());
    assertEquals("POST", testProducer.getOperation());
    assertEquals("POST", testProducer.getProperties("http_method").iterator().next().getValue());
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:33,代码来源:NettyNoResponseHttpITest.java


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