List of usage examples for org.apache.commons.vfs2.provider.ftp FtpFileSystemConfigBuilder setDataTimeout
public void setDataTimeout(final FileSystemOptions opts, final Integer dataTimeout)
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Sets the scheme.//from w w w .j a v a 2 s .c o m * * @param scheme the scheme * * @return the file system options * * @throws MotuException the motu exception */ public FileSystemOptions setSchemeOpts(String scheme, String host) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("setSchemeOpts(String, String) - start"); } if (Organizer.isNullOrEmpty(scheme)) { if (LOG.isDebugEnabled()) { LOG.debug("setSchemeOpts(String, String) - end"); } return opts; } if (opts == null) { opts = new FileSystemOptions(); } FileSystemConfigBuilder fscb = null; MotuConfigFileSystemWrapper<Boolean> wrapperBoolean = new MotuConfigFileSystemWrapper<Boolean>(); MotuConfigFileSystemWrapper<Period> wrapperPeriod = new MotuConfigFileSystemWrapper<Period>(); MotuConfigFileSystemWrapper<String> wrapperString = new MotuConfigFileSystemWrapper<String>(); try { try { fscb = standardFileSystemManager.getFileSystemConfigBuilder(scheme); } catch (FileSystemException e) { LOG.error("setSchemeOpts(String)", e); fscb = standardFileSystemManager.getFileSystemConfigBuilder(VFSManager.DEFAULT_SCHEME); } if (fscb instanceof FtpFileSystemConfigBuilder) { FtpFileSystemConfigBuilder ftpFscb = (FtpFileSystemConfigBuilder) fscb; Boolean userDirIsRoot = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_FTPUSERDIRISROOT); if (userDirIsRoot != null) { ftpFscb.setUserDirIsRoot(opts, userDirIsRoot); } else { ftpFscb.setUserDirIsRoot(opts, false); } Boolean passiveMode = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_FTPPASSIVEMODE); ; if (passiveMode != null) { ftpFscb.setPassiveMode(opts, passiveMode); } Period dataTimeOut = wrapperPeriod.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_FTPDATATIMEOUT); if (dataTimeOut != null) { long value = dataTimeOut.toStandardDuration().getMillis(); if (value > Integer.MAX_VALUE) { throw new MotuException(String.format( "Motu Configuration : sftp timeout value is too large '%ld' milliseconds. Max is '%d'", value, Integer.MAX_VALUE)); } if (value > 0) { ftpFscb.setDataTimeout(opts, (int) value); } } } if (fscb instanceof HttpFileSystemConfigBuilder) { HttpFileSystemConfigBuilder httpFscb = (HttpFileSystemConfigBuilder) fscb; Boolean isUseProxy = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_USEHTTPPROXY); if ((isUseProxy != null) && (isUseProxy)) { String proxyHost = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_HTTPPROXYHOST); String proxyPort = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_HTTPPROXYPORT); httpFscb.setProxyHost(opts, proxyHost); httpFscb.setProxyPort(opts, Integer.parseInt(proxyPort)); } } if (fscb instanceof SftpFileSystemConfigBuilder) { SftpFileSystemConfigBuilder sftpFscb = (SftpFileSystemConfigBuilder) fscb; Boolean userDirIsRoot = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_SFTPUSERDIRISROOT); if (userDirIsRoot != null) { sftpFscb.setUserDirIsRoot(opts, userDirIsRoot); } else { sftpFscb.setUserDirIsRoot(opts, false); } String strictHostKeyChecking = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_STRICTHOSTKEYCHECKING); if (strictHostKeyChecking != null) { sftpFscb.setStrictHostKeyChecking(opts, strictHostKeyChecking); } Period SftpSessionTimeOut = wrapperPeriod.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_SFTPSESSIONTIMEOUT); if (SftpSessionTimeOut != null) { long value = SftpSessionTimeOut.toStandardDuration().getMillis(); if (value > Integer.MAX_VALUE) { throw new MotuException(String.format( "Motu Configuration : sftp timeout value is too large '%ld' milliseconds. Max is '%d'", value, Integer.MAX_VALUE)); } if (value > 0) { sftpFscb.setTimeout(opts, (int) value); } } Boolean isUseProxy = wrapperBoolean.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_USESFTPPROXY); if ((isUseProxy != null) && (isUseProxy)) { String proxyHost = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_SFTPPROXYHOST); String proxyPort = wrapperString.getFieldValue(host, MotuConfigFileSystemWrapper.PROP_SFTPPROXYPORT); sftpFscb.setProxyHost(opts, proxyHost); sftpFscb.setProxyPort(opts, Integer.parseInt(proxyPort)); } } } catch (FileSystemException e) { LOG.error("setSchemeOpts(String, String)", e); throw new MotuException("Error in VFSManager#setScheme", e); } if (LOG.isDebugEnabled()) { LOG.debug("setSchemeOpts(String, String) - end"); } return opts; }