List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:gov.nih.nci.caarray.services.external.v1_0.grid.service.globus.resource.CaArraySvc_v1_0ResourceBase.java
public CaArraySvc_v1_0ResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/*from ww w . ja v a 2s. c om*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/CaArraySvc_v1_0"; 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 = (CaArraySvc_v1_0ResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:it.infn.ct.security.actions.RegisterUser.java
private void sendMail(UserRequest usreq) throws MailException { javax.mail.Session session = null;/*from ww w . ja v a 2 s . c o m*/ try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); session = (javax.mail.Session) envCtx.lookup("mail/Users"); } catch (Exception ex) { log.error("Mail resource lookup error"); log.error(ex.getMessage()); throw new MailException("Mail Resource not available"); } Message mailMsg = new MimeMessage(session); try { mailMsg.setFrom(new InternetAddress(mailFrom, idPAdmin)); InternetAddress mailTo[] = new InternetAddress[1]; mailTo[0] = new InternetAddress(usreq.getPreferredMail(), usreq.getTitle() + " " + usreq.getGivenname() + " " + usreq.getSurname()); mailMsg.setRecipients(Message.RecipientType.TO, mailTo); String ccMail[] = mailCC.split(";"); InternetAddress mailCCopy[] = new InternetAddress[ccMail.length]; for (int i = 0; i < ccMail.length; i++) { mailCCopy[i] = new InternetAddress(ccMail[i]); } mailMsg.setRecipients(Message.RecipientType.CC, mailCCopy); mailMsg.setSubject(mailSubject); mailBody = mailBody.replaceAll("_USER_", usreq.getTitle() + " " + usreq.getGivenname() + " " + usreq.getSurname()); mailMsg.setText(mailBody); Transport.send(mailMsg); } catch (UnsupportedEncodingException ex) { log.error(ex); throw new MailException("Mail from address format not valid"); } catch (MessagingException ex) { log.error(ex); throw new MailException("Mail message has problems"); } }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//*from ww w .ja v a 2s.c om*/ public void testGetObjectInstance_fnblcore() 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 minIdle = new StringRefAddr("minIdle", "3"); ref.add(minIdle); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (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:gov.nih.nci.ess.ae.service.service.globus.resource.AdverseEventEnterpriseServiceResourceBase.java
public AdverseEventEnterpriseServiceResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }/* www . j av a 2 s .c o m*/ MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/AdverseEventEnterpriseService"; 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 = (AdverseEventEnterpriseServiceResourceConfiguration) initialContext .lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:gov.nih.nci.ess.safetyreporting.management.service.globus.resource.SafetyReportManagementResourceBase.java
public SafetyReportManagementResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }//from w w w. j av a 2s . co m MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/SafetyReportManagement"; 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 = (SafetyReportManagementResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:Controllers.AppointmentController.java
/** * return list on all appointments./*from ww w. j a v a 2 s . c om*/ * * @return */ public Appointment[] fetchAppointments() { Appointment[] appointments = null; try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("jdbc/medicalCareDataSource"); connection = ds.getConnection(); Statement stmt = connection.createStatement(); String smtquery = "SELECT * FROM appointments"; ResultSet resultSet; resultSet = stmt.executeQuery(smtquery); List<Appointment> appointmentsList = new ArrayList<Appointment>(); while (resultSet.next()) { Appointment appointment = new Appointment(); appointment.setAccountId(resultSet.getInt("accountId")); appointment.setAppointmentId(resultSet.getInt("appointmentId")); appointment.setDate(resultSet.getDate("date")); appointment.setDepartmentId(resultSet.getInt("departmentId")); appointment.setMessage(resultSet.getString("message")); appointmentsList.add(appointment); } appointments = new Appointment[appointmentsList.size()]; appointments = appointmentsList.toArray(appointments); stmt.close(); } catch (NamingException ex) { Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex); } return appointments; }
From source file:gov.nih.nci.ess.safetyreporting.service.globus.resource.SafetyReportingEnterpriseServiceResourceBase.java
public SafetyReportingEnterpriseServiceResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }//from w w w. j av a 2 s.c o m MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/SafetyReportingEnterpriseService"; 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 = (SafetyReportingEnterpriseServiceResourceConfiguration) initialContext .lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:gov.nih.nci.iso21090.reference.service.globus.resource.ISO21090ReferenceServiceResourceBase.java
public ISO21090ReferenceServiceResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }//from ww w .j a va2s . co m MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/ISO21090ReferenceService"; 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 = (ISO21090ReferenceServiceResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }
From source file:it.infn.ct.security.utilities.LDAPCleaner.java
private void sendUserRemainder(UserRequest ur, int days) { javax.mail.Session session = null;//from w w w. j a v a 2 s . c o m try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); session = (javax.mail.Session) envCtx.lookup("mail/Users"); Message mailMsg = new MimeMessage(session); mailMsg.setFrom(new InternetAddress(rb.getString("mailSender"), rb.getString("IdPAdmin"))); InternetAddress mailTo[] = new InternetAddress[1]; mailTo[0] = new InternetAddress(getGoodMail(ur), ur.getTitle() + " " + ur.getGivenname() + " " + ur.getSurname()); mailMsg.setRecipients(Message.RecipientType.TO, mailTo); if (rb.containsKey("mailCopy") && !rb.getString("mailCopy").isEmpty()) { String ccMail[] = rb.getString("mailCopy").split(";"); InternetAddress mailCCopy[] = new InternetAddress[ccMail.length]; for (int i = 0; i < ccMail.length; i++) { mailCCopy[i] = new InternetAddress(ccMail[i]); } mailMsg.setRecipients(Message.RecipientType.CC, mailCCopy); } if (days > 0) { mailMsg.setSubject( rb.getString("mailNotificationSubject").replace("_DAYS_", Integer.toString(days))); mailMsg.setText(rb.getString("mailNotificationBody") .replaceAll("_USER_", ur.getTitle() + " " + ur.getGivenname() + " " + ur.getSurname()) .replace("_DAYS_", Integer.toString(days))); } else { mailMsg.setSubject(rb.getString("mailDeleteSubject").replace("_DAYS_", Integer.toString(days))); mailMsg.setText(rb.getString("mailDeleteBody") .replaceAll("_USER_", ur.getTitle() + " " + ur.getGivenname() + " " + ur.getSurname()) .replace("_DAYS_", Integer.toString(days))); } Transport.send(mailMsg); } catch (Exception ex) { _log.error("Mail resource lookup error"); _log.error(ex.getMessage()); } }
From source file:gov.nih.nci.cagrid.cabio.service.globus.resource.CaBIO42GridSvcResourceBase.java
public CaBIO42GridSvcResourceConfiguration getConfiguration() { if (this.configuration != null) { return this.configuration; }// ww w .j a v a 2 s.c o m MessageContext ctx = MessageContext.getCurrentContext(); String servicePath = ctx.getTargetService(); servicePath = servicePath.substring(0, servicePath.lastIndexOf("/")); servicePath += "/CaBIO42GridSvc"; 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 = (CaBIO42GridSvcResourceConfiguration) initialContext.lookup(jndiName); } catch (Exception e) { logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e); } return this.configuration; }