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); } }
/** * The host to which this client should connect. * * @param host The host to connect to. * * @return a new {@link TcpClient} */ public final TcpClient host(String host) { Objects.requireNonNull(host, "host"); return bootstrap(b -> TcpUtils.updateHost(b, host)); }
@Override protected TcpClient tcpConfiguration() { return source.tcpConfiguration() .bootstrap(this); }
/** * Apply a wire logger configuration using {@link TcpClient} category * and {@code DEBUG} logger level * * @return a new {@link TcpClient} * @deprecated Use {@link TcpClient#wiretap(boolean)} */ @Deprecated public final TcpClient wiretap() { return bootstrap(b -> BootstrapHandlers.updateLogSupport(b, LOGGING_HANDLER)); }
/** * The port to which this client should connect. * * @param port The port to connect to. * * @return a new {@link TcpClient} */ public final TcpClient port(int port) { return bootstrap(b -> TcpUtils.updatePort(b, port)); }
/** * Assign an {@link AddressResolverGroup}. * * @param resolver the new {@link AddressResolverGroup} * * @return a new {@link TcpClient} */ public final TcpClient resolver(AddressResolverGroup<?> resolver) { Objects.requireNonNull(resolver, "resolver"); return bootstrap(b -> b.resolver(resolver)); }
@Override protected TcpClient tcpConfiguration() { return source.tcpConfiguration() .bootstrap(this); }
@Override protected TcpClient tcpConfiguration() { return source.tcpConfiguration() .bootstrap(this); }
/** * Apply a wire logger configuration using {@link TcpClient} category * and {@code DEBUG} logger level * * @return a new {@link TcpClient} * @deprecated Use {@link TcpClient#wiretap(boolean)} */ @Deprecated public final TcpClient wiretap() { return bootstrap(b -> BootstrapHandlers.updateLogSupport(b, LOGGING_HANDLER)); }
/** * Assign an {@link AddressResolverGroup}. * * @param resolver the new {@link AddressResolverGroup} * * @return a new {@link TcpClient} */ public final TcpClient resolver(AddressResolverGroup<?> resolver) { Objects.requireNonNull(resolver, "resolver"); return bootstrap(b -> b.resolver(resolver)); }
@Override public WebsocketFinalizer send(Function<? super HttpClientRequest, ? extends Publisher<Void>> sender) { Objects.requireNonNull(sender, "requestBody"); return new WebsocketFinalizer(cachedConfiguration.bootstrap(b -> HttpClientConfiguration.body(b, (req, out) -> sender.apply(req)))); }
@Override public WebsocketFinalizer send(Function<? super HttpClientRequest, ? extends Publisher<Void>> sender) { Objects.requireNonNull(sender, "requestBody"); return new WebsocketFinalizer(cachedConfiguration.bootstrap(b -> HttpClientConfiguration.body(b, (req, out) -> sender.apply(req)))); }
@Override public HttpClientFinalizer send(BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>> sender) { Objects.requireNonNull(sender, "requestBody"); return new HttpClientFinalizer(cachedConfiguration.bootstrap(b -> HttpClientConfiguration.body(b, sender))); }
/** * Apply a wire logger configuration using {@link HttpClient} category * and {@code DEBUG} logger level * * @return a new {@link HttpClient} * @deprecated Use {@link HttpClient#wiretap(boolean)} */ @Deprecated public final HttpClient wiretap() { return tcpConfiguration(tcpClient -> tcpClient.bootstrap( b -> BootstrapHandlers.updateLogSupport(b, LOGGING_HANDLER))); }
@Override public HttpClientFinalizer send(BiFunction<? super HttpClientRequest, ? super NettyOutbound, ? extends Publisher<Void>> sender) { Objects.requireNonNull(sender, "requestBody"); return new HttpClientFinalizer(cachedConfiguration.bootstrap(b -> HttpClientConfiguration.body(b, sender))); }
/** * Apply a wire logger configuration using {@link HttpClient} category * and {@code DEBUG} logger level * * @return a new {@link HttpClient} * @deprecated Use {@link HttpClient#wiretap(boolean)} */ @Deprecated public final HttpClient wiretap() { return tcpConfiguration(tcpClient -> tcpClient.bootstrap( b -> BootstrapHandlers.updateLogSupport(b, LOGGING_HANDLER))); }
/** * The HTTP protocol to support. Default is {@link HttpProtocol#HTTP11}. * * @param supportedProtocols The various {@link HttpProtocol} this server will support * * @return a new {@link HttpClient} */ public final HttpClient protocol(HttpProtocol... supportedProtocols) { return tcpConfiguration(tcpClient -> tcpClient.bootstrap(b -> HttpClientConfiguration.protocols(b, supportedProtocols))); }
/** * The address to which this client should connect for each subscribe. * * @param connectAddressSupplier A supplier of the address to connect to. * * @return a new {@link TcpClient} */ public final TcpClient addressSupplier(Supplier<? extends SocketAddress> connectAddressSupplier) { SocketAddress lazy = TcpUtils.lazyAddress(connectAddressSupplier); return bootstrap(b -> b.remoteAddress(lazy)); }
/** * The HTTP protocol to support. Default is {@link HttpProtocol#HTTP11}. * * @param supportedProtocols The various {@link HttpProtocol} this server will support * * @return a new {@link HttpClient} */ public final HttpClient protocol(HttpProtocol... supportedProtocols) { return tcpConfiguration(tcpClient -> tcpClient.bootstrap(b -> HttpClientConfiguration.protocols(b, supportedProtocols))); }
/** * Use the passed HTTP method to connect the {@link HttpClient}. * * @param method the HTTP method to send * * @return a {@link RequestSender} ready to finalize request and consume for response */ public RequestSender request(HttpMethod method) { Objects.requireNonNull(method, "method"); TcpClient tcpConfiguration = tcpConfiguration().bootstrap(b -> HttpClientConfiguration.method(b, method)); return new HttpClientFinalizer(tcpConfiguration); }