Example usage for javax.naming InitialContext lookup

List of usage examples for javax.naming InitialContext lookup

Introduction

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

Prototype

public Object lookup(Name name) throws NamingException 

Source Link

Usage

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

public static ApplicationSecurityBean getInstance() {
    try {//from  w w  w .  j  av a 2 s  .  c o  m
        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.codeasylum.stress.api.OuroborosImpl.java

public static Ouroboros getRemoteInterface(String rmiHost) throws NamingException {

    Ouroboros ouroboros;/* w w w . j  a v  a 2  s .  c  o m*/
    InitialContext initContext;
    Context rmiContext;

    initContext = new InitialContext();
    rmiContext = (Context) initContext.lookup("rmi://" + rmiHost + ':' + registryPort.get());
    ouroboros = (Ouroboros) PortableRemoteObject.narrow(rmiContext.lookup(Ouroboros.class.getName()),
            Ouroboros.class);
    rmiContext.close();
    initContext.close();

    return ouroboros;
}

From source file:be.fedict.eid.idp.sp.StartupServletContextListener.java

private static Object getComponent(String jndiName) {

    try {/*ww  w.  j a v a 2s.  c  o  m*/
        InitialContext initialContext = new InitialContext();
        return initialContext.lookup(jndiName);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.ecr.runtime.api.DataSourceHelper.java

/**
 * Look up a datasource given a partial name.
 * <p>/*from   w  w w  . j a  v a2  s  .c  om*/
 * For a datasource {@code "jdbc/foo"}, then it's sufficient to pass {@code
 * "foo"} to this method.
 *
 * @param partialName the partial name
 * @return the datasource
 * @throws NamingException
 */
public static DataSource getDataSource(String partialName) throws NamingException {
    String jndiName = getDataSourceJNDIName(partialName);
    InitialContext context = new InitialContext();
    Object resolved = context.lookup(jndiName);
    if (resolved instanceof Reference) {
        try {
            resolved = NamingManager.getObjectInstance(resolved, new CompositeName(jndiName), context, null);
        } catch (Exception e) {
            throw new Error("Cannot get access to " + jndiName, e);
        }
    }
    return (DataSource) resolved;
}

From source file:org.jbpm.bpel.tutorial.atm.terminal.AtmTerminal.java

private static FrontEnd createAtmFrontEnd() {
    try {/*from   ww w  .  j ava  2s .co  m*/
        InitialContext jndiContext = new InitialContext();
        AtmFrontEndService service = (AtmFrontEndService) jndiContext.lookup("java:comp/env/service/ATM");
        jndiContext.close();

        return service.getFrontEndPort();
    } catch (NamingException e) {
        log.error("could not retrieve service instance", e);
        return null;
    } catch (ServiceException e) {
        log.error("could not get port proxy", e);
        return null;
    }
}

From source file:edu.harvard.i2b2.crc.util.HibernateUtil.java

/**
 * Function to fetch session via jboss hibernate mbean
 * Enables filter condition for delete_flag in query
 * tables//from   ww w.  j  a  va 2  s  .c  om
 * @return Session
 */
public static Session getSession() {
    Session session = null;

    InitialContext ctx;
    SessionFactory factory;

    try {
        ctx = new InitialContext();
        factory = (SessionFactory) ctx.lookup(DATASOURCE_JNDI_NAME);
        // session = factory.openSession();
        session = factory.getCurrentSession();
        session.enableFilter("deleteInstanceFlagFilter").setParameter("deleteFlagFilterParam", "N");
        session.enableFilter("deleteMasterFlagFilter").setParameter("deleteFlagFilterParam", "N");
        session.enableFilter("deleteResultInstanceFlagFilter").setParameter("deleteFlagFilterParam", "N");
    } catch (NamingException e) {
        log.error("DB Session jndi lookup[" + DATASOURCE_JNDI_NAME + "] failed", e);
        throw new ExceptionInInitializerError(e);
    }

    return session;
}

From source file:com.legstar.host.server.EngineHolder.java

/**
 * This method initializes the work manager used by the engine. We will
 * first attempt to lookup the work manager from the JNDI location
 * specified in the engine config file. If not specified, or unable to load,
 * we will use the default work manager.
 *//*  ww w  . ja  va2  s.c  o  m*/
private static void initializeWorkManager() {
    LOG.debug("Initializing Work Manager.");
    String workMgrLocation = sConfig.getWorkManagerJNDILocation();
    if (workMgrLocation != null && workMgrLocation.length() > 0) {
        try {
            InitialContext ic = new InitialContext();
            sWorkManager = (WorkManager) ic.lookup(workMgrLocation);
        } catch (Exception e) {
            sWorkManager = null;
        }
    } else {
        sWorkManager = null;
    }

    if (sWorkManager == null) {
        int threadPoolSize = sConfig.getThreadPoolSize();
        sExecutor = Executors.newFixedThreadPool(threadPoolSize);
        sWorkManager = new WorkManagerImpl(sExecutor);
    }
}

From source file:org.wso2.appcloud.core.DBUtil.java

public static void initDatasource() {

    try {//from www. j  a v  a2 s. c  o m
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        threadLocalCarbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
        try {
            String datasourceName = AppCloudUtil.getPropertyValue(DATASOURCE_NAME);
            InitialContext context = new InitialContext();
            dataSource = (DataSource) context.lookup(datasourceName);
            if (log.isDebugEnabled()) {
                log.debug("Initialized datasource : " + datasourceName + " successfully");
            }
        } catch (NamingException e) {
            log.error("Error while initializing datasource : " + DATASOURCE_NAME, e);
            throw new ExceptionInInitializerError(e);
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }

}

From source file:org.wso2.intcloud.core.DBUtil.java

public static void initDatasource() {

    try {//from w ww  . j  a v  a 2 s  . com
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        threadLocalCarbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
        try {
            String datasourceName = IntCloudUtil.getPropertyValue(DATASOURCE_NAME);
            InitialContext context = new InitialContext();
            dataSource = (DataSource) context.lookup(datasourceName);
            if (log.isDebugEnabled()) {
                log.debug("Initialized datasource : " + datasourceName + " successfully");
            }
        } catch (NamingException e) {
            log.error("Error while initializing datasource : " + DATASOURCE_NAME, e);
            throw new ExceptionInInitializerError(e);
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }

}

From source file:com.tdclighthouse.prototype.utils.EmailUtils.java

public static Session getMailSession(final String sessionName) {
    Session result = null;// ww  w .  j av a 2  s .  c  o  m
    InitialContext initialContext = null;
    try {
        initialContext = new InitialContext();
        Context context = (Context) initialContext.lookup("java:comp/env");
        result = (Session) context.lookup(sessionName);
    } catch (NamingException e) {
        throw new HstComponentException(e);
    } finally {
        try {
            if (initialContext != null) {
                initialContext.close();
            }
        } catch (NamingException e) {
            LOG.error(e.getMessage(), e);
        }
    }

    return result;
}