Package org.apache.camel.component.file

Examples of org.apache.camel.component.file.GenericFileOperationFailedException


            // Do an explicit test for a null body and decide what to do
            if (endpoint.isAllowNullBody()) {
                LOG.trace("Writing empty file.");
                is = new ByteArrayInputStream(new byte[]{});
            } else {
                throw new GenericFileOperationFailedException("Cannot write null body to file: " + name);
            }
        }

        try {
            channel = (ChannelExec) session.openChannel("exec");
            channel.setCommand(getScpCommand(cfg, file));
            channel.connect(timeout);
            LOG.trace("Channel connected to {}", cfg.remoteServerInformation());

            try {
                if (is == null) {
                    is = exchange.getIn().getMandatoryBody(InputStream.class);
                }
                write(channel, file, is, cfg);
            } catch (InvalidPayloadException e) {
                throw new GenericFileOperationFailedException("Cannot store file: " + name, e);
            } catch (IOException e) {
                throw new GenericFileOperationFailedException("Failed to write file " + file, e);
            } finally {
                // must close stream after usage
                IOHelper.close(is);
            }
        } catch (JSchException e) {
            throw new GenericFileOperationFailedException("Failed to write file " + file, e);
        } finally {
            if (channel != null) {
                LOG.trace("Disconnecting 'exec' scp channel");
                channel.disconnect();
                channel = null;
View Full Code Here


        return endpoint.getConfiguration().getDirectory();
    }

    @Override
    public void changeCurrentDirectory(String path) throws GenericFileOperationFailedException {
        throw new GenericFileOperationFailedException("Operation 'cd " + path + "' not supported by the scp: protocol");
    }
View Full Code Here

        throw new GenericFileOperationFailedException("Operation 'cd " + path + "' not supported by the scp: protocol");
    }

    @Override
    public void changeToParentDirectory() throws GenericFileOperationFailedException {
        throw new GenericFileOperationFailedException("Operation 'cd ..' not supported by the scp: protocol");
    }
View Full Code Here

        throw new GenericFileOperationFailedException("Operation 'cd ..' not supported by the scp: protocol");
    }

    @Override
    public List<ScpFile> listFiles() throws GenericFileOperationFailedException {
        throw new GenericFileOperationFailedException("Operation 'ls' not supported by the scp: protocol");
    }
View Full Code Here

        throw new GenericFileOperationFailedException("Operation 'ls' not supported by the scp: protocol");
    }

    @Override
    public List<ScpFile> listFiles(String path) throws GenericFileOperationFailedException {
        throw new GenericFileOperationFailedException("Operation 'ls " + path + "' not supported by the scp: protocol");
    }
View Full Code Here

        if (!isConnected()) {
            session = createSession(configuration instanceof ScpConfiguration ? (ScpConfiguration)configuration : null);
            // TODO: deal with reconnection attempts
            if (!isConnected()) {
                session = null;
                throw new GenericFileOperationFailedException("Failed to connect to " + configuration.remoteServerInformation());
            }
        }
        return true;
    }
View Full Code Here

        // First time for this aggregation
        if (oldExchange == null) {
            try {
                zipFile = FileUtil.createTempFile(this.filePrefix, this.fileSuffix);
            } catch (IOException e) {
                throw new GenericFileOperationFailedException(e.getMessage(), e);
            }
            DefaultEndpoint endpoint = (DefaultEndpoint) newExchange.getFromEndpoint();
            answer = endpoint.createExchange();
            answer.addOnCompletion(new DeleteZipFileOnCompletion(zipFile));
        } else {
            zipFile = oldExchange.getIn().getBody(File.class);
        }
       
        // Handle GenericFileMessages
        if (GenericFileMessage.class.isAssignableFrom(newExchange.getIn().getClass())) {
            try {
                File appendFile =  newExchange.getIn().getBody(File.class);
                if (appendFile != null) {
                    addFilesToZip(zipFile, new File[]{appendFile});
                    GenericFile<File> genericFile =
                        FileConsumer.asGenericFile(
                            zipFile.getParent(),
                            zipFile,
                            Charset.defaultCharset().toString());
                    genericFile.bindToExchange(answer);
                } else {
                    throw new GenericFileOperationFailedException("Could not get body as file.");
                }
            } catch (IOException e) {
                throw new GenericFileOperationFailedException(e.getMessage(), e);
            }
        } else {
            // Handle all other messages
            byte[] buffer = newExchange.getIn().getBody(byte[].class);
            try {
                addEntryToZip(zipFile, newExchange.getIn().getMessageId(), buffer, buffer.length);
                GenericFile<File> genericFile = FileConsumer.asGenericFile(
                    zipFile.getParent(), zipFile, Charset.defaultCharset().toString());
                genericFile.bindToExchange(answer);
            } catch (IOException e) {
                throw new GenericFileOperationFailedException(e.getMessage(), e);
            }
        }
       
        return answer;
    }
View Full Code Here

        public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {
        }

        public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause) throws Exception {
            GenericFileOperationFailedException e = assertIsInstanceOf(GenericFileOperationFailedException.class, cause);
            assertEquals(530, e.getCode());

            // stop the consumer
            consumer.stop();

            latch.countDown();
View Full Code Here

        this.endpoint = (ScpEndpoint)endpoint;
    }

    @Override
    public boolean deleteFile(String name) throws GenericFileOperationFailedException {
        throw new GenericFileOperationFailedException("Operation 'delete' not supported by the scp: protocol");
    }
View Full Code Here

        return false;
    }

    @Override
    public boolean renameFile(String from, String to) throws GenericFileOperationFailedException {
        throw new GenericFileOperationFailedException("Operation 'rename' not supported by the scp: protocol");
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.file.GenericFileOperationFailedException

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.