List of usage examples for javax.naming InitialContext lookup
public Object lookup(Name name) throws NamingException
From source file:org.meveo.service.job.JobInstanceService.java
public List<Job> getJobs() { List<Job> jobs = new ArrayList<Job>(); for (HashMap<String, String> jobInfos : jobEntries.values()) { for (String url : jobInfos.values()) { try { InitialContext ic = new InitialContext(); Job job = (Job) ic.lookup(url); jobs.add(job);//from w w w. j a v a 2s . c om } catch (NamingException e) { log.error("Failed to get job by url {}", url, e); } } } return jobs; }
From source file:org.nuxeo.ecm.platform.importer.base.TxHelper.java
protected Transaction createTxFromTM() { InitialContext context = null; try {//from w w w . jav a 2s . c o m context = new InitialContext(); } catch (Exception e) { disabled = true; return null; } TransactionManager tm = null; try { tm = (TransactionManager) context.lookup(TM_NAME); } catch (NamingException ne) { try { tm = (TransactionManager) context.lookup(TM_NAME_ALT); } catch (NamingException ne2) { } } if (tm == null) { disabled = true; return null; } try { return tm.getTransaction(); } catch (SystemException e) { disabled = true; return null; } }
From source file:br.ufc.ivela.web.action.GenericAction.java
public void addHistory(String title, String description, SystemUser systemUser, String... params) { if (historyRemote == null) { try {//from www . j a v a 2 s . c o m InitialContext initialContext = new InitialContext(); java.lang.Object ejbRemoteRef = initialContext .lookup("HistoryBean#br.ufc.ivela.ejb.interfaces.HistoryRemote"); historyRemote = (HistoryRemote) javax.rmi.PortableRemoteObject.narrow(ejbRemoteRef, HistoryRemote.class); } catch (NamingException e) { e.printStackTrace(); historyRemote = null; } } List<History> historyList = historyRemote.getBySystemUser(systemUser.getId()); boolean insert = true; for (History h : historyList) { if (h.getDescription().equalsIgnoreCase(description) && h.getTitle().equalsIgnoreCase(title)) { List<HistoryParams> historyParamsList = historyParamsRemote.getByHistory(h.getId()); int equal = 0; for (int i = 0; i < params.length; i++) { for (HistoryParams hp : historyParamsList) { if (hp.getParam().equalsIgnoreCase(String.valueOf(i)) && hp.getValue().equalsIgnoreCase(params[i])) { equal++; break; } } } if (equal == params.length) { insert = false; break; } } } if (insert) { History history = new History(); history.setSystemUser(systemUser); history.setDatetime(new Date()); history.setTitle(title); history.setDescription(description); Long id = historyRemote.add(history); for (int i = 0; params != null && i < params.length; i++) { HistoryParams historyParams = new HistoryParams(); historyParams.setHistoryId(id); historyParams.setParam(String.valueOf(i)); historyParams.setValue(params[i]); historyParamsRemote.add(historyParams); } } }
From source file:br.ufc.ivela.web.action.GenericAction.java
public void addHistory(String title, String description, String... params) { if (historyRemote == null) { try {/*from w w w.j a v a2 s. co m*/ InitialContext initialContext = new InitialContext(); java.lang.Object ejbRemoteRef = initialContext .lookup("HistoryBean#br.ufc.ivela.ejb.interfaces.HistoryRemote"); historyRemote = (HistoryRemote) javax.rmi.PortableRemoteObject.narrow(ejbRemoteRef, HistoryRemote.class); } catch (NamingException e) { e.printStackTrace(); historyRemote = null; } } List<History> historyList = historyRemote.getBySystemUser(getAuthenticatedUser().getId()); boolean insert = true; for (History h : historyList) { if (h.getDescription().equalsIgnoreCase(description) && h.getTitle().equalsIgnoreCase(title)) { List<HistoryParams> historyParamsList = historyParamsRemote.getByHistory(h.getId()); int equal = 0; for (int i = 0; i < params.length; i++) { for (HistoryParams hp : historyParamsList) { if (hp.getParam().equalsIgnoreCase(String.valueOf(i)) && hp.getValue().equalsIgnoreCase(params[i])) { equal++; break; } } } if (equal == params.length) { insert = false; break; } } } if (insert) { History history = new History(); history.setSystemUser(getAuthenticatedUser()); history.setDatetime(new Date()); history.setTitle(title); history.setDescription(description); Long id = historyRemote.add(history); for (int i = 0; params != null && i < params.length; i++) { HistoryParams historyParams = new HistoryParams(); historyParams.setHistoryId(id); historyParams.setParam(String.valueOf(i)); historyParams.setValue(params[i]); historyParamsRemote.add(historyParams); } } }
From source file:io.apiman.gateway.test.junit.servlet.ServletGatewayTestServer.java
/** * Called after stopping the gateway./* w w w . ja v a 2 s . co m*/ */ private void postStop() throws Exception { if (node != null) { client.execute(new DeleteIndex.Builder("apiman_gateway").build()); SimpleJestClientFactory.clearClientCache(); } if (ds != null) { try (Connection connection = ds.getConnection()) { connection.prepareStatement("DROP ALL OBJECTS").execute(); } ds.close(); ds = null; InitialContext ctx = TestUtil.initialContext(); Context pctx = (Context) ctx.lookup("java:/comp/env/jdbc"); pctx.unbind("ApiGatewayDS"); } if (cacheContainer != null) { cacheContainer.stop(); cacheContainer = null; InitialContext ctx = TestUtil.initialContext(); Context pctx = (Context) ctx.lookup("java:jboss/infinispan"); pctx.unbind("apiman"); } }
From source file:eu.uqasar.web.dashboard.widget.datadeviation.DataDeviationSettingsPanel.java
public DataDeviationSettingsPanel(String id, IModel<DataDeviationWidget> model) { super(id, model); setOutputMarkupPlaceholderTag(true); // Get the project from the settings projectName = getModelObject().getSettings().get("project"); // DropDown select for Projects TreeNodeService treeNodeService = null; try {/*from w w w . ja v a 2s . c om*/ 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(); } //Form and WMCs final Form<Widget> form = new Form<>("form"); wmcGeneral = newWebMarkupContainer("wmcGeneral"); form.add(wmcGeneral); //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); int noOfObjs = OBJS.size(); int noOfIndis = INDIS.size(); if (index + 1 == 1 && noOfObjs > 0) { buffer.append("<optgroup label='Quality Objectives'></optgroup>"); } 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); 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); DataDeviationWidgetView widgetView = (DataDeviationWidgetView) widgetPanel.getWidgetView(); target.add(widgetView); 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.meveo.service.job.JobInstanceService.java
private void scheduleUnscheduleJob(JobInstance jobInstance) { try {// w ww. jav a 2 s .c o m if (!jobEntries.containsKey(jobInstance.getJobCategoryEnum())) { log.error("Not registered job category {} for jobInstance {}", jobInstance.getJobCategoryEnum(), jobInstance.getCode()); throw new RuntimeException("Not registered job category " + jobInstance.getJobCategoryEnum()); } HashMap<String, String> jobs = jobEntries.get(jobInstance.getJobCategoryEnum()); if (!jobs.containsKey(jobInstance.getJobTemplate())) { log.error("cannot find job {} for jobInstance {}", jobInstance.getJobTemplate(), jobInstance.getCode()); throw new RuntimeException("cannot find job " + jobInstance.getJobTemplate()); } if (jobTimers.containsKey(jobInstance.getId())) { try { Timer timer = jobTimers.get(jobInstance.getId()); timer.cancel(); jobTimers.remove(jobInstance.getId()); log.info("Cancelled timer {}, id={}", jobInstance.getJobTemplate(), jobInstance.getId()); } catch (Exception ex) { log.error("Failed to cancel timer {}, id={}", jobInstance.getJobTemplate(), jobInstance.getId(), ex); } } if (jobInstance.isActive() && jobInstance.getTimerEntity() != null) { InitialContext ic = new InitialContext(); Job job = (Job) ic.lookup(jobs.get(jobInstance.getJobTemplate())); log.info("Scheduling job {} : timer {}", job, jobInstance.getId()); jobTimers.put(jobInstance.getId(), job.createTimer(jobInstance.getTimerEntity().getScheduleExpression(), jobInstance)); } else { log.debug("Job {} is inactive or has no timer and will not be scheduled", jobInstance.getCode()); } } catch (NamingException e) { log.error("Failed to schedule job", e); } }
From source file:org.pepstock.jem.ant.tasks.utilities.sort.DefaultComparator.java
/** * Checks if COMMAND data description is allocated. If not, uses the default string * comparator. Otherwise loads all comparators. * //from w w w . j av a 2s . co m * @throws Exception if any IO of parsing commands exception occurs * */ public DefaultComparator() { // new initial context to access by JNDI to COMMAND DataDescription InitialContext ic; try { ic = ContextUtils.getContext(); // gets inputstream Object filein = (Object) ic.lookup(DATA_DESCRIPTION_NAME); // reads content of inout stream StringBuilder recordsSB = read((InputStream) filein); // trims result to see if is empty String records = recordsSB.toString().trim(); // loads commands loadCommands(records); } catch (NamingException e) { LogAppl.getInstance().emit(AntMessage.JEMA044W, e, e.getMessage()); } catch (ParseException e) { LogAppl.getInstance().emit(AntMessage.JEMA058W, e, e.getMessage()); } catch (IOException e) { LogAppl.getInstance().emit(AntMessage.JEMA058W, e, e.getMessage()); } }
From source file:org.pepstock.jem.jbpm.tasks.utilities.sort.DefaultComparator.java
/** * Checks if COMMAND data description is allocated. If not, uses the default string * comparator. Otherwise loads all comparators. * /*from w w w. ja va 2 s. c om*/ * @throws Exception if any IO of parsing commands exception occurs * */ public DefaultComparator() { // new initial context to access by JNDI to COMMAND DataDescription InitialContext ic; try { ic = ContextUtils.getContext(); // gets inputstream Object filein = (Object) ic.lookup(DATA_DESCRIPTION_NAME); // reads content of inout stream StringBuilder recordsSB = read((InputStream) filein); // trims result to see if is empty String records = recordsSB.toString().trim(); // loads commands loadCommands(records); } catch (NamingException e) { LogAppl.getInstance().emit(JBpmMessage.JEMM044W, e, e.getMessage()); } catch (ParseException e) { LogAppl.getInstance().emit(JBpmMessage.JEMM058W, e, e.getMessage()); } catch (IOException e) { LogAppl.getInstance().emit(JBpmMessage.JEMM058W, e, e.getMessage()); } }
From source file:org.jboss.as.test.integration.security.loginmodules.RemotingLoginModuleTestCase.java
/** * Tests if client access is denied for untrusted clients. * * @throws Exception//w w w .ja v a 2s .c o m */ @Test public void testNotTrustedClient() throws Exception { final Properties env = configureEjbClient(CLIENT_NOT_TRUSTED_NAME); InitialContext ctx = new InitialContext(env); try { ctx.lookup(HELLOBEAN_LOOKUP_NAME); fail("The JNDI lookup should fail for untrusted client."); } catch (NamingException e) { //OK } ctx.close(); }