List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:org.apache.servicemix.jms.AbstractJmsTestSupport.java
protected void configureJbiContainer() throws Exception { container.setEmbedded(true);//from w w w . ja v a2 s. co m container.setUseMBeanServer(false); container.setCreateMBeanServer(false); container.setCreateJmxConnector(false); container.setRootDir("target/smx-data"); container.setMonitorInstallationDirectory(false); container.setNamingContext(new InitialContext()); container.setTransactionManager(new GeronimoPlatformTransactionManager()); }
From source file:com.silverpeas.components.model.AbstractSpringJndiDaoTest.java
@Before public void init() throws Exception { InitialContext ic = new InitialContext(); Properties props = new Properties(); props.load(AbstractTestDao.class.getClassLoader().getResourceAsStream("jdbc.properties")); jndiName = props.getProperty("jndi.name"); rebind(ic, jndiName, this.dataSource); ic.rebind(jndiName, this.dataSource); IDatabaseConnection connection = getConnection(); getSetUpOperation().execute(connection, getDataSet()); connection.close();//from w ww. ja va2s.c o m }
From source file:com.jsquant.listener.JsquantContextListener.java
protected String getFileCachePath(ServletContext context) { String fileCachePath = null;//from w w w . j a v a2 s.c om try { InitialContext initial = new InitialContext(); fileCachePath = (String) initial.lookup(JNDI_DATA_PATH); } catch (Throwable err) { // ignore when JNDI not available or no param set } if (fileCachePath == null) { fileCachePath = System.getProperty("filecache.path"); } if (fileCachePath == null) { fileCachePath = DEFAULT_FILE_CACHE_PATH; } log.info("fileCachePath=" + fileCachePath); return fileCachePath; }
From source file:arena.utils.ServletUtils.java
public static String getHostSetting(String jndiParam, String jvmArg) { String hostSetting = null;//from w w w. j av a 2s . c o m // Get host settings via JNDI if available if (jndiParam != null) try { InitialContext initial = new InitialContext(); hostSetting = (String) initial.lookup(jndiParam); } catch (Throwable err) { /* Ignore - no jndi available, or no param set */ } if (hostSetting == null) { hostSetting = System.getProperty(jvmArg); } return hostSetting; }
From source file:com.alfaariss.oa.util.database.jdbc.DataSourceFactory.java
/** * Creates a DataSource object specified by the supplied properties: * /*from www .ja va 2 s . c o m*/ * <ul> * <li>environment_context</li> * <li>resource-ref</li> * </ul> * * or: * *<ul> * <li>password</li> * <li>url</li> * <li>username</li> * <li>driverClassName</li> * <li>maxActive</li> * <li>maxIdle</li> * <li>maxWait</li> * <li>minIdle</li> * <li>defaultAutoCommit</li> * <li>defaultReadOnly</li> * <li>defaultTransactionIsolation</li> * <li>defaultCatalog</li> * <li>initialSize</li> * <li>testOnBorrow</li> * <li>testOnReturn</li> * <li>timeBetweenEvictionRunsMillis</li> * <li>numTestsPerEvictionRun</li> * <li>minEvictableIdleTimeMillis</li> * <li>testWhileIdle</li> * <li>validationQuery</li> * <li>accessToUnderlyingConnectionAllowed</li> * <li>removeAbandoned</li> * <li>removeAbandonedTimeout</li> * <li>logAbandoned</li> * <li>poolPreparedStatements</li> * <li>maxOpenPreparedStatements</li> * <li>connectionProperties</li> * </ul> * @param pConfig config properties * @return DataSource object * @throws DatabaseException if creation fails */ public static DataSource createDataSource(Properties pConfig) throws DatabaseException { DataSource ds = null; try { if (pConfig.containsKey("environment_context")) { String sContext = pConfig.getProperty("environment_context"); Context envCtx = null; try { envCtx = (Context) new InitialContext().lookup(sContext); } catch (NamingException e) { _logger.warn("Could not find context: " + sContext, e); throw new DatabaseException(SystemErrors.ERROR_INIT); } String sResourceRef = pConfig.getProperty("resource-ref"); try { ds = (DataSource) envCtx.lookup(sResourceRef); } catch (NamingException e) { _logger.warn("Could not find resource ref: " + sResourceRef, e); throw new DatabaseException(SystemErrors.ERROR_INIT); } _logger.info("Created DataSource by reading from context"); } else { ds = BasicDataSourceFactory.createDataSource(pConfig); _logger.info("Created DataSource by reading properties object"); } } catch (Exception e) { _logger.fatal("Could not initialize object", e); throw new DatabaseException(SystemErrors.ERROR_INTERNAL); } return ds; }
From source file:it.infn.ct.futuregateway.apiserver.APIContextListener.java
@Override public final void contextInitialized(final ServletContextEvent sce) { log.info("Creation of the Hibernate SessionFactory for the context"); try {// w ww . j ava2 s .com entityManagerFactory = Persistence .createEntityManagerFactory("it.infn.ct.futuregateway.apiserver.container"); } catch (Exception ex) { log.warn("Resource 'jdbc/FutureGatewayDB' not accessuible or" + " not properly configured for the application. An" + " alternative resource is created on the fly."); entityManagerFactory = Persistence.createEntityManagerFactory("it.infn.ct.futuregateway.apiserver.app"); } sce.getServletContext().setAttribute(Constants.SESSIONFACTORY, entityManagerFactory); String path = sce.getServletContext().getInitParameter("CacheDir"); if (path == null || path.isEmpty()) { path = sce.getServletContext().getRealPath("/") + ".." + FileSystems.getDefault().getSeparator() + ".." + FileSystems.getDefault().getSeparator() + "FutureGatewayData"; } log.info("Created the cache directory: " + path); sce.getServletContext().setAttribute(Constants.CACHEDIR, path); try { Files.createDirectories(Paths.get(path)); log.info("Cache dir enabled"); } catch (FileAlreadyExistsException faee) { log.debug("Message for '" + path + "':" + faee.getMessage()); log.info("Cache dir enabled"); } catch (Exception e) { log.error("Impossible to initialise the temporary store"); } ExecutorService tpe; try { Context ctx = new InitialContext(); tpe = (ExecutorService) ctx.lookup("java:comp/env/threads/Submitter"); } catch (NamingException ex) { log.warn("Submitter thread not defined in the container. A thread " + "pool is created using provided configuration parameters " + "and defaults values"); int threadPoolSize = Constants.DEFAULTTHREADPOOLSIZE; try { threadPoolSize = Integer .parseInt(sce.getServletContext().getInitParameter("SubmissioneThreadPoolSize")); } catch (NumberFormatException nfe) { log.info("Parameter 'SubmissioneThreadPoolSize' has a wrong" + " value or it is not present. Default value " + "10 is used"); } tpe = ThreadPoolFactory.getThreadPool(threadPoolSize, Constants.MAXTHREADPOOLSIZETIMES * threadPoolSize, Constants.MAXTHREADIDLELIFE); } sce.getServletContext().setAttribute(Constants.SUBMISSIONPOOL, tpe); }
From source file:eu.uqasar.web.dashboard.widget.uqasardatavisualization.UqasarDataVisualizationSettingsPanel.java
public UqasarDataVisualizationSettingsPanel(String id, IModel<UqasarDataVisualizationWidget> model) { super(id, model); setOutputMarkupPlaceholderTag(true); //Form and WMCs final Form<Widget> form = new Form<>("form"); wmcGeneral = newWebMarkupContainer("wmcGeneral"); form.add(wmcGeneral);/*from w ww . j ava2 s.c om*/ // Get the project from the settings projectName = getModelObject().getSettings().get("project"); // DropDown select for Projects TreeNodeService treeNodeService = null; try { InitialContext ic = new InitialContext(); treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService"); projects = treeNodeService.getAllProjectsOfLoggedInUser(); if (projects != null && projects.size() != 0) { if (projectName == null || projectName.isEmpty()) { projectName = projects.get(0).getName(); } project = treeNodeService.getProjectByName(projectName); recreateAllProjectTreeChildrenForProject(project); } } catch (NamingException e) { e.printStackTrace(); } //project List<String> joinedQualityParameters = ListUtils.union(ListUtils.union(OBJS, INDIS), MTRX); qualityParameterChoice = new DropDownChoice<String>("qualityParams", new PropertyModel<String>(this, "qualityParams"), joinedQualityParameters) { @Override protected void appendOptionHtml(AppendingStringBuffer buffer, String choice, int index, String selected) { super.appendOptionHtml(buffer, choice, index, selected); if (UqasarDataVisualizationWidget.ALL.get(0).equals(choice)) { buffer.append("<optgroup label='Quality Objectives'></optgroup>"); } int noOfObjs = OBJS.size(); int noOfIndis = INDIS.size(); if (index + 1 == noOfObjs && noOfObjs > 0) { buffer.append("<optgroup label='Quality Indicators'></optgroup>"); } if (index + 1 == (noOfObjs + noOfIndis) && noOfIndis > 0) { buffer.append("<optgroup label='Metrics'></optgroup>"); } } }; qualityParameterChoice.setOutputMarkupId(true); wmcGeneral.add(qualityParameterChoice); // project projectChoice = new DropDownChoice<>("projects", new PropertyModel<Project>(this, "project"), projects); if (project != null) { projectChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { System.out.println(project); recreateAllProjectTreeChildrenForProject(project); qualityParameterChoice.setChoices(ListUtils.union(ListUtils.union(OBJS, INDIS), MTRX)); target.add(qualityParameterChoice); target.add(wmcGeneral); target.add(form); } }); } wmcGeneral.setOutputMarkupId(true); wmcGeneral.add(projectChoice); form.add(new AjaxSubmitLink("submit") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { if (project != null) { getModelObject().getSettings().put("qualityParams", qualityParams); getModelObject().getSettings().put("project", project.getName()); Dashboard dashboard = findParent(DashboardPanel.class).getDashboard(); DbDashboard dbdb = (DbDashboard) dashboard; WidgetPanel widgetPanel = findParent(WidgetPanel.class); UqasarDataVisualizationWidgetView widgetView = (UqasarDataVisualizationWidgetView) widgetPanel .getWidgetView(); target.add(widgetPanel); hideSettingPanel(target); // Do not save the default dashboard if (dbdb.getId() != null && dbdb.getId() != 0) { dashboardContext.getDashboardPersiter().save(dashboard); PageParameters params = new PageParameters(); params.add("id", dbdb.getId()); setResponsePage(DashboardViewPage.class, params); } } } }); form.add(new AjaxLink<Void>("cancel") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { hideSettingPanel(target); } }); add(form); }
From source file:org.ualerts.chat.database.EmbeddedHsqlDatabaseServer.java
private boolean wantEmbeddedDatabase() { boolean useEmbedded = false; try {//from w w w. java2 s . c o m Context initCtx = new InitialContext(); DataSource ds = (DataSource) initCtx.lookup(dataSourceName); Class<?> dataSourceClass = ds.getClass(); Method urlMethod = dataSourceClass.getMethod("getUrl"); String url = (String) urlMethod.invoke(ds); useEmbedded = url.endsWith("/" + DEFAULT_DATABASE_NAME); } catch (NoSuchMethodException ex) { logger.warn("data source has no accessor for the URL"); } catch (IllegalAccessException ex) { logger.warn("cannot access the data source URL"); } catch (InvocationTargetException ex) { logger.warn("error accessing the data source URL"); } catch (NamingException ex) { logger.warn("JNDI lookup failed: " + ex); } return useEmbedded; }
From source file:com.silverpeas.components.model.SilverpeasJndiCase.java
public void configureJNDIDatasource() throws IOException, NamingException, Exception { InitialContext ic = new InitialContext(); if (datasource == null) { Properties props = new Properties(); props.load(SilverpeasJndiCase.class.getClassLoader().getResourceAsStream("jdbc.properties")); datasource = (BasicDataSource) BasicDataSourceFactory.createDataSource(props); jndiName = props.getProperty("jndi.name"); ic.rebind(jndiName, datasource); }//from w w w . j a v a 2 s. co m }