reactor.netty.http.client.HttpClient.newConnection()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中reactor.netty.http.client.HttpClient.newConnection()方法的一些代码示例,展示了HttpClient.newConnection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.newConnection()方法的具体详情如下:
包路径:reactor.netty.http.client.HttpClient
类名称:HttpClient
方法名:newConnection

HttpClient.newConnection介绍

[英]Prepare an unpooled HttpClient. UriConfiguration#uri(String) or #baseUrl(String) should be invoked after a verb #request(HttpMethod) is selected.
[中]准备一个未冷却的HttpClient。UriConfiguration#uri(字符串)或#baseUrl(字符串)应在选择动词#请求(HttpMethod)后调用。

代码示例

代码示例来源:origin: scalecube/scalecube-services

private WebsocketClientTransport createRSocketTransport(ClientSettings settings) {
 String path = "/";
 HttpClient httpClient =
   HttpClient.newConnection()
     .followRedirect(settings.followRedirect())
     .tcpConfiguration(
       tcpClient -> {
        if (settings.sslProvider() != null) {
         tcpClient = tcpClient.secure(settings.sslProvider());
        }
        return tcpClient.runOn(loopResources).host(settings.host()).port(settings.port());
       });
 return WebsocketClientTransport.create(httpClient, path);
}

代码示例来源:origin: reactor/reactor-netty

@Test
public void disableChunkForced2() {
  Tuple2<HttpResponseStatus, String> r =
      HttpClient.newConnection()
           .tcpConfiguration(tcpClient -> tcpClient.host("google.com"))
           .wiretap(true)
           .keepAlive(false)
           .chunkedTransfer(false)
           .get()
           .uri("/unsupportedURI")
           .responseSingle((res, conn) -> Mono.just(res.status())
                             .zipWith(conn.asString()))
           .block(Duration.ofSeconds(30));
  assertThat(r).isNotNull();
  Assert.assertEquals(r.getT1(), HttpResponseStatus.NOT_FOUND);
}

代码示例来源:origin: reactor/reactor-netty

@Test
public void testIssue196() throws Exception {
  ExecutorService threadPool = Executors.newCachedThreadPool();
  int testServerPort = SocketUtils.findAvailableTcpPort();
  TestServer testServer = new TestServer(testServerPort);
  Future<?> f = threadPool.submit(testServer);
  if(!testServer.await(10, TimeUnit.SECONDS)){
    throw new IOException("Fail to start test server");
  }
  HttpClient client =
      HttpClient.newConnection()
           .port(testServerPort)
           .wiretap(true);
  Flux.range(0, 2)
    .concatMap(i -> client.get()
              .uri("/205")
              .responseContent()
              .aggregate()
              .asString()
              .log())
    .blockLast(Duration.ofSeconds(10));
  testServer.close();
  assertThat(f.get()).isNull();
}

代码示例来源:origin: scalecube/scalecube-services

/**
 * Creates instance of websocket client transport.
 *
 * @param settings client settings
 * @param codec client message codec
 * @param loopResources loop resources
 */
public WebsocketClientTransport(
  ClientSettings settings, ClientCodec<ByteBuf> codec, LoopResources loopResources) {
 this.codec = codec;
 this.settings = settings;
 httpClient =
   HttpClient.newConnection()
     .followRedirect(settings.followRedirect())
     .tcpConfiguration(
       tcpClient -> {
        if (settings.sslProvider() != null) {
         tcpClient = tcpClient.secure(settings.sslProvider());
        }
        return tcpClient.runOn(loopResources).host(settings.host()).port(settings.port());
       });
}

代码示例来源:origin: reactor/reactor-netty

@Test
public void disableChunkForced() {
  Tuple2<HttpResponseStatus, String> r =
      HttpClient.newConnection()
           .tcpConfiguration(tcpClient -> tcpClient.host("google.com"))
           .wiretap(true)
           .chunkedTransfer(false)
           .request(HttpMethod.GET)
           .uri("/unsupportedURI")
           .send(ByteBufFlux.fromString(Flux.just("hello")))
           .responseSingle((res, conn) -> Mono.just(res.status())
                             .zipWith(conn.asString()))
           .block(Duration.ofSeconds(30));
  assertThat(r).isNotNull();
  Assert.assertEquals(r.getT1(), HttpResponseStatus.NOT_FOUND);
}

相关文章