List of usage examples for javax.naming Context lookup
public Object lookup(String name) throws NamingException;
From source file:de.iai.ilcd.configuration.ConfigurationService.java
ConfigurationService() { try {/*from w w w .j a va 2 s . co m*/ this.appConfig = new PropertiesConfiguration("app.properties"); } catch (ConfigurationException e) { throw new RuntimeException("FATAL ERROR: application properties could not be initialized", e); } // log application version message this.versionTag = this.appConfig.getString("version.tag"); this.logger.info(this.versionTag); // validate/migrate database schema this.migrateDatabaseSchema(); URL resourceUrl = Thread.currentThread().getContextClassLoader().getResource("log4j.properties"); String decodedPath = ""; // now extract path and decode it try { // note, that URLs getPath() method does not work, because it don't // decode encoded Urls, but URI's does this decodedPath = resourceUrl.toURI().getPath(); } catch (URISyntaxException ex) { this.logger.error("Cannot extract base path from resource files", ex); } // base path it relative to web application root directory this.basePath = decodedPath.replace("/WEB-INF/classes/log4j.properties", ""); this.logger.info("base path of web application: {}", this.basePath); // Obtain our environment naming context Context initCtx; Context envCtx; String propertiesFilePath = null; try { initCtx = new InitialContext(); envCtx = (Context) initCtx.lookup("java:comp/env"); propertiesFilePath = (String) envCtx.lookup("soda4LCAProperties"); } catch (NamingException e1) { this.logger.error(e1.getMessage()); } if (propertiesFilePath == null) { this.logger.info("using default application properties at {}", this.defaultPropertiesFile); propertiesFilePath = this.defaultPropertiesFile; } else { this.logger.info("reading application configuration properties from {}", propertiesFilePath); } try { // OK, now load configuration file this.fileConfig = new PropertiesConfiguration(propertiesFilePath); this.featureNetworking = this.fileConfig.getString("feature.networking"); configureLanguages(); } catch (ConfigurationException ex) { this.logger.error( "Cannot find application configuration properties file under {}, either put it there or set soda4LCAProperties environment entry via JNDI.", propertiesFilePath, ex); throw new RuntimeException("application configuration properties not found", ex); } }
From source file:org.apache.wookie.beans.jcr.JCRPersistenceManager.java
/** * Initialize implementation with configuration. * /* ww w.j a v a2 s . c o m*/ * @param configuration configuration properties * @param initializeStore truncate and initialize persistent store */ public static void initialize(Configuration configuration, boolean initializeStore) { try { // configuration repositoryUser = configuration.getString(PERSISTENCE_MANAGER_USER_PROPERTY_NAME); repositoryPassword = configuration.getString(PERSISTENCE_MANAGER_PASSWORD_PROPERTY_NAME); repositoryWorkspace = configuration.getString(PERSISTENCE_MANAGER_WORKSPACE_PROPERTY_NAME); rootPath = configuration.getString(PERSISTENCE_MANAGER_ROOT_PATH_PROPERTY_NAME); for (Map.Entry<Class<? extends IBean>, Class<? extends IBean>> mapping : BEAN_INTERFACE_TO_CLASS_MAP .entrySet()) { Class<? extends IBean> beanClass = mapping.getValue(); Class<? extends IBean> beanInterface = mapping.getKey(); String name = beanInterface.getSimpleName(); if (name.startsWith("I")) { name = name.substring(1); } if (!name.endsWith("s")) { name = name + "s"; } String nodeRootPath = rootPath + "/" + name; beanClassNodeRootPaths.put(beanClass, nodeRootPath); } // create JCR credentials session pool PoolableObjectFactory sessionFactory = new BasePoolableObjectFactory() { /* (non-Javadoc) * @see org.apache.commons.pool.BasePoolableObjectFactory#passivateObject(java.lang.Object) */ public void passivateObject(Object obj) throws Exception { // clear OCM object cache ((ObjectContentManagerImpl) obj).setRequestObjectCache(new RequestObjectCacheImpl()); } /* (non-Javadoc) * @see org.apache.commons.pool.BasePoolableObjectFactory#makeObject() */ public Object makeObject() throws Exception { // lookup JCR repository from context Context initialContext = new InitialContext(); Repository repository = (Repository) initialContext .lookup(WIDGET_REPOSITORY_JNDI_REPOSITORY_FULL_NAME); // create and login JCR session Credentials credentials = new SimpleCredentials(repositoryUser, repositoryPassword.toCharArray()); Session session = ((repositoryWorkspace != null) ? repository.login(credentials, repositoryWorkspace) : repository.login(credentials)); // return session object content manager for session return new SessionObjectContentManagerImpl(session, new AnnotationMapperImpl(CLASS_LIST)); } /* (non-Javadoc) * @see org.apache.commons.pool.BasePoolableObjectFactory#destroyObject(java.lang.Object) */ public void destroyObject(Object obj) throws Exception { // logout and close object content manager and session ((ObjectContentManagerImpl) obj).logout(); } }; ocmPool = new GenericObjectPool(sessionFactory, 0, GenericObjectPool.WHEN_EXHAUSTED_GROW, 0, 5); ocmPool.setTimeBetweenEvictionRunsMillis(60000); ocmPool.setMinEvictableIdleTimeMillis(300000); // initialize persistent store if (initializeStore) { // borrow object content manager and initialization session from pool ObjectContentManager ocm = (ObjectContentManager) ocmPool.borrowObject(); Session session = ocm.getSession(); // initialize root path in repository // Jackrabbit/JCR 2.X //boolean rootPathNodeExists = session.nodeExists(rootPath); // Jackrabbit/JCR 1.X boolean rootPathNodeExists = session.itemExists(rootPath); if (rootPathNodeExists) { // delete nodes of root path node // Jackrabbit/JCR 2.X //Node rootNode = session.getNode(rootPath); // Jackrabbit/JCR 1.X Node rootNode = (Node) session.getItem(rootPath); NodeIterator nodesIter = rootNode.getNodes(); while (nodesIter.hasNext()) { nodesIter.nextNode().remove(); } } else { // create unstructured node hierarchy int rootPathParentIndex = -1; int rootPathIndex = rootPath.indexOf('/', 1); while (rootPathIndex != -1) { // Jackrabbit/JCR 2.X //Node parentNode = session.getNode(rootPath.substring(0, ((rootPathParentIndex != -1) ? rootPathParentIndex : 1))); // Jackrabbit/JCR 1.X Node parentNode = (Node) session.getItem( rootPath.substring(0, ((rootPathParentIndex != -1) ? rootPathParentIndex : 1))); String nodeName = rootPath.substring( ((rootPathParentIndex != -1) ? rootPathParentIndex + 1 : 1), rootPathIndex); parentNode.addNode(nodeName, "nt:unstructured"); rootPathParentIndex = rootPathIndex; rootPathIndex = rootPath.indexOf('/', rootPathIndex + 1); } // Jackrabbit/JCR 2.X //Node parentNode = session.getNode(rootPath.substring(0, ((rootPathParentIndex != -1) ? rootPathParentIndex : 1))); // Jackrabbit/JCR 1.X Node parentNode = (Node) session.getItem( rootPath.substring(0, ((rootPathParentIndex != -1) ? rootPathParentIndex : 1))); String nodeName = rootPath .substring(((rootPathParentIndex != -1) ? rootPathParentIndex + 1 : 1)); parentNode.addNode(nodeName, "nt:unstructured"); } // create bean class node root paths // Jackrabbit/JCR 2.X //Node rootNode = session.getNode(rootPath); // Jackrabbit/JCR 1.X Node rootNode = (Node) session.getItem(rootPath); for (String nodeRootPath : beanClassNodeRootPaths.values()) { String nodeName = nodeRootPath.substring(rootPath.length() + 1); rootNode.addNode(nodeName, "nt:unstructured"); } session.save(); // register/reregister repository node types NodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager(); InputStream nodeTypesCNDStream = JCRPersistenceManager.class .getResourceAsStream("wookie-schema.cnd"); if (nodeTypesCNDStream == null) { throw new IllegalArgumentException( "Unable to load node types configuration: wookie-schema.cnd"); } // Jackrabbit/JCR 2.X //Reader nodeTypesCNDReader = new InputStreamReader(nodeTypesCNDStream); //NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry(); //ValueFactory valueFactory = session.getValueFactory(); //CndImporter.registerNodeTypes(nodeTypesCNDReader, "wookie-schema.cnd", nodeTypeManager, namespaceRegistry, valueFactory, true); // Jackrabbit/JCR 1.X ((NodeTypeManagerImpl) nodeTypeManager).registerNodeTypes(nodeTypesCNDStream, NodeTypeManagerImpl.TEXT_X_JCR_CND, true); // save session used to load node types session.save(); logger.info("Persistent store initialized at " + rootPath); // return object content manager and initialization session to pool ocmPool.returnObject(ocm); } logger.info("Initialized"); } catch (Exception e) { throw new RuntimeException("Unable to initialize: " + e, e); } }
From source file:com.opensymphony.module.propertyset.database.JDBCPropertySet.java
public void init(Map config, Map args) { // args//w w w.j a v a 2s . c o m globalKey = (String) args.get("globalKey"); // config --> modified by chirs chen 2007-07-03 try { InitialContext initCtx = new InitialContext(); Context context = (Context) initCtx.lookup("java:comp/env"); ds = (DataSource) context.lookup((String) config.get("datasource")); } catch (Exception e) { log.fatal("Could not get DataSource", e); } tableName = (String) config.get("table.name"); colGlobalKey = (String) config.get("col.globalKey"); colItemKey = (String) config.get("col.itemKey"); colItemType = (String) config.get("col.itemType"); colString = (String) config.get("col.string"); colDate = (String) config.get("col.date"); colData = (String) config.get("col.data"); colFloat = (String) config.get("col.float"); colNumber = (String) config.get("col.number"); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSMWar.CFAsteriskSMWarRequestResetPasswordHtml.java
protected void sendPasswordResetEMail(HttpServletRequest request, ICFSecuritySecUserObj resetUser, ICFSecurityClusterObj cluster) throws AddressException, MessagingException, NamingException { final String S_ProcName = "sendPasswordResetEMail"; Properties props = System.getProperties(); String clusterDescription = cluster.getRequiredDescription(); Context ctx = new InitialContext(); String smtpEmailFrom = (String) ctx.lookup("java:comp/env/CFAsterisk24SmtpEmailFrom"); if ((smtpEmailFrom == null) || (smtpEmailFrom.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "JNDI lookup for CFAsterisk24SmtpEmailFrom"); }/*from ww w . j av a2 s . c o m*/ smtpUsername = (String) ctx.lookup("java:comp/env/CFAsterisk24SmtpUsername"); if ((smtpUsername == null) || (smtpUsername.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "JNDI lookup for CFAsterisk24SmtpUsername"); } smtpPassword = (String) ctx.lookup("java:comp/env/CFAsterisk24SmtpPassword"); if ((smtpPassword == null) || (smtpPassword.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "JNDI lookup for CFAsterisk24SmtpPassword"); } Session emailSess = Session.getInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUsername, smtpPassword); } }); String thisURI = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI().toString(); int lastSlash = thisURI.lastIndexOf('/'); String baseURI = thisURI.substring(0, lastSlash); UUID resetUUID = resetUser.getOptionalPasswordResetUuid(); String msgBody = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" + "<HTML>\n" + "<BODY>\n" + "<p>\n" + "You requested a password reset for " + resetUser.getRequiredEMailAddress() + " used for accessing " + clusterDescription + ".\n" + "<p>" + "Please click on the following link to reset your password:<br>\n" + "<A HRef=\"" + baseURI + "/CFAsteriskSMWarResetPasswordHtml?ResetUUID=" + resetUUID.toString() + "\">" + baseURI + "/CFAsteriskSMWarResetPasswordHtml?ResetUUID=" + resetUUID.toString() + "</A>\n" + "<p>" + "Or click on the following link to cancel the reset request:<br>\n" + "<A HRef=\"" + baseURI + "/CFAsteriskSMWarCancelResetPasswordHtml?ResetUUID=" + resetUUID.toString() + "\">" + baseURI + "/CFAsteriskSMWarCancelResetPasswordHtml?ResetUUID=" + resetUUID.toString() + "</A>\n" + "</BODY>\n" + "</HTML>\n"; MimeMessage msg = new MimeMessage(emailSess); msg.setFrom(new InternetAddress(smtpEmailFrom)); InternetAddress mailTo[] = InternetAddress.parse(resetUser.getRequiredEMailAddress(), false); msg.setRecipient(Message.RecipientType.TO, mailTo[0]); msg.setSubject("You requested a password reset for your account with " + clusterDescription + "?"); msg.setContent(msgBody, "text/html"); msg.setSentDate(new Date()); msg.saveChanges(); Transport.send(msg); }
From source file:com.silverpeas.jcrutil.model.impl.AbstractJcrTestCase.java
/** * Workaround to be able to use Sun's JNDI file system provider on Unix * * @param ic : the JNDI initial context * @param jndiName : the binding name//from w w w .j a v a 2 s. c o m * @param ref : the reference to be bound * @throws NamingException */ protected void rebind(InitialContext ic, String jndiName, Object ref) throws NamingException { Context currentContext = ic; StringTokenizer tokenizer = new StringTokenizer(jndiName, "/", false); while (tokenizer.hasMoreTokens()) { String name = tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { try { currentContext = (Context) currentContext.lookup(name); } catch (javax.naming.NameNotFoundException nnfex) { currentContext = currentContext.createSubcontext(name); } } else { currentContext.rebind(name, ref); } } }
From source file:org.apache.beehive.controls.system.jdbc.JdbcControlImpl.java
/** * Get a connection from a DataSource./* w ww . ja v a2s .c om*/ * * @param jndiName Specifed in the subclasse's ConnectionDataSource annotation * @param jndiFactory Specified in the subclasse's ConnectionDataSource Annotation. * @return null if a connection cannot be established * @throws SQLException */ private Connection getConnectionFromDataSource(String jndiName, Class<? extends JdbcControl.JndiContextFactory> jndiFactory) throws SQLException { Connection con = null; try { JndiContextFactory jf = (JndiContextFactory) jndiFactory.newInstance(); Context jndiContext = jf.getContext(); _dataSource = (DataSource) jndiContext.lookup(jndiName); con = _dataSource.getConnection(); } catch (IllegalAccessException iae) { throw new ControlException("IllegalAccessException:", iae); } catch (InstantiationException ie) { throw new ControlException("InstantiationException:", ie); } catch (NamingException ne) { throw new ControlException("NamingException:", ne); } return con; }
From source file:org.geoserver.security.jdbc.AbstractJDBCService.java
/** * initialize a {@link DataSource} form a * {@link JdbcSecurityServiceConfig} object * //from w ww .j a va 2 s . co m * @param config * @throws IOException */ public void initializeDSFromConfig(SecurityNamedServiceConfig namedConfig) throws IOException { JDBCSecurityServiceConfig config = (JDBCSecurityServiceConfig) namedConfig; if (config.isJndi()) { String jndiName = config.getJndiName(); try { Context initialContext = new InitialContext(); datasource = (DataSource) initialContext.lookup(jndiName); } catch (NamingException e) { throw new IOException(e); } } else { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(config.getDriverClassName()); bds.setUrl(config.getConnectURL()); bds.setUsername(config.getUserName()); bds.setPassword(config.getPassword()); bds.setDefaultAutoCommit(false); bds.setDefaultTransactionIsolation(DEFAULT_ISOLATION_LEVEL); bds.setMaxActive(10); datasource = bds; } }
From source file:com.google.enterprise.connector.salesforce.storetype.DBStore.java
public DBStore(BaseConnector connector) { Connection connection = null; logger = Logger.getLogger(this.getClass().getPackage().getName()); logger.log(Level.INFO, "Initialize DBStore "); this.connector = connector; //each connector instance has its own table in the same database this.instance_table = "i_" + connector.getInstanceName(); Statement Stmt = null;/* w w w . ja v a 2 s . com*/ ResultSet RS = null; DatabaseMetaData dbm = null; boolean table_exists = false; try { //check if the datasource/database exists Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); ds = (DataSource) envCtx.lookup(BaseConstants.CONNECTOR_DATASOURCE); connection = ds.getConnection(); connection.setAutoCommit(true); dbm = connection.getMetaData(); logger.log(Level.INFO, "Connected to databaseType " + dbm.getDatabaseProductName()); } catch (Exception ex) { logger.log(Level.SEVERE, "Exception initializing Store Datasource " + ex); connection = null; return; } try { if (dbm.getDatabaseProductName().equals("MySQL")) { //check if the per-connector table exists logger.log(Level.FINE, "Checking to see if connector DB exists..."); Stmt = connection.createStatement(); RS = Stmt.executeQuery("desc " + instance_table); ResultSetMetaData rsMetaData = RS.getMetaData(); if (rsMetaData.getColumnCount() > 0) table_exists = true; RS.close(); Stmt.close(); } else { logger.log(Level.SEVERE, "Unsupported DATABASE TYPE..." + dbm.getDatabaseProductName()); } } catch (Exception ex) { logger.log(Level.SEVERE, "Exception initializing Store " + ex); } try { //if the per-instance table doesn't exist, create it if (!table_exists) { logger.log(Level.INFO, "Creating Instance Table " + instance_table); if (dbm.getDatabaseProductName().equals("MySQL")) { Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); String create_stmt = ""; create_stmt = "CREATE TABLE `" + this.instance_table + "` (" + "`crawl_set` decimal(19,5) NOT NULL," + "`insert_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP," + "`crawl_data` MEDIUMTEXT default NULL," + "PRIMARY KEY (`crawl_set`)," + "KEY `set_index` (`crawl_set`)" + ") ENGINE=MyISAM;"; statement.addBatch(create_stmt); statement.executeBatch(); statement.close(); } else { logger.log(Level.INFO, "Instance Table " + instance_table + " already exists"); //connection.close(); //TODO: somehow figure out if we should delete this table here } } boolean qrtz_table_exists = false; if (dbm.getDatabaseProductName().equals("MySQL")) { //check if the per-connector table exists logger.log(Level.FINE, "Checking to see if quartz tables exists..."); Stmt = connection.createStatement(); try { RS = Stmt.executeQuery("desc QRTZ_JOB_DETAILS"); ResultSetMetaData rsMetaData = RS.getMetaData(); if (rsMetaData.getColumnCount() > 0) qrtz_table_exists = true; } catch (Exception ex) { logger.log(Level.INFO, "Could not find Quartz Tables...creating now.."); } RS.close(); Stmt.close(); } else { logger.log(Level.SEVERE, "Unsupported DATABASE TYPE..." + dbm.getDatabaseProductName()); } if (!qrtz_table_exists) { logger.log(Level.INFO, "Creating Global Quartz Table "); //the quartz db setup scripts are at //quartz-1.8.0/docs/dbTables/tables_mysql.sql //one set of Quartz tables can handle any number of triggers/crons Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); String create_stmt = "CREATE TABLE QRTZ_JOB_DETAILS (JOB_NAME VARCHAR(200) NOT NULL,JOB_GROUP VARCHAR(200) NOT NULL,DESCRIPTION VARCHAR(250) NULL,JOB_CLASS_NAME VARCHAR(250) NOT NULL,IS_DURABLE VARCHAR(1) NOT NULL,IS_VOLATILE VARCHAR(1) NOT NULL,IS_STATEFUL VARCHAR(1) NOT NULL,REQUESTS_RECOVERY VARCHAR(1) NOT NULL,JOB_DATA BLOB NULL,PRIMARY KEY (JOB_NAME,JOB_GROUP));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_JOB_LISTENERS ( JOB_NAME VARCHAR(200) NOT NULL, JOB_GROUP VARCHAR(200) NOT NULL, JOB_LISTENER VARCHAR(200) NOT NULL, PRIMARY KEY (JOB_NAME,JOB_GROUP,JOB_LISTENER), FOREIGN KEY (JOB_NAME,JOB_GROUP) REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_FIRED_TRIGGERS ( ENTRY_ID VARCHAR(95) NOT NULL, TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, IS_VOLATILE VARCHAR(1) NOT NULL, INSTANCE_NAME VARCHAR(200) NOT NULL, FIRED_TIME BIGINT(13) NOT NULL, PRIORITY INTEGER NOT NULL, STATE VARCHAR(16) NOT NULL, JOB_NAME VARCHAR(200) NULL, JOB_GROUP VARCHAR(200) NULL, IS_STATEFUL VARCHAR(1) NULL, REQUESTS_RECOVERY VARCHAR(1) NULL, PRIMARY KEY (ENTRY_ID));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_TRIGGERS ( TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, JOB_NAME VARCHAR(200) NOT NULL, JOB_GROUP VARCHAR(200) NOT NULL, IS_VOLATILE VARCHAR(1) NOT NULL, DESCRIPTION VARCHAR(250) NULL, NEXT_FIRE_TIME BIGINT(13) NULL, PREV_FIRE_TIME BIGINT(13) NULL, PRIORITY INTEGER NULL, TRIGGER_STATE VARCHAR(16) NOT NULL, TRIGGER_TYPE VARCHAR(8) NOT NULL, START_TIME BIGINT(13) NOT NULL, END_TIME BIGINT(13) NULL, CALENDAR_NAME VARCHAR(200) NULL, MISFIRE_INSTR SMALLINT(2) NULL, JOB_DATA BLOB NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (JOB_NAME,JOB_GROUP) REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_SIMPLE_TRIGGERS ( TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, REPEAT_COUNT BIGINT(7) NOT NULL, REPEAT_INTERVAL BIGINT(12) NOT NULL, TIMES_TRIGGERED BIGINT(10) NOT NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_CRON_TRIGGERS ( TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, CRON_EXPRESSION VARCHAR(200) NOT NULL, TIME_ZONE_ID VARCHAR(80), PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_BLOB_TRIGGERS ( TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, BLOB_DATA BLOB NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_TRIGGER_LISTENERS ( TRIGGER_NAME VARCHAR(200) NOT NULL, TRIGGER_GROUP VARCHAR(200) NOT NULL, TRIGGER_LISTENER VARCHAR(200) NOT NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_LISTENER), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_CALENDARS ( CALENDAR_NAME VARCHAR(200) NOT NULL, CALENDAR BLOB NOT NULL, PRIMARY KEY (CALENDAR_NAME));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS ( TRIGGER_GROUP VARCHAR(200) NOT NULL, PRIMARY KEY (TRIGGER_GROUP));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_SCHEDULER_STATE ( INSTANCE_NAME VARCHAR(200) NOT NULL, LAST_CHECKIN_TIME BIGINT(13) NOT NULL, CHECKIN_INTERVAL BIGINT(13) NOT NULL, PRIMARY KEY (INSTANCE_NAME));"; statement.addBatch(create_stmt); create_stmt = "CREATE TABLE QRTZ_LOCKS ( LOCK_NAME VARCHAR(40) NOT NULL, PRIMARY KEY (LOCK_NAME));"; statement.addBatch(create_stmt); create_stmt = "INSERT INTO QRTZ_LOCKS values('TRIGGER_ACCESS');"; statement.addBatch(create_stmt); create_stmt = "INSERT INTO QRTZ_LOCKS values('JOB_ACCESS');"; statement.addBatch(create_stmt); create_stmt = "INSERT INTO QRTZ_LOCKS values('CALENDAR_ACCESS');"; statement.addBatch(create_stmt); create_stmt = "INSERT INTO QRTZ_LOCKS values('STATE_ACCESS');"; statement.addBatch(create_stmt); create_stmt = "INSERT INTO QRTZ_LOCKS values('MISFIRE_ACCESS');"; statement.addBatch(create_stmt); statement.executeBatch(); statement.close(); } else { logger.log(Level.INFO, "Global Quartz Table already exists "); } connection.close(); } catch (Exception ex) { logger.log(Level.SEVERE, "Exception Creating StoreTable " + ex); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstSMWar.CFAstSMWarRequestResetPasswordHtml.java
protected void sendPasswordResetEMail(HttpServletRequest request, ICFAstSecUserObj resetUser, ICFAstClusterObj cluster) throws AddressException, MessagingException, NamingException { final String S_ProcName = "sendPasswordResetEMail"; Properties props = System.getProperties(); String clusterDescription = cluster.getRequiredDescription(); Context ctx = new InitialContext(); String smtpEmailFrom = (String) ctx.lookup("java:comp/env/CFAst22SmtpEmailFrom"); if ((smtpEmailFrom == null) || (smtpEmailFrom.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "JNDI lookup for CFAst22SmtpEmailFrom"); }// ww w .ja v a2 s . c o m smtpUsername = (String) ctx.lookup("java:comp/env/CFAst22SmtpUsername"); if ((smtpUsername == null) || (smtpUsername.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "JNDI lookup for CFAst22SmtpUsername"); } smtpPassword = (String) ctx.lookup("java:comp/env/CFAst22SmtpPassword"); if ((smtpPassword == null) || (smtpPassword.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "JNDI lookup for CFAst22SmtpPassword"); } Session emailSess = Session.getInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUsername, smtpPassword); } }); String thisURI = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI().toString(); int lastSlash = thisURI.lastIndexOf('/'); String baseURI = thisURI.substring(0, lastSlash); UUID resetUUID = resetUser.getOptionalPasswordResetUuid(); String msgBody = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" + "<HTML>\n" + "<BODY>\n" + "<p>\n" + "You requested a password reset for " + resetUser.getRequiredEMailAddress() + " used for accessing " + clusterDescription + ".\n" + "<p>" + "Please click on the following link to reset your password:<br>\n" + "<A HRef=\"" + baseURI + "/CFAstSMWarResetPasswordHtml?ResetUUID=" + resetUUID.toString() + "\">" + baseURI + "/CFAstSMWarResetPasswordHtml?ResetUUID=" + resetUUID.toString() + "</A>\n" + "<p>" + "Or click on the following link to cancel the reset request:<br>\n" + "<A HRef=\"" + baseURI + "/CFAstSMWarCancelResetPasswordHtml?ResetUUID=" + resetUUID.toString() + "\">" + baseURI + "/CFAstSMWarCancelResetPasswordHtml?ResetUUID=" + resetUUID.toString() + "</A>\n" + "</BODY>\n" + "</HTML>\n"; MimeMessage msg = new MimeMessage(emailSess); msg.setFrom(new InternetAddress(smtpEmailFrom)); InternetAddress mailTo[] = InternetAddress.parse(resetUser.getRequiredEMailAddress(), false); msg.setRecipient(Message.RecipientType.TO, mailTo[0]); msg.setSubject("You requested a password reset for your account with " + clusterDescription + "?"); msg.setContent(msgBody, "text/html"); msg.setSentDate(new Date()); msg.saveChanges(); Transport.send(msg); }
From source file:net.sf.ehcache.distribution.JNDIManualRMICacheManagerPeerProvider.java
/** * The last lookup and test isStale may have caused context to be null for jndiProviderUrl. * @param jndiProviderUrl//from ww w . j a v a 2 s . c o m * @return * @throws NamingException */ private CachePeer lookupRemoteCachePeer(String jndiProviderUrl) throws NamingException { Context context = getContext(jndiProviderUrl); if (context == null) { context = registerPeerToContext(jndiProviderUrl); } return (CachePeer) context.lookup(extractCacheName(jndiProviderUrl)); }