Package org.apache.camel.component.dropbox.util

Examples of org.apache.camel.component.dropbox.util.DropboxException


        } else if (this.configuration.getOperation() == DropboxOperation.get) {
            return new DropboxGetProducer(this, configuration);
        } else if (this.configuration.getOperation() == DropboxOperation.move) {
            return new DropboxMoveProducer(this, configuration);
        } else {
            throw new DropboxException("operation specified is not valid for producer!");
        }
    }
View Full Code Here


        } else if (this.configuration.getOperation() == DropboxOperation.get) {
            consumer = new DropboxScheduledPollGetConsumer(this, processor, configuration);
            consumer.setDelay(POLL_CONSUMER_DELAY);
            return consumer;
        } else {
            throw new DropboxException("operation specified is not valid for consumer!");
        }
    }
View Full Code Here

    public void createClient() throws DropboxException {
        DbxRequestConfig config =
                new DbxRequestConfig(clientIdentifier, Locale.getDefault().toString());
        DbxClient client = new DbxClient(config, accessToken);
        if (client == null) {
            throw new DropboxException("can't establish a Dropbox conenction!");
        }
        this.client = client;

    }
View Full Code Here

        String dropboxPath = remotePath == null ? localPath : remotePath;
        DbxEntry entry = null;
        try {
            entry = DropboxAPIFacade.client.getMetadata(dropboxPath);
        } catch (DbxException e) {
            throw new DropboxException(dropboxPath + " does not exist or can't obtain metadata");
        }
        File fileLocalPath = new File(localPath);
        //verify uploading of a single file
        if (fileLocalPath.isFile()) {
            //check if dropbox file exists
            if (entry != null && !entry.isFile()) {
                throw new DropboxException(dropboxPath + " exists on dropbox and is not a file!");
            }
            //in case the entry not exists on dropbox check if the filename should be appended
            if (entry == null) {
                if (dropboxPath.endsWith(DROPBOX_FILE_SEPARATOR)) {
                    dropboxPath = dropboxPath + fileLocalPath.getName();
                }
            }
            resultEntries = new HashMap<String, DropboxResultCode>(1);
            try {
                DbxEntry.File uploadedFile = putSingleFile(fileLocalPath, dropboxPath, mode);
                if (uploadedFile == null) {
                    resultEntries.put(dropboxPath, DropboxResultCode.KO);
                } else {
                    resultEntries.put(dropboxPath, DropboxResultCode.OK);
                }

            } catch (Exception ex) {
                resultEntries.put(dropboxPath, DropboxResultCode.KO);
            } finally {
                result.setResultEntries(resultEntries);
            }
            return result;
        } else {       //verify uploading of a list of files inside a dir
            LOG.info("uploading a dir...");
            //check if dropbox folder exists
            if (entry != null && !entry.isFolder()) {
                throw new DropboxException(dropboxPath + " exists on dropbox and is not a folder!");
            }
            if (!dropboxPath.endsWith(DROPBOX_FILE_SEPARATOR)) {
                dropboxPath = dropboxPath + DROPBOX_FILE_SEPARATOR;
            }
            //revert to old path
            String oldDropboxPath = dropboxPath;
            //list all files in a dir
            Collection<File> listFiles = FileUtils.listFiles(fileLocalPath, null, true);
            if (listFiles == null || listFiles.isEmpty()) {
                throw new DropboxException(localPath + " doesn't contain any files");
            }
            resultEntries = new HashMap<String, DropboxResultCode>(listFiles.size());
            for (File file : listFiles) {
                String absPath = file.getAbsolutePath();
                int indexRemainingPath = localPath.length();
View Full Code Here

        if (query == null) {
            LOG.info("search no query");
            try {
                listing = DropboxAPIFacade.client.getMetadataWithChildren(remotePath);
            } catch (DbxException e) {
                throw new DropboxException(remotePath + " does not exist or can't obtain metadata");
            }
            result.setResultEntries(listing.children);
        } else {
            LOG.info("search by query:" + query);
            List<DbxEntry> entries = null;
            try {
                entries = DropboxAPIFacade.client.searchFileAndFolderNames(remotePath, query);
            } catch (DbxException e) {
                throw new DropboxException(remotePath + " does not exist or can't obtain metadata");
            }
            result.setResultEntries(entries);
        }
        return result;
    }
View Full Code Here

    public DropboxResult del(String remotePath) throws DropboxException {
        DropboxResult result = null;
        try {
            DropboxAPIFacade.client.delete(remotePath);
        } catch (DbxException e) {
            throw new DropboxException(remotePath + " does not exist or can't obtain metadata");
        }
        result = new DropboxDelResult();
        result.setResultEntries(remotePath);
        return result;
    }
View Full Code Here

    public DropboxResult move(String remotePath, String newRemotePath) throws DropboxException {
        DropboxResult result = null;
        try {
            DropboxAPIFacade.client.move(remotePath, newRemotePath);
        } catch (DbxException e) {
            throw new DropboxException(remotePath + " does not exist or can't obtain metadata");
        }
        result = new DropboxMoveResult();
        result.setResultEntries(remotePath + "-" + newRemotePath);
        return result;
    }
View Full Code Here

    private void downloadFilesInFolder(String path, Map<String, ByteArrayOutputStream> resultEntries) throws DropboxException {
        DbxEntry.WithChildren listing = null;
        try {
            listing = DropboxAPIFacade.client.getMetadataWithChildren(path);
        } catch (DbxException e) {
            throw new DropboxException(path + " does not exist or can't obtain metadata");
        }
        if (listing.children == null) {
            LOG.info("downloading a single file...");
            downloadSingleFile(path, resultEntries);
            return;
View Full Code Here

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DbxEntry.File downloadedFile;
        try {
            downloadedFile = DropboxAPIFacade.client.getFile(path, null, baos);
        } catch (DbxException e) {
            throw new DropboxException(path + " does not exist or can't obtain metadata");
        } catch (IOException e) {
            throw new DropboxException(path + " can't obtain a stream");
        }
        if (downloadedFile != null) {
            resultEntries.put(path, baos);
            LOG.info("downloaded path:" + path + " - baos size:" + baos.size());
        }
View Full Code Here

        }
    }

    private static void validateCommonProperties(DropboxConfiguration configuration) throws DropboxException {
        if (configuration.getAccessToken() == null || configuration.getAccessToken().equals("")) {
            throw new DropboxException("option <accessToken> is not present or not valid!");
        }
        if (configuration.getClientIdentifier() == null || configuration.getClientIdentifier().equals("")) {
            throw new DropboxException("option <clientIdentifier> is not present or not valid!");
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.dropbox.util.DropboxException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.