Search in sources :

Example 71 with ResourceException

use of javax.resource.ResourceException in project teiid by teiid.

the class ExcelMetadataProcessor method process.

public void process(MetadataFactory mf, FileConnection conn) throws TranslatorException {
    if (this.excelFileName == null) {
        // $NON-NLS-1$
        throw new TranslatorException(ExcelPlugin.Event.TEIID23004, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23004, "importer.ExcelFileName"));
    }
    try {
        File xlsFile = conn.getFile(this.excelFileName);
        if (xlsFile.isDirectory()) {
            File[] files = xlsFile.listFiles();
            if (files.length > 0) {
                xlsFile = files[0];
            }
        }
        if (xlsFile.isDirectory() || !xlsFile.exists()) {
            throw new TranslatorException(ExcelPlugin.Event.TEIID23005, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23005, xlsFile.getName()));
        }
        String extension = getFileExtension(xlsFile);
        FileInputStream xlsFileStream = new FileInputStream(xlsFile);
        try {
            Workbook workbook = null;
            if (extension.equalsIgnoreCase("xls")) {
                // $NON-NLS-1$
                workbook = new HSSFWorkbook(xlsFileStream);
            } else if (extension.equalsIgnoreCase("xlsx")) {
                // $NON-NLS-1$
                workbook = new XSSFWorkbook(xlsFileStream);
            }
            int sheetCount = workbook.getNumberOfSheets();
            for (int i = 0; i < sheetCount; i++) {
                Sheet sheet = workbook.getSheetAt(i);
                addTable(mf, sheet, xlsFile.getName(), this.excelFileName);
            }
        } finally {
            xlsFileStream.close();
        }
    } catch (ResourceException e) {
        throw new TranslatorException(e);
    } catch (IOException e) {
        throw new TranslatorException(e);
    }
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) File(java.io.File) Sheet(org.apache.poi.ss.usermodel.Sheet) FileInputStream(java.io.FileInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 72 with ResourceException

use of javax.resource.ResourceException in project teiid by teiid.

the class FileExecutionFactory method createProcedureExecution.

// @Override
public ProcedureExecution createProcedureExecution(final Call command, final ExecutionContext executionContext, final RuntimeMetadata metadata, final Connection conn) throws TranslatorException {
    if (conn instanceof VirtualFileConnection) {
        return new VirtualFileProcedureExecution(command, (VirtualFileConnection) conn);
    }
    final FileConnection fc = (FileConnection) conn;
    if (command.getProcedureName().equalsIgnoreCase(SAVEFILE)) {
        return new ProcedureExecution() {

            @Override
            public void execute() throws TranslatorException {
                String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
                Object file = command.getArguments().get(1).getArgumentValue().getValue();
                if (file == null || filePath == null) {
                    // $NON-NLS-1$
                    throw new TranslatorException(UTIL.getString("non_null"));
                }
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Saving", filePath);
                InputStream is = null;
                try {
                    if (file instanceof SQLXML) {
                        is = ((SQLXML) file).getBinaryStream();
                    } else if (file instanceof Clob) {
                        is = new ReaderInputStream(((Clob) file).getCharacterStream(), encoding);
                    } else if (file instanceof Blob) {
                        is = ((Blob) file).getBinaryStream();
                    } else {
                        // $NON-NLS-1$
                        throw new TranslatorException(UTIL.getString("unknown_type"));
                    }
                    ObjectConverterUtil.write(is, fc.getFile(filePath));
                } catch (IOException e) {
                    // $NON-NLS-1$
                    throw new TranslatorException(e, UTIL.getString("error_writing"));
                } catch (SQLException e) {
                    // $NON-NLS-1$
                    throw new TranslatorException(e, UTIL.getString("error_writing"));
                } catch (ResourceException e) {
                    // $NON-NLS-1$
                    throw new TranslatorException(e, UTIL.getString("error_writing"));
                }
            }

            @Override
            public void close() {
            }

            @Override
            public void cancel() throws TranslatorException {
            }

            @Override
            public List<?> next() throws TranslatorException, DataNotAvailableException {
                return null;
            }

            @Override
            public List<?> getOutputParameterValues() throws TranslatorException {
                return Collections.emptyList();
            }
        };
    } else if (command.getProcedureName().equalsIgnoreCase(DELETEFILE)) {
        return new ProcedureExecution() {

            @Override
            public void execute() throws TranslatorException {
                String filePath = (String) command.getArguments().get(0).getArgumentValue().getValue();
                if (filePath == null) {
                    // $NON-NLS-1$
                    throw new TranslatorException(UTIL.getString("non_null"));
                }
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Deleting", filePath);
                try {
                    File f = fc.getFile(filePath);
                    if (!f.exists()) {
                        if (exceptionIfFileNotFound) {
                            // $NON-NLS-1$
                            throw new TranslatorException(DataPlugin.Util.gs("file_not_found", filePath));
                        }
                    } else if (!f.delete()) {
                        // $NON-NLS-1$
                        throw new TranslatorException(UTIL.getString("error_deleting"));
                    }
                } catch (ResourceException e) {
                    // $NON-NLS-1$
                    throw new TranslatorException(e, UTIL.getString("error_deleting"));
                }
            }

            @Override
            public void close() {
            }

            @Override
            public void cancel() throws TranslatorException {
            }

            @Override
            public List<?> next() throws TranslatorException, DataNotAvailableException {
                return null;
            }

            @Override
            public List<?> getOutputParameterValues() throws TranslatorException {
                return Collections.emptyList();
            }
        };
    }
    return new FileProcedureExecution(command, fc);
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) ReaderInputStream(org.teiid.core.util.ReaderInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) SQLXML(java.sql.SQLXML) ReaderInputStream(org.teiid.core.util.ReaderInputStream) ProcedureExecution(org.teiid.translator.ProcedureExecution) TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) List(java.util.List) ArrayList(java.util.ArrayList) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) Clob(java.sql.Clob) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) VirtualFileConnection(org.teiid.file.VirtualFileConnection) VirtualFileConnection(org.teiid.file.VirtualFileConnection) FileConnection(org.teiid.translator.FileConnection)

Example 73 with ResourceException

use of javax.resource.ResourceException in project teiid by teiid.

the class FtpManagedConnectionFactory method createClient.

protected FTPClient createClient() throws IOException, ResourceException {
    FTPClient client = createClientInstance();
    beforeConnectProcessing(client);
    client.connect(this.host, this.port);
    if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
        // $NON-NLS-1$
        throw new ResourceException(UTIL.getString("ftp_connect_failed", this.host, this.port));
    }
    if (!client.login(this.username, this.password)) {
        // $NON-NLS-1$
        throw new IllegalStateException(UTIL.getString("ftp_login_failed", client.getReplyString()));
    }
    afterConnectProcessing(client);
    return client;
}
Also used : ResourceException(javax.resource.ResourceException) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 74 with ResourceException

use of javax.resource.ResourceException in project teiid by teiid.

the class ConnectorManager method buildCapabilities.

private BasicSourceCapabilities buildCapabilities(ExecutionFactory<Object, Object> translator) throws TranslatorException {
    if (translator.isSourceRequiredForCapabilities()) {
        Object connection = null;
        Object connectionFactory = null;
        try {
            connectionFactory = getConnectionFactory();
            if (connectionFactory != null) {
                connection = translator.getConnection(connectionFactory, null);
            }
            if (connection == null) {
                // $NON-NLS-1$);
                throw new TranslatorException(QueryPlugin.Event.TEIID31108, QueryPlugin.Util.getString("datasource_not_found", getConnectionName()));
            }
            if (connection instanceof WrappedConnection) {
                try {
                    connection = ((WrappedConnection) connection).unwrap();
                } catch (ResourceException e) {
                    throw new TranslatorException(QueryPlugin.Event.TEIID30477, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30477, getConnectionName()));
                }
            }
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Initializing the capabilities for", translatorName);
            synchronized (executionFactory) {
                executionFactory.initCapabilities(connection);
            }
        } finally {
            if (connection != null) {
                translator.closeConnection(connection, connectionFactory);
            }
        }
    }
    BasicSourceCapabilities resultCaps = CapabilitiesConverter.convertCapabilities(translator, id);
    return resultCaps;
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) WrappedConnection(org.teiid.resource.spi.WrappedConnection)

Example 75 with ResourceException

use of javax.resource.ResourceException in project teiid by teiid.

the class LDAPConnectionImpl method initializeLDAPContext.

/**
 * Setup a standard initial LDAP context using JNDI's context factory.
 * This method may be extended to support Sun-specific and AD-specific
 * contexts, in order to support the different paging implementations they provide.
 * @return the initial LDAP Context
 */
private InitialLdapContext initializeLDAPContext() throws ResourceException {
    // Create the root context.
    InitialLdapContext initContext;
    Hashtable connenv = new Hashtable();
    connenv.put(Context.INITIAL_CONTEXT_FACTORY, this.config.getLdapContextFactory());
    connenv.put(Context.PROVIDER_URL, this.config.getLdapUrl());
    connenv.put(Context.REFERRAL, LDAP_REFERRAL_MODE);
    String userName = this.config.getLdapAdminUserDN();
    String password = this.config.getLdapAdminUserPassword();
    String authType = this.config.getLdapAuthType();
    // if security-domain is specified and caller identity is used; then use
    // credentials from subject
    Subject subject = ConnectionContext.getSubject();
    if (subject != null) {
        userName = ConnectionContext.getUserName(subject, this.config, userName);
        password = ConnectionContext.getPassword(subject, this.config, userName, password);
    }
    connenv.put(Context.SECURITY_AUTHENTICATION, authType);
    if (!authType.equals("none")) {
        if (userName == null) {
            // $NON-NLS-1$
            final String msg = LDAPPlugin.Util.getString("LDAPConnection.adminUserDNPropNotFound");
            throw new ResourceException(msg);
        }
        if (password == null) {
            // $NON-NLS-1$
            final String msg = LDAPPlugin.Util.getString("LDAPConnection.adminUserPassPropNotFound");
            throw new ResourceException(msg);
        }
        connenv.put(Context.SECURITY_PRINCIPAL, userName);
        connenv.put(Context.SECURITY_CREDENTIALS, password);
    }
    if (this.config.getLdapTxnTimeoutInMillis() != null && this.config.getLdapTxnTimeoutInMillis() != -1) {
        // $NON-NLS-1$
        connenv.put("com.sun.jndi.ldap.connect.timeout", this.config.getLdapTxnTimeoutInMillis().toString());
    }
    // Enable connection pooling for the Initial context.
    // $NON-NLS-1$ //$NON-NLS-2$
    connenv.put("com.sun.jndi.ldap.connect.pool", "true");
    // $NON-NLS-1$ //$NON-NLS-2$
    connenv.put("com.sun.jndi.ldap.connect.pool.debug", "fine");
    try {
        initContext = new InitialLdapContext(connenv, null);
    } catch (NamingException ne) {
        // $NON-NLS-1$
        final String msg = LDAPPlugin.Util.getString("LDAPConnection.directoryNamingError", ne.getExplanation());
        throw new ResourceException(msg, ne);
    }
    // $NON-NLS-1$
    LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Successfully obtained initial LDAP context.");
    return initContext;
}
Also used : Hashtable(java.util.Hashtable) InitialLdapContext(javax.naming.ldap.InitialLdapContext) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) Subject(javax.security.auth.Subject)

Aggregations

ResourceException (javax.resource.ResourceException)163 TranslatorException (org.teiid.translator.TranslatorException)26 SQLException (java.sql.SQLException)18 IOException (java.io.IOException)17 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)14 ManagedConnection (javax.resource.spi.ManagedConnection)13 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)13 NamingException (javax.naming.NamingException)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 SObject (com.sforce.soap.partner.sobject.SObject)9 ConnectionException (com.sforce.ws.ConnectionException)9 UnexpectedErrorFault (com.sforce.soap.partner.fault.UnexpectedErrorFault)8 ArrayList (java.util.ArrayList)8 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)7 InvalidSObjectFault (com.sforce.soap.partner.fault.InvalidSObjectFault)6 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)6 Set (java.util.Set)6 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)6 XAResource (javax.transaction.xa.XAResource)6 InvalidFieldFault (com.sforce.soap.partner.fault.InvalidFieldFault)5