Example usage for javax.naming InitialContext InitialContext

List of usage examples for javax.naming InitialContext InitialContext

Introduction

In this page you can find the example usage for javax.naming InitialContext InitialContext.

Prototype

public InitialContext() throws NamingException 

Source Link

Document

Constructs an initial context.

Usage

From source file:com.stratelia.silverpeas.silverStatisticsPeas.control.PerfVolumeTest.java

@AfterClass
public static void teardownDataSource() throws NamingException, SQLException {
    InitialContext ic = new InitialContext();
    BasicDataSource ds = (BasicDataSource) ic.lookup("java:/datasources/silverpeas-jdbc");
    ds.close();//ww w  .  j av a  2s . c o m
    SimpleMemoryContextFactory.tearDownAsInitialContext();
}

From source file:br.ufac.sion.converter.LocalidadeConverter.java

private LocalidadeFacadeLocal lookupLocalidadeFacadeLocal() {
    try {// ww w .  j ava2 s. 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:net.lr.jmsbridge.ConnectionPool.java

public ConnectionFactory getConnectionFactory(UserNameAndPassword auth) {
    ConnectionFactory connectionFactory = connectionFactoryMap.get(auth);
    if (connectionFactory != null) {
        return connectionFactory;
    }//from   w  w w. j  ava  2  s. c  o 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.mg.jet.birt.report.data.oda.ejbql.HibernateUtil.java

private static synchronized void initSessionFactory(String hibfile, String mapdir, String jndiName)
        throws HibernateException {
    //ClassLoader cl1;

    if (sessionFactory == null) {

        if (jndiName == null || jndiName.trim().length() == 0)
            jndiName = CommonConstant.DEFAULT_JNDI_URL;
        Context initCtx = null;//from   w  ww .  j  a  v  a2s  .  co  m
        try {
            initCtx = new InitialContext();
            sessionFactory = (SessionFactory) initCtx.lookup(jndiName);
            return;
        } catch (Exception e) {
            logger.log(Level.INFO, "Unable to get JNDI data source connection", e);
        } finally {
            if (initCtx != null)
                try {
                    initCtx.close();
                } catch (NamingException e) {
                    //ignore
                }
        }

        Thread thread = Thread.currentThread();
        try {
            //Class.forName("org.hibernate.Configuration");
            //Configuration ffff = new Configuration();
            //Class.forName("org.apache.commons.logging.LogFactory");

            oldloader = thread.getContextClassLoader();
            //Class thwy = oldloader.loadClass("org.hibernate.cfg.Configuration");
            //Class thwy2 = oldloader.loadClass("org.apache.commons.logging.LogFactory");
            //refreshURLs();
            //ClassLoader changeLoader = new URLClassLoader( (URL [])URLList.toArray(new URL[0]),HibernateUtil.class.getClassLoader());
            ClassLoader testLoader = new URLClassLoader((URL[]) URLList.toArray(new URL[0]), pluginLoader);
            //changeLoader = new URLClassLoader( (URL [])URLList.toArray(new URL[0]));

            thread.setContextClassLoader(testLoader);
            //Class thwy2 = changeLoader.loadClass("org.hibernate.cfg.Configuration");
            //Class.forName("org.apache.commons.logging.LogFactory", true, changeLoader);
            //Class cls = Class.forName("org.hibernate.cfg.Configuration", true, changeLoader);
            //Configuration cfg=null;
            //cfg = new Configuration();
            //Object oo = cls.newInstance();
            //Configuration cfg = (Configuration)oo;
            Configuration cfg = new Configuration();
            buildConfig(hibfile, mapdir, cfg);

            Class<? extends Driver> driverClass = testLoader
                    .loadClass(cfg.getProperty("connection.driver_class")).asSubclass(Driver.class);
            Driver driver = driverClass.newInstance();
            WrappedDriver wd = new WrappedDriver(driver, cfg.getProperty("connection.driver_class"));

            boolean foundDriver = false;
            Enumeration<Driver> drivers = DriverManager.getDrivers();
            while (drivers.hasMoreElements()) {
                Driver nextDriver = (Driver) drivers.nextElement();
                if (nextDriver.getClass() == wd.getClass()) {
                    if (nextDriver.toString().equals(wd.toString())) {
                        foundDriver = true;
                        break;
                    }
                }
            }
            if (!foundDriver) {

                DriverManager.registerDriver(wd);
            }

            sessionFactory = cfg.buildSessionFactory();
            //configuration = cfg;
            HibernateMapDirectory = mapdir;
            HibernateConfigFile = hibfile;
        } catch (Throwable e) {
            e.printStackTrace();
            throw new HibernateException("No Session Factory Created " + e.getLocalizedMessage(), e);
        } finally {
            thread.setContextClassLoader(oldloader);
        }
    }
}

From source file:br.gov.jfrj.siga.persistencia.oracle.JDBCUtilOracle.java

public static Connection getConnectionPool(final String dataSource) {

    Context initContext = null;/*ww  w . ja  v  a  2  s . c  o m*/
    Context envContext = null;
    Connection conn = null;

    try {
        JDBCUtilOracle.log.debug("Criando variavel de contexto");
        initContext = new InitialContext();

        envContext = (Context) initContext.lookup("java:/comp/env");
        JDBCUtilOracle.log.debug("Criando datasource ");
        final DataSource ds = (DataSource) envContext.lookup(dataSource);
        conn = ds.getConnection();

    } catch (final NamingException e) {
        JDBCUtilOracle.log.error(Messages.getString("Oracle.LookUpErro"));
        System.err.print(Messages.getString("Oracle.LookUpErro") + e.getMessage());

    } catch (final SQLException ex) {
        System.err.print(Messages.getString("Oracle.SQLErro") + ex.getMessage());
    }
    return conn;
}

From source file:com.t2tierp.controller.T2TiSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    try {/*  w w  w .  j  a va 2s . c o  m*/
        InitialContext initialContext = new InitialContext();
        dao = (UsuarioDAO) initialContext.lookup("java:comp/ejb/usuarioDAO");
        Usuario usuario = dao.getUsuario(authentication.getName());
        request.getSession().setAttribute("usuarioT2TiERP", usuario);
    } catch (Exception e) {
        //e.printStackTrace();
    }
    super.onAuthenticationSuccess(request, response, authentication);
}

From source file:com.sktelecom.cep.notebook.repo.JDBCNotebookRepo.java

public JDBCNotebookRepo(ZeppelinConfiguration conf) throws IOException, NamingException {
    this.conf = conf;

    Context ctx = new InitialContext();
    dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/cepDS");
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}

From source file:com.mycompany.FacebookManager.java

public FacebookManager() {
    byteStream = new ByteArrayOutputStream();

    try {//from   www .  ja v  a2  s  .co m
        javax.naming.Context con = new InitialContext();
        facade = (EmpeopleFacadeRemote) con.lookup("com.mycompany.EmpeopleFacadeRemote");
        faceManager = (FaceManagerRemote) con.lookup("com.mycompany.FaceManagerRemote");
    } catch (NamingException ex) {
        Logger.getLogger(FacebookManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    this.peopleList = facade.findAll();
}

From source file:com.geodetix.geo.dao.PostGisGeometryDAOImpl.java

/** Initializes the bean. */
public void init() {
    try {//from  w  w  w. j a v a  2  s .  co  m

        jndiCntx = new InitialContext();
        dataSource = (DataSource) jndiCntx.lookup(PostGisGeometryDAO.DATASOURCE_NAME);

    } catch (NamingException ne) {
        throw new EJBException(ne);
    }
}