Search in sources :

Example 1 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class SQLConnection method initWithJNDI.

protected void initWithJNDI(final String jndiName) {
    // myCtr = connectionCtr;
    try {
        IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
        DataSource dataSource = datasourceService.getDataSource(jndiName);
        if (dataSource != null) {
            nativeConnection = captureConnection(dataSource.getConnection());
            if (nativeConnection == null) {
                logger.error(Messages.getInstance().getErrorString("ConnectFactory.ERROR_0001_INVALID_CONNECTION", // $NON-NLS-1$
                jndiName));
                // clear datasource cache
                datasourceService.clearDataSource(jndiName);
            } else {
                enhanceConnection(nativeConnection);
            }
        } else {
            logger.error(Messages.getInstance().getErrorString("ConnectFactory.ERROR_0001_INVALID_CONNECTION", // $NON-NLS-1$
            jndiName));
            // clear datasource cache
            datasourceService.clearDataSource(jndiName);
        }
    } catch (Exception e) {
        logger.error(Messages.getInstance().getErrorString("ConnectFactory.ERROR_0001_INVALID_CONNECTION", jndiName), // $NON-NLS-1$
        e);
        // do not allow connection to be used as it might not be enhanced
        close();
        // clear datasource cache
        try {
            IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
            datasourceService.clearDataSource(jndiName);
        } catch (ObjectFactoryException objface) {
            logger.error(Messages.getInstance().getErrorString("ConnectFactory.ERROR_0002_UNABLE_TO_FACTORY_OBJECT=Unable to factory object", jndiName), // $NON-NLS-1$
            e);
        }
    }
}
Also used : ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) SQLException(java.sql.SQLException) PentahoSystemException(org.pentaho.platform.api.engine.PentahoSystemException) DataSource(javax.sql.DataSource)

Example 2 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class AggregateObjectFactory method get.

@Override
public <T> T get(Class<T> interfaceClass, String key, IPentahoSession session) throws ObjectFactoryException {
    // if they want it by id, check for that first
    if (key != null) {
        readLock.lock();
        try {
            for (IPentahoObjectFactory fact : factories) {
                if (fact.objectDefined(key)) {
                    T object = fact.get(interfaceClass, key, session);
                    logger.debug(MessageFormat.format("Found object for key: {0} in factory: {1}", key, fact.getName()));
                    return object;
                }
            }
        } finally {
            readLock.unlock();
        }
    }
    T fromType = get(interfaceClass, session, null);
    if (fromType != null) {
        return fromType;
    }
    String msg = Messages.getInstance().getString("AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_RETRIEVE_OBJECT", interfaceClass.getSimpleName());
    throw new ObjectFactoryException(msg);
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException)

Example 3 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class CipherEncryptionService method afterPropertiesSet.

public void afterPropertiesSet() throws ObjectFactoryException {
    if ((saltString == null) || (algorithm == null) || (encryptionKey == null)) {
        throw new ObjectFactoryException("Required properties not set - need Salt, algorithm and encryption key");
    }
    if (saltString.length() != this.saltLength) {
        // Make sure that the salt length is 8 bytes - the PBEParameterSpec doesn't anything but
        if (saltString.length() < saltLength) {
            // postfix bytes to pad it out
            saltString = (saltString + "!@#$%^&*").substring(0, saltLength);
        } else if (saltString.length() > saltLength) {
            // Trim off longer than 8-bytes
            saltString = saltString.substring(0, saltLength);
        }
    }
    byte[] saltBytes = saltString.getBytes();
    paramSpec = new PBEParameterSpec(saltBytes, getIterations());
    PBEKeySpec skeySpec = new PBEKeySpec(getEncryptionKey().toCharArray(), saltBytes, getIterations());
    try {
        secretKey = SecretKeyFactory.getInstance(getAlgorithm()).generateSecret(skeySpec);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new ObjectFactoryException("Encryption requested not available");
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) PBEParameterSpec(javax.crypto.spec.PBEParameterSpec) PasswordServiceException(org.pentaho.platform.api.util.PasswordServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException)

Example 4 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class NonPooledDatasourceSystemListener method startup.

public boolean startup(final IPentahoSession session) {
    try {
        // $NON-NLS-1$
        Logger.debug(this, "DatasourceSystemListener: called for startup ...");
        ICacheManager cacheManager = addCacheRegions();
        List<IDatabaseConnection> databaseConnections = getListOfDatabaseConnections(session);
        String dsName = "";
        DataSource ds = null;
        for (IDatabaseConnection databaseConnection : databaseConnections) {
            if (databaseConnection != null) {
                // $NON-NLS-1$
                Logger.debug(this, "  Setting up datasource - " + databaseConnection);
                dsName = databaseConnection.getName();
                // http://jira.pentaho.com/browse/BISERVER-12244
                if (!databaseConnection.getAccessType().equals(DatabaseAccessType.JNDI)) {
                    // if connection's port used by server there is no sense to get DataSource for this
                    ds = isPortUsedByServer(databaseConnection) ? null : setupDataSourceForConnection(databaseConnection);
                } else {
                    Logger.debug(this, // $NON-NLS-1$
                    "(Datasource \"" + IDBDatasourceService.JDBC_DATASOURCE + dsName + // $NON-NLS-1$
                    "\" not cached)");
                    continue;
                }
                cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds);
                Logger.debug(this, // $NON-NLS-1$
                "(Storing datasource under key \"" + IDBDatasourceService.JDBC_DATASOURCE + dsName + // $NON-NLS-1$
                "\")");
            }
        }
        // $NON-NLS-1$
        Logger.debug(this, "DatasourceSystemListener: Completed startup.");
        return true;
    } catch (ObjectFactoryException objface) {
        Logger.error(this, Messages.getInstance().getErrorString("DatasourceSystemListener.ERROR_0001_UNABLE_TO_INSTANTIATE_OBJECT"), // $NON-NLS-1$
        objface);
        return false;
    } catch (DatasourceMgmtServiceException dmse) {
        Logger.error(this, Messages.getInstance().getErrorString("DatasourceSystemListener.ERROR_0002_UNABLE_TO_GET_DATASOURCE"), // $NON-NLS-1$
        dmse);
        return false;
    }
}
Also used : ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 5 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class StandaloneObjectFactoryTest method testLocalObjectFail1.

public void testLocalObjectFail1() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    // $NON-NLS-1$
    factory.defineObject(Object1.class.getSimpleName(), "bogus", Scope.LOCAL);
    // $NON-NLS-1$
    IPentahoSession session1 = new StandaloneSession("test user 1");
    try {
        factory.get(Object1.class, session1);
        // $NON-NLS-1$
        assertFalse("exception expected", true);
    } catch (ObjectFactoryException e) {
        // $NON-NLS-1$
        assertTrue("exception expected", true);
    }
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)

Aggregations

ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)27 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)10 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)7 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)5 DataSource (javax.sql.DataSource)4 IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)4 ArrayList (java.util.ArrayList)3 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)3 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)3 SQLException (java.sql.SQLException)2 List (java.util.List)2 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Principal (java.security.Principal)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 PBEKeySpec (javax.crypto.spec.PBEKeySpec)1 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)1