This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git
The following commit(s) were added to refs/heads/master by this push:
new 78967ea6 [NET-650] Delegate host resolution to Socket.connect()
78967ea6 is described below
commit 78967ea6ab0a1bd4cbdd68e7377d33b3082ffa22
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Jan 9 08:40:19 2023 -0500
[NET-650] Delegate host resolution to Socket.connect()
- Encapsulate new field
- Sort test members
- Bump version when adding a public or protected element
---
pom.xml | 6 ++---
src/changes/changes.xml | 9 ++++---
.../java/org/apache/commons/net/SocketClient.java | 20 +++++++++++----
.../org/apache/commons/net/SocketClientTest.java | 30 +++++++++++-----------
4 files changed, 38 insertions(+), 27 deletions(-)
diff --git a/pom.xml b/pom.xml
index bc78418c..9b81dbc9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
- <version>3.9.0</version>
+ <version>3.10.0</version>
<name>Apache Commons Net</name>
<!-- N.B. the description content is deliberately not indented ! to
improve the layout of the Release Notes generated
by mvn changes:announcement-generate -->
@@ -56,12 +56,12 @@ Supported protocols include: Echo, Finger, FTP, NNTP, NTP,
POP3(S), SMTP(S), Tel
<jacoco.skip>false</jacoco.skip>
<!-- Current release -->
- <commons.release.version>3.9.0</commons.release.version>
+ <commons.release.version>3.10.0</commons.release.version>
<commons.rc.version>RC1</commons.rc.version>
<commons.release.desc>(Requires Java ${maven.compiler.target} or
later)</commons.release.desc>
<!-- Release plugin defines -->
- <commons.bc.version>3.8.0</commons.bc.version>
+ <commons.bc.version>3.9.0</commons.bc.version>
<commons.release.isDistModule>true</commons.release.isDistModule>
<commons.releaseManagerName>Gary Gregory</commons.releaseManagerName>
<commons.releaseManagerKey>86fdc7e2a11262cb</commons.releaseManagerKey>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f8478518..c1830b3e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -62,7 +62,11 @@ The <action> type attribute can be add,update,fix,remove.
-->
<body>
- <release version="3.9.1" date="202Y-MM-DD" description="Maintenance and
bug fix release (Java 8).">
+ <release version="3.10.0" date="202Y-MM-DD" description="Maintenance and
bug fix release (Java 8).">
+ <!-- FIX -->
+ <action type="fix" issue="NET-650" dev="ggregory" due-to="Matthew
McGillis, exceptionfactory, sebbASF">
+ Delegate host resolution to Socket.connect() #138.
+ </action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">
Bump commons-parent from 54 to 56 #132, #137.
@@ -101,9 +105,6 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" issue="NET-707" dev="ggregory" due-to="Dmytro
Sylaiev, sebbASF, Gary Gregory">
Process files with spaces in name for OS400 #95.
</action>
- <action type="fix" issue="NET-650" dev="ggregory" due-to="Matthew
McGillis, exceptionfactory, sebbASF">
- Delegate host resolution to Socket.connect() #138.
- </action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">
[FTP] Add FTPClient.mdtmInstant(String).
diff --git a/src/main/java/org/apache/commons/net/SocketClient.java
b/src/main/java/org/apache/commons/net/SocketClient.java
index 9ca80f48..bbc46185 100644
--- a/src/main/java/org/apache/commons/net/SocketClient.java
+++ b/src/main/java/org/apache/commons/net/SocketClient.java
@@ -71,8 +71,8 @@ public abstract class SocketClient {
/** The hostname used for the connection (null = no hostname supplied). */
protected String _hostname_;
- /** The remote socket address used for the connection */
- protected InetSocketAddress _remoteAddress_;
+ /** The remote socket address used for the connection. */
+ protected InetSocketAddress remoteInetSocketAddress;
/** The default port the client should connect to. */
protected int _defaultPort_;
@@ -121,8 +121,8 @@ public abstract class SocketClient {
}
// helper method to allow code to be shared with connect(String,...)
methods
- private void _connect(final InetSocketAddress remoteAddress, final
InetAddress localAddr, final int localPort) throws IOException {
- _remoteAddress_ = remoteAddress;
+ private void _connect(final InetSocketAddress remoteInetSocketAddress,
final InetAddress localAddr, final int localPort) throws IOException {
+ this.remoteInetSocketAddress = remoteInetSocketAddress;
_socket_ = _socketFactory_.createSocket();
if (receiveBufferSize != -1) {
_socket_.setReceiveBufferSize(receiveBufferSize);
@@ -133,7 +133,7 @@ public abstract class SocketClient {
if (localAddr != null) {
_socket_.bind(new InetSocketAddress(localAddr, localPort));
}
- _socket_.connect(remoteAddress, connectTimeout);
+ _socket_.connect(remoteInetSocketAddress, connectTimeout);
_connectAction_();
}
@@ -457,6 +457,16 @@ public abstract class SocketClient {
return _socket_.getInetAddress();
}
+ /**
+ * Gets the remote socket address used for the connection.
+ * @return the remote socket address used for the connection
+ *
+ * @since 3.10.0
+ */
+ protected InetSocketAddress getRemoteInetSocketAddress() {
+ return remoteInetSocketAddress;
+ }
+
/**
* Returns the port number of the remote host to which the client is
connected. Delegates to {@link Socket#getPort()}
*
diff --git a/src/test/java/org/apache/commons/net/SocketClientTest.java
b/src/test/java/org/apache/commons/net/SocketClientTest.java
index b6ba96b4..d024496c 100644
--- a/src/test/java/org/apache/commons/net/SocketClientTest.java
+++ b/src/test/java/org/apache/commons/net/SocketClientTest.java
@@ -43,25 +43,12 @@ public class SocketClientTest {
private static final String UNRESOLVED_HOST = "unresolved";
private static final int REMOTE_PORT = 21;
- /**
- * A simple test to verify that the Proxy is being set.
- */
- @Test
- public void testProxySettings() {
- final SocketClient socketClient = new FTPClient();
- assertNull(socketClient.getProxy());
- final Proxy proxy = new Proxy(Proxy.Type.SOCKS, new
InetSocketAddress(PROXY_HOST, PROXY_PORT));
- socketClient.setProxy(proxy);
- assertEquals(proxy, socketClient.getProxy());
- assertFalse(socketClient.isConnected());
- }
-
@Test
public void testConnectResolved() {
final SocketClient socketClient = new FTPClient();
assertThrows(IOException.class, () ->
socketClient.connect(LOCALHOST_ADDRESS, REMOTE_PORT));
- final InetSocketAddress remoteAddress = socketClient._remoteAddress_;
+ final InetSocketAddress remoteAddress =
socketClient.getRemoteInetSocketAddress();
assertFalse(remoteAddress.isUnresolved());
assertEquals(LOCALHOST_ADDRESS, remoteAddress.getHostString());
assertEquals(REMOTE_PORT, remoteAddress.getPort());
@@ -72,9 +59,22 @@ public class SocketClientTest {
final SocketClient socketClient = new FTPClient();
assertThrows(UnknownHostException.class, () ->
socketClient.connect(UNRESOLVED_HOST, REMOTE_PORT, null, -1));
- final InetSocketAddress remoteAddress = socketClient._remoteAddress_;
+ final InetSocketAddress remoteAddress =
socketClient.getRemoteInetSocketAddress();
assertTrue(remoteAddress.isUnresolved());
assertEquals(UNRESOLVED_HOST, remoteAddress.getHostString());
assertEquals(REMOTE_PORT, remoteAddress.getPort());
}
+
+ /**
+ * A simple test to verify that the Proxy is being set.
+ */
+ @Test
+ public void testProxySettings() {
+ final SocketClient socketClient = new FTPClient();
+ assertNull(socketClient.getProxy());
+ final Proxy proxy = new Proxy(Proxy.Type.SOCKS, new
InetSocketAddress(PROXY_HOST, PROXY_PORT));
+ socketClient.setProxy(proxy);
+ assertEquals(proxy, socketClient.getProxy());
+ assertFalse(socketClient.isConnected());
+ }
}