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

NET-650 Delegate host resolution to Socket.connect() #138

Merged
merged 1 commit into from
Jan 9, 2023

Conversation

exceptionfactory
Copy link
Contributor

This pull request presents a solution of NET-650, delegating remote host resolution to java.net.Socket.connect() instead of performing host resolution earlier in org.apache.commons.net.SocketClient.connect() methods.

For SocketClient.connect() methods that accept a String value for the hostname argument, the existing implementation calls InetAddress.getByName(hostname), performing host resolution prior to calling Socket.connect(). This works for use cases where the remote host DNS address is resolvable, but does not work for scenarios where the remote host must be resolved through a proxy server.

The new InetSocketAddress(String hostname, int port) constructor attempts name resolution, but catches the UnknownHostException and allows the hostname to remain unresolved. This behavior allows custom Java SocketFactory implementations to pass the unresolved hostname to a remote proxy server, where name resolution may succeed, allowing the connection to proceed.

Changing the SocketClient.connect() methods to construct an InetSocketAddress should support existing standard behavior while also supporting additional use cases like proxy-based name resolution.

The pull request includes a new _remoteAddress_ member in SocketClient, which supports new unit test methods that check the status of InetSocketAddress.isUnresolved() after expecting particular exceptions.

- Replaced InetAddress.getByName() with InetSocketAddress for private SocketClient._connect()
@garydgregory garydgregory merged commit 69ca429 into apache:master Jan 9, 2023
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 this pull request may close these issues.

2 participants