List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:com.opensymphony.module.propertyset.database.JDBCPropertySet.java
public void init(Map config, Map args) { // args/*from w w w .ja va2 s. 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:com.duroty.application.mail.manager.MailManager.java
/** * Creates a new MailManager object./* w w w .j ava 2 s. co m*/ * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws NamingException */ public MailManager(HashMap mail) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NamingException { super(); String messageFactory = (String) mail.get(Constants.MESSAGES_FACTORY); if ((messageFactory != null) && !messageFactory.trim().equals("")) { Class clazz = null; clazz = Class.forName(messageFactory.trim()); this.messageable = (Messageable) clazz.newInstance(); this.messageable.setProperties(mail); } this.folderAll = (String) mail.get(Constants.MAIL_FOLDER_ALL); this.folderInbox = (String) mail.get(Constants.MAIL_FOLDER_INBOX); this.folderSent = (String) mail.get(Constants.MAIL_FOLDER_SENT); this.folderTrash = (String) mail.get(Constants.MAIL_FOLDER_TRASH); this.folderBlog = (String) mail.get(Constants.MAIL_FOLDER_BLOG); this.folderDraft = (String) mail.get(Constants.MAIL_FOLDER_DRAFT); this.folderSpam = (String) mail.get(Constants.MAIL_FOLDER_SPAM); this.folderImportant = (String) mail.get(Constants.MAIL_FOLDER_IMPORTANT); this.folderHidden = (String) mail.get(Constants.MAIL_FOLDER_HIDDEN); this.folderChat = (String) mail.get(Constants.MAIL_FOLDER_CHAT); this.quoteSizeAlert = Integer.valueOf((String) mail.get(Constants.MAIL_QUOTE_SIZE_ALERT)).intValue(); tidy.setUpperCaseTags(true); tidy.setInputEncoding(Charset.defaultCharset().displayName()); tidy.setOutputEncoding(Charset.defaultCharset().displayName()); tidy.setMakeBare(true); tidy.setMakeClean(true); tidy.setShowWarnings(false); tidy.setErrout(new PrintWriter(new NullWriter())); tidy.setWord2000(true); tidy.setDropProprietaryAttributes(true); tidy.setFixBackslash(true); tidy.setXHTML(true); //tidy.setXmlOut(true); tidy.setWrapSection(true); tidy.setWrapScriptlets(true); tidy.setWrapPhp(true); tidy.setQuiet(true); tidy.setBreakBeforeBR(true); tidy.setEscapeCdata(true); tidy.setForceOutput(true); tidy.setHideComments(false); tidy.setPrintBodyOnly(true); tidy.setTidyMark(false); Map options = ApplicationConstants.options; Context ctx = new InitialContext(); this.extensions = (HashMap) ctx.lookup((String) options.get(Constants.EXTENSION_CONFIG)); }
From source file:de.iai.ilcd.configuration.ConfigurationService.java
private void migrateDatabaseSchema() { try {//from w ww . ja v a 2 s. c o m Context ctx = new InitialContext(); DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/soda4LCAdbconnection"); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.setBasePackage("de.iai.ilcd.db.migrations"); flyway.setBaseDir("sql/migrations"); this.logSchemaStatus(flyway); try { flyway.validate(); } catch (ValidationException e) { this.logger.error( "database schema: could not successfully validate database status, database needs to be initialized"); throw new RuntimeException("FATAL ERROR: database schema is not properly initialized", e); } int migrations = flyway.migrate(); if (migrations > 0) { this.logger.info("database schema: successfully migrated"); this.logSchemaStatus(flyway); } } catch (FlywayException e) { this.logger.error("error migrating database schema", e); throw new RuntimeException("FATAL ERROR: database schema is not properly initialized", e); } catch (NamingException e) { this.logger.error("error looking up datasource", e); throw new RuntimeException("FATAL ERROR: could not lookup datasource", e); } }
From source file:ca.nrc.cadc.db.DBUtil.java
/** * Find a JNDI DataSource in the specified context. * //from w ww.j a va 2 s. c o m * @param dataSource * @param envContextName * @return * @throws NamingException */ public static DataSource findJNDIDataSource(String dataSource, String envContextName) throws NamingException { log.debug("getDataSource: " + dataSource); Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup(envContextName); DataSource ds = (DataSource) envContext.lookup(dataSource); return ds; }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//*from w w w. j a v a 2 s. c om*/ public void testGetObjectInstance_fnblcore_with_wrappedFactory() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnblcore"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr wrFactory = new StringRefAddr("wrappedFactory", "org.apache.commons.dbcp.BasicDataSourceFactory"); ref.add(wrFactory); RefAddr minIdle = new StringRefAddr("minIdle", "3"); ref.add(minIdle); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.commons.dbcp.BasicDataSource); org.apache.commons.dbcp.BasicDataSource bds = (org.apache.commons.dbcp.BasicDataSource) result; assertEquals(3, bds.getMinIdle()); // // These are read from the db.xml // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); // // These are read from the fnblds.xml // assertEquals("ss", bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); }
From source file:it.cnr.icar.eric.server.persistence.rdb.SQLPersistenceManagerImpl.java
@SuppressWarnings("unused") private SQLPersistenceManagerImpl() { loadUsernamePassword();// w ww . j ava 2 s. c o m constructDatabaseURL(); // define transaction isolation if ("TRANSACTION_READ_COMMITTED".equalsIgnoreCase( RegistryProperties.getInstance().getProperty("eric.persistence.rdb.transactionIsolation"))) { transactionIsolation = Connection.TRANSACTION_READ_COMMITTED; } else { transactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED; } useConnectionPool = Boolean.valueOf( RegistryProperties.getInstance().getProperty("eric.persistence.rdb.useConnectionPooling", "true")) .booleanValue(); skipReferenceCheckOnRemove = Boolean.valueOf(RegistryProperties.getInstance() .getProperty("eric.persistence.rdb.skipReferenceCheckOnRemove", "false")).booleanValue(); dumpStackOnQuery = Boolean.valueOf( RegistryProperties.getInstance().getProperty("eric.persistence.rdb.dumpStackOnQuery", "false")) .booleanValue(); boolean debugConnectionPool = Boolean .valueOf(RegistryProperties.getInstance().getProperty("eric.persistence.rdb.pool.debug", "false")) .booleanValue(); // Create JNDI context if (useConnectionPool) { if (!debugConnectionPool) { // Use Container's connection pooling String ericName = RegistryProperties.getInstance().getProperty("eric.name", "eric"); String envName = "java:comp/env"; String dataSourceName = "jdbc/" + ericName + "-registry"; Context ctx = null; try { ctx = new InitialContext(); if (null == ctx) { log.info(ServerResourceBundle.getInstance().getString("message.UnableToGetInitialContext")); } } catch (NamingException e) { log.info(ServerResourceBundle.getInstance().getString("message.UnableToGetInitialContext"), e); ctx = null; } if (null != ctx) { try { ctx = (Context) ctx.lookup(envName); if (null == ctx) { log.info(ServerResourceBundle.getInstance().getString( "message.UnableToGetJNDIContextForDataSource", new Object[] { envName })); } } catch (NamingException e) { log.info( ServerResourceBundle.getInstance().getString( "message.UnableToGetJNDIContextForDataSource", new Object[] { envName }), e); ctx = null; } } if (null != ctx) { try { ds = (DataSource) ctx.lookup(dataSourceName); if (null == ds) { log.info(ServerResourceBundle.getInstance().getString( "message.UnableToGetJNDIContextForDataSource", new Object[] { envName + "/" + dataSourceName })); } } catch (NamingException e) { log.info(ServerResourceBundle.getInstance().getString( "message.UnableToGetJNDIContextForDataSource", new Object[] { envName + "/" + dataSourceName }), e); ds = null; } } if (null != ds) { // Create a test connection to make sure all is well with // DataSource Connection connection = null; try { connection = ds.getConnection(); } catch (Exception e) { log.info(ServerResourceBundle.getInstance().getString( "message.UnableToCreateTestConnectionForDataSource", new Object[] { envName + "/" + dataSourceName }), e); ds = null; } finally { if (connection != null) { try { connection.close(); } catch (Exception e1) { // Do nothing. connection = null; } } } } } if (ds == null) { // No DataSource available so create our own ConnectionPool loadDatabaseDriver(); createConnectionPool(); } } else { loadDatabaseDriver(); } }
From source file:edu.harvard.i2b2.crc.util.QueryProcessorUtil.java
public StartAnalysisLocal getStartAnalysisLocal() throws I2B2Exception { InitialContext ctx;//from ww w . j av a 2s . c o m try { ctx = new InitialContext(); return (StartAnalysisLocal) ctx.lookup("QP1/StartAnalysis/local"); } catch (NamingException e) { throw new I2B2Exception("Bean lookup error Analysis ", e); } }
From source file:org.jboss.as.test.smoke.embedded.deployment.rar.AS7_1452.AS7_1452TestCase.java
/** * Test config properties//from www .j a v a 2 s .com * * @throws Throwable Thrown if case of an error */ @Test public void testConfigProperties() throws Throwable { Context ctx = new InitialContext(); ConfigPropertyConnectionFactory connectionFactory = (ConfigPropertyConnectionFactory) ctx .lookup(CF_JNDI_NAME); assertNotNull(connectionFactory); ConfigPropertyAdminObjectInterface adminObject = (ConfigPropertyAdminObjectInterface) ctx .lookup(AO_JNDI_NAME); assertNotNull(adminObject); ConfigPropertyConnection connection = connectionFactory.getConnection(); assertNotNull(connection); assertEquals("A", connection.getResourceAdapterProperty()); assertEquals("B", connection.getManagedConnectionFactoryProperty()); assertEquals("C", adminObject.getProperty()); connection.close(); }
From source file:edu.northwestern.bioinformatics.studycalendar.grid.service.globus.resource.BaseResource.java
public ResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/*from w ww . ja va2s. c o m*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration"; logger.debug("Will read configuration from jndi name: " + jndiName); try { Context initialContext = new InitialContext(); this.configuration = (ResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:com.hiperf.common.ui.server.storage.impl.PersistenceHelper.java
private PersistenceHelper(TYPE t, String unitName) { startLicenseCheck();//w w w . j av a2s.c om this.type = t; try { emf = Persistence.createEntityManagerFactory(unitName); emByThread = new ThreadLocal<EntityManager>(); } catch (Exception ee) { logger.log(Level.SEVERE, "Exception while init Persistence.xml...", ee); throw new RuntimeException(ee); } if (this.type.equals(TYPE.JTA)) { try { Context c = new InitialContext(); tx = new JtaTransaction((UserTransaction) c.lookup("java:comp/UserTransaction")); } catch (NamingException e) { logger.log(Level.SEVERE, "Exception while initializing PersistenceHelper in JTA...", e); type = TYPE.LOCAL; } } if (emf.getMetamodel().getEntities() != null && !emf.getMetamodel().getEntities().isEmpty()) { for (EntityType e : emf.getMetamodel().getEntities()) { try { initClassMapping(e.getBindableJavaType().getName()); } catch (Exception e1) { logger.log(Level.SEVERE, "Exception", e1); } } } endLicenseCheck(); }