Example usage for javax.resource ResourceException ResourceException

List of usage examples for javax.resource ResourceException ResourceException

Introduction

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

Prototype

public ResourceException(Throwable cause) 

Source Link

Document

Constructs a new throwable with the specified cause.

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 {/*from   w  ww  .  j a v  a  2  s  .com*/
            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);
}

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

/**
 * Deliver the input stream to the filePath
 * //from   w w  w.jav a2s.  c  om
 * @param filePath
 * @param inputStream
 * @throws ResourceException
 */
private void deliverInputStream(String filePath, InputStream inputStream) throws ResourceException {
    this.fileName = filePath;
    if (this.tempFileName == null || this.tempFileName.trim().length() == 0) {
        this.tempFileName = filePath + this.renameExtension;
    }
    String tempFilePath = this.tempFileName;

    if (!this.overwriteExisting) {
        if (fileExists(this.fileName)) {
            throw new ResourceException(
                    "Cannot deliver file [" + this.fileName + "] as a file of that name already exists");
        }
    }

    this.putAttempted = true;
    putWithOutputStream(tempFilePath, inputStream);
}

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

/**
 * Deliver the mapped record// w ww. j  a v a2  s  .c  om
 * 
 * @param mappedRecord
 * @throws ResourceException
 */
private void deliverMappedRecord(BaseFileTransferMappedRecord mappedRecord) throws ResourceException {
    this.fileName = mappedRecord.getName();
    if (this.tempFileName == null || this.tempFileName.trim().length() == 0) {
        this.tempFileName = this.fileName + this.renameExtension;
    }
    mappedRecord.setName(this.tempFileName);

    if (!this.overwriteExisting) {
        if (fileExists(this.fileName)) {
            throw new ResourceException(
                    "Cannot deliver file [" + this.fileName + "] as a file of that name already exists");
        }
    }

    this.putAttempted = true;
    putFile(mappedRecord);
}

From source file:org.nuxeo.ecm.core.jca.JCAManagedConnection.java

/**
 * Create a new session.//from www.j  ava 2 s .c  om
 */
private Session openSession(JCAConnectionRequestInfo cri) throws ResourceException {
    Map<String, Serializable> ctx = cri.getSessionContext();

    try {
        Session session = mcf.getRepository().getSession(ctx);
        log("Created session for repository " + mcf.getRepository().getName());
        return session;
    } catch (DocumentException e) {
        log("Failed to create workspace session", e);
        throw new ResourceException(e);
    }
}

From source file:org.soulwing.oaq.MessageActivationSpec.java

/**
 * {@inheritDoc}/*from  w  w  w .jav  a  2 s  .c o  m*/
 */
@Override
public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException {
    // JCA 1.7 Section 5.3
    if (resourceAdapter != null) {
        throw new ResourceException("resource adapter already set");
    }
    // It must be an instance of our resource adapter
    if (!(resourceAdapter instanceof MessageResourceAdapter)) {
        throw new ResourceException("Unrecognized resource adapter type");
    }
    this.resourceAdapter = resourceAdapter;
}

From source file:org.soulwing.oaq.OAQManagedConnection.java

/**
 * {@inheritDoc}//from   w  ww.ja  va  2 s  .  c o m
 */
@Override
public void associateConnection(Object connection) throws ResourceException {
    if (!(connection instanceof ManagedConnectionProxy)) {
        throw new ResourceException("cannot associate connection of type " + connection.getClass().getName());
    }
    connectionManager.add((ManagedConnectionProxy) connection);
}

From source file:org.teiid.resource.adapter.ftp.FtpFileConnectionImpl.java

@Override
public void close() throws ResourceException {
    try {//from ww w . j a  v  a 2 s.  c  om
        this.closeable.close();
    } catch (IOException e) {
        throw new ResourceException(e);
    }
}

From source file:org.teiid.resource.adapter.ftp.FtpFileConnectionImpl.java

@Override
public VirtualFile[] getFiles(String pattern) throws ResourceException {
    if (this.getFile(pattern).exists()) {
        return new VirtualFile[] { this.getFile(pattern) };
    }/*from  w  w w  .  j a  v  a 2 s  .co m*/

    throw new ResourceException("Can not open multiple ftp stream based file in one connection"); //$NON-NLS-1$ 
}

From source file:org.teiid.resource.adapter.ftp.FtpManagedConnectionFactory.java

@SuppressWarnings("serial")
@Override/*from  w ww  .  j  a  v  a2s .com*/
public BasicConnectionFactory<FtpFileConnectionImpl> createConnectionFactory() throws ResourceException {

    final Map<String, String> map = StringUtil.valueOf(this.fileMapping, Map.class);

    return new BasicConnectionFactory<FtpFileConnectionImpl>() {

        @Override
        public FtpFileConnectionImpl getConnection() throws ResourceException {
            try {
                return new FtpFileConnectionImpl(createClient(), parentDirectory, map);
            } catch (IOException e) {
                throw new ResourceException(e);
            }
        }
    };
}

From source file:org.teiid.resource.adapter.ftp.FtpManagedConnectionFactory.java

protected FTPClient createClient() throws IOException, ResourceException {

    FTPClient client = createClientInstance();

    beforeConnectProcessing(client);/*from   w w  w .ja v  a2  s . co  m*/

    client.connect(this.host, this.port);

    if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
        throw new ResourceException(UTIL.getString("ftp_connect_failed", this.host, this.port)); //$NON-NLS-1$
    }

    if (!client.login(this.username, this.password)) {
        throw new IllegalStateException(UTIL.getString("ftp_login_failed", client.getReplyString())); //$NON-NLS-1$
    }

    afterConnectProcessing(client);

    return client;

}