Author: rgoers Date: Tue Nov 2 14:03:42 2010 New Revision: 1030046 URL: http://svn.apache.org/viewvc?rev=1030046&view=rev Log: Fix VFS-315 and VFS-316. NullPointerExceptions in WebdavFileObject and adding preemptive authentication
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileProvider.java commons/proper/vfs/trunk/src/changes/changes.xml Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java?rev=1030046&r1=1030045&r2=1030046&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpClientFactory.java Tue Nov 2 14:03:42 2010 @@ -23,6 +23,7 @@ import org.apache.commons.httpclient.Use import org.apache.commons.httpclient.HttpConnectionManager; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.params.HttpConnectionManagerParams; +import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileSystemOptions; @@ -109,6 +110,12 @@ public final class HttpClientFactory client.getState().setProxyCredentials(null, proxyHost, proxyCreds); } + + if (builder.isPreemptiveAuth(fileSystemOptions)) { + HttpClientParams httpClientParams = new HttpClientParams(); + httpClientParams.setAuthenticationPreemptive(true); + client.setParams(httpClientParams); + } } Cookie[] cookies = builder.getCookies(fileSystemOptions); Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java?rev=1030046&r1=1030045&r2=1030046&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/http/HttpFileSystemConfigBuilder.java Tue Nov 2 14:03:42 2010 @@ -35,8 +35,10 @@ public class HttpFileSystemConfigBuilder private static final int DEFAULT_MAX_HOST_CONNECTIONS = 5; private static final int DEFAULT_MAX_CONNECTIONS = 50; - - protected HttpFileSystemConfigBuilder(String prefix) + + private static final String OPTION_NAME__PREEMPTIVE_AUTHENTICATION = "preemptiveAuth"; + + protected HttpFileSystemConfigBuilder(String prefix) { super(prefix); } @@ -205,7 +207,30 @@ public class HttpFileSystemConfigBuilder return getInteger(opts, HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, DEFAULT_MAX_HOST_CONNECTIONS); } - protected Class getConfigClass() + /** + * Determines if the FileSystemOptions indicate that preemptive + * authentication is requested. + * @param opts The FileSystemOptions. + * @return true if preemptiveAuth is requested. + */ + public boolean isPreemptiveAuth(FileSystemOptions opts) { + return getBoolean(opts, OPTION_NAME__PREEMPTIVE_AUTHENTICATION, Boolean.FALSE).booleanValue(); + } + + /** + * Sets the given value for preemptive HTTP authentication (using BASIC) on the + * given FileSystemOptions object. Defaults to false if not set. It may be + * appropriate to set to true in cases when the resulting chattiness of the + * conversation outweighs any architectural desire to use a stronger authentication + * scheme than basic/preemptive. + * @param opts The FileSystemOptions. + * @param preemptiveAuth the desired setting; true=enabled and false=disabled. + */ + public void setPreemptiveAuth(FileSystemOptions opts, boolean preemptiveAuth) { + setParam(opts, OPTION_NAME__PREEMPTIVE_AUTHENTICATION, Boolean.valueOf(preemptiveAuth)); + } + + protected Class getConfigClass() { return HttpFileSystem.class; } Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java?rev=1030046&r1=1030045&r2=1030046&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java Tue Nov 2 14:03:42 2010 @@ -296,7 +296,15 @@ public class WebdavFileObject extends Ht if (!attributes.containsKey(property.getName())) { property = getProperty(fileName, property.getName()); - attributes.put(property.getName().toString(), property.getValue()); + if (property != null) + { + Object name = property.getName(); + Object value = property.getValue(); + if (name != null && value != null) + { + attributes.put(name.toString(), value); + } + } } } return attributes; Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileProvider.java?rev=1030046&r1=1030045&r2=1030046&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileProvider.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/webdav/WebdavFileProvider.java Tue Nov 2 14:03:42 2010 @@ -72,8 +72,12 @@ public class WebdavFileProvider setFileNameParser(WebdavFileNameParser.getInstance()); } - /** - * Creates a {...@link FileSystem}. + /** + * Creates a {...@link FileSystem}. If you're looking at this method and wondering how to + * get a FileSystemOptions object bearing the proxy host and credentials configuration through + * to this method so it's used for resolving a {...@link FileObject} in the FileSystem, then be sure + * to use correct signature of the {...@link FileSystemManager} resolveFile method. + * @see org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(FileObject, String, FileSystemOptions). */ protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) throws FileSystemException Modified: commons/proper/vfs/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1030046&r1=1030045&r2=1030046&view=diff ============================================================================== --- commons/proper/vfs/trunk/src/changes/changes.xml (original) +++ commons/proper/vfs/trunk/src/changes/changes.xml Tue Nov 2 14:03:42 2010 @@ -23,6 +23,12 @@ <body> <release version="2.0" date="in SVN" description=""> + <action dev="rgoers" type="fix" issue="VFS-315" due-to="David Hausladen"> + Fix potential NullPointerException if the DavProperty is null or contains null values. + </action> + <action dev="rgoers" type="fix" issue="VFS-316" due-to="David Hausladen"> + Add option for preemptive authentication for HTTP based protocols. + </action> <action dev="rgoers" type="fix" issue="VFS-322" due-to="Curtis Boyden"> Allow tar files that contain files over 2GB in size. </action>