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

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

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

HttpClient.create介绍

[英]Prepare a pooled HttpClient. UriConfiguration#uri(String) or #baseUrl(String) should be invoked before a verb #request(HttpMethod) is selected.
[中]准备一个池式HttpClient。UriConfiguration#uri(字符串)或#baseUrl(字符串)应在选择动词#请求(HttpMethod)之前调用。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Default constructor.
 */
public ReactorNettyWebSocketClient() {
  this(HttpClient.create());
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Default constructor. Initializes {@link HttpClient} via:
 * <pre class="code">
 * HttpClient.create().compress()
 * </pre>
 */
public ReactorClientHttpConnector() {
  this.httpClient = defaultInitializer.apply(HttpClient.create());
}

代码示例来源:origin: org.springframework/spring-web

/**
 * Default constructor. Initializes {@link HttpClient} via:
 * <pre class="code">
 * HttpClient.create().compress()
 * </pre>
 */
public ReactorClientHttpConnector() {
  this.httpClient = defaultInitializer.apply(HttpClient.create());
}

代码示例来源:origin: spring-projects/spring-framework

private static HttpClient initHttpClient(ReactorResourceFactory resourceFactory) {
  ConnectionProvider provider = resourceFactory.getConnectionProvider();
  LoopResources resources = resourceFactory.getLoopResources();
  Assert.notNull(provider, "No ConnectionProvider: is ReactorResourceFactory not initialized yet?");
  Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?");
  return HttpClient.create(provider).tcpConfiguration(tcpClient -> tcpClient.runOn(resources));
}

代码示例来源:origin: org.springframework/spring-web

private static HttpClient initHttpClient(ReactorResourceFactory resourceFactory) {
  ConnectionProvider provider = resourceFactory.getConnectionProvider();
  LoopResources resources = resourceFactory.getLoopResources();
  Assert.notNull(provider, "No ConnectionProvider: is ReactorResourceFactory not initialized yet?");
  Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?");
  return HttpClient.create(provider).tcpConfiguration(tcpClient -> tcpClient.runOn(resources));
}

代码示例来源:origin: codecentric/spring-boot-admin

private static WebClient.Builder createDefaultWebClient(Duration connectTimeout, Duration readTimeout) {
    HttpClient httpClient = HttpClient.create()
                     .compress(true)
                     .tcpConfiguration(tcp -> tcp.bootstrap(bootstrap -> bootstrap.option(
                       ChannelOption.CONNECT_TIMEOUT_MILLIS,
                       (int) connectTimeout.toMillis()
                     )).observe((connection, newState) -> {
                       if (ConnectionObserver.State.CONNECTED.equals(newState)) {
                         connection.addHandlerLast(new ReadTimeoutHandler(readTimeout.toMillis(),
                           TimeUnit.MILLISECONDS
                         ));
                       }
                     }));
    ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
    return WebClient.builder().clientConnector(connector);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-gateway

@Before
public void setup() {
  try {
    SslContext sslContext = SslContextBuilder.forClient()
        .trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    HttpClient httpClient = HttpClient.create().secure(ssl -> {
      ssl.sslContext(sslContext);
    });
    ClientHttpConnector httpConnector = new ReactorClientHttpConnector(
        httpClient);
    baseUri = "https://localhost:" + port;
    this.webClient = WebClient.builder().clientConnector(httpConnector)
        .baseUrl(baseUri).build();
    this.testClient = WebTestClient.bindToServer(httpConnector).baseUrl(baseUri).build();
  }
  catch (SSLException e) {
    throw new RuntimeException(e);
  }        
}

代码示例来源:origin: spring-cloud/spring-cloud-gateway

HttpClient httpClient = HttpClient.create(connectionProvider)
  .tcpConfiguration(tcpClient -> {

代码示例来源:origin: rsocket/rsocket-java

@DisplayName("creates client with HttpClient")
@Test
void createHttpClient() {
 assertThat(WebsocketClientTransport.create(HttpClient.create(), "/")).isNotNull();
}

代码示例来源:origin: rsocket/rsocket-java

@DisplayName("create throws NullPointerException with null path")
@Test
void createNullPath() {
 assertThatNullPointerException()
   .isThrownBy(() -> WebsocketClientTransport.create(HttpClient.create(), null))
   .withMessage("path must not be null");
}

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

/**
 * Prepare a pooled {@link HttpClient}. {@link UriConfiguration#uri(String)} or
 * {@link #baseUrl(String)} should be invoked before a verb
 * {@link #request(HttpMethod)} is selected.
 *
 * @return a {@link HttpClient}
 */
public static HttpClient create() {
  return create(HttpResources.get());
}

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

/**
 * Prepare a pooled {@link HttpClient}. {@link UriConfiguration#uri(String)} or
 * {@link #baseUrl(String)} should be invoked before a verb
 * {@link #request(HttpMethod)} is selected.
 *
 * @return a {@link HttpClient}
 */
public static HttpClient create() {
  return create(HttpResources.get());
}

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

private HttpClient createHttpClientForContextWithAddress(DisposableServer context,
    ConnectionProvider pool) {
  HttpClient client;
  if (pool == null) {
    client = HttpClient.create();
  }
  else {
    client = HttpClient.create(pool);
  }
  return client.addressSupplier(context::address)
         .wiretap(true);
}

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

private HttpClient createHttpClientForContextWithPort(DisposableServer context,
    ConnectionProvider pool) {
  HttpClient client;
  if (pool == null) {
    client = HttpClient.create();
  }
  else {
    client = HttpClient.create(pool);
  }
  return client.port(context.port())
         .wiretap(true);
}

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

@Test
public void simpleTest404() {
  doSimpleTest404(HttpClient.create()
               .baseUrl("google.com"));
}

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

private Mono<String> login(int port) {
    return HttpClient.create()
             .port(port)
             .wiretap(true)
             .post()
             .uri("/login")
             .responseSingle((res, buf) -> Mono.just(res.status().code() + ""));
  }
}

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

@Test
public void testRestart() {
  doTestRestart(HttpServer.create()
              .port(8080),
         HttpClient.create()
              .port(8080));
  doTestRestart(HttpServer.create()
              // Any local address
              .tcpConfiguration(tcpServer -> tcpServer.addressSupplier(() -> new InetSocketAddress(8080))),
         HttpClient.create()
              .port(8080));
}

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

private Mono<Void> proxy(HttpServerRequest request, HttpServerResponse response) {
  return HttpClient.create()
           .wiretap(true)
           .headers(h -> h.add(filterRequestHeaders(request.requestHeaders())))
           .get()
           .uri(URI.create("http://localhost:" + CONTENT_SERVER_PORT +
                   "/" + request.path())
               .toString())
           .response((targetResponse, buf) -> response.headers(filterResponseHeaders(targetResponse.responseHeaders()))
                            .send(buf.retain())
                            .then())
           .then();
}

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

@Test
public void gettingOptionsDuplicates() {
  HttpClient client = HttpClient.create()
                 .tcpConfiguration(tcpClient -> tcpClient.host("foo"))
                 .wiretap(true)
                 .port(123)
                 .compress(true);
  assertThat(client.tcpConfiguration())
      .isNotSameAs(HttpClient.DEFAULT_TCP_CLIENT)
      .isNotSameAs(client.tcpConfiguration());
}

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

@Test
public void simpleTest404_1() {
  ConnectionProvider pool = ConnectionProvider.fixed("http", 1);
  HttpClient client =
      HttpClient.create(pool)
           .port(80)
           .tcpConfiguration(tcpClient -> tcpClient.host("google.com"))
           .wiretap(true);
  doSimpleTest404(client);
  doSimpleTest404(client);
  pool.dispose();
}

相关文章