Example usage for org.apache.commons.vfs2 FileSystemException getMessage

List of usage examples for org.apache.commons.vfs2 FileSystemException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileSystemException getMessage.

Prototype

@Override
public String getMessage() 

Source Link

Document

Retrieves message from bundle.

Usage

From source file:com.stratuscom.harvester.liaison.VirtualFileSystemConfiguration.java

/** Inject the working directory for this application  (which might actually
be a jar file).  This injection is//from   www. j a v  a2  s. c  o m
done using reflection by the ServiceStarterDeployer when the application
is setup.  This way, the Configuration can be loaded without any hard-coded
directories, etc.
@param workingDirectory
 */
public static void setWorkingDirectory(File workingDirectory) {
    /* Before we do anything, setup the class loader for the vfs manager.
     */

    setManagerClassLoader();
    try {
        if (workingDirectory.isDirectory()) {
            FileObject root = VFS.getManager().toFileObject(workingDirectory);
            VirtualFileSystemConfiguration.rootDirectory = root;
        } else { /* Try to create a virtual file system based on the file. */
            FileObject rootFileObject = VFS.getManager().toFileObject(workingDirectory);
            FileObject root = VFS.getManager().createFileSystem(Strings.JAR, rootFileObject);
            VirtualFileSystemConfiguration.rootDirectory = root;
        }
    } catch (FileSystemException ex) {
        /* Problem here is that we can't just throw the exception,
        because we expect to be called reflectively from code in a 
        different classloader, that won't have the exception class.
        So, we have to instead throw an exception that is part of the 
        jre platform.
         */
        log.log(Level.SEVERE, "Problem setting working directory", ex);
        ex.printStackTrace();
        throw new RuntimeException(ex.getMessage());
    }

}

From source file:com.stehno.sanctuary.core.remote.FileSystemRemoteStore.java

@Override
public void init() {
    Assert.isTrue(remoteDir.exists(), "Remote directory does not exist.");
    Assert.isTrue(remoteDir.canRead(), "Remote directory is not readable.");
    Assert.isTrue(remoteDir.canWrite(), "Remote directory is not writable.");

    try {/*from w ww  .jav a 2  s  .co  m*/
        this.fileSystemManager = VFS.getManager();
        this.remoteRoot = fileSystemManager.toFileObject(remoteDir);

    } catch (FileSystemException e) {
        log.fatal("Unable to retrieve filesystem manager: " + e.getMessage(), e);
    }

    if (log.isInfoEnabled())
        log.info("Initialized for: " + remoteRoot);
}

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/*  w ww  .  jav a 2 s.c  o m*/
 */
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:dslab.crawler.pack.CrawlerPack.java

public String getFromRemote(String uri) {

    // clear cache
    fileSystem.getFilesCache().close();//from ww  w  .  j  a  va 2 s.c  o m

    String remoteContent;
    String remoteEncoding = "utf-8";

    log.debug("Loading remote URI:" + uri);
    FileContent fileContent;

    try {
        // set cookie if cookies set
        if (0 < this.cookies.size()) {
            FileSystemOptions fsOptions = new FileSystemOptions();
            HttpFileSystemConfigBuilder.getInstance().setCookies(fsOptions, getCookies(uri));
            fileContent = fileSystem.resolveFile(uri, fsOptions).getContent();
        } else
            fileContent = fileSystem.resolveFile(uri).getContent();

        // 2016-03-22 only pure http/https auto detect encoding
        if ("http".equalsIgnoreCase(uri.substring(0, 4))) {
            fileContent.getSize(); // pass a bug {@link https://issues.apache.org/jira/browse/VFS-427}
            remoteEncoding = fileContent.getContentInfo().getContentEncoding();
        }

        if (null == remoteEncoding)
            remoteEncoding = "utf-8";

        if (!"utf".equalsIgnoreCase(remoteEncoding.substring(0, 3))) {
            log.debug("remote content encoding: " + remoteEncoding);

            // force charset encoding if setRemoteEncoding set
            if (!"utf".equalsIgnoreCase(encoding.substring(0, 3))) {
                remoteEncoding = encoding;
            } else {
                // auto detecting encoding
                remoteEncoding = detectCharset(IOUtils.toByteArray(fileContent.getInputStream()));
                log.info("real encoding: " + remoteEncoding);
            }
        }

        // 2016-02-29 fixed
        remoteContent = IOUtils.toString(fileContent.getInputStream(), remoteEncoding);

    } catch (FileSystemException fse) {
        log.warn(fse.getMessage());
        remoteContent = null;
    } catch (IOException ioe) {
        // return empty
        log.warn(ioe.getMessage());
        remoteContent = null;
    } catch (StringIndexOutOfBoundsException stre) {
        log.warn("uri: " + uri);
        log.warn(stre.getMessage());
        remoteContent = null;
    }

    clearCookies();

    // any exception will return "null"
    return remoteContent;
}

From source file:io.hops.hopsworks.api.zeppelin.util.ZeppelinResource.java

private FileObject[] getPidFiles(Project project) throws URISyntaxException, FileSystemException {
    ZeppelinConfig zepConf = zeppelinConfFactory.getProjectConf(project.getName());
    if (zepConf == null) {
        return new FileObject[0];
    }/*  w ww. ja  va 2  s  .co  m*/
    ZeppelinConfiguration conf = zepConf.getConf();
    URI filesystemRoot;
    FileSystemManager fsManager;
    String runPath = conf.getRelativeDir("run");
    try {
        filesystemRoot = new URI(runPath);
    } catch (URISyntaxException e1) {
        throw new URISyntaxException("Not a valid URI", e1.getMessage());
    }

    if (filesystemRoot.getScheme() == null) { // it is local path
        try {
            filesystemRoot = new URI(new File(runPath).getAbsolutePath());
        } catch (URISyntaxException e) {
            throw new URISyntaxException("Not a valid URI", e.getMessage());
        }
    }
    FileObject[] pidFiles = null;
    try {
        fsManager = VFS.getManager();
        //      pidFiles = fsManager.resolveFile(filesystemRoot.toString() + "/").
        pidFiles = fsManager.resolveFile(filesystemRoot.getPath()).getChildren();
    } catch (FileSystemException ex) {
        throw new FileSystemException("Directory not found: " + filesystemRoot.getPath(), ex.getMessage());
    }
    return pidFiles;
}

From source file:com.seeburger.vfs2.util.VFSClassLoader.java

/**
 * Calls super.getPermissions both for the code source and also
 * adds the permissions granted to the parent layers.
 * @param cs the CodeSource./*from   w  w w. java  2  s .  c o  m*/
 * @return The PermissionCollections.
 */
@Override
protected PermissionCollection getPermissions(final CodeSource cs) {
    try {
        final String url = cs.getLocation().toString();
        FileObject file = lookupFileObject(url);
        if (file == null) {
            return super.getPermissions(cs);
        }

        FileObject parentLayer = file.getFileSystem().getParentLayer();
        if (parentLayer == null) {
            return super.getPermissions(cs);
        }

        Permissions combi = new Permissions();
        PermissionCollection permCollect = super.getPermissions(cs);
        copyPermissions(permCollect, combi);

        for (FileObject parent = parentLayer; parent != null; parent = parent.getFileSystem()
                .getParentLayer()) {
            final CodeSource parentcs = new CodeSource(parent.getURL(), parent.getContent().getCertificates());
            permCollect = super.getPermissions(parentcs);
            copyPermissions(permCollect, combi);
        }

        return combi;
    } catch (final FileSystemException fse) {
        throw new SecurityException(fse.getMessage());
    }
}

From source file:com.flicklib.folderscanner.AdvancedFolderScanner.java

/**
 * Scans the folders/*from  w w  w  .ja v a 2  s  . com*/
 * 
 * @param folders
 * @return a List of MovieInfo
 *
 * TODO get rid of the synchronized and create a factory or pass all state data
 */
@Override
public synchronized List<FileGroup> scan(final Set<FileObject> folders, AsyncMonitor monitor) {
    movies = new ArrayList<FileGroup>();

    if (monitor != null) {
        monitor.start();
    }
    for (FileObject folder : folders) {
        try {
            URL url = folder.getURL();
            if (folder.exists()) {
                currentLabel = folder.getName().getBaseName();
                LOGGER.info("scanning " + url);
                try {
                    browse(folder, monitor);
                } catch (InterruptedException ie) {
                    LOGGER.info("task is cancelled!" + ie.getMessage());
                    return null;
                }
            } else {
                LOGGER.warn("folder " + folder.getURL() + " does not exist!");
            }
        } catch (FileSystemException e) {
            LOGGER.error("error during checking  " + folder + ", " + e.getMessage(), e);
        }
    }
    if (monitor != null) {
        monitor.finish();
    }
    return movies;
}

From source file:com.github.abola.crawler.CrawlerPack.java

/**
 * ?? Apache Common VFS  ???//from www .j  a  va  2  s .c o  m
 *
 * ??
 * @see <a href="https://commons.apache.org/proper/commons-vfs/filesystems.html">commons-vfs filesystems</a>
 */
public String getFromRemote(String uri) {

    // clear cache
    fileSystem.getFilesCache().close();

    String remoteContent;
    String remoteEncoding = "utf-8";

    log.debug("getFromRemote: Loading remote URI=" + uri);
    FileContent fileContent;

    try {

        FileSystemOptions fsOptions = new FileSystemOptions();
        // set userAgent
        HttpFileSystemConfigBuilder.getInstance().setUserAgent(fsOptions, userAgent);

        // set cookie if cookies set
        if (0 < this.cookies.size()) {
            HttpFileSystemConfigBuilder.getInstance().setCookies(fsOptions, getCookies(uri));
        }

        log.debug("getFromRemote: userAgent=" + userAgent);
        log.debug("getFromRemote: cookieSize=" + cookies.size());
        log.debug("getFromRemote: cookies=" + cookies.toString());

        fileContent = fileSystem.resolveFile(uri, fsOptions).getContent();

        // 2016-03-22 only pure http/https auto detect encoding
        if ("http".equalsIgnoreCase(uri.substring(0, 4))) {
            fileContent.getSize(); // pass a bug {@link https://issues.apache.org/jira/browse/VFS-427}
            remoteEncoding = fileContent.getContentInfo().getContentEncoding();
        }

        log.debug("getFromRemote: remoteEncoding=" + remoteEncoding + "(auto detect) ");

        // 2016-03-21 zip file getContentEncoding null
        if (null == remoteEncoding)
            remoteEncoding = "utf-8";

        if (!"utf".equalsIgnoreCase(remoteEncoding.substring(0, 3))) {
            log.debug("getFromRemote: remote content encoding=" + remoteEncoding);

            // force charset encoding if setRemoteEncoding set
            if (!"utf".equalsIgnoreCase(encoding.substring(0, 3))) {
                remoteEncoding = encoding;
            } else {
                // auto detecting encoding
                remoteEncoding = detectCharset(IOUtils.toByteArray(fileContent.getInputStream()));
                log.debug("getFromRemote: real encoding=" + remoteEncoding);
            }
        }

        // ??  Apache VFS ??
        // 2016-02-29 fixed
        remoteContent = IOUtils.toString(fileContent.getInputStream(), remoteEncoding);

    } catch (FileSystemException fse) {
        log.warn("getFromRemote: FileSystemException=" + fse.getMessage());
        remoteContent = null;
    } catch (IOException ioe) {
        // return empty
        log.warn("getFromRemote: IOException=" + ioe.getMessage());
        remoteContent = null;
    } catch (StringIndexOutOfBoundsException stre) {
        log.warn("getFromRemote: StringIndexOutOfBoundsException=" + stre.getMessage());
        log.warn("getFromRemote: uri=" + uri);
        log.warn(stre.getMessage());
        remoteContent = null;
    }

    clearCookies();

    log.debug("getFromRemote: remoteContent=\n" + remoteContent);
    // any exception will return "null"
    return remoteContent;
}

From source file:com.streamsets.pipeline.lib.remote.FTPRemoteConnector.java

@Override
public void verifyAndReconnect() throws StageException {
    boolean done = false;
    int retryCounter = 0;
    boolean reconnect = false;
    while (!done && retryCounter < MAX_RETRIES) {
        try {/*from   w  w  w .  j  a va2s.c om*/
            if (reconnect) {
                remoteDir = VFS.getManager().resolveFile(remoteURI.toString(), options);
                reconnect = false;
            }
            remoteDir.refresh();
            // A call to getChildren() and then refresh() is needed in order to properly refresh if files were updated
            // A possible bug in VFS?
            remoteDir.getChildren();
            remoteDir.refresh();
            done = true;
        } catch (FileSystemException fse) {
            // Refresh can fail due to session is down, a timeout, etc; so try getting a new connection
            if (retryCounter < MAX_RETRIES - 1) {
                LOG.info("Got FileSystemException when trying to refresh remote directory. '{}'",
                        fse.getMessage(), fse);
                LOG.warn("Retrying connection to remote directory");
                reconnect = true;
            } else {
                throw new StageException(Errors.REMOTE_09, fse.getMessage(), fse);
            }
        }
        retryCounter++;
    }
}

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

/**
 * Send the given message over the VFS transport
 *
 * @param msgCtx the axis2 message context
 * @throws AxisFault on error/*from  w  w w .j  a v  a 2s. c o m*/
 */
public void sendMessage(MessageContext msgCtx, String targetAddress, OutTransportInfo outTransportInfo)
        throws AxisFault {

    if (waitForSynchronousResponse(msgCtx)) {
        throw new AxisFault("The VFS transport doesn't support synchronous responses. "
                + "Please use the appropriate (out only) message exchange pattern.");
    }

    VFSOutTransportInfo vfsOutInfo = null;

    if (targetAddress != null) {
        vfsOutInfo = new VFSOutTransportInfo(targetAddress, globalFileLockingFlag);
    } else if (outTransportInfo != null && outTransportInfo instanceof VFSOutTransportInfo) {
        vfsOutInfo = (VFSOutTransportInfo) outTransportInfo;
    }

    if (vfsOutInfo != null) {
        FileObject replyFile = null;
        try {

            boolean wasError = true;
            int retryCount = 0;
            int maxRetryCount = vfsOutInfo.getMaxRetryCount();
            long reconnectionTimeout = vfsOutInfo.getReconnectTimeout();
            boolean append = vfsOutInfo.isAppend();

            while (wasError) {

                try {
                    retryCount++;
                    replyFile = fsManager.resolveFile(vfsOutInfo.getOutFileURI());

                    if (replyFile == null) {
                        log.error("replyFile is null");
                        throw new FileSystemException("replyFile is null");
                    }
                    wasError = false;

                } catch (FileSystemException e) {
                    log.error("cannot resolve replyFile", e);
                    if (maxRetryCount <= retryCount) {
                        handleException("cannot resolve replyFile repeatedly: " + e.getMessage(), e);
                    }
                }

                if (wasError) {
                    try {
                        Thread.sleep(reconnectionTimeout);
                    } catch (InterruptedException e2) {
                        e2.printStackTrace();
                    }
                }
            }

            if (replyFile.exists()) {

                if (replyFile.getType() == FileType.FOLDER) {
                    // we need to write a file containing the message to this folder
                    FileObject responseFile = fsManager.resolveFile(replyFile,
                            VFSUtils.getFileName(msgCtx, vfsOutInfo));

                    // if file locking is not disabled acquire the lock
                    // before uploading the file
                    if (vfsOutInfo.isFileLockingEnabled()) {
                        acquireLockForSending(responseFile, vfsOutInfo);
                        if (!responseFile.exists()) {
                            responseFile.createFile();
                        }
                        populateResponseFile(responseFile, msgCtx, append, true);
                        VFSUtils.releaseLock(fsManager, responseFile);
                    } else {
                        if (!responseFile.exists()) {
                            responseFile.createFile();
                        }
                        populateResponseFile(responseFile, msgCtx, append, false);
                    }

                } else if (replyFile.getType() == FileType.FILE) {

                    // if file locking is not disabled acquire the lock
                    // before uploading the file
                    if (vfsOutInfo.isFileLockingEnabled()) {
                        acquireLockForSending(replyFile, vfsOutInfo);
                        populateResponseFile(replyFile, msgCtx, append, true);
                        VFSUtils.releaseLock(fsManager, replyFile);
                    } else {
                        populateResponseFile(replyFile, msgCtx, append, false);
                    }

                } else {
                    handleException("Unsupported reply file type : " + replyFile.getType() + " for file : "
                            + vfsOutInfo.getOutFileURI());
                }
            } else {
                // if file locking is not disabled acquire the lock before uploading the file
                if (vfsOutInfo.isFileLockingEnabled()) {
                    acquireLockForSending(replyFile, vfsOutInfo);
                    replyFile.createFile();
                    populateResponseFile(replyFile, msgCtx, append, true);
                    VFSUtils.releaseLock(fsManager, replyFile);
                } else {
                    replyFile.createFile();
                    populateResponseFile(replyFile, msgCtx, append, false);
                }
            }
        } catch (FileSystemException e) {
            handleException("Error resolving reply file : " + vfsOutInfo.getOutFileURI(), e);
        } finally {
            if (replyFile != null) {
                try {
                    replyFile.close();
                } catch (FileSystemException ignore) {
                }
            }
        }
    } else {
        handleException("Unable to determine out transport information to send message");
    }
}