use of org.pentaho.platform.api.engine.ISystemConfig in project pentaho-platform by pentaho.
the class StandaloneSpringPentahoObjectFactoryTest method testFallbackPenBean.
/**
* Test <pen:bean> fallback behavior when no object is published matching the request. It should fall-back to
* PentahoSystem.get() behavior where beans matching the simple-name of the queried class are returned.
*
* @throws Exception
*/
public void testFallbackPenBean() throws Exception {
PentahoSystem.shutdown();
ISystemConfig config = mock(ISystemConfig.class);
when(config.getProperty("system.dampening-timeout")).thenReturn("3000");
PentahoSystem.registerObject(config);
StandaloneSession session = new StandaloneSession();
PentahoSessionHolder.setSession(session);
StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
PentahoSystem.registerObjectFactory(factory);
// fallback
SimpleObjectHolder integerHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder", session);
// to
// simpleName
assertNotNull(integerHolder);
assertEquals(123, (int) integerHolder.getVal());
// fallback
SimpleObjectHolder stringHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleStringHolder", session);
// to
// simpleName
assertNotNull(stringHolder);
assertEquals("testing_fallback_by_interface", stringHolder.getVal().toString());
// checks
SimpleObjectHolder integerHolder2 = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder2", session);
// ID
assertNotNull(integerHolder2);
assertEquals(456, (int) integerHolder2.getVal());
}
use of org.pentaho.platform.api.engine.ISystemConfig in project pentaho-platform by pentaho.
the class SolutionContextListener method getServerParameter.
private String getServerParameter(String paramName, boolean suppressWarning) {
String result = context.getInitParameter(paramName);
if (result == null) {
ISystemConfig config = PentahoSystem.get(ISystemConfig.class);
result = config.getProperty("server." + paramName);
} else {
if (!suppressWarning) {
logger.warn(Messages.getInstance().getString("SolutionContextListener.WARN_WEB_XML_PARAM_DEPRECATED", paramName, // $NON-NLS-1$
result));
}
}
return result;
}
use of org.pentaho.platform.api.engine.ISystemConfig in project pentaho-platform by pentaho.
the class RequestParameterAuthenticationFilterTest method beforeTest.
@Before
public void beforeTest() throws KettleException, IOException {
KettleClientEnvironment.init();
filter = new RequestParameterAuthenticationFilter();
authManagerMock = mock(AuthenticationManager.class);
filter.setAuthenticationManager(authManagerMock);
final Properties properties = new Properties();
properties.setProperty("requestParameterAuthenticationEnabled", "true");
IConfiguration config = mock(IConfiguration.class);
ISystemConfig mockISystemConfig = mock(ISystemConfig.class);
mockISystemConfig.registerConfiguration(config);
filter.setSystemConfig(mockISystemConfig);
doReturn(config).when(mockISystemConfig).getConfiguration("security");
doReturn(properties).when(config).getProperties();
}
use of org.pentaho.platform.api.engine.ISystemConfig in project pentaho-platform by pentaho.
the class SolutionContextListener method contextInitialized.
public void contextInitialized(final ServletContextEvent event) {
context = event.getServletContext();
// $NON-NLS-1$
String encoding = getServerParameter("encoding");
if (encoding != null) {
LocaleHelper.setSystemEncoding(encoding);
}
// $NON-NLS-1$
String textDirection = getServerParameter("text-direction");
if (textDirection != null) {
LocaleHelper.setTextDirection(textDirection);
}
// $NON-NLS-1$
String localeLanguage = getServerParameter("locale-language");
// $NON-NLS-1$
String localeCountry = getServerParameter("locale-country");
boolean localeSet = false;
if (!StringUtils.isEmpty(localeLanguage) && !StringUtils.isEmpty(localeCountry)) {
Locale[] locales = Locale.getAvailableLocales();
if (locales != null) {
for (Locale element : locales) {
if (element.getLanguage().equals(localeLanguage) && element.getCountry().equals(localeCountry)) {
LocaleHelper.setLocale(element);
localeSet = true;
break;
}
}
}
}
if (!localeSet) {
// do this thread in the default locale
LocaleHelper.setLocale(Locale.getDefault());
}
LocaleHelper.setDefaultLocale(LocaleHelper.getLocale());
// log everything that goes on here
// $NON-NLS-1$
logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_INITIALIZING"));
// $NON-NLS-1$
logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_SERVLET_CONTEXT", context));
// $NON-NLS-1$
SolutionContextListener.contextPath = context.getRealPath("");
logger.info(// $NON-NLS-1$
Messages.getInstance().getString("SolutionContextListener.INFO_CONTEXT_PATH", SolutionContextListener.contextPath));
SolutionContextListener.solutionPath = PentahoHttpSessionHelper.getSolutionPath(context);
if (StringUtils.isEmpty(SolutionContextListener.solutionPath)) {
// $NON-NLS-1$
String errorMsg = Messages.getInstance().getErrorString("SolutionContextListener.ERROR_0001_NO_ROOT_PATH");
logger.error(errorMsg);
/*
* Since we couldn't find solution repository path there is no point in going forward and the user should know
* that a major config setting was not found. So we are throwing in a RunTimeException with the requisite message.
*/
throw new RuntimeException(errorMsg);
}
logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_ROOT_PATH", // $NON-NLS-1$
SolutionContextListener.solutionPath));
// $NON-NLS-1$
String fullyQualifiedServerUrl = getServerParameter("fully-qualified-server-url");
if (fullyQualifiedServerUrl == null) {
// assume this is a demo installation
// TODO: Create a servlet that's loaded on startup to set this value
// $NON-NLS-1$
fullyQualifiedServerUrl = "http://localhost:8080/pentaho/";
}
IApplicationContext applicationContext = new WebApplicationContext(SolutionContextListener.solutionPath, fullyQualifiedServerUrl, context.getRealPath(""), // $NON-NLS-1$
context);
/*
* Copy out all the Server.properties from to the application context
*/
Properties props = new Properties();
ISystemConfig systemConfig = PentahoSystem.get(ISystemConfig.class);
if (systemConfig != null) {
IConfiguration config = systemConfig.getConfiguration("server");
if (config != null) {
try {
props.putAll(config.getProperties());
} catch (IOException e) {
logger.error("Could not find/read the server.properties file.");
}
}
}
/*
* Copy out all the initParameter values from the servlet context and put them in the application context.
*/
Enumeration<?> initParmNames = context.getInitParameterNames();
String initParmName;
while (initParmNames.hasMoreElements()) {
initParmName = (String) initParmNames.nextElement();
props.setProperty(initParmName, getServerParameter(initParmName, true));
}
((WebApplicationContext) applicationContext).setProperties(props);
setSystemCfgFile(context);
setObjectFactory(context);
serverStatusProvider.setStatus(IServerStatusProvider.ServerStatus.STARTING);
serverStatusProvider.setStatusMessages(new String[] { "Caution, the system is initializing. Do not shut down or restart the system at this time." });
PeriodicStatusLogger.start();
boolean initOk = false;
try {
initOk = PentahoSystem.init(applicationContext);
} finally {
updateStatusMessages(initOk);
PeriodicStatusLogger.stop();
}
this.showInitializationMessage(initOk, fullyQualifiedServerUrl);
}
use of org.pentaho.platform.api.engine.ISystemConfig in project pentaho-platform by pentaho.
the class SqlMetadataQueryExecTest method testDriverClassesToForceMetaIOE.
@Test
public void testDriverClassesToForceMetaIOE() throws IOException {
ISystemConfig sysConfig = mock(ISystemConfig.class);
IConfiguration config = mock(IConfiguration.class);
when(sysConfig.getConfiguration(SqlMetadataQueryExec.CONFIG_ID)).thenReturn(config);
when(config.getProperties()).thenThrow(new IOException());
SqlMetadataQueryExec sqlMetadataQueryExec = new SqlMetadataQueryExec(sysConfig);
assertEquals(0, sqlMetadataQueryExec.driverClassesToForceMeta.size());
}
Aggregations