List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:com.francetelecom.clara.cloud.commons.JasyptPrerequisites.java
private void assertJasyptPrerequisites(String passPhraseEnvName, String passPhraseJndiName) { Validate.notEmpty(passPhraseEnvName, "passPhraseEnvName cannot be empty, neither null"); String passPhrase = System.getenv(passPhraseEnvName); if (!isPassPhraseCorrect(passPhrase)) { try {//from ww w . j a v a 2 s . c o m InitialContext ctx = new InitialContext(); String jndiValue = (String) ctx.lookup(passPhraseJndiName); passPhrase = jndiValue; } catch (NamingException e) { logger.info("No Jndi jasypt secret named " + passPhraseJndiName, e); } } if (!isPassPhraseCorrect(passPhrase)) { throw new TechnicalException( "Jasypt require pass phrase into environment or jndi variables : '" + passPhraseEnvName + "'"); } }
From source file:com.silverpeas.admin.SpacesManagersTest.java
@BeforeClass public static void setUpClass() throws Exception { SimpleMemoryContextFactory.setUpAsInitialContext(); context = new ClassPathXmlApplicationContext( new String[] { "spring-admin-spacemanagers-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:io.seldon.db.jdbc.JDBCConnectionFactory.java
public JDBCConnectionFactory() { try {/* w ww . ja v a 2s. c o m*/ ctx = new InitialContext(); } catch (NamingException e) { ctx = null; logger.error("Couldn't start JDNI context", e); } factory = this; }
From source file:almira.weblogic.JndiInjectorTest.java
@Before public void setUp() throws NamingException, IOException { SimpleNamingContextBuilder.emptyActivatedContextBuilder(); ic = new InitialContext(); injector = new JndiInjector(ic); }
From source file:com.googlecode.datasourcetester.server.DataSourceTesterServiceImpl.java
public String[][] queryDataSource(String dataSourceJndiName, String query) { Connection conn = null;// ww w.ja va 2 s .c om try { InitialContext jndiContext = new InitialContext(); DataSource ds = (DataSource) jndiContext.lookup(dataSourceJndiName); conn = ds.getConnection(); PreparedStatement stmt = conn.prepareStatement(query); ResultSet rs = stmt.executeQuery(); ResultSetMetaData resMeta = rs.getMetaData(); LinkedList<String[]> rowList = new LinkedList<String[]>(); String[] colLabels = new String[resMeta.getColumnCount()]; for (int colNr = 1; colNr <= resMeta.getColumnCount(); colNr++) { colLabels[colNr - 1] = resMeta.getColumnName(colNr); } rowList.add(colLabels); while (rs.next()) { String[] rowData = new String[resMeta.getColumnCount()]; for (int colNr = 1; colNr <= resMeta.getColumnCount(); colNr++) { rowData[colNr - 1] = rs.getString(colNr); } rowList.add(rowData); } conn.close(); return rowList.toArray(new String[rowList.size()][]); } catch (Exception e) { logger.error(e.getMessage(), e); try { if (conn != null && !conn.isClosed()) { conn.close(); } } catch (SQLException sqlEx) { logger.error(sqlEx.getMessage(), sqlEx); } return null; } }
From source file:com.xpn.xwiki.internal.XWikiCfgConfigurationSource.java
/** * @return the location where to find the configuration *///from w w w . ja va2 s . c o m public static String getConfigPath() { String configurationLocation; try { Context envContext = (Context) new InitialContext().lookup("java:comp/env"); configurationLocation = (String) envContext.lookup(CFG_ENV_NAME); } catch (Exception e) { configurationLocation = "/etc/xwiki/xwiki.cfg"; if (!new File(configurationLocation).exists()) { configurationLocation = "/WEB-INF/xwiki.cfg"; } } return configurationLocation; }
From source file:dk.itst.oiosaml.sp.service.session.jdbc.JndiFactory.java
public SessionHandler getHandler() { try {//from w w w . ja v a2s. co m InitialContext ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(name); return new JdbcSessionHandler(ds); } catch (NamingException e) { throw new RuntimeException(e); } }
From source file:com.stratelia.silverpeas.silverStatisticsPeas.control.PerfVolumeTest.java
@BeforeClass public static void setupDataSource() throws NamingException { SimpleMemoryContextFactory.setUpAsInitialContext(); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("org.postgresql.Driver"); ds.setUsername("postgres"); ds.setPassword("postgres"); ds.setUrl("jdbc:postgresql://localhost:5432/extranet"); InitialContext ic = new InitialContext(); ic.bind("java:/datasources/silverpeas-jdbc", ds); ic.bind("java:/datasources/DocumentStoreDS", ds); }
From source file:com.baidu.stqa.signet.web.service.impl.RoleServiceImpl.java
@Override public boolean generateRole(String name, String roleTag, Long spaceId, Long type) throws NamingException { InitialContext initialContext = new InitialContext(); String path = SysProperty.getImgPath(); Role condiRole = new Role(); condiRole.setRoleTag(roleTag);/* ww w . j a v a 2 s . co m*/ // ?false if (!roleMapper.selectByCondi(condiRole).isEmpty()) { return false; } else {// ????true Role role = new Role(); role.setName(name); role.setRoleTag(roleTag); role.setProjectId(spaceId); role.setRoleSignType(type); try { roleMapper.insert(role); File f = new File(path + spaceId); // if (!f.exists()) { f.mkdirs(); } ImgGenerator.generateImg(name, type, path + spaceId + "/" + roleTag + ".jpg"); return true; } catch (Exception e) { e.printStackTrace(); return false; } } }
From source file:com.alliander.osgp.webdevicesimulator.application.config.WebDeviceSimulatorInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {/* w ww . j a v a 2 s. c om*/ // Force the timezone of application to UTC (required for // Hibernate/JDBC) TimeZone.setDefault(TimeZone.getTimeZone("UTC")); final Context initialContext = new InitialContext(); final String logLocation = (String) initialContext .lookup("java:comp/env/osp/webDeviceSimulator/log-config"); LogbackConfigurer.initLogging(logLocation); InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory()); final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationContext.class); final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); servletContext.addListener(new ContextLoaderListener(rootContext)); } catch (final NamingException e) { throw new ServletException("naming exception", e); } catch (final FileNotFoundException e) { throw new ServletException("Logging file not found", e); } catch (final JoranException e) { throw new ServletException("Logback exception", e); } }