1 package fr.jayasoft.ivy.repository.vfs; 2 3 import java.io.IOException ; 4 5 import org.apache.commons.httpclient.HttpClient; 6 import org.apache.commons.httpclient.HttpURL; 7 import org.apache.commons.vfs.FileSystemException; 8 import org.apache.commons.vfs.FileSystemOptions; 9 import org.apache.commons.vfs.provider.webdav.WebdavConnectionManager; 10 import org.apache.commons.vfs.provider.webdav.WebdavFileSystemConfigBuilder; 11 import org.apache.webdav.lib.WebdavResource; 12 13 import fr.jayasoft.ivy.url.HttpClientHandler; 14 15 25 class IvyWebdavClientFactory { 26 27 private IvyWebdavClientFactory() { 28 } 29 30 33 public static HttpClient createConnection(String hostname, int port, String username, 34 String password, FileSystemOptions fileSystemOptions) throws FileSystemException { 35 HttpClient client; 37 try { 38 final HttpURL url = new HttpURL(username, password, hostname, port, "/"); 39 40 WebdavResource resource = new WebdavResource() { 42 }; 43 44 if (fileSystemOptions != null) { 45 String proxyHost = WebdavFileSystemConfigBuilder.getInstance().getProxyHost( 46 fileSystemOptions); 47 int proxyPort = WebdavFileSystemConfigBuilder.getInstance().getProxyPort( 48 fileSystemOptions); 49 50 if (proxyHost != null && proxyPort > 0) { 51 resource.setProxy(proxyHost, proxyPort); 53 } 54 } 55 56 60 resource.setHttpURL(url, WebdavResource.NOACTION, 1); 61 62 client = resource.retrieveSessionInstance(); 63 HttpClientHandler handler = new HttpClientHandler(); 64 int httpClientVersion = handler.getHttpClientMajorVersion(); 65 if (httpClientVersion == 2) { 66 client.setHttpConnectionManager(new WebdavConnectionManager()); 68 } else { 69 client.setHttpConnectionManager(new IvyWebdavConnectionManager()); 70 } 71 } catch (final IOException e) { 72 throw new FileSystemException("vfs.provider.webdav/connect.error", hostname, e); 73 } 74 75 return client; 76 } 77 } 78 | Popular Tags |