mock ftp
This commit is contained in:
parent
25cdca97e1
commit
f91e19e8f6
5
pom.xml
5
pom.xml
|
@ -60,6 +60,11 @@
|
|||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jaxen</groupId>
|
||||
<artifactId>jaxen</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.dom4j.Document;
|
||||
|
@ -83,8 +84,9 @@ public class Oai2FtpService {
|
|||
info.setExecutionStatus(ExecutionStatus.COMPLETED);
|
||||
} catch (final Throwable e) {
|
||||
info.setExecutionStatus(ExecutionStatus.FAILED);
|
||||
info.setMessage(e.getMessage());
|
||||
info.setMessage(e.getMessage() + ": " + ExceptionUtils.getStackTrace(e));
|
||||
} finally {
|
||||
info.setEnd(LocalDateTime.now());
|
||||
ftp.disconnect();
|
||||
collectionLogEntryRepository.save(SimpleUtils.infoToLog(info));
|
||||
}
|
||||
|
@ -134,7 +136,7 @@ public class Oai2FtpService {
|
|||
} else {
|
||||
return collectionLogEntryRepository.findById(jobId)
|
||||
.map(SimpleUtils::logToInfo)
|
||||
.orElse(null);
|
||||
.orElseThrow(() -> new RuntimeException("Invalid id: " + jobId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
|
@ -21,7 +22,9 @@ public class FtpClientWrapper {
|
|||
|
||||
private FTPClient ftpConnect(final String server, final boolean secure) {
|
||||
try {
|
||||
if (secure) {
|
||||
if (StringUtils.isBlank(server)) {
|
||||
return new MockFtpClient();
|
||||
} else if (secure) {
|
||||
final FTPSClient ftp = new FTPSClient();
|
||||
ftp.connect(server);
|
||||
// Set protection buffer size
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package eu.dnetlib.apps.oai2ftp.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
|
||||
public class MockFtpClient extends FTPClient {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MockFtpClient.class);
|
||||
|
||||
public MockFtpClient() {
|
||||
log.debug("MOCK FTP CLIENT - Constructor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean login(final String username, final String password) throws IOException {
|
||||
log.debug("MOCK FTP CLIENT - login: " + username + ", " + password);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
log.debug("MOCK FTP CLIENT - isConnected");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() throws IOException {
|
||||
log.debug("MOCK FTP CLIENT - disconnect");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setFileType(final int fileType) throws IOException {
|
||||
log.debug("MOCK FTP CLIENT - setFileType");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBufferSize(final int bufSize) {
|
||||
log.debug("MOCK FTP CLIENT - setBufferSize");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterLocalPassiveMode() {
|
||||
log.debug("MOCK FTP CLIENT - enterLocalPassiveMode");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean changeWorkingDirectory(final String pathname) throws IOException {
|
||||
log.debug("MOCK FTP CLIENT - changeWorkingDirectory: " + pathname);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean makeDirectory(final String pathname) throws IOException {
|
||||
log.debug("MOCK FTP CLIENT - makeDirectory: " + pathname);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storeFile(final String remote, final InputStream local) throws IOException {
|
||||
log.debug("MOCK FTP CLIENT - storeFile: " + remote);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReplyCode() {
|
||||
log.debug("MOCK FTP CLIENT - getReplyCode");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReplyString() {
|
||||
log.debug("MOCK FTP CLIENT - getReplyString");
|
||||
return "MOCK";
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ spring.jpa.hibernate.ddl-auto=update
|
|||
spring.jpa.properties.hibernate.format_sql=true
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||
|
||||
oai2ftp.conf.ftp.server = localhost
|
||||
oai2ftp.conf.ftp.server =
|
||||
oai2ftp.conf.ftp.user = test
|
||||
oai2ftp.conf.ftp.password = testPwd
|
||||
oai2ftp.conf.ftp.basedir = /oai
|
||||
|
|
Loading…
Reference in New Issue