List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:csiro.pidsvc.core.Settings.java
private Settings(HttpServlet servlet) throws NullPointerException, IOException { // Retrieve manifest. if ((_servlet = servlet) != null) { ServletConfig config = _servlet.getServletConfig(); if (config != null) { ServletContext application = config.getServletContext(); _manifest = new Manifest(application.getResourceAsStream("/META-INF/MANIFEST.MF")); }//from w ww . j av a 2 s. co m } // Retrieve settings. FileInputStream fis = null; try { InitialContext context = new InitialContext(); String settingsFile = (String) context.lookup("java:comp/env/" + SETTINGS_OPT); fis = new FileInputStream(settingsFile); _properties = new PropertyResourceBundle(fis); } catch (NamingException ex) { _logger.debug("Using default pidsvc.properties file."); _properties = ResourceBundle.getBundle("pidsvc"); } finally { if (fis != null) fis.close(); } // Get additional system properties. _serverProperties.put("serverJavaVersion", System.getProperty("java.version")); _serverProperties.put("serverJavaVendor", System.getProperty("java.vendor")); _serverProperties.put("javaHome", System.getProperty("java.home")); _serverProperties.put("serverOsArch", System.getProperty("os.arch")); _serverProperties.put("serverOsName", System.getProperty("os.name")); _serverProperties.put("serverOsVersion", System.getProperty("os.version")); }
From source file:chronos.TestJob.java
/** * @param scheduler//from w w w . j a v a 2s .c om * the {@link Scheduler} * @throws SchedulerException * on exception */ public static final void initializeTestJob(final Scheduler scheduler) throws SchedulerException { try { final Class<?> clazz = Class.forName(TestJob.class.getName()); final JobDetail jobDetail = new JobDetail(TEST_JOB_NAME, CHRONOS, clazz); final JobDataMap jobDataMap = jobDetail.getJobDataMap(); jobDataMap.put(InitialContext.class.getName(), new InitialContext()); final Trigger trigger = TriggerUtils.makeMinutelyTrigger(); trigger.setStartTime(TriggerUtils.getEvenMinuteDate(new Date())); trigger.setName("TestTrigger"); scheduler.scheduleJob(jobDetail, trigger); } catch (final NamingException e) { logger.error("JNDI Exception: " + e.getMessage(), e); } catch (final ClassNotFoundException e) { logger.error(e.getMessage(), e); } }
From source file:io.github.benas.projector.PropertiesInjectorImplTest.java
@Before public void setUp() throws Exception { System.setProperty("threshold", "30"); context = new InitialContext(); context.bind("foo.property", "jndi"); properties = new Properties(); properties.load(this.getClass().getClassLoader().getResourceAsStream("myProperties.properties")); resourceBundle = ResourceBundle.getBundle("i18n/messages"); propertiesInjector = new PropertiesInjectorBuilder().build(); bean = new Bean(); propertiesInjector.injectProperties(bean); }
From source file:net.chrisrichardson.foodToGo.ejb3.facadeWithSpringDI.SpringBeanReferenceInitializer.java
public void destroy() throws Exception { logger.debug("Inside ServicePOJOImpl.destroy()"); InitialContext ctx = new InitialContext(); for (String jndiName : jndiNames) { ctx.unbind(jndiName);/*from w w w .j a va 2s . c o m*/ logger.debug("unbind: " + jndiName); } }
From source file:com.dattack.naming.StandaloneJndiTest.java
@Ignore("Validate the response against the JNDI specification") @Test/*from ww w. ja v a 2 s . c o m*/ public void testBindInvalidContext() throws NamingException { exception.expect(NamingException.class); final InitialContext context = new InitialContext(); final String name = getCompositeName(INVALID_CONTEXT, "testBind"); final Object obj = new Integer(10); context.bind(name, obj); fail(String.format("This test must fail because the name '%s' not exists (object: %s)", INVALID_CONTEXT, ObjectUtils.toString(obj))); }
From source file:blueprint.sdk.experimental.florist.db.ConnectionListener.java
public void contextInitialized(final ServletContextEvent arg0) { Properties poolProp = new Properties(); try {/* w w w. j av a 2s. c om*/ Context initContext = new InitialContext(); // load pool properties file (from class path) poolProp.load(ConnectionListener.class.getResourceAsStream("/jdbc_pools.properties")); StringTokenizer stk = new StringTokenizer(poolProp.getProperty("PROP_LIST")); // process all properties files list in pool properties (from class // path) while (stk.hasMoreTokens()) { try { String propName = stk.nextToken(); LOGGER.info(this, "loading jdbc properties - " + propName); Properties prop = new Properties(); prop.load(ConnectionListener.class.getResourceAsStream(propName)); DataSource dsr; if (prop.containsKey("JNDI_NAME")) { // lookup DataSource from JNDI // FIXME JNDI support is not tested yet. SPI or Factory // is needed here. LOGGER.warn(this, "JNDI DataSource support needs more hands on!"); dsr = (DataSource) initContext.lookup(prop.getProperty("JNDI_NAME")); } else { // create new BasicDataSource BasicDataSource bds = new BasicDataSource(); bds.setMaxActive(Integer.parseInt(prop.getProperty("MAX_ACTIVE"))); bds.setMaxIdle(Integer.parseInt(prop.getProperty("MAX_IDLE"))); bds.setMaxWait(Integer.parseInt(prop.getProperty("MAX_WAIT"))); bds.setInitialSize(Integer.parseInt(prop.getProperty("INITIAL"))); bds.setDriverClassName(prop.getProperty("CLASS_NAME")); bds.setUrl(prop.getProperty("URL")); bds.setUsername(prop.getProperty("USER")); bds.setPassword(prop.getProperty("PASSWORD")); bds.setValidationQuery(prop.getProperty("VALIDATION")); dsr = bds; } boundDsrs.put(prop.getProperty("POOL_NAME"), dsr); initContext.bind(prop.getProperty("POOL_NAME"), dsr); } catch (RuntimeException e) { LOGGER.trace(e); } } } catch (IOException | NamingException e) { LOGGER.trace(e); } }
From source file:com.sf.ddao.UseStatementFactoryTest.java
protected void setUp() throws Exception { super.setUp(); JDBCMockObjectFactory factory = getJDBCMockObjectFactory(); MockDataSource ds = factory.getMockDataSource(); MockContextFactory.setAsInitial();//from ww w .ja va2 s . c o m InitialContext context = new InitialContext(); context.rebind(JNDIDataSourceHandler.DS_CTX_PREFIX + "jdbc/testdb", ds); this.injector = Guice.createInjector(new ChainModule(UserDao.class)); }
From source file:com.silverpeas.admin.UsersAndGroupsTest.java
@BeforeClass public static void setUpClass() throws Exception { SimpleMemoryContextFactory.setUpAsInitialContext(); context = new ClassPathXmlApplicationContext( new String[] { "spring-domains-embbed-datasource.xml", "spring-domains.xml" }); dataSource = context.getBean("jpaDataSource", DataSource.class); InitialContext ic = new InitialContext(); ic.rebind("jdbc/Silverpeas", dataSource); DBUtil.getInstanceForTest(dataSource.getConnection()); }
From source file:com.autentia.tnt.util.ConfigurationUtil.java
/** * Constructor//w w w .j ava2 s. c o m * * @param jndiPathVar * JNDI variable in which configuration directory is stored * @param file * path to configuration file */ public ConfigurationUtil(String jndiPathVar, String file) throws ConfigurationException, NamingException { Context ctx = new InitialContext(); configDir = ctx.lookup(jndiPathVar).toString(); if (!configDir.endsWith("/") && !configDir.endsWith("\\")) { configDir = configDir.trim() + "/"; } config = new PropertiesConfiguration(configDir + file); }
From source file:com.t2tierp.controller.LoginController.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String nomeUsuario = authentication.getName(); String senha = authentication.getCredentials().toString(); try {/* ww w . j a v a 2 s. c o m*/ InitialContext initialContext = new InitialContext(); dao = (UsuarioDAO) initialContext.lookup("java:comp/ejb/usuarioDAO"); Md5PasswordEncoder enc = new Md5PasswordEncoder(); senha = enc.encodePassword(nomeUsuario + senha, null); Usuario usuario = dao.getUsuario(nomeUsuario, senha); if (usuario != null) { List<PapelFuncao> funcoes = dao.getPapelFuncao(usuario); List<GrantedAuthority> grantedAuths = new ArrayList<>(); for (PapelFuncao p : funcoes) { grantedAuths.add(new SimpleGrantedAuthority(p.getFuncao().getNome())); } Authentication auth = new UsernamePasswordAuthenticationToken(nomeUsuario, senha, grantedAuths); return auth; } } catch (Exception e) { //e.printStackTrace(); } return null; }