List of usage examples for org.apache.commons.vfs2.provider.webdav WebdavFileSystemConfigBuilder getInstance
public static HttpFileSystemConfigBuilder getInstance()
From source file:maspack.fileutil.FileCacher.java
public static void setDefaultFsOptions(FileSystemOptions opts) throws FileSystemException { // SSH Defaults // Don't check host key // Use paths relative to root (as opposed to the user's home dir) // 10 second timeout SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000); /**/*from w w w.j a v a2s. co m*/ * Allow connection to silly UBC servers who don't update their credentials */ TrustStrategy[] ts = { new UnsafeTrustStrategy() }; HttpFileSystemConfigBuilder httpBuilder = HttpFileSystemConfigBuilder.getInstance(); WebdavFileSystemConfigBuilder webdavBuilder = WebdavFileSystemConfigBuilder.getInstance(); // allow all SSL connections httpBuilder.setTrustStrategies(opts, ts); webdavBuilder.setTrustStrategies(opts, ts); // silly deprecated UBC cipher suite String[] ciphers = httpBuilder.getDefaultSSLCipherSuites(); ciphers = Arrays.copyOf(ciphers, ciphers.length + 1); ciphers[ciphers.length - 1] = "SSL_RSA_WITH_RC4_128_SHA"; httpBuilder.setEnabledSSLCipherSuites(opts, ciphers); webdavBuilder.setEnabledSSLCipherSuites(opts, ciphers); }
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * This function will check the string for protocol, and if neccessary applys an proxy object to it. * * @param absoluteFile/*from ww w . j av a2s. c om*/ * The absolute file path to the file. It should be absolute, because this function was not testet against * relative files. * @return The file object. */ public static FileObject checkProxyFor(final String absoluteFile, final FileSystemManager fsManager) throws FileSystemException { final Proxy proxy = ProxyUtilities.getProxy(); KalypsoCommonsDebug.DEBUG.printf("Should use proxy: %s%n", String.valueOf(proxy.useProxy())); //$NON-NLS-1$ // TODO: VFS usually accepts file-pathes (without protocoll), but creating an url here will prohibit this. // TODO: handle file pathes differently if (proxy.useProxy() && !ProxyUtilities.isNonProxyHost(absoluteFile)) { final String proxyHost = proxy.getProxyHost(); final int proxyPort = proxy.getProxyPort(); KalypsoCommonsDebug.DEBUG.printf("Proxy host: %s%n", proxyHost); //$NON-NLS-1$ KalypsoCommonsDebug.DEBUG.printf("Proxy port: %s%n", String.valueOf(proxyPort)); //$NON-NLS-1$ /* Get the credentials. */ final String user = proxy.getUser(); final String password = proxy.getPassword(); final Pattern p = Pattern.compile("(.+)://.+"); //$NON-NLS-1$ final Matcher m = p.matcher(absoluteFile); if (m.find() == true) { KalypsoCommonsDebug.DEBUG.printf("File: %s%n", absoluteFile); //$NON-NLS-1$ KalypsoCommonsDebug.DEBUG.printf("Protocol: %s%n", m.group(1)); //$NON-NLS-1$ if (m.group(1).equals("webdav")) //$NON-NLS-1$ { WebdavFileSystemConfigBuilder.getInstance().setProxyHost(THE_WEBDAV_OPTIONS, proxyHost); WebdavFileSystemConfigBuilder.getInstance().setProxyPort(THE_WEBDAV_OPTIONS, proxyPort); /* If there are credentials given, set them. */ if (user != null && password != null) { final UserAuthenticator authenticator = new StaticUserAuthenticator(null, user, password); WebdavFileSystemConfigBuilder.getInstance().setProxyAuthenticator(THE_WEBDAV_OPTIONS, authenticator); } return fsManager.resolveFile(absoluteFile, THE_WEBDAV_OPTIONS); } else if (m.group(1).equals("http")) //$NON-NLS-1$ { HttpFileSystemConfigBuilder.getInstance().setProxyHost(THE_HTTP_OPTIONS, proxyHost); HttpFileSystemConfigBuilder.getInstance().setProxyPort(THE_HTTP_OPTIONS, proxyPort); /* If there are credentials given, set them. */ if (user != null && password != null) { final UserAuthenticator authenticator = new StaticUserAuthenticator(null, user, password); HttpFileSystemConfigBuilder.getInstance().setProxyAuthenticator(THE_HTTP_OPTIONS, authenticator); } return fsManager.resolveFile(absoluteFile, THE_HTTP_OPTIONS); } else if (m.group(1).equals("https")) //$NON-NLS-1$ { HttpFileSystemConfigBuilder.getInstance().setProxyHost(THE_HTTPS_OPTIONS, proxyHost); HttpFileSystemConfigBuilder.getInstance().setProxyPort(THE_HTTPS_OPTIONS, proxyPort); /* If there are credentials given, set them. */ if (user != null && password != null) { final UserAuthenticator authenticator = new StaticUserAuthenticator(null, user, password); HttpFileSystemConfigBuilder.getInstance().setProxyAuthenticator(THE_HTTPS_OPTIONS, authenticator); } return fsManager.resolveFile(absoluteFile, THE_HTTPS_OPTIONS); } } } return fsManager.resolveFile(absoluteFile); }