List of usage examples for javax.naming Context lookup
public Object lookup(String name) throws NamingException;
From source file:br.ufac.sion.converter.LocalidadeConverter.java
private LocalidadeFacadeLocal lookupLocalidadeFacadeLocal() { try {//from ww w . ja v a2s. c o m Context c = new InitialContext(); return (LocalidadeFacadeLocal) c.lookup("java:global/sion-ear/sion-ejb-2.0/LocalidadeFacade"); } catch (NamingException ne) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne); throw new RuntimeException(ne); } }
From source file:com.versatus.jwebshield.DBHelper.java
public DBHelper(Configuration config) throws Exception { try {// w ww . j av a 2 s . com Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); SubnodeConfiguration fields = ((XMLConfiguration) config).configurationAt("securityLock"); if (envCtx != null) { ds = (DataSource) envCtx.lookup(fields.getString("dbJndiName")); } } catch (javax.naming.NoInitialContextException ne) { } catch (Exception e) { logger.error("constructor", e); } }
From source file:com.nabla.wapp.server.database.TomcatConnectionPool.java
/** * Constructor/*from www . ja v a 2s . c om*/ * @param dbName - database name as defined in pool * @throws SQLException */ public TomcatConnectionPool(final String dbName) throws SQLException { Assert.argumentNotNull(dbName, "Have you set the database name in your web.xml file?"); try { final Context initContext = new InitialContext(); final Context ctx = (Context) initContext.lookup("java:/comp/env"); dataSource = (DataSource) ctx.lookup("jdbc/" + dbName); } catch (NamingException e) { if (log.isDebugEnabled()) log.debug("fail to get datasource '" + dbName + "'", e); throw new SQLException("fail to get database '" + dbName + "'"); } }
From source file:de.highbyte_le.weberknecht.db.DefaultWebDbConnectionProvider.java
public Connection getConnection() throws DBConnectionException { try {// w w w .j a va 2 s .c o m //JNDI-Context Context ctx = new InitialContext(); Context envCtx = (Context) ctx.lookup("java:comp/env"); //JNDI-Lookup for jdbc connection DataSource ds = (DataSource) envCtx.lookup("jdbc/mydb"); Connection con = ds.getConnection(); return con; } catch (NamingException e) { logger.error("NamingException: " + e.getMessage(), e); throw new DBConnectionException("database connection is not yet configured (naming exception)", e); } catch (SQLException e) { logger.error("SQLException: " + e.getMessage(), e); throw new DBConnectionException("cannot connect to database (sql exception)", e); } }
From source file:com.taobao.ad.es.common.datasource.DataSourceFactory.java
public Connection getConnection(String contextPath, int dsType, String dataSource) throws BeansException, SQLException, NamingException { Connection connection = null; switch (dsType) { case JobData.JOBDATA_DATA_DATASOURCE_TYPE_DYNAMIC: // BeanFactoryLocator sysCtxLocator = // SingletonBeanFactoryLocator.getInstance(WebAgentConstants.DATASOURCE_CONTEXT); // BeanFactoryReference brf = // sysCtxLocator.useBeanFactory(WebAgentConstants.DATASOURCE_CONTEXT_KEY); // connection = ((DataSource) // brf.getFactory().getBean(dataSource)).getConnection(); AbstractXmlApplicationContext context = null; if (StringUtils.isEmpty(contextPath)) { context = new ClassPathXmlApplicationContext("classpath:es-agent-ds.xml"); } else {//from ww w .j a v a 2 s .c o m context = new FileSystemXmlApplicationContext(contextPath); } connection = ((DataSource) context.getBean(dataSource)).getConnection(); break; default: Context cxt = new InitialContext(); Context envCtx = (Context) cxt.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/" + dataSource); connection = ds.getConnection(); break; } return connection; }
From source file:com.jobhunt.rest.Login.java
private UserSessionRemote lookupUserSessionRemote() { try {//from w w w .j a v a2s . c o m Context c = new InitialContext(); return (UserSessionRemote) c.lookup("java:global/JobhuntEJB/UserSessionBean"); } catch (NamingException ne) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne); throw new RuntimeException(ne); } }
From source file:com.alliander.osgp.signing.server.application.config.SigningServerInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {/*from w w w . j av 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/signingServer/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.alliander.osgp.adapter.protocol.iec61850.application.config.OsgpProtocolAdapterIec61850Initializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {//w w w .j av a 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/osgpAdapterProtocolIec61850/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.alliander.osgp.adapter.protocol.oslp.application.config.OsgpProtocolAdapterOslpInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {/* w ww . j a v a2s . c o m*/ // 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/osgpAdapterProtocolOslp/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.alliander.osgp.adapter.protocol.oslp.elster.application.config.OsgpProtocolAdapterOslpInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {/*from w w w .j ava2s . c o m*/ // 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/osgpAdapterProtocolOslpElster/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); } }