aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-dmaap-client/src
diff options
context:
space:
mode:
authorChengkai Yan <martin.c.yan@est.tech>2018-10-15 13:55:55 +0200
committerChengkai Yan <martin.c.yan@est.tech>2018-10-15 17:01:55 +0200
commit36ca816e964d2f5a4b3f4702e4a76a1104740fc8 (patch)
tree3363846a995ab6cce0d93a8cc9c4fdbf5c888b58 /datafile-dmaap-client/src
parentb47ed92edbf3b4f50b814a4b1912b5ef6185c294 (diff)
Improve setKeyManager & setTrustManager
Change-Id: I14b1bd6872e40496ce233ec4974ad9e5fd92d949 Signed-off-by: Chengkai Yan <martin.c.yan@est.tech> Issue-ID: DCAEGEN2-867
Diffstat (limited to 'datafile-dmaap-client/src')
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FTPSClientWrapper.java4
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java5
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java26
-rw-r--r--datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/IFTPSClient.java2
-rw-r--r--datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java1
5 files changed, 33 insertions, 5 deletions
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FTPSClientWrapper.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FTPSClientWrapper.java
index 77048042..2ccf1bab 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FTPSClientWrapper.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FTPSClientWrapper.java
@@ -89,4 +89,8 @@ public class FTPSClientWrapper implements IFTPSClient {
return ftpsClient.retrieveFile(remote, local);
}
+ @Override
+ public void setTimeout(Integer t) {
+ this.ftpsClient.setDefaultTimeout(t);
+ }
}
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
index 6cd048ac..c5962172 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectResult.java
@@ -36,7 +36,10 @@ public class FileCollectResult {
}
public String getErrorData() {
- return errorData.toString();
+ if (errorData != null) {
+ return errorData.toString();
+ }
+ return "";
}
@Override
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java
index a88072c7..120868c6 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java
@@ -57,6 +57,8 @@ public class FtpsClient extends FileCollectClient {
private IFile lf;
private IFileSystemResource fileResource;
private IOutputStream os;
+ private boolean keyManagerSet = false;
+ private boolean trustManagerSet = false;
@Override
public FileCollectResult retryCollectFile() {
@@ -84,19 +86,27 @@ public class FtpsClient extends FileCollectClient {
private boolean setUpKeyManager(IFTPSClient ftps) {
boolean result = true;
+ if (keyManagerSet) {
+ return result;
+ }
try {
IKeyManagerUtils keyManagerUtils = getKeyManagerUtils();
keyManagerUtils.setCredentials(keyCertPath, keyCertPassword);
ftps.setKeyManager(keyManagerUtils.getClientKeyManager());
+ keyManagerSet = true;
} catch (GeneralSecurityException | IOException e) {
addError("Unable to use own key store " + keyCertPath, e);
result = false;
}
+ logger.trace("complete setUpKeyManager");
return result;
}
private boolean setUpTrustedCA(IFTPSClient ftps) {
boolean result = true;
+ if (trustManagerSet) {
+ return result;
+ }
try {
IFileSystemResource fileSystemResource = getFileSystemResource();
fileSystemResource.setPath(trustedCAPath);
@@ -107,11 +117,13 @@ public class FtpsClient extends FileCollectClient {
ITrustManagerFactory tmf = getTrustManagerFactory();
tmf.init(ks.getKeyStore());
ftps.setTrustManager(tmf.getTrustManagers()[0]);
+ trustManagerSet = true;
} catch (Exception e) {
addError("Unable to trust xNF's CA, " + trustedCAPath, e);
result = false;
}
+ logger.trace("complete setUpTrustedCA");
return result;
}
@@ -119,7 +131,7 @@ public class FtpsClient extends FileCollectClient {
boolean result = true;
try {
ftps.connect(fileServerData.serverAddress(), fileServerData.port());
-
+ logger.trace("after ftp connect");
boolean loginSuccesful = ftps.login(fileServerData.userId(), fileServerData.password());
if (!loginSuccesful) {
ftps.logout();
@@ -135,7 +147,8 @@ public class FtpsClient extends FileCollectClient {
ftps.execPROT("P");
} else {
ftps.disconnect();
- addError("Unable to connect to xNF. " + fileServerData + "xNF reply code: " + ftps.getReplyCode(), null);
+ addError("Unable to connect to xNF. " + fileServerData + " xNF reply code: " + ftps.getReplyCode(),
+ null);
result = false;
}
} catch (Exception ex) {
@@ -157,8 +170,13 @@ public class FtpsClient extends FileCollectClient {
IOutputStream outputStream = getOutputStream();
OutputStream output = outputStream.getOutputStream(outfile.getFile());
- ftps.retrieveFile(remoteFile, output);
-
+ result = ftps.retrieveFile(remoteFile, output);
+ if (!result) {
+ output.close();
+ logger.debug("Unable to retrieve file from xNF. Cause unknown!");
+ addError("Unable to retrieve file from xNF. Cause unknown!", null);
+ return result;
+ }
output.close();
logger.debug("File {} Download Successfull from xNF", localFile);
} catch (IOException ex) {
diff --git a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/IFTPSClient.java b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/IFTPSClient.java
index 2f370b98..b1472026 100644
--- a/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/IFTPSClient.java
+++ b/datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/IFTPSClient.java
@@ -48,4 +48,6 @@ public interface IFTPSClient {
public void execPROT(String prot) throws IOException;
public boolean retrieveFile(String remote, OutputStream local) throws IOException;
+
+ void setTimeout(Integer t);
}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
index e9e00c38..e5693d50 100644
--- a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
+++ b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
@@ -102,6 +102,7 @@ public class FtpsClientTest {
when(localFileMock.getFile()).thenReturn(fileMock);
OutputStream osMock = mock(OutputStream.class);
when(outputStreamMock.getOutputStream(fileMock)).thenReturn(osMock);
+ when(ftpsClientMock.retrieveFile(REMOTE_FILE_PATH, osMock)).thenReturn(true);
ImmutableFileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(XNF_ADDRESS)
.userId(USERNAME).password(PASSWORD).port(PORT).build();