use of org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder in project artisynth_core by artisynth.
the class FileCacher method setDefaultFsOptions.
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);
/**
* 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);
}
use of org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder in project commons-vfs by apache.
the class HttpClientFactory method createConnection.
/**
* Creates a new connection to the server.
*
* @param builder The HttpFileSystemConfigBuilder.
* @param scheme The protocol.
* @param hostname The hostname.
* @param port The port number.
* @param username The username.
* @param password The password
* @param fileSystemOptions The file system options.
* @return a new HttpClient connection.
* @throws FileSystemException if an error occurs.
* @since 2.0
*/
public static HttpClient createConnection(final HttpFileSystemConfigBuilder builder, final String scheme, final String hostname, final int port, final String username, final String password, final FileSystemOptions fileSystemOptions) throws FileSystemException {
final HttpClient client;
try {
final HttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
final HttpConnectionManagerParams connectionMgrParams = mgr.getParams();
client = new HttpClient(mgr);
final HostConfiguration config = new HostConfiguration();
config.setHost(hostname, port, scheme);
if (fileSystemOptions != null) {
final String proxyHost = builder.getProxyHost(fileSystemOptions);
final int proxyPort = builder.getProxyPort(fileSystemOptions);
if (!StringUtils.isEmpty(proxyHost) && proxyPort > 0) {
config.setProxy(proxyHost, proxyPort);
}
final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions);
if (proxyAuth != null) {
final UserAuthenticationData authData = UserAuthenticatorUtils.authenticate(proxyAuth, new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD });
if (authData != null) {
final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials(UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)), UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null)));
final AuthScope scope = new AuthScope(proxyHost, AuthScope.ANY_PORT);
client.getState().setProxyCredentials(scope, proxyCreds);
}
if (builder.isPreemptiveAuth(fileSystemOptions)) {
final HttpClientParams httpClientParams = new HttpClientParams();
httpClientParams.setAuthenticationPreemptive(true);
client.setParams(httpClientParams);
}
}
final Cookie[] cookies = builder.getCookies(fileSystemOptions);
if (cookies != null) {
client.getState().addCookies(cookies);
}
}
/*
* ConnectionManager set methods must be called after the host & port and proxy host & port are set in the
* HostConfiguration. They are all used as part of the key when HttpConnectionManagerParams tries to locate
* the host configuration.
*/
connectionMgrParams.setMaxConnectionsPerHost(config, builder.getMaxConnectionsPerHost(fileSystemOptions));
connectionMgrParams.setMaxTotalConnections(builder.getMaxTotalConnections(fileSystemOptions));
connectionMgrParams.setConnectionTimeout(DurationUtils.toMillisInt(builder.getConnectionTimeoutDuration(fileSystemOptions)));
connectionMgrParams.setSoTimeout(DurationUtils.toMillisInt(builder.getSoTimeoutDuration(fileSystemOptions)));
client.setHostConfiguration(config);
if (username != null) {
final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
final AuthScope scope = new AuthScope(hostname, AuthScope.ANY_PORT);
client.getState().setCredentials(scope, creds);
}
} catch (final Exception exc) {
throw new FileSystemException("vfs.provider.http/connect.error", exc, hostname);
}
return client;
}
use of org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder in project commons-vfs by apache.
the class HttpsGetContentInfoFunctionalTest method getOptionsWithProxy.
FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
// get proxy host and port from env var "https_proxy"
String proxyHost = null;
int proxyPort = -1;
final String proxyUrl = System.getenv("https_proxy");
if (proxyUrl != null) {
final URL url = new URL(proxyUrl);
proxyHost = url.getHost();
proxyPort = url.getPort();
}
// return null if proxy host or port invalid
if (proxyHost == null || proxyPort == -1) {
return null;
}
// return options with proxy
final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
final FileSystemOptions opts = new FileSystemOptions();
builder.setProxyHost(opts, proxyHost);
builder.setProxyPort(opts, proxyPort);
return opts;
}
use of org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder in project commons-vfs by apache.
the class HttpGetContentInfoFunctionalTest method getOptionsWithProxy.
FileSystemOptions getOptionsWithProxy() throws MalformedURLException {
// get proxy host and port from env var "https_proxy"
String proxyHost = null;
int proxyPort = -1;
final String proxyUrl = System.getenv("https_proxy");
if (proxyUrl != null) {
final URL url = new URL(proxyUrl);
proxyHost = url.getHost();
proxyPort = url.getPort();
}
// return null if proxy host or port invalid
if (proxyHost == null || proxyPort == -1) {
return null;
}
// return options with proxy
final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
final FileSystemOptions opts = new FileSystemOptions();
builder.setProxyHost(opts, proxyHost);
builder.setProxyPort(opts, proxyPort);
return opts;
}
use of org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder in project commons-vfs by apache.
the class HttpProviderTestCase method testHttpTimeoutConfig.
/**
* Ensure VFS-453 options are present.
*/
@Test
public void testHttpTimeoutConfig() {
final FileSystemOptions options = new FileSystemOptions();
final HttpFileSystemConfigBuilder builder = HttpFileSystemConfigBuilder.getInstance();
// ensure defaults are 0
assertEquals(0, builder.getConnectionTimeout(options));
assertEquals(0, builder.getConnectionTimeoutDuration(options).toMillis());
assertEquals(0, builder.getSoTimeout(options));
assertEquals("Jakarta-Commons-VFS", builder.getUserAgent(options));
// Set with deprecated milliseconds APIs.
builder.setConnectionTimeout(options, 60000);
builder.setSoTimeout(options, 60000);
builder.setUserAgent(options, "foo/bar");
// ensure changes are visible
assertEquals(60000, builder.getConnectionTimeout(options));
assertEquals(ONE_MINUTE, builder.getConnectionTimeoutDuration(options));
assertEquals(60000, builder.getSoTimeout(options));
assertEquals("foo/bar", builder.getUserAgent(options));
// Set with Duration APIs.
builder.setConnectionTimeout(options, ONE_MINUTE);
builder.setSoTimeout(options, ONE_MINUTE);
// ensure changes are visible
assertEquals(60000, builder.getConnectionTimeout(options));
assertEquals(ONE_MINUTE, builder.getConnectionTimeoutDuration(options));
assertEquals(60000, builder.getSoTimeout(options));
assertEquals(ONE_MINUTE, builder.getSoTimeoutDuration(options));
assertEquals("foo/bar", builder.getUserAgent(options));
// TODO: should also check the created HTTPClient
}
Aggregations