Example usage for javax.resource ResourceException getCause

List of usage examples for javax.resource ResourceException getCause

Introduction

In this page you can find the example usage for javax.resource ResourceException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.ikasan.connector.basefiletransfer.outbound.command.DeliverFileCommand.java

@Override
protected ExecutionOutput performExecute() throws ResourceException {
    boolean changeDirectory = false;
    logger.info("execute called on this command: [" + this + "]"); //$NON-NLS-1$ //$NON-NLS-2$

    String originalDirectory = printWorkingDirectoryName();
    if (!this.outputDirectory.equals(".") && !this.outputDirectory.equals(originalDirectory)) {
        try {/*w w  w . j  a  va 2 s .c o  m*/
            changeDirectory(this.outputDirectory);
            changeDirectory = true;
        } catch (ResourceException e) {
            if (this.createParentDirectory && e.getCause() instanceof ClientCommandCdException) {
                logger.warn("Failed to change directory, creating missing parent directories...");
                try {
                    getClient().mkdir(this.outputDirectory);
                    changeDirectory(this.outputDirectory);
                    changeDirectory = true;
                } catch (ClientCommandMkdirException e1) {
                    throw new ResourceException(e1);
                }
            } else {
                throw e;
            }
        }
    }

    BaseFileTransferMappedRecord mappedRecord = (BaseFileTransferMappedRecord) this.executionContext
            .get(ExecutionContext.BASE_FILE_TRANSFER_MAPPED_RECORD);

    if (mappedRecord != null) {
        deliverMappedRecord(mappedRecord);
    } else {
        InputStream inputStream = (InputStream) this.executionContext
                .getRequired(ExecutionContext.FILE_INPUT_STREAM);
        String filePath = (String) this.executionContext.getRequired(ExecutionContext.RELATIVE_FILE_PATH_PARAM);

        deliverInputStream(filePath, inputStream);
    }

    if (changeDirectory) {
        changeDirectory(originalDirectory);
    }

    String destinationPath = this.outputDirectory + this.FILE_SEPARATOR + this.tempFileName;

    logger.info("delivered file as hidden: [" + destinationPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$
    return new ExecutionOutput(destinationPath);
}