public PointUpdaterDaemon() { con = null; stm = null; // rs = null; // affectedRow = 0; recordCounter = 0; statCreate = false; statMonthly = false; statQuarterly = false; statGrandprize = false; workingDir = System.getProperty("user.dir"); monthlyFile = PropertiesLoader.getProperty("POINT_MONTHLY_FILE"); quarterlyFile = PropertiesLoader.getProperty("POINT_QUARTERLY_FILE"); grandprizeFile = PropertiesLoader.getProperty("POINT_GRANDPRIZE_FILE"); recSeparator = '|'; escChar = '\''; headerLine = 1; // Establishing a Single DB Connection. // This Connection is usable across app life-cycle. try { db_object = new MysqlConnect(); con = db_object.getConnection(); } catch (ClassNotFoundException nfe) { nfe.printStackTrace(); } catch (SQLException sqle) { sqle.printStackTrace(); } }
@Test public void systemProperty() throws IOException { System.setProperty("p1", "sys"); PropertiesLoader pl = new PropertiesLoader("classpath:/test1.properties", "classpath:/test2.properties"); assertThat(pl.getProperty("p1")).isEqualTo("sys"); System.clearProperty("p1"); }
@Test public void notExistProperty() throws IOException { PropertiesLoader pl = new PropertiesLoader("classpath:/notexist.properties"); try { assertThat(pl.getProperty("notexist")).isNull(); fail("should fail here"); } catch (NoSuchElementException e) { } assertThat(pl.getProperty("notexist", "defaultValue")).isEqualTo("defaultValue"); }
@Override public void execute() { // This is an implementation just for demonstration and testing purposes resultSheet = loader.toTable(); success = true; }
/** 获取配置 */ public static String getConfig(String key) { String value = map.get(key); if (value == null) { value = propertiesLoader.getProperty(key); map.put(key, value); } return value; }
public static ConfigAccessor loadExternalProperties(final String... externalPropertiesFilenames) { final Properties properties = new Properties(); for (int i = 0; i < externalPropertiesFilenames.length; ++i) { String currentPropertyFilename = externalPropertiesFilenames[i]; PropertiesLoader.loadExternalPropertiesFile(properties, currentPropertyFilename); } final PropertiesConfigAccessor config = new PropertiesConfigAccessor(properties); return config; }
private String getCommandIfMissing(String propertiesFile, String rawCommand) { if (rawCommand == null || rawCommand.isEmpty()) { rawCommand = loader.getProperty("cmd"); if (rawCommand == null) { throw new RuntimeException( "Mandatory parameter 'cmd' not found in properties (" + propertiesFile + ")."); } } return rawCommand; }
public static ConfigAccessor loadInternalProperties( final ClassLoader classLoader, final String... classpathPropertiesFilenames) { final Properties properties = new Properties(); for (int i = 0; i < classpathPropertiesFilenames.length; ++i) { String currentPropertyFilename = classpathPropertiesFilenames[i]; PropertiesLoader.loadClasspathPropertiesFile( classLoader, properties, currentPropertyFilename); } final PropertiesConfigAccessor config = new PropertiesConfigAccessor(properties); return config; }
static { // If there are more objects to instantiate in future, we could solve // the following by reflection! // 1. try to instantiate the UserAction object String className = PropertiesLoader.getUserActionImpl(); if (Utils.isEmpty(className)) { RequestCycleHandler.logger.error("Empty UserAction implementation class name provided"); } else { try { final Class<?> clazz = Class.forName(className); RequestCycleHandler.userAction = (UserAction) clazz.newInstance(); RequestCycleHandler.logger.info("UserAction initialized to {}", className); } catch (final Throwable e) { RequestCycleHandler.logger.error( "UserAction implementation {} could not be instantiated", className); throw new RuntimeException( "UserAction implementation " + className + " could not be instantiated", e); //$NON-NLS-1$ } } // 2. try to instantiate the UserPathBuilder object className = PropertiesLoader.getUserPathBuilderImpl(); if (Utils.isEmpty(className)) { RequestCycleHandler.logger.error("Empty UserPathBuilder implementation class name provided"); } else { try { final Class<?> clazz = Class.forName(className); RequestCycleHandler.userPathBuilder = (UserPathBuilder) clazz.newInstance(); RequestCycleHandler.logger.info("UserPathBuilder initialized to {}", className); } catch (final Throwable e) { RequestCycleHandler.logger.error( "UserPathBuilder implementation {} could not be instantiated", className); throw new RuntimeException( "UserPathBuilder implementation " + className + " could not be instantiated", e); //$NON-NLS-1$ } } }
/** * Build a properties out of several locations. * * @param configs * @param locations */ static void build(Properties configs, Comparable[] locations) { List<Comparable> listLocations = Arrays.asList(locations); // sort by priority. Collections.sort(listLocations); // reverse the list so we can load from low priority to high priority. Collections.reverse(listLocations); for (Comparable comparable : listLocations) { Properties props = PropertiesLoader.loadFromFileResource(comparable.toString()); configs.putAll(props); } }
/** * changeMasterKey * * @param newMasterKey */ public synchronized void changeMasterKey(String newMasterKey) { String currMasterPasswd = getMasterKey(); // Change value in properties file first pl = new PropertiesLoader(propertiesFile); Properties prop = pl.getPropetiesFromFile(); prop.setProperty("meerkat.password.master", newMasterKey); pl.writePropertiesToFile(prop, propertiesFile); // Update the password for all applications BasicTextEncryptor oldTextEncrypt = new BasicTextEncryptor(); oldTextEncrypt.setPassword(currMasterPasswd); Iterator<WebApp> it = wac.getWebAppCollectionIterator(); WebApp curr; String passwd, currPasswd; while (it.hasNext()) { curr = it.next(); String type = curr.getType(); if (type.equals(WebApp.TYPE_SSH)) { // If SSH we need to update the encrypted password SecureShellSSH app = (SecureShellSSH) curr; passwd = app.getPassword(); currPasswd = oldTextEncrypt.decrypt(passwd); app.setPasswd(currPasswd); } else if (type.equals( WebApp.TYPE_DATABASE)) { // If SQL we need to update the encrypted password SQLService app = (SQLService) curr; passwd = app.getPassword(); currPasswd = oldTextEncrypt.decrypt(passwd); app.setPassword(currPasswd); } } wac.saveConfigXMLFile(); }
public PropertiesWatchDog(String filename) { properties = PropertiesLoader.loadProperties(filename); watchdog = new FileWatchdog(filename) { protected void doOnChange() { String oldProps = properties.toString(); properties = PropertiesLoader.loadProperties(filename); LOG.info( "method:watch,desc:loadProperties,oldProps:" + oldProps + ",newProps:" + properties); } }; }
public void testTissueSpecimenReadAccess() { List<Object> result = null; try { result = getApplicationService() .query( CqlUtility.getTissueSpecimensForCP( PropertiesLoader.getCPTitleForScientistReadForTissueSpecimen())); for (Object o : result) { TissueSpecimen t = (TissueSpecimen) o; if (t.getCreatedOn() != null) { assertFalse("Failed to retrieve Tissue Specimens having masked data", true); } } } catch (ApplicationException e) { e.printStackTrace(); assertFalse("Not able to retrieve Fuild Specimen list using API", true); } }
@Test public void integerDoubleAndBooleanProperty() { PropertiesLoader pl = new PropertiesLoader("classpath:/test1.properties", "classpath:/test2.properties"); assertThat(pl.getInteger("p1")).isEqualTo(new Integer(1)); try { pl.getInteger("notExist"); fail("should fail here"); } catch (NoSuchElementException e) { } assertThat(pl.getInteger("notExist", 100)).isEqualTo(new Integer(100)); assertThat(pl.getBoolean("p4")).isEqualTo(new Boolean(true)); assertThat(pl.getBoolean("p4", true)).isEqualTo(new Boolean(true)); try { pl.getBoolean("notExist"); fail("should fail here"); } catch (NoSuchElementException e) { } assertThat(pl.getBoolean("notExist", true)).isEqualTo(new Boolean(true)); }
public ScientistWithReadAccessTestCases() { loginName = PropertiesLoader.getScientistReadUsername(); password = PropertiesLoader.getScientistReadPassword(); }
private void parseConfigurationString(String configurationOptions) throws FileNotFoundException, IOException { loader.loadFromString(configurationOptions); }
/** The start() method loads the configuration for the QosD daemon and registers for events */ @Override protected void onStart() { String jnp_host; // Get a reference to the QosD logger instance assigned by OpenNMS LOG.info("Qosd.start(): Preparing to load configuration"); // set application context for AlarmListConnectionManager try { LOG.debug( "Qosd.start():setting application context for alarmListConnectionManager: m.context.toString:{}", m_context.toString()); alarmListConnectionManager.setApplicationContext(m_context); } catch (Exception ex) { throw new IllegalArgumentException( "Qosd.start(): Error setting spring application context: " + ex); } // Load the configuration file QosD-Configuration.xml This file contains // all the UEIs that will be sent as alarms if useUeiList = true. try { config = QoSDConfigFactory.getConfig(); LOG.info("QoSD QoSD-configuration.xml - Configuration Loaded Successfully"); // loading list of UEI's which trigger this daemon triggerUeiList = new Hashtable<String, String>(); String[] temp = config.getEventlist().getUei(); for (int i = 0; i < temp.length; i++) triggerUeiList.put(temp[i], "1"); } catch (MarshalException mrshl_ex) { // write an error message to the log file LOG.error( "Qosd.start(): Marshal Exception thrown whilst getting QoSD configuration\n\t\t\t\tEnsure tags have correct names", mrshl_ex); throw new UndeclaredThrowableException(mrshl_ex); } catch (ValidationException vldtn_ex) { LOG.error( "Qosd.start(): Validation Exception thrown whilst getting QoSD configuration\n\t\t\t\tMake sure all the tags are formatted correctly within QoSD-configuration.xml", vldtn_ex); throw new UndeclaredThrowableException(vldtn_ex); } catch (IOException io_ex) { // Get the OpenNMS home directory String configFile = System.getProperty("opennms.home"); // if there is '/' at the end... if (configFile.endsWith(java.io.File.separator)) { // ... remove it so that we can compose a valid filename configFile = configFile.substring(0, configFile.length() - 1); } configFile += java.io.File.separator + "etc" + java.io.File.separator + "QoSD-configuration.xml"; LOG.error( "Qosd.start(): Failed to load configuration file: {}\n\t\t\t\tMake sure that it exists", configFile, io_ex); throw new UndeclaredThrowableException(io_ex); } if (useUeiList) LOG.info( "Qosd.start(): useUeiList = true = using QoSD QoSD-configuration.xml UEI list selects which alarms are sent"); try { // Load the properties file containing the JNDI connection address etc. props = PropertiesLoader.getInstance(); } catch (FileNotFoundException fnf_ex) { // record in log that the properties file could not be found String propertiesFilename = System.getProperty("propertiesFile"); LOG.error("Qosd.start(): Could not find properties file: {}", propertiesFilename, fnf_ex); throw new UndeclaredThrowableException(fnf_ex); } catch (IOException io_ex) { // record in log that the properties file could not be read String propertiesFilename = System.getProperty("propertiesFile"); LOG.error( "Qosd.start(): Could not read from properties file: {}\n\t\t\t\tPlease check the file permissions", propertiesFilename, io_ex); throw new UndeclaredThrowableException(io_ex); } LOG.info("Qosd.start(): QosD Properties File Loaded"); if (System.getSecurityManager() == null) System.setSecurityManager(new RMISecurityManager()); /*The following if-statement checks if the naming provider property exists in * the properties file. If it does then it stores it in the jnp_host string. If * it doesn't then it uses a default naming provider string "jbossjmsserver1:1099" and * assigns it to jnp_host, stating this in the log file. */ if (props.getProperty("org.openoss.opennms.spring.qosd.naming.provider") != null) { jnp_host = (String) props.getProperty("org.openoss.opennms.spring.qosd.naming.provider"); LOG.info("Using JNP: {}", jnp_host); } else { LOG.warn( "Qosd.start(): Naming provider property not set, Using default: jnp://jbossjmsserver1:1099"); jnp_host = "jnp://jbossjmsserver1:1099"; } /* Fill a new properties object with the properties supplied in * the properties file. */ env = new Properties(); env.setProperty("java.naming.provider.url", jnp_host); env.setProperty( "java.naming.factory.initial", props.getProperty("org.openoss.opennms.spring.qosd.naming.contextfactory")); env.setProperty( "java.naming.factory.url.pkgs", props.getProperty("org.openoss.opennms.spring.qosd.naming.pkg")); // start a new connection manager thread try { alarmListConnectionManager.init(props, env); alarmListConnectionManager.start(); // wait until the AlarmListConnectionManager has connected to bean LOG.info("Qosd.start(): Waiting Connection Manager Thread to get JMS connection"); while (alarmListConnectionManager.getStatus() != AlarmListConnectionManager.CONNECTED) ; LOG.info("Qosd.start(): Connection Manager Thread JMS connection successfully registered"); LOG.info("Qosd.start(): openNMS just restarted - sending alarm list rebuilt event"); // send alarm list rebuilt event to EJB via the connection manager thread. alarmListConnectionManager.reset_list( "openNMS just restarted - alarm list rebuilt. Time:" + new Date()); // send an alarm list rebuilt event } catch (Throwable iae) { LOG.error("Qosd.start(): Exception caught starting alarmListConnectionManager", iae); throw new UndeclaredThrowableException(iae); } // setting up ossDao to access the OpenNMS database try { LOG.debug( "Qosd.start(): Using ossDao instance: {}", (ossDao == null ? "IS NULL" : ossDao.toString())); LOG.info("Qosd.start(): Initialising the Node and alarm Caches"); ossDao.init(); // TODO REMOVE // ossDao.updateNodeCaches(); LOG.info( "Qosd.start(): Set up ossDao call back interface to QoSD for forwarding changes to alarm list"); ossDao.setQoSD(this); } catch (Throwable ex) { LOG.error("Qosd.start(): Exception caught setting callback interface from ossDao", ex); throw new UndeclaredThrowableException(ex); } // set up thread to handle incoming OpenNMS events LOG.info("Qosd.start(): initialising OpenNMSEventHandlerThread"); try { openNMSEventHandlerThread = new OpenNMSEventHandlerThread(); openNMSEventHandlerThread.setOssDao(ossDao); openNMSEventHandlerThread.init(); openNMSEventHandlerThread.start(); } catch (Throwable ex) { LOG.error("Qosd.start(): Exception caught initialising OpenNMSEventHandlerThread", ex); throw new UndeclaredThrowableException(ex); } // send all the alarmList to EJB via the connection manager thread. LOG.info("Qosd.start(): openNMS just restarted - sending all alarms in rebuilt alarm list"); try { // this.sendAlarms(); // interface has just started up. Send all alarms openNMSEventHandlerThread.sendAlarmList(); } catch (Exception e) { LOG.error("Qosd.start(): problem sending initial alarm list Error:", e); } // register listener for OpenNMS events LOG.info("Qosd.start(): Starting OpenNMS event listener"); try { registerListener(); } catch (Exception e) { LOG.error("Qosd.start(): problem registering event listener Error:", e); } // TODO - replace ack handler code with QoSDrx receiver code LOG.info("QoSD Started"); }
/** * getMasterKey * * @return */ public final String getMasterKey() { pl = new PropertiesLoader(propertiesFile); Properties prop = pl.getPropetiesFromFile(); return prop.getProperty("meerkat.password.master"); }
public void ResetConfigurationFromString(String configurationOptions) throws FileNotFoundException, IOException { loader = new PropertiesLoader(); loader.loadFromString(configurationOptions); }
public SheetEcho(List<List<String>> ParameterTable) throws FileNotFoundException, IOException { loader.loadFromString("QUERY"); resultSheet = ParameterTable; myFixture = new SheetFixture("", "", this); }