springreactor-netty

HTTP Proxy Setup does not work if not done at create() time


I am setting up a HttpClient to use a proxy. This works if I do it at the time that the httpClient is created.

HttpClient httpClient = HttpClient.create()

       .proxy(proxy ->

           proxy.type(ProxyProvider.Proxy.HTTP)

               .host("proxyserverURL")

               .port(3128)

       );

If I do it not at the same time, because I'm conditionally using a proxy, the proxy connection does not work.

HttpClient httpClient = HttpClient.create();

   if(true)
   {
     httpClient.proxy(proxy ->

         proxy.type(ProxyProvider.Proxy.HTTP)

             .host("proxyServerURL")

             .port(3128)

     );

   }

Shouldn't the above code work?

Below is the complete test code I used. Had to trim some stacktrace so it post would fit.

public class NettyImplTest {


 @Test

 public void proxyWorks() {



   HttpClient httpClient = HttpClient.create()

       .proxy(proxy ->

           proxy.type(ProxyProvider.Proxy.HTTP)

               .host("proxyserverURL")

               .port(3128)

       );



   WebClient client = WebClient.builder()

       .baseUrl("https://www.cisco.com")

       .clientConnector(new ReactorClientHttpConnector(httpClient))

           .exchangeStrategies(ExchangeStrategies.builder().codecs(it->

               it.defaultCodecs().maxInMemorySize(2000000)).build())



       .build();



   String response = client.get()

       .uri("/")

       .retrieve()

       .bodyToMono(String.class)

       .block();





   assertNotNull(response);



 }



 @Test

 public void proxyFails() {



   HttpClient httpClient = HttpClient.create();



   if(true)

   {

     httpClient.proxy(proxy ->

         proxy.type(ProxyProvider.Proxy.HTTP)

             .host("proxyServerURL")

             .port(3128)

     );

   }





   WebClient client = WebClient.builder()

       .baseUrl("https://www.cisco.com")

       .clientConnector(new ReactorClientHttpConnector(httpClient))

       .exchangeStrategies(ExchangeStrategies.builder().codecs(it->

           it.defaultCodecs().maxInMemorySize(2000000)).build())



       .build();



   String response = client.get()

       .uri("/")

       .retrieve()

       .bodyToMono(String.class)

       .block();





   assertNotNull(response);



 }

}

Proxy Works

15:03:33.840 [main] DEBUG org.springframework.web.reactive.function.client.ExchangeFunctions -- [724b939e] HTTP GET https://www.cisco.com/

15:03:33.843 [main] DEBUG reactor.netty.resources.PooledConnectionProvider -- Creating a new [http] client pool [PoolFactory{evictionInterval=PT0S, leasingStrategy=fifo, maxConnections=500, maxIdleTime=-1, maxLifeTime=-1, metricsEnabled=false, pendingAcquireMaxCount=1000, pendingAcquireTimeout=45000}] for [www.cisco.com/<unresolved>:443]

15:03:33.843 [reactor-http-nio-3] DEBUG reactor.netty.resources.PooledConnectionProvider -- [2f5ffff3] Created a new pooled channel, now: 0 active connections, 0 inactive connections and 0 pending acquire requests.

15:03:33.845 [reactor-http-nio-3] DEBUG reactor.netty.tcp.SslProvider -- [2f5ffff3] SSL enabled using engine SSLEngine[hostname=www.cisco.com, port=443, Session(1683842613845|SSL_NULL_WITH_NULL_NULL)] and SNI www.cisco.com/<unresolved>:443

15:03:33.845 [reactor-http-nio-3] DEBUG reactor.netty.transport.TransportConfig -- [2f5ffff3] Initialized pipeline DefaultChannelPipeline{(HttpProxyHandler$HttpClientCodecWrapper#0 = io.netty.handler.proxy.HttpProxyHandler$HttpClientCodecWrapper), (reactor.left.proxyHandler = io.netty.handler.proxy.HttpProxyHandler), (reactor.left.sslHandler = io.netty.handler.ssl.SslHandler), (reactor.left.sslReader = reactor.netty.tcp.SslProvider$SslReadHandler), (reactor.left.httpCodec = io.netty.handler.codec.http.HttpClientCodec), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)}

15:03:33.846 [reactor-http-nio-3] DEBUG reactor.netty.transport.TransportConnector -- [2f5ffff3] Connecting to [www.cisco.com/<unresolved>:443].

15:03:33.930 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/10.9.7.10:3128] Registering pool release on close event for channel

15:03:33.930 [reactor-http-nio-3] DEBUG reactor.netty.resources.PooledConnectionProvider -- [2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] Channel connected, now: 1 active connections, 0 inactive connections and 0 pending acquire requests.

15:03:34.131 [reactor-http-nio-3] DEBUG io.netty.handler.ssl.SslHandler -- [id: 0x2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] HANDSHAKEN: protocol:TLSv1.3 cipher suite:TLS_AES_256_GCM_SHA384

15:03:34.131 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] onStateChange(PooledConnection{channel=[id: 0x2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128]}, [connected])

15:03:34.134 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] onStateChange(GET{uri=null, connection=PooledConnection{channel=[id: 0x2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128]}}, [configured])

15:03:34.135 [reactor-http-nio-3] DEBUG reactor.netty.http.client.HttpClientConnect -- [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] Handler is being applied: {uri=https://www.cisco.com/, method=GET}

15:03:34.136 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] onStateChange(GET{uri=/, connection=PooledConnection{channel=[id: 0x2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128]}}, [request_prepared])

15:03:34.141 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] onStateChange(GET{uri=/, connection=PooledConnection{channel=[id: 0x2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128]}}, [request_sent])

15:03:34.259 [reactor-http-nio-3] DEBUG reactor.netty.http.client.HttpClientOperations -- [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] Received response (auto-read:false) : RESPONSE(decodeResult: success, version: HTTP/1.1)

HTTP/1.1 200 OK

x-frame-options: <filtered>

x-vhost: <filtered>

Content-Type: <filtered>

X-Content-Type-Options: <filtered>

X-Served-By: <filtered>

X-Timer: <filtered>

Expires: <filtered>

Cache-Control: <filtered>

Pragma: <filtered>

Date: <filtered>

Transfer-Encoding: <filtered>

Connection: <filtered>

Connection: <filtered>

Set-Cookie: <filtered>

Content-Security-Policy: <filtered>

Strict-Transport-Security: <filtered>

15:03:34.259 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] onStateChange(GET{uri=/, connection=PooledConnection{channel=[id: 0x2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128]}}, [response_received])

15:03:34.262 [reactor-http-nio-3] DEBUG org.springframework.web.reactive.function.client.ExchangeFunctions -- [724b939e] [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] Response 200 OK

15:03:34.271 [reactor-http-nio-3] DEBUG reactor.netty.channel.FluxReceive -- [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] [terminated=false, cancelled=false, pending=0, error=null]: subscribing inbound receiver

15:03:34.489 [reactor-http-nio-3] DEBUG reactor.netty.http.client.HttpClientOperations -- [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] Received last HTTP packet

15:03:34.492 [reactor-http-nio-3] DEBUG org.springframework.core.codec.StringDecoder -- [724b939e] [2f5ffff3-1, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] Decoded "<EOL><!DOCTYPE HTML><EOL><EOL><html lang="en-US" dir="ltr"><EOL>    <head><EOL>    <meta charset="UTF-8"/><EOL>    <meta nam (truncated)..."

15:03:34.493 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] onStateChange(GET{uri=/, connection=PooledConnection{channel=[id: 0x2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128]}}, [response_completed])

15:03:34.493 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] onStateChange(GET{uri=/, connection=PooledConnection{channel=[id: 0x2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128]}}, [disconnecting])

15:03:34.493 [reactor-http-nio-3] DEBUG reactor.netty.resources.DefaultPooledConnectionProvider -- [2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] Releasing channel

15:03:34.493 [reactor-http-nio-3] DEBUG reactor.netty.resources.PooledConnectionProvider -- [2f5ffff3, L:/x.x.x.x:58444 - R:proxyServerURL/x.x.x.x:3128] Channel cleaned, now: 0 active connections, 1 inactive connections and 0 pending acquire requests.

Proxy Fails

15:03:23.147 [main] DEBUG reactor.util.Loggers -- Using Slf4j logging framework

15:03:23.161 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory -- Using SLF4J as the default logging framework

15:03:23.162 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- -Dio.netty.noUnsafe: false

15:03:23.162 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- Java version: 17

15:03:23.163 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- sun.misc.Unsafe.theUnsafe: available

15:03:23.163 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- sun.misc.Unsafe.copyMemory: available

15:03:23.163 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- sun.misc.Unsafe.storeFence: available

15:03:23.163 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- java.nio.Buffer.address: available

15:03:23.164 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- direct buffer constructor: unavailable: Reflective setAccessible(true) disabled

15:03:23.164 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- java.nio.Bits.unaligned: available, true

15:03:23.164 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable: class io.netty.util.internal.PlatformDependent0$7 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @80503

15:03:23.165 [main] DEBUG io.netty.util.internal.PlatformDependent0 -- java.nio.DirectByteBuffer.<init>(long, int): unavailable

15:03:23.165 [main] DEBUG io.netty.util.internal.PlatformDependent -- sun.misc.Unsafe: available

15:03:23.169 [main] DEBUG io.netty.util.internal.PlatformDependent -- maxDirectMemory: 4294967296 bytes (maybe)

15:03:23.169 [main] DEBUG io.netty.util.internal.PlatformDependent -- -Dio.netty.tmpdir: /var/folders/bl/wd3g1y9d5d1_v8hw6xmcn9000000gq/T (java.io.tmpdir)

15:03:23.169 [main] DEBUG io.netty.util.internal.PlatformDependent -- -Dio.netty.bitMode: 64 (sun.arch.data.model)

15:03:23.169 [main] DEBUG io.netty.util.internal.PlatformDependent -- Platform: MacOS

15:03:23.170 [main] DEBUG io.netty.util.internal.PlatformDependent -- -Dio.netty.maxDirectMemory: -1 bytes

15:03:23.170 [main] DEBUG io.netty.util.internal.PlatformDependent -- -Dio.netty.uninitializedArrayAllocationThreshold: -1

15:03:23.170 [main] DEBUG io.netty.util.internal.CleanerJava9 -- java.nio.ByteBuffer.cleaner(): available

15:03:23.170 [main] DEBUG io.netty.util.internal.PlatformDependent -- -Dio.netty.noPreferDirect: false

15:03:23.186 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap -- -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024

15:03:23.186 [main] DEBUG io.netty.util.internal.InternalThreadLocalMap -- -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096

15:03:23.198 [main] DEBUG io.netty.util.ResourceLeakDetector -- -Dio.netty.leakDetection.level: simple

15:03:23.198 [main] DEBUG io.netty.util.ResourceLeakDetector -- -Dio.netty.leakDetection.targetRecords: 4

15:03:23.426 [main] DEBUG io.netty.util.NetUtil -- -Djava.net.preferIPv4Stack: false

15:03:23.426 [main] DEBUG io.netty.util.NetUtil -- -Djava.net.preferIPv6Addresses: false

15:03:23.429 [main] DEBUG io.netty.util.NetUtilInitializations -- Loopback interface: lo0 (lo0, 0:0:0:0:0:0:0:1%lo0)

15:03:23.430 [main] DEBUG io.netty.util.NetUtil -- Failed to get SOMAXCONN from sysctl and file /proc/sys/net/core/somaxconn. Default: 128

15:03:23.437 [main] DEBUG org.springframework.web.reactive.function.client.ExchangeFunctions -- [2015b2cd] HTTP GET https://www.cisco.com/

15:03:23.446 [main] DEBUG io.netty.handler.ssl.OpenSsl -- netty-tcnative not in the classpath; OpenSslEngine will be unavailable.

15:03:23.529 [main] DEBUG io.netty.handler.ssl.JdkSslContext -- Default protocols (JDK): [TLSv1.3, TLSv1.2] 

15:03:23.529 [main] DEBUG io.netty.handler.ssl.JdkSslContext -- Default cipher suites (JDK): [TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384]

15:03:23.538 [main] DEBUG reactor.netty.tcp.TcpResources -- [http] resources will use the default LoopResources: DefaultLoopResources {prefix=reactor-http, daemon=true, selectCount=10, workerCount=10}

15:03:23.538 [main] DEBUG reactor.netty.tcp.TcpResources -- [http] resources will use the default ConnectionProvider: reactor.netty.resources.DefaultPooledConnectionProvider@ec8f4b9

15:03:23.539 [main] DEBUG reactor.netty.resources.DefaultLoopIOUring -- Default io_uring support : false

15:03:23.550 [main] DEBUG reactor.netty.resources.DefaultLoopEpoll -- Default Epoll support : false

15:03:23.551 [main] DEBUG reactor.netty.resources.DefaultLoopKQueue -- Default KQueue support : false

15:03:23.553 [main] DEBUG io.netty.channel.MultithreadEventLoopGroup -- -Dio.netty.eventLoopThreads: 20

15:03:23.557 [main] DEBUG io.netty.util.concurrent.GlobalEventExecutor -- -Dio.netty.globalEventExecutor.quietPeriodSeconds: 1

15:03:23.563 [main] DEBUG io.netty.channel.nio.NioEventLoop -- -Dio.netty.noKeySetOptimization: false

15:03:23.563 [main] DEBUG io.netty.channel.nio.NioEventLoop -- -Dio.netty.selectorAutoRebuildThreshold: 512

15:03:23.566 [main] DEBUG io.netty.util.internal.PlatformDependent -- org.jctools-core.MpscChunkedArrayQueue: available

15:03:23.579 [main] DEBUG io.netty.resolver.DefaultHostsFileEntriesResolver -- -Dio.netty.hostsFileRefreshInterval: 0

15:03:23.581 [main] DEBUG io.netty.util.internal.NativeLibraryLoader -- -Dio.netty.native.workdir: /var/folders/bl/wd3g1y9d5d1_v8hw6xmcn9000000gq/T (io.netty.tmpdir)

15:03:23.581 [main] DEBUG io.netty.util.internal.NativeLibraryLoader -- -Dio.netty.native.deleteLibAfterLoading: true

15:03:23.581 [main] DEBUG io.netty.util.internal.NativeLibraryLoader -- -Dio.netty.native.tryPatchShadedId: true

15:03:23.581 [main] DEBUG io.netty.util.internal.NativeLibraryLoader -- -Dio.netty.native.detectNativeLibraryDuplicates: true

15:03:23.720 [main] DEBUG io.netty.util.internal.NativeLibraryLoader -- Successfully loaded the library /var/folders/bl/wd3g1y9d5d1_v8hw6xmcn9000000gq/T/libnetty_resolver_dns_native_macos_aarch_646961405862670348556.dylib

15:03:23.726 [main] DEBUG io.netty.resolver.dns.DnsServerAddressStreamProviders -- io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider: available

15:03:23.729 [main] DEBUG reactor.netty.resources.PooledConnectionProvider -- Creating a new [http] client pool [PoolFactory{evictionInterval=PT0S, leasingStrategy=fifo, maxConnections=500, maxIdleTime=-1, maxLifeTime=-1, metricsEnabled=false, pendingAcquireMaxCount=1000, pendingAcquireTimeout=45000}] for [www.cisco.com/<unresolved>:443]

15:03:23.743 [main] DEBUG io.netty.channel.DefaultChannelId -- -Dio.netty.processId: 1148 (auto-detected)

15:03:23.744 [main] DEBUG io.netty.channel.DefaultChannelId -- -Dio.netty.machineId: bc:d0:74:ff:fe:4a:fa:58 (auto-detected)

15:03:23.754 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.numHeapArenas: 20

15:03:23.754 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.numDirectArenas: 20

15:03:23.754 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.pageSize: 8192

15:03:23.754 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.maxOrder: 9

15:03:23.754 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.chunkSize: 4194304

15:03:23.754 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.smallCacheSize: 256

15:03:23.754 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.normalCacheSize: 64

15:03:23.754 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.maxCachedBufferCapacity: 32768

15:03:23.755 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.cacheTrimInterval: 8192

15:03:23.755 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.cacheTrimIntervalMillis: 0

15:03:23.755 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.useCacheForAllThreads: false

15:03:23.755 [main] DEBUG io.netty.buffer.PooledByteBufAllocator -- -Dio.netty.allocator.maxCachedByteBuffersPerChunk: 1023

15:03:23.759 [main] DEBUG io.netty.buffer.ByteBufUtil -- -Dio.netty.allocator.type: pooled

15:03:23.759 [main] DEBUG io.netty.buffer.ByteBufUtil -- -Dio.netty.threadLocalDirectBufferSize: 0

15:03:23.759 [main] DEBUG io.netty.buffer.ByteBufUtil -- -Dio.netty.maxThreadLocalCharBufferSize: 16384

15:03:23.767 [reactor-http-nio-2] DEBUG reactor.netty.resources.PooledConnectionProvider -- [95c4ab7f] Created a new pooled channel, now: 0 active connections, 0 inactive connections and 0 pending acquire requests.

15:03:23.777 [reactor-http-nio-2] DEBUG reactor.netty.tcp.SslProvider -- [95c4ab7f] SSL enabled using engine SSLEngine[hostname=www.cisco.com, port=443, Session(1683842603771|SSL_NULL_WITH_NULL_NULL)] and SNI www.cisco.com/<unresolved>:443

15:03:23.783 [reactor-http-nio-2] DEBUG io.netty.buffer.AbstractByteBuf -- -Dio.netty.buffer.checkAccessible: true

15:03:23.784 [reactor-http-nio-2] DEBUG io.netty.buffer.AbstractByteBuf -- -Dio.netty.buffer.checkBounds: true

15:03:23.784 [reactor-http-nio-2] DEBUG io.netty.util.ResourceLeakDetectorFactory -- Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@4bf3a212

15:03:23.786 [reactor-http-nio-2] DEBUG reactor.netty.transport.TransportConfig -- [95c4ab7f] Initialized pipeline DefaultChannelPipeline{(reactor.left.sslHandler = io.netty.handler.ssl.SslHandler), (reactor.left.sslReader = reactor.netty.tcp.SslProvider$SslReadHandler), (reactor.left.httpCodec = io.netty.handler.codec.http.HttpClientCodec), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)}

15:03:23.802 [reactor-http-nio-1] DEBUG io.netty.util.ResourceLeakDetectorFactory -- Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@255a37e2

15:03:23.803 [reactor-http-nio-1] DEBUG io.netty.resolver.dns.DnsQueryContext -- [id: 0xce3a079d] WRITE: UDP, [8977: /10.7.28.247:53], DefaultDnsQuestion(www.cisco.com. IN A)

15:03:23.806 [reactor-http-nio-1] DEBUG io.netty.util.Recycler -- -Dio.netty.recycler.maxCapacityPerThread: 4096

15:03:23.806 [reactor-http-nio-1] DEBUG io.netty.util.Recycler -- -Dio.netty.recycler.ratio: 8

15:03:23.806 [reactor-http-nio-1] DEBUG io.netty.util.Recycler -- -Dio.netty.recycler.chunkSize: 32

15:03:23.806 [reactor-http-nio-1] DEBUG io.netty.util.Recycler -- -Dio.netty.recycler.blocking: false

15:03:23.806 [reactor-http-nio-1] DEBUG io.netty.util.Recycler -- -Dio.netty.recycler.batchFastThreadLocalOnly: true

15:03:23.810 [reactor-http-nio-1] DEBUG io.netty.resolver.dns.DnsQueryContext -- [id: 0xce3a079d] WRITE: UDP, [53508: /10.7.28.247:53], DefaultDnsQuestion(www.cisco.com. IN AAAA)

15:03:28.814 [reactor-http-nio-1] DEBUG io.netty.resolver.dns.DnsQueryContext -- [id: 0xce3a079d] WRITE: UDP, [60238: /10.220.0.247:53], DefaultDnsQuestion(www.cisco.com. IN A)

15:03:28.816 [reactor-http-nio-1] DEBUG io.netty.resolver.dns.DnsQueryContext -- [id: 0xce3a079d] WRITE: UDP, [41267: /10.220.0.247:53], DefaultDnsQuestion(www.cisco.com. IN AAAA)


org.springframework.web.reactive.function.client.WebClientRequestException: Failed to resolve 'www.cisco.com' [A(1), AAAA(28)] and search domain query for configured domains failed as well: [cp.ad.xxx.com, lan]


    at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:136)

    Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below: 

Error has been observed at the following site(s):

    *__checkpoint ⇢ Request to GET https://www.cisco.com/ [DefaultWebClient]

Original Stack Trace:

        at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:136)

    
        at reactor.netty.transport.TransportConnector$MonoChannelPromise.tryFailure(TransportConnector.java:587)

        at reactor.netty.transport.TransportConnector.lambda$doResolveAndConnect$11(TransportConnector.java:394)

        at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)

        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:557)

        at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)

        at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)

        at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:629)

        at io.netty.util.concurrent.DefaultPromise.setFailure(DefaultPromise.java:110)

        at io.netty.resolver.InetSocketAddressResolver$2.operationComplete(InetSocketAddressResolver.java:86)

        at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)

        at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583)

        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559)

        at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)

        at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)

        at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:629)

        at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:118)

        at io.netty.resolver.dns.DnsResolveContext$1.operationComplete(DnsResolveContext.java:236)

        at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)

        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:557)

        at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)

        at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)

        at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:629)

        at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:118)

        at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1096)

        at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:1035)

        at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:422)

        at io.netty.resolver.dns.DnsResolveContext.access$700(DnsResolveContext.java:66)

        at io.netty.resolver.dns.DnsResolveContext$2.operationComplete(DnsResolveContext.java:493)

        at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)

        at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583)

        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559)

        at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)

        at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)

        at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:629)

        at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:118)

        at io.netty.resolver.dns.DnsQueryContext.tryFailure(DnsQueryContext.java:261)

        at io.netty.resolver.dns.DnsQueryContext$4.run(DnsQueryContext.java:208)

        at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)

        at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:153)

        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)

        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)

        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)

        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)

        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)

        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)

        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)

        at java.base/java.lang.Thread.run(Thread.java:833)

    Suppressed: java.lang.Exception: #block terminated with an error

        at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)

        at reactor.core.publisher.Mono.block(Mono.java:1710)

        at com.xxx.sourcing.service.NettyImplTest.proxyFails(NettyImplTest.java:92)

        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.base/java.lang.reflect.Method.invoke(Method.java:568)

        at 

Caused by: io.netty.resolver.dns.DnsResolveContext$SearchDomainUnknownHostException: Failed to resolve 'www.cisco.com' [A(1), AAAA(28)] and search domain query for configured domains failed as well: [cp.ad.xxx.com, lan]

    at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1088)



Caused by: io.netty.resolver.dns.DnsNameResolverTimeoutException: [41267: /10.220.0.247:53] DefaultDnsQuestion(www.cisco.com. IN AAAA) query '41267' via UDP timed out after 5000 milliseconds (no stack trace available)

Solution

  • You need to assign the http client once you do a new configuration. See

       if(true)
    
       {
    
         httpClient = httpClient.proxy(proxy ->
    
             proxy.type(ProxyProvider.Proxy.HTTP)
    
                 .host("proxyServerURL")
    
                 .port(3128)
    
         );
    
       }
    

    For more information check the javadoc