Search in sources :

Example 1 with WebdavFileSystemConfigBuilder

use of org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder 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);
}
Also used : TrustStrategy(org.apache.http.ssl.TrustStrategy) HttpFileSystemConfigBuilder(org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder) WebdavFileSystemConfigBuilder(org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder)

Example 2 with WebdavFileSystemConfigBuilder

use of org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder in project commons-vfs by apache.

the class WebdavVersioningTests method testVersioning.

@Test
public void testVersioning() throws Exception {
    final FileObject scratchFolder = createScratchFolder();
    final FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
    final WebdavFileSystemConfigBuilder builder = (WebdavFileSystemConfigBuilder) getManager().getFileSystemConfigBuilder("webdav");
    builder.setVersioning(opts, true);
    final FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
    final FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
    assertSame(opts, newOpts);
    assertTrue(builder.isVersioning(newOpts));
    assertFalse(file.exists());
    file.createFile();
    assertTrue(file.exists());
    assertSame(FileType.FILE, file.getType());
    assertTrue(file.isFile());
    assertEquals(0, file.getContent().getSize());
    assertTrue(file.getContent().isEmpty());
    assertFalse(file.isExecutable());
    assertFalse(file.isHidden());
    assertTrue(file.isReadable());
    assertTrue(file.isWriteable());
    Map<?, ?> map = file.getContent().getAttributes();
    final String name = ((URLFileName) file.getName()).getUserName();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
    // Create the source file
    final String content = "Here is some sample content for the file.  Blah Blah Blah.";
    try (OutputStream os = file.getContent().getOutputStream()) {
        os.write(content.getBytes(StandardCharsets.UTF_8));
    }
    assertSameContent(content, file);
    map = file.getContent().getAttributes();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertEquals(name, map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
    builder.setVersioning(opts, false);
}
Also used : URLFileName(org.apache.commons.vfs2.provider.URLFileName) OutputStream(java.io.OutputStream) FileObject(org.apache.commons.vfs2.FileObject) WebdavFileSystemConfigBuilder(org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 3 with WebdavFileSystemConfigBuilder

use of org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder in project commons-vfs by apache.

the class WebdavProviderTestCase method getBaseTestFolder.

/**
 * Returns the base folder for tests.
 */
@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
    String uri = getSystemTestUriOverride();
    if (uri == null) {
        uri = ConnectionUri;
    }
    final WebdavFileSystemConfigBuilder builder = (WebdavFileSystemConfigBuilder) manager.getFileSystemConfigBuilder("webdav");
    final FileSystemOptions opts = new FileSystemOptions();
    builder.setRootURI(opts, uri);
    return manager.resolveFile(uri, opts);
}
Also used : WebdavFileSystemConfigBuilder(org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 4 with WebdavFileSystemConfigBuilder

use of org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder in project commons-vfs by apache.

the class WebdavVersioningTests method testVersioningWithCreator.

@Test
public void testVersioningWithCreator() throws Exception {
    final FileObject scratchFolder = createScratchFolder();
    final FileSystemOptions opts = scratchFolder.getFileSystem().getFileSystemOptions();
    final WebdavFileSystemConfigBuilder builder = (WebdavFileSystemConfigBuilder) getManager().getFileSystemConfigBuilder("webdav");
    builder.setVersioning(opts, true);
    builder.setCreatorName(opts, "testUser");
    final FileObject file = getManager().resolveFile(scratchFolder, "file1.txt", opts);
    final FileSystemOptions newOpts = file.getFileSystem().getFileSystemOptions();
    assertSame(opts, newOpts);
    assertTrue(builder.isVersioning(newOpts));
    assertFalse(file.exists());
    file.createFile();
    assertTrue(file.exists());
    assertSame(FileType.FILE, file.getType());
    assertTrue(file.isFile());
    assertEquals(0, file.getContent().getSize());
    assertTrue(file.getContent().isEmpty());
    assertFalse(file.isExecutable());
    assertFalse(file.isHidden());
    assertTrue(file.isReadable());
    assertTrue(file.isWriteable());
    Map<?, ?> map = file.getContent().getAttributes();
    final String name = ((URLFileName) file.getName()).getUserName();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    assertEquals("testUser", map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
        assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
    // Create the source file
    final String content = "Here is some sample content for the file.  Blah Blah Blah.";
    try (OutputStream os = file.getContent().getOutputStream()) {
        os.write(content.getBytes(StandardCharsets.UTF_8));
    }
    assertSameContent(content, file);
    map = file.getContent().getAttributes();
    assertTrue(map.containsKey(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    assertEquals("testUser", map.get(DeltaVConstants.CREATOR_DISPLAYNAME.toString()));
    if (name != null) {
        assertTrue(map.containsKey(DeltaVConstants.COMMENT.toString()));
        assertEquals("Modified by user " + name, map.get(DeltaVConstants.COMMENT.toString()));
    }
    assertTrue(map.containsKey(VersionControlledResource.CHECKED_IN.toString()));
    builder.setVersioning(opts, false);
    builder.setCreatorName(opts, null);
}
Also used : URLFileName(org.apache.commons.vfs2.provider.URLFileName) OutputStream(java.io.OutputStream) FileObject(org.apache.commons.vfs2.FileObject) WebdavFileSystemConfigBuilder(org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Aggregations

WebdavFileSystemConfigBuilder (org.apache.commons.vfs2.provider.webdav.WebdavFileSystemConfigBuilder)4 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)3 OutputStream (java.io.OutputStream)2 FileObject (org.apache.commons.vfs2.FileObject)2 URLFileName (org.apache.commons.vfs2.provider.URLFileName)2 Test (org.junit.Test)2 HttpFileSystemConfigBuilder (org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder)1 TrustStrategy (org.apache.http.ssl.TrustStrategy)1