List of usage examples for javax.naming Context lookup
public Object lookup(String name) throws NamingException;
From source file:org.osgp.adapter.protocol.dlms.application.config.ProtocolAdapterDlmsInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {// w w w .ja va 2 s.com // 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/osgpAdapterProtocolDlms/log-config"); LogbackConfigurer.initLogging(logLocation); final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationContext.class); 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); } }
From source file:com.jobhunt.rest.Login.java
private ApplicationUserRemote lookupApplicationUserManagementRemote() { try {//from w ww .j av a2s .com Context c = new InitialContext(); return (ApplicationUserRemote) c.lookup("java:global/JobhuntEJB/ApplicationUserBean"); } catch (NamingException ne) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne); throw new RuntimeException(ne); } }
From source file:org.cloudgraph.rdb.connect.JNDIDataSourceProvider.java
public JNDIDataSourceProvider() { Properties props = new Properties(); for (Property property : PlasmaRuntime.getInstance().getDataAccessProvider(DataAccessProviderName.JDBC) .getProperties()) {/*from ww w .java 2s. c om*/ props.put(property.getName(), property.getValue()); } String datasourceName = props.getProperty(ConfigurationConstants.JDBC_DATASOURCE_NAME); if (datasourceName == null) throw new DataAccessException("cannot lookup datasource - datasource name property '" + ConfigurationConstants.JDBC_DATASOURCE_NAME + "' not found in configuration for " + "data access provider '" + DataAccessProviderName.JDBC.name() + "' - a fully qualified JNDI name is required"); try { Context initialContext = new InitialContext(); this.datasource = (DataSource) initialContext.lookup(datasourceName); if (this.datasource == null) { throw new DataAccessException("cannot lookup datasource '" + datasourceName + "'"); } } catch (NamingException ex) { log.error("cannot lookup datasource '" + datasourceName + "'", ex); throw new DataAccessException(ex); } }
From source file:co.com.sigemco.alfa.admin.logica.LogoLogica.java
/** * Funcion con la cual obtengo la ruta base de sigemco para las aplicaciones * @return //from ww w. j a v a 2 s . c o m */ public String obtieneParametroContext() { String parametro = ""; try { Context initCtx = new InitialContext(); String envCtx = (String) initCtx.lookup("java:comp/env/RutaBaseApp"); parametro = envCtx; } catch (Exception e) { e.printStackTrace(); } return parametro; }
From source file:net.przemkovv.sphinx.config.JpaConfig.java
@Bean public EntityManagerFactory entityManagerFactory() throws NamingException { logger.debug("Bean initialization: EntityManagerFactory"); Context ctx = new InitialContext(); return (EntityManagerFactory) ctx.lookup("java:comp/env/persistence/net.przemkovv.sphinx_PU"); }
From source file:ch.maxant.generic_jca_adapter.demo.Config.java
@Bean(name = "xa/bookingService") public BasicTransactionAssistanceFactory bookingSystemFactory() throws NamingException { Context ctx = new BitronixContext(); BasicTransactionAssistanceFactory microserviceFactory = (BasicTransactionAssistanceFactory) ctx .lookup("xa/bookingService"); return microserviceFactory; }
From source file:ch.maxant.generic_jca_adapter.demo.Config.java
@Bean(name = "xa/letterService") public BasicTransactionAssistanceFactory letterServiceFactory() throws NamingException { Context ctx = new BitronixContext(); BasicTransactionAssistanceFactory microserviceFactory = (BasicTransactionAssistanceFactory) ctx .lookup("xa/letterService"); return microserviceFactory; }
From source file:SeeAccount.java
public void doGet(HttpServletRequest inRequest, HttpServletResponse outResponse) throws ServletException, IOException { PrintWriter out = null;// w w w . j a va 2 s . com Connection connection = null; Statement statement = null; ResultSet rs; try { outResponse.setContentType("text/html"); out = outResponse.getWriter(); Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/AccountsDB"); connection = ds.getConnection(); statement = connection.createStatement(); rs = statement.executeQuery("SELECT * FROM acc_acc"); ResultSetMetaData md = rs.getMetaData(); out.println("<HTML><HEAD><TITLE> Thumbnail Identification Record</TITLE></HEAD>"); out.println("<BODY>"); out.println("Account Information:<BR>"); out.println("<table>"); out.println("<tr><td>"); for (int i = 1; i <= md.getColumnCount(); i++) { out.println("Column #" + i + "<BR>"); out.println("getColumnName : " + md.getColumnName(i) + "<BR>"); out.println("getColumnClassName : " + md.getColumnClassName(i) + "<BR>"); out.println("getColumnDisplaySize : " + md.getColumnDisplaySize(i) + "<BR>"); out.println("getColumnType : " + md.getColumnType(i) + "<BR>"); out.println("getTableName : " + md.getTableName(i) + "<BR>"); out.println("<HR>"); } out.println("</BODY></HTML>"); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.lr.jmsbridge.ConnectionPool.java
public ConnectionFactory getConnectionFactory(UserNameAndPassword auth) { ConnectionFactory connectionFactory = connectionFactoryMap.get(auth); if (connectionFactory != null) { return connectionFactory; }//from www. j a v a2 s. co m try { Context context = new InitialContext(); Context envContext = (Context) context.lookup("java:comp/env"); ConnectionFactory innerConnectionFactory = (ConnectionFactory) envContext .lookup("jms/ConnectionFactory"); UserCredentialsConnectionFactoryAdapter credConnectionFactory = new UserCredentialsConnectionFactoryAdapter(); credConnectionFactory.setTargetConnectionFactory(innerConnectionFactory); credConnectionFactory.setUsername(auth.getUserName()); credConnectionFactory.setPassword(auth.getPassword()); connectionFactory = new SingleConnectionFactory(innerConnectionFactory); connectionFactoryMap.put(auth, connectionFactory); return connectionFactory; } catch (NamingException e) { throw new RuntimeException("Could not find Connectionfactory in JNDI", e); } }
From source file:com.janrain.backplane.server.config.InitSystemProps.java
private void load(String paramName) { String result = System.getProperty(paramName); if (StringUtils.isBlank(result)) { try {/* w w w.ja va 2 s . c om*/ javax.naming.Context initCtx = new InitialContext(); result = (String) initCtx.lookup("java:comp/env/" + paramName); System.setProperty(paramName, result); logger.info("Parameter " + paramName + " fetched from context and inserted as system property"); } catch (Exception e) { //continue logger.info("An error occurred trying to locate required parameter " + paramName + " => " + e.getMessage()); } } else { logger.info("Parameter " + paramName + " exists as a system property"); } }