Example usage for org.apache.commons.vfs2.impl StandardFileSystemManager setConfiguration

List of usage examples for org.apache.commons.vfs2.impl StandardFileSystemManager setConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.impl StandardFileSystemManager setConfiguration.

Prototype

public void setConfiguration(final URL configUri) 

Source Link

Document

Sets the configuration file for this manager.

Usage

From source file:fr.cls.atoll.motu.processor.wps.TestVFS.java

public static void testBugDoReplicateFile() {

    StandardFileSystemManager standardFileSystemManager = new StandardFileSystemManager();
    standardFileSystemManager.setLogger(LogFactory.getLog(VFS.class));
    standardFileSystemManager.setClassLoader(TestVFS.class.getClassLoader());
    try {/* ww w .java2s.c  om*/
        URL configUrl = new URL(
                "file:/J:/dev/atoll-v2/atoll-motu/atoll-motu-library/src/main/resources/motuVFSProvider.xml");
        standardFileSystemManager.setConfiguration(configUrl);
        standardFileSystemManager.setCacheStrategy(CacheStrategy.ON_CALL);
        standardFileSystemManager.init();

        String uri = "jar:file:/C:/Documents%20and%20Settings/dearith/.m2/repository/org/jvnet/ogc/iso-19139-d_2006_05_04-schema/1.0.0-PATCH-CLS/iso-19139-d_2006_05_04-schema-1.0.0-PATCH-CLS.jar!/schema/iso19139";
        FileSystemOptions opts = new FileSystemOptions();

        FileObject fileObject = standardFileSystemManager.resolveFile(uri, opts);

    } catch (FileSystemException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:fr.cls.atoll.motu.library.misc.ftp.TestFtp.java

public static void testVFS(String user, String pwd, String scheme, String host, String file) {

    StandardFileSystemManager fsManager = null;

    try {/* w ww . j a  v  a 2s  .  c  o  m*/
        fsManager = new StandardFileSystemManager();
        fsManager.setLogger(_LOG);

        StaticUserAuthenticator auth = new StaticUserAuthenticator(null, user, pwd);

        fsManager.setConfiguration(ConfigLoader.getInstance().get(Organizer.getVFSProviderConfig()));
        fsManager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        // fsManager.addProvider("moi", new DefaultLocalFileProvider());
        fsManager.init();

        FileSystemOptions opts = new FileSystemOptions();
        FileSystemConfigBuilder fscb = fsManager.getFileSystemConfigBuilder(scheme);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

        System.out.println(fsManager.getProviderCapabilities(scheme));

        if (fscb instanceof FtpFileSystemConfigBuilder) {
            FtpFileSystemConfigBuilder ftpFscb = (FtpFileSystemConfigBuilder) fscb;
            ftpFscb.setUserDirIsRoot(opts, true);
            ftpFscb.setPassiveMode(opts, true);

        }
        if (fscb instanceof HttpFileSystemConfigBuilder) {
            HttpFileSystemConfigBuilder httpFscb = (HttpFileSystemConfigBuilder) fscb;
            httpFscb.setProxyHost(opts, "proxy.cls.fr");
            httpFscb.setProxyPort(opts, 8080);

        }
        if (fscb instanceof SftpFileSystemConfigBuilder) {
            SftpFileSystemConfigBuilder sftpFscb = (SftpFileSystemConfigBuilder) fscb;
            sftpFscb.setUserDirIsRoot(opts, false);

            // TrustEveryoneUserInfo trustEveryoneUserInfo = new TrustEveryoneUserInfo();
            // trustEveryoneUserInfo.promptYesNo("eddfsdfs");
            // sftpFscb.setUserInfo(opts, new TrustEveryoneUserInfo());
            sftpFscb.setTimeout(opts, 5000);
            // SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
            // SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");

        }
        // FileObject fo =
        // fsManager.resolveFile("ftp://ftp.cls.fr/pub/oceano/AVISO/NRT-SLA/maps/rt/j2/h/msla_rt_j2_err_21564.nc.gz",
        // opts);

        // String uri = String.format("%s://%s/%s", scheme, host, file);
        // String uri = String.format("%s://%s/", scheme, host);
        // FileObject originBase = fsManager.resolveFile(uri, opts);
        // fsManager.setBaseFile(originBase);

        File tempDir = new File("c:/tempVFS");
        // File tempFile = File.createTempFile("AsciiEnvisat", ".txt", tempDir);
        File hostFile = new File(file);
        String fileName = hostFile.getName();
        File newFile = new File(tempDir, fileName);
        newFile.createNewFile();

        DefaultFileReplicator dfr = new DefaultFileReplicator(tempDir);
        fsManager.setTemporaryFileStore(dfr);
        // System.out.println(fsManager.getBaseFile());
        // System.out.println(dfr);
        // System.out.println(fsManager.getTemporaryFileStore());

        // FileObject ff = fsManager.resolveFile("sftp://t:t@CLS-EARITH.pc.cls.fr/AsciiEnvisat.txt",
        // opts);
        String uri = String.format("%s://%s/%s", scheme, host, file);
        FileObject ff = fsManager.resolveFile(uri, opts);
        FileObject dest = fsManager.toFileObject(newFile);

        //ff.getContent().getInputStream();
        dest.copyFrom(ff, Selectors.SELECT_ALL);
        //dest.copyFrom(ff, Selectors.SELECT_ALL);

        //            
        // URL url = ff.getURL();
        //            
        // url.openConnection();
        // URLConnection conn = url.openConnection();
        // InputStream in = conn.getInputStream();
        // in.close();

        // InputStream in = ff.getContent().getInputStream();

    } catch (FileSystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MotuException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        // fsManager.close();
        // fsManager.freeUnusedResources();
    }

}

From source file:com.yenlo.synapse.transport.vfs.VFSTransportSender.java

/**
 * Initialize the VFS file system manager and be ready to send messages
 * @param cfgCtx the axis2 configuration context
 * @param transportOut the transport-out description
 * @throws AxisFault on error//from   www  .ja  va  2  s.c  om
 */
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {

    super.init(cfgCtx, transportOut);
    try {
        StandardFileSystemManager fsm = new StandardFileSystemManager();
        fsm.setConfiguration(getClass().getClassLoader().getResource("providers.xml"));
        fsm.init();
        fsManager = fsm;
        Parameter lckFlagParam = transportOut.getParameter(VFSConstants.TRANSPORT_FILE_LOCKING);
        if (lckFlagParam != null) {
            String strLockingFlag = lckFlagParam.getValue().toString();
            // by-default enabled, if explicitly specified as "disable" make it disable
            if (VFSConstants.TRANSPORT_FILE_LOCKING_DISABLED.equals(strLockingFlag)) {
                globalFileLockingFlag = false;
            }
        }
    } catch (FileSystemException e) {
        handleException("Error initializing the file transport : " + e.getMessage(), e);
    }
}

From source file:com.yenlo.synapse.transport.vfs.VFSTransportListener.java

@Override
protected void doInit() throws AxisFault {
    super.doInit();
    try {/* ww w  . ja va  2  s.  c  o m*/
        StandardFileSystemManager fsm = new StandardFileSystemManager();
        fsm.setConfiguration(getClass().getClassLoader().getResource("providers.xml"));
        fsm.init();
        this.workerPool = super.workerPool;
        fsManager = fsm;
        Parameter lockFlagParam = getTransportInDescription().getParameter(VFSConstants.TRANSPORT_FILE_LOCKING);
        if (lockFlagParam != null) {
            String strLockingFlag = lockFlagParam.getValue().toString();
            // by-default enabled, if explicitly specified as "disable" make it disable
            if (VFSConstants.TRANSPORT_FILE_LOCKING_DISABLED.equals(strLockingFlag)) {
                globalFileLockingFlag = false;
            }
        }
    } catch (FileSystemException e) {
        handleException("Error initializing the file transport : " + e.getMessage(), e);
    }
}

From source file:org.kalypso.commons.io.VFSUtilities.java

/**
 * This function returns a new private StandardFileSystemManager. It is the caller's responsibility to close the
 * manager and release any resources associated with its file systems.
 *///from w  ww  . ja  v  a  2 s  . c o  m
public static FileSystemManagerWrapper getNewManager() throws FileSystemException {
    // create new file system manager
    final StandardFileSystemManager fsManager = new StandardFileSystemManager();
    fsManager.setConfiguration(VFSUtilities.class.getResource("vfs-providers.xml")); //$NON-NLS-1$
    fsManager.init();

    configureManager(fsManager);

    return new FileSystemManagerWrapper(fsManager, FILE_SYSTEM_MANAGER_DELEGATE);
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.file.FilePollingConsumer.java

public FilePollingConsumer(Properties vfsProperties, String name, SynapseEnvironment synapseEnvironment,
        long scanInterval) {
    this.vfsProperties = vfsProperties;
    this.name = name;
    this.synapseEnvironment = synapseEnvironment;
    this.scanInterval = scanInterval;
    this.lastRanTime = null;

    setupParams();//from ww w.j  a  va 2  s .c  o  m
    try {
        StandardFileSystemManager fsm = new StandardFileSystemManager();
        fsm.setConfiguration(getClass().getClassLoader().getResource("providers.xml"));
        fsm.init();
        fsManager = fsm;
    } catch (Exception e) {
        log.error(e);
        throw new RuntimeException(e);
    }
    //Setup SFTP Options
    try {
        fso = VFSUtils.attachFileSystemOptions(parseSchemeFileOptions(fileURI), fsManager);
    } catch (Exception e) {
        log.warn("Unable to set the sftp Options", e);
        fso = null;
    }
}

From source file:org.wso2.carbon.transport.file.connector.server.FileConsumer.java

public FileConsumer(String id, Map<String, String> fileProperties, CarbonMessageProcessor messageProcessor)
        throws ServerConnectorException {
    this.serviceName = id;
    this.fileProperties = fileProperties;
    this.messageProcessor = messageProcessor;

    setupParams();/*from   w  w w  .  j a v  a 2s .c o m*/
    try {
        StandardFileSystemManager fsm = new StandardFileSystemManager();
        fsm.setConfiguration(getClass().getClassLoader().getResource("providers.xml"));
        fsm.init();
        fsManager = fsm;
    } catch (FileSystemException e) {
        throw new ServerConnectorException(
                "Could not initialize File System Manager from " + "the configuration: providers.xml", e);
    }
    Map<String, String> options = parseSchemeFileOptions(fileURI);
    fso = FileTransportUtils.attachFileSystemOptions(options, fsManager);

    if (options != null && Constants.SCHEME_FTP.equals(options.get(Constants.SCHEME))) {
        FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fso, true);
    }

    try {
        fileObject = fsManager.resolveFile(fileURI, fso);
    } catch (FileSystemException e) {
        throw new FileServerConnectorException(
                "Failed to resolve fileURI: " + FileTransportUtils.maskURLPassword(fileURI), e);
    }
}