NIFI-12188 Upgraded Commons Net from 3.9.0 to 3.10.0

- Removed ProxyFTPClient extension of standard FTPClient no longer required following changes implemented in NET-650

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #7855.
This commit is contained in:
exceptionfactory 2023-10-06 08:23:27 -05:00 committed by Pierre Villard
parent a584251f0a
commit 457973d133
No known key found for this signature in database
GPG Key ID: F92A93B30C07C6D5
4 changed files with 4 additions and 139 deletions

View File

@ -1,55 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.processors.standard.ftp;
import org.apache.commons.net.ftp.FTPClient;
import javax.net.SocketFactory;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Objects;
/**
* Proxy extension of FTP Client supporting connections using unresolved addresses
*/
public class ProxyFTPClient extends FTPClient {
/**
* Proxy FTP Client constructor with required Socket Factory configured for proxy access
*
* @param socketFactory Socket Factory
*/
public ProxyFTPClient(final SocketFactory socketFactory) {
setSocketFactory(Objects.requireNonNull(socketFactory, "Socket Factory required"));
}
/**
* Connect using host and port without attempting DNS resolution using InetAddress.getByName()
*
* @param host FTP host
* @param port FTP port number
* @throws IOException Thrown when failing to complete a socket connection
*/
@Override
public void connect(final String host, final int port) throws IOException {
final InetSocketAddress socketAddress = new InetSocketAddress(host, port);
_socket_ = _socketFactory_.createSocket();
_socket_.connect(socketAddress, connectTimeout);
_connectAction_();
}
}

View File

@ -172,12 +172,10 @@ public class StandardFTPClientProvider implements FTPClientProvider {
final Proxy.Type proxyType = proxyConfiguration.getProxyType();
FTPClient client;
if (Proxy.Type.DIRECT == proxyType) {
client = new FTPClient();
} else {
final FTPClient client = new FTPClient();
if (Proxy.Type.HTTP == proxyType || Proxy.Type.SOCKS == proxyType) {
final SocketFactory socketFactory = SOCKET_FACTORY_PROVIDER.getSocketFactory(proxyConfiguration);
client = new ProxyFTPClient(socketFactory);
client.setSocketFactory(socketFactory);
// Disable NAT workaround for proxy connections
client.setPassiveNatWorkaroundStrategy(null);
}

View File

@ -1,78 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.processors.standard.ftp;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import javax.net.SocketFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class ProxyFTPClientTest {
@Mock
private SocketFactory socketFactory;
@Mock
private Socket socket;
@Captor
private ArgumentCaptor<InetSocketAddress> socketAddressCaptor;
private static final String HOST = "host.unresolved";
private static final String WELCOME_REPLY = "220 Welcome";
private ProxyFTPClient client;
@BeforeEach
public void setClient() {
client = new ProxyFTPClient(socketFactory);
}
@Test
public void testConnect() throws IOException {
when(socketFactory.createSocket()).thenReturn(socket);
when(socket.getInputStream()).thenReturn(new ByteArrayInputStream(WELCOME_REPLY.getBytes(StandardCharsets.US_ASCII)));
when(socket.getOutputStream()).thenReturn(new ByteArrayOutputStream());
client.connect(HOST, 0);
verify(socket).connect(socketAddressCaptor.capture(), anyInt());
final InetSocketAddress socketAddress = socketAddressCaptor.getValue();
assertNotNull(socketAddress);
assertEquals(HOST, socketAddress.getHostString());
assertEquals(0, socketAddress.getPort());
}
}

View File

@ -113,7 +113,7 @@
<org.apache.commons.codec.version>1.16.0</org.apache.commons.codec.version>
<org.apache.commons.compress.version>1.24.0</org.apache.commons.compress.version>
<org.apache.commons.lang3.version>3.13.0</org.apache.commons.lang3.version>
<org.apache.commons.net.version>3.9.0</org.apache.commons.net.version>
<org.apache.commons.net.version>3.10.0</org.apache.commons.net.version>
<org.apache.commons.io.version>2.14.0</org.apache.commons.io.version>
<org.apache.commons.text.version>1.10.0</org.apache.commons.text.version>
<org.apache.httpcomponents.httpclient.version>4.5.14</org.apache.httpcomponents.httpclient.version>