Search in sources :

Example 1 with StandardFileSystemManager

use of org.apache.commons.vfs2.impl.StandardFileSystemManager in project wso2-synapse by wso2.

the class VFSTransportListener method doInit.

@Override
protected void doInit() throws AxisFault {
    super.doInit();
    try {
        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);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) Parameter(org.apache.axis2.description.Parameter)

Example 2 with StandardFileSystemManager

use of org.apache.commons.vfs2.impl.StandardFileSystemManager in project wso2-synapse by wso2.

the class VFSTransportSender method init.

/**
 * 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
 */
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;
            }
        }
        Parameter strAutoLock = transportOut.getParameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE);
        boolean autoLockRelease = false;
        boolean autoLockReleaseSameNode = true;
        Long autoLockReleaseInterval = null;
        if (strAutoLock != null && strAutoLock.getValue() != null && !strAutoLock.getValue().toString().isEmpty()) {
            try {
                autoLockRelease = Boolean.parseBoolean(strAutoLock.getValue().toString());
            } catch (Exception e) {
                autoLockRelease = false;
                log.warn("VFS Auto lock removal not set properly. Given value is : " + strAutoLock + ", defaults to - " + autoLockRelease, e);
            }
            if (autoLockRelease) {
                Parameter strAutoLockInterval = transportOut.getParameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_INTERVAL);
                if (strAutoLockInterval != null && strAutoLockInterval.getValue() != null && !strAutoLockInterval.getValue().toString().isEmpty()) {
                    try {
                        autoLockReleaseInterval = Long.parseLong(strAutoLockInterval.getValue().toString());
                    } catch (Exception e) {
                        autoLockReleaseInterval = null;
                        log.warn("VFS Auto lock release interval is not set properly. Given value is : " + strAutoLockInterval + ", defaults to - null", e);
                    }
                }
                Parameter strAutoLockReleaseSameNode = transportOut.getParameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_SAME_NODE);
                if (strAutoLockReleaseSameNode != null && strAutoLockReleaseSameNode.getValue() != null && !strAutoLockReleaseSameNode.getValue().toString().isEmpty()) {
                    try {
                        autoLockReleaseSameNode = Boolean.parseBoolean(strAutoLockReleaseSameNode.getValue().toString());
                    } catch (Exception e) {
                        autoLockReleaseSameNode = true;
                        log.warn("VFS Auto lock removal same node property not set properly. Given value is : " + autoLockReleaseSameNode + ", defaults to - " + autoLockReleaseSameNode, e);
                    }
                }
            }
        }
        vfsParamDTO = new VFSParamDTO();
        vfsParamDTO.setAutoLockRelease(autoLockRelease);
        vfsParamDTO.setAutoLockReleaseInterval(autoLockReleaseInterval);
        vfsParamDTO.setAutoLockReleaseSameNode(autoLockReleaseSameNode);
    } catch (FileSystemException e) {
        handleException("Error initializing the file transport : " + e.getMessage(), e);
    }
}
Also used : VFSParamDTO(org.apache.synapse.commons.vfs.VFSParamDTO) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) Parameter(org.apache.axis2.description.Parameter) IOException(java.io.IOException)

Example 3 with StandardFileSystemManager

use of org.apache.commons.vfs2.impl.StandardFileSystemManager in project Orthanc_Tools by salimkanoun.

the class ExportFiles method export.

public void export() {
    FileInputStream fis = null;
    try {
        File localFile = new File(this.filePath);
        switch(chosenOption) {
            case OPTION_FTP:
                FTPClient client = new FTPClient();
                client.connect(this.serverAdress, this.port);
                client.login(this.login, this.pwd);
                client.enterLocalPassiveMode();
                client.setFileType(FTPClient.BINARY_FILE_TYPE);
                String remoteFile = this.remotePath + this.remoteFileName;
                fis = new FileInputStream(localFile);
                client.storeFile(remoteFile, fis);
                client.logout();
                break;
            case OPTION_SFTP:
                StandardFileSystemManager manager = new StandardFileSystemManager();
                manager.init();
                FileObject localFileSFTP = manager.resolveFile(this.filePath);
                FileObject remoteFileSFTP = manager.resolveFile("sftp://" + this.login + ":" + this.pwd + "@" + this.serverAdress + ":" + this.port + this.remotePath + this.remoteFileName);
                // Copy local file to sftp server
                remoteFileSFTP.copyFrom(localFileSFTP, Selectors.SELECT_SELF);
                manager.close();
                break;
            case OPTION_WEBDAV:
                fis = new FileInputStream(localFile);
                Sardine sardine = SardineFactory.begin(this.login, this.pwd);
                sardine.put(this.serverAdress + this.remotePath + this.remoteFileName, fis);
                break;
            default:
                break;
        }
    } catch (IOException e) {
        // Getting the exception message, that we will give to VueAnon with getResult
        this.result = e.getMessage();
    } finally {
        try {
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : Sardine(com.github.sardine.Sardine) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 4 with StandardFileSystemManager

use of org.apache.commons.vfs2.impl.StandardFileSystemManager in project jackrabbit by apache.

the class VFSDataStore method createFileSystemManager.

/**
 * Creates a {@link FileSystemManager} instance.
 * @return a {@link FileSystemManager} instance.
 * @throws RepositoryException if an error occurs creating the manager.
 */
protected FileSystemManager createFileSystemManager() throws RepositoryException {
    FileSystemManager fileSystemManager = null;
    try {
        if (getFileSystemManagerClassName() == null) {
            fileSystemManager = new StandardFileSystemManager();
        } else {
            final Class<?> mgrClass = Class.forName(getFileSystemManagerClassName());
            fileSystemManager = (FileSystemManager) mgrClass.newInstance();
        }
        if (fileSystemManager instanceof DefaultFileSystemManager) {
            ((DefaultFileSystemManager) fileSystemManager).init();
        }
    } catch (final FileSystemException e) {
        throw new RepositoryException("Could not initialize file system manager of class: " + getFileSystemManagerClassName(), e);
    } catch (final Exception e) {
        throw new RepositoryException("Could not create file system manager of class: " + getFileSystemManagerClassName(), e);
    }
    return fileSystemManager;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) RepositoryException(javax.jcr.RepositoryException) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException)

Example 5 with StandardFileSystemManager

use of org.apache.commons.vfs2.impl.StandardFileSystemManager in project jackrabbit by apache.

the class VFSFileSystem method createFileSystemManager.

/**
 * Creates a {@link FileSystemManager} instance.
 * @return a {@link FileSystemManager} instance.
 * @throws FileSystemException if an error occurs creating the manager.
 */
protected FileSystemManager createFileSystemManager() throws FileSystemException {
    FileSystemManager fileSystemManager = null;
    try {
        if (getFileSystemManagerClassName() == null) {
            fileSystemManager = new StandardFileSystemManager();
        } else {
            final Class<?> mgrClass = Class.forName(getFileSystemManagerClassName());
            fileSystemManager = (FileSystemManager) mgrClass.newInstance();
        }
        if (fileSystemManager instanceof DefaultFileSystemManager) {
            ((DefaultFileSystemManager) fileSystemManager).init();
        }
    } catch (final Exception e) {
        throw new FileSystemException("Could not create file system manager of class: " + getFileSystemManagerClassName(), e);
    }
    return fileSystemManager;
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException)

Aggregations

StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)6 IOException (java.io.IOException)5 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 RepositoryException (javax.jcr.RepositoryException)2 Parameter (org.apache.axis2.description.Parameter)2 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)2 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)2 Sardine (com.github.sardine.Sardine)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FTPClient (org.apache.commons.net.ftp.FTPClient)1 FileObject (org.apache.commons.vfs2.FileObject)1 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)1 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)1 VFSParamDTO (org.apache.synapse.commons.vfs.VFSParamDTO)1