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:JndiFilter.java

public void init(FilterConfig filterConfig) throws ServletException {

    this.config = filterConfig;

    try {/*from   www.j a va2  s  . c  o m*/

        env = (Context) new InitialContext();

    } catch (NamingException ne) {

        throw new ServletException(ne);

    }

}

From source file:de.highbyte_le.weberknecht.conf.ContextConfig.java

public ContextConfig() throws NamingException {
    Context ctx = new InitialContext();
    envCtx = (Context) ctx.lookup("java:comp/env"); //$NON-NLS-1$
}

From source file:DbMetaServlet.java

public void init() throws ServletException {

    Context env = null;//from w ww  .j  av  a2  s.co  m

    try {

        env = (Context) new InitialContext().lookup("java:comp/env");

        pool = (DataSource) env.lookup("jdbc/oracle-8i-athletes");

        if (pool == null)
            throw new ServletException("'oracle-8i-athletes' is an unknown DataSource");

    } catch (NamingException ne) {

        throw new ServletException(ne);

    }
}

From source file:ece356.UserDBAO.java

public static Connection getConnection() throws ClassNotFoundException, SQLException, NamingException {
    InitialContext cxt = new InitialContext();
    if (cxt == null) {
        throw new RuntimeException("Unable to create naming context!");
    }// w w w .j  a v a  2  s  .co  m
    Context dbContext = (Context) cxt.lookup("java:comp/env");
    DataSource ds = (DataSource) dbContext.lookup("jdbc/myDatasource");
    if (ds == null) {
        throw new RuntimeException("Data source not found!");
    }
    Connection con = ds.getConnection();

    /*Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection(url, user, pwd);*/
    Statement stmt = null;
    try {
        con.createStatement();
        stmt = con.createStatement();
        stmt.execute("USE ece356db_" + nid);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
    return con;
}

From source file:com.wso2telco.core.mnc.resolver.dao.OperatorDAO.java

public static void initializeDatasources() throws MobileNtException {
    if (datasource != null) {
        return;/* w  ww. j av  a  2  s .  c o m*/
    }

    try {
        Context ctx = new InitialContext();
        datasource = (DataSource) ctx.lookup(DataSourceNames.WSO2TELCO_DEP_DB.jndiName());
    } catch (NamingException e) {
        handleException("Error while looking up the data source: " + DataSourceNames.WSO2TELCO_DEP_DB, e);
    }
}

From source file:be.fedict.hsm.model.security.ApplicationSecurityBean.java

public static ApplicationSecurityBean getInstance() {
    try {//from ww  w . j av a2 s .c om
        InitialContext initialContext = new InitialContext();
        return (ApplicationSecurityBean) initialContext.lookup(JNDI_NAME);
    } catch (NamingException e) {
        throw new RuntimeException("JNDI error: " + e.getMessage(), e);
    }
}

From source file:com.ibm.liberty.starter.StarterUtil.java

private static String getServerOutputDir() {
    if (serverOutputDir == null) {
        try {/*  ww w  .  j  a v  a 2s . c  o  m*/
            serverOutputDir = processPath(((String) (new InitialContext().lookup("serverOutputDir"))));
            if (!serverOutputDir.endsWith("/")) {
                serverOutputDir += "/";
            }
            log.info("serverOutputDir=" + serverOutputDir);
        } catch (NamingException ne) {
            log.severe("NamingException occurred while retrieving the value of 'serverOutputDir': " + ne);
            throw new ValidationException(
                    "NamingException occurred while retrieving the value of 'serverOutputDir': " + ne);
        }
    }
    return serverOutputDir;
}

From source file:$.DeviceTypeDAO.java

public static void initDeviceTypeDAO() {
        try {/*from w w w .j a  v  a  2  s  . c  o m*/
            Context ctx = new InitialContext();
            dataSource = (DataSource) ctx.lookup(DeviceTypeConstants.DATA_SOURCE_NAME);
        } catch (NamingException e) {
            log.error("Error while looking up the data source: " + DeviceTypeConstants.DATA_SOURCE_NAME);
        }
    }

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  .jav  a 2 s .  c om
 */
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:airport.services.dispatcher.GeneratorFlightJMS.java

public GeneratorFlightJMS() {
    try {//from   www  .j  a  v a2  s.co  m
        this.topic = (Topic) new InitialContext().lookup("jms/FlightTopic");
    } catch (NamingException ex) {

    }
}