/** @param timeout the timeout to set */ public void setTimeout(int timeout) { this.timeout = timeout; transferService.setTimeout(timeout); }
public Host( String server, String rootPath, Integer port, String user, String password, ProxyDetails proxyDetails, int timeoutMillis, Cache<Folder, List<Resource>> cache, FileSyncer fileSyncer) { super( (cache != null ? cache : new MemoryCache<Folder, List<Resource>>("resource-cache-default", 50, 20))); if (server == null) { throw new IllegalArgumentException("host name cannot be null"); } this.rootPath = rootPath; this.timeout = timeoutMillis; this.server = server; this.port = port; this.user = user; this.password = password; client = new DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSoTimeout(params, 10000); if (user != null) { client .getCredentialsProvider() .setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); PreemptiveAuthInterceptor interceptor = new PreemptiveAuthInterceptor(); client.addRequestInterceptor(interceptor); } HttpRequestRetryHandler handler = new DefaultHttpRequestRetryHandler(0, false); client.setHttpRequestRetryHandler(handler); if (proxyDetails != null) { if (proxyDetails.isUseSystemProxy()) { System.setProperty("java.net.useSystemProxies", "true"); } else { System.setProperty("java.net.useSystemProxies", "false"); if (proxyDetails.getProxyHost() != null && proxyDetails.getProxyHost().length() > 0) { HttpHost proxy = new HttpHost(proxyDetails.getProxyHost(), proxyDetails.getProxyPort(), "http"); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (proxyDetails.hasAuth()) { client .getCredentialsProvider() .setCredentials( new AuthScope(proxyDetails.getProxyHost(), proxyDetails.getProxyPort()), new UsernamePasswordCredentials( proxyDetails.getUserName(), proxyDetails.getPassword())); } } } } transferService = new TransferService(client, connectionListeners); transferService.setTimeout(timeoutMillis); this.fileSyncer = fileSyncer; }