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);
}
}
}
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);
}
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");
}
}
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;
}
}
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);
}
}
Aggregations