public LocalFileModel( final String url, final HttpClientManager.HttpClientBuilderFacade clientBuilder, final String username, final String password, final String hostName, int port ) { if ( url == null ) { throw new NullPointerException(); } this.url = url; this.username = username; this.password = password; this.context = HttpClientContext.create(); if ( !StringUtil.isEmpty( hostName ) ) { // Preemptive Basic Authentication HttpHost target = new HttpHost( hostName, port, "http" ); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local // auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put( target, basicAuth ); // Add AuthCache to the execution context this.context.setAuthCache( authCache ); } clientBuilder.setCookieSpec( CookieSpecs.DEFAULT ); clientBuilder.setMaxRedirects( 10 ); clientBuilder.allowCircularRedirects(); clientBuilder.allowRelativeRedirect(); }
private FileSystem createWebFileSystem( final LayeredFileName genericRootName, final FileSystemOptions fileSystemOptions ) throws FileSystemException { final GenericFileName outerName = (GenericFileName) genericRootName.getOuterName(); String scheme = outerName.getScheme(); String hostName = outerName.getHostName(); int port = outerName.getPort(); String userName = outerName.getUserName(); String password = outerName.getPassword(); HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder(); if ( !StringUtil.isEmpty( hostName ) ) { clientBuilder.setProxy( hostName, port, scheme ); } if ( !StringUtil.isEmpty( userName ) ) { clientBuilder.setCredentials( userName, password ); } final PentahoSolutionsFileSystemConfigBuilder configBuilder = new PentahoSolutionsFileSystemConfigBuilder(); final int timeOut = configBuilder.getTimeOut( fileSystemOptions ); clientBuilder.setSocketTimeout( Math.max( 0, timeOut ) ); return new WebSolutionFileSystem( genericRootName, fileSystemOptions, new LocalFileModel( outerName.getURI(), clientBuilder, userName, password, hostName, port ) ); }
public HttpClientBuilderFacade createBuilder() { return new HttpClientBuilderFacade(); }
public HttpClientBuilderFacade setCredentials( String user, String password ) { return setCredentials( user, password, AuthScope.ANY ); }
public HttpClientBuilderFacade setProxy( String proxyHost, int proxyPort ) { setProxy( proxyHost, proxyPort, "http" ); return this; }