Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netty Connector proxy handler to support JDK's options #4978

Closed
olotenko opened this issue Feb 7, 2022 · 1 comment · Fixed by #5071
Closed

Netty Connector proxy handler to support JDK's options #4978

olotenko opened this issue Feb 7, 2022 · 1 comment · Fixed by #5071
Milestone

Comments

@olotenko
Copy link

olotenko commented Feb 7, 2022

JDK's proxy handling supports a range of options, like -Dhttp.proxyHost=11.11.69.53 or -Dhttp.nonProxyHosts=*.lan|localhost|127.*|docker.for.mac.localhost|*.|*.default

It is easy to add this support using JDK's Proxy API. A patch showcasing its use by Netty Connector is attached.
netty_proxy_opts.zip

This patch will support the options, if no PROXY is specified explicitly.

@jansupol
Copy link
Contributor

Goy an internal review:

I was the one to test the jersey-netty-connector code. I pulled his code changes and tested it in my local OKE environment. Proxy is set using -Dhttp.proxyHost and -Dhttp.proxyPort properties. I was unable to make any outbound invocation. (edited)

{
  "level": "ERROR",
  "logger": "oic.gen3.adapter.adapter-runtime.AsyncOutboundRequestHandler",
  "thread": "adapter-outbound-executor-thread-9",
  "ts": 1647383475086,
  "msg": "rootCauseException:
java.nio.channels.UnresolvedAddressException: null
  at java.base/sun.nio.ch.Net.checkAddress(Net.java:130)
  at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:675)
  at io.netty.util.internal.SocketUtils$3.run(SocketUtils.java:91)
  at io.netty.util.internal.SocketUtils$3.run(SocketUtils.java:88)
  at java.base/java.security.AccessController.doPrivileged(Native Method)
  at io.netty.util.internal.SocketUtils.connect(SocketUtils.java:88)
  at io.netty.channel.socket.nio.NioSocketChannel.doConnect(NioSocketChannel.java:315)
  at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.connect(AbstractNioChannel.java:248)
  at io.netty.channel.DefaultChannelPipeline$HeadContext.connect(DefaultChannelPipeline.java:1342)
  at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:548)
  at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:533)
  at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.connect(CombinedChannelDuplexHandler.java:495)
  at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:51)
  at io.netty.channel.CombinedChannelDuplexHandler.connect(CombinedChannelDuplexHandler.java:296)
  at io.netty.handler.proxy.HttpProxyHandler$HttpClientCodecWrapper.connect(HttpProxyHandler.java:299)
  at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:548)
  at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:533)
  at io.netty.handler.proxy.ProxyHandler.connect(ProxyHandler.java:178)
  at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:548)
  at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:533)
  at io.netty.handler.ssl.SslHandler.connect(SslHandler.java:713)
  at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:548)
  at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:533)
  at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.connect(CombinedChannelDuplexHandler.java:495)
  at io.netty.channel.ChannelOutboundHandlerAdapter.connect(ChannelOutboundHandlerAdapter.java:51)
  at io.netty.channel.CombinedChannelDuplexHandler.connect(CombinedChannelDuplexHandler.java:296)
  at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:548)
  at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:533)
  at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:517)
  at io.netty.channel.DefaultChannelPipeline.connect(DefaultChannelPipeline.java:978)
  at io.netty.channel.AbstractChannel.connect(AbstractChannel.java:265)
  at io.netty.bootstrap.Bootstrap$3.run(Bootstrap.java:250)
  at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
  at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
  at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
  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:834)
",
  "rep.fid": "nJVglqSvEeypL6VYz08Lww",
  "oic.service-instance": "...",
  "oic.trace": "bee05fc9557193d2bcfcb5014fbd254c",
  "oic.partition": "0",
  "opc-request-id": "/D10118EA8F7713835600E6840857EBD9",
  "oic.user": "..."
}
ProxySelector sel = ProxySelector.getDefault();
for (Proxy proxy : sel.select(requestUri)) {
    if (proxy.type().equals(Proxy.Type.HTTP)) {
        SocketAddress proxyAddress = proxy.address();

        if (proxy.address() instanceof InetSocketAddress) {
            InetSocketAddress isa = (InetSocketAddress) proxy.address();
            proxyAddress = isa;
            if (isa.isUnresolved()) {
                proxyAddress = new InetSocketAddress(isa.getHostString(), isa.getPort());
            }
        }
        p.addLast(new HttpProxyHandler(proxyAddress));
        break;
    }
}

@jansupol jansupol linked a pull request May 27, 2022 that will close this issue
@senivam senivam added this to the 2.36 milestone Jun 9, 2022
This was referenced Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants