из-за политики безопасности нашей компании я не могу установить пароль FTP-сервера в простых файлах свойств. Для этого я хочу получить соединение через JNDI. Наш сервер поддерживает протокол FTPS, поэтому я использовал класс org.apache.commons.net.ftp.FTPSClient
.
но проблема в том, как я могу получить доступ к FTPSClient
через JNDI
ресурс FTP моего tomcat
<Resource name="url/ftpService"
auth="Container"
type="org.apache.commons.net.ftp.FTPSClient"
factory="URLFactory"
username="usr" password="encyrepte_pass"
url="host" />
URLFactory
public class URLFactory implements ObjectFactory {
private Encryptor encryptor = null;
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
FTPSClient ftpClient = new FTPSClient(false);
try {
//decrept pass...
ftpClient.connect(host, port);
int reply = ftpClient.getReplyCode();
if (FTPReply.isPositiveCompletion(reply)) {
if (ftpClient.login(username, password)) {
ftpClient.execPBSZ(0);
ftpClient.execPROT("P");
ftpClient.enterLocalPassiveMode();
} else {
System.out.println("FTP login failed");
}
} else {
System.out.println("FTP connect to host failed");
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return ftpClient;
}
}
в моем приложении
web.xml
<resource-ref>
<res-ref-name>ftp/ftpService</res-ref-name>
<res-type>org.apache.commons.net.ftp.FTPClient</res-type>
<res-auth>Container</res-auth>
</resource-ref>
пружина
<bean id="urlFtpResource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="url/ftpService"/>
<property name="resourceRef" value="true"/>
</bean>
мое исключение
Could not convert constructor argument value of type [org.apache.commons.net.ftp.FTPSClient] to required type [java.net.URL]
через кого можно получить FTPSClient в качестве URL ресурсов JNDI?