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:edu.ucsd.library.dams.api.FileStoreServlet.java

/**
 * Initialize the servlet.//from   www  . j  a v a  2  s . c  o m
 * @see HttpServlet#init().
 */
public void init() throws ServletException {
    /* begin ucsd changes */
    try {
        InitialContext ctx = new InitialContext();
        String damsHome = null;
        try {
            damsHome = (String) ctx.lookup("java:comp/env/dams/home");
        } catch (Exception ex) {
            damsHome = "dams";
        }
        props = DAMSAPIServlet.loadConfig();
        fsDefault = props.getProperty("fs.default");
        df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
        // RFC 822, Wed, 23 May 2012 11:54:18 GMT
    } catch (Exception ex) {
        log.warn("Unable to lookup default filestore", ex);
        throw new ServletException("Unable to lookup default filestore");
    }
    /* end ucsd changes */
}

From source file:org.apache.axis.providers.java.EJBProvider.java

protected Object getEJBHome(InitialContext context, String beanJndiName)
        throws AxisFault, javax.naming.NamingException {
    // Do the JNDI lookup
    return context.lookup(beanJndiName);
}

From source file:it.doqui.index.ecmengine.client.engine.EcmEngineDirectDelegateImpl.java

protected EcmEngineSearchBusinessInterface createSearchService() throws Throwable {
    this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] BEGIN ");

    Properties properties = new Properties();

    /* Caricamento del file contenenti le properties su cui fare il binding */
    rb = ResourceBundle.getBundle(ECMENGINE_PROPERTIES_FILE);

    /*/*from w w  w. j a v a2s . c  om*/
    * Caricamento delle proprieta' su cui fare il binding all'oggetto di business delle funzionalita'
    * implementate per la ricerca.
    */
    try {
        this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] P-Delegata di search.");

        this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] context factory vale : "
                + rb.getString(ECMENGINE_CONTEXT_FACTORY));
        properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_CONTEXT_FACTORY));
        this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] url to connect vale : "
                + rb.getString(ECMENGINE_URL_TO_CONNECT));
        properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_URL_TO_CONNECT));

        /* Controllo che la property cluster partition sia valorizzata per capire se
         * sto lavorando in una configurazione in cluster oppure no */
        String clusterPartition = rb.getString(ECMENGINE_CLUSTER_PARTITION);
        this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] clusterPartition vale : "
                + clusterPartition);
        if (clusterPartition != null && clusterPartition.length() > 0) {
            properties.put("jnp.partitionName", clusterPartition);
            this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] disable discovery vale : "
                    + rb.getString(ECMENGINE_DISABLE_DISCOVERY));
            properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_DISABLE_DISCOVERY));
        }

        // Get an initial context
        InitialContext jndiContext = new InitialContext(properties);
        log.debug("[" + getClass().getSimpleName() + "::createSearchService] context istanziato");

        // Get a reference to the Bean
        Object ref = jndiContext.lookup(ECMENGINE_SEARCH_JNDI_NAME);

        // Get a reference from this to the Bean's Home interface
        EcmEngineSearchHome home = (EcmEngineSearchHome) PortableRemoteObject.narrow(ref,
                EcmEngineSearchHome.class);

        // Create an Adder object from the Home interface
        return home.create();

    } catch (Throwable e) {
        this.log.error("[" + getClass().getSimpleName() + "::createSearchService] "
                + "Impossibile l'EJB di management: " + e.getMessage());
        throw e;
    } finally {
        this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] END ");
    }
}

From source file:it.doqui.index.ecmengine.client.engine.EcmEngineDirectDelegateImpl.java

protected EcmEngineSecurityBusinessInterface createSecurityService() throws Throwable {
    this.log.debug("[" + getClass().getSimpleName() + "::createSecurityService] BEGIN ");

    Properties properties = new Properties();

    // Caricamento del file contenenti le properties su cui fare il binding
    rb = ResourceBundle.getBundle(ECMENGINE_PROPERTIES_FILE);

    // Caricamento delle proprieta' su cui fare il binding all'oggetto di business delle funzionalita'
    // implementate per la ricerca.
    try {/*from   w w  w .  j av  a  2  s .c  o  m*/
        this.log.debug("[" + getClass().getSimpleName() + "::createSecurityService] P-Delegata di backoffice.");

        this.log.debug("[" + getClass().getSimpleName() + "::createSecurityService] context factory vale : "
                + rb.getString(ECMENGINE_CONTEXT_FACTORY));
        properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_CONTEXT_FACTORY));
        this.log.debug("[" + getClass().getSimpleName() + "::createSecurityService] url to connect vale : "
                + rb.getString(ECMENGINE_URL_TO_CONNECT));
        properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_URL_TO_CONNECT));

        // Controllo che la property cluster partition sia valorizzata per capire se
        // sto lavorando in una configurazione in cluster oppure no
        String clusterPartition = rb.getString(ECMENGINE_CLUSTER_PARTITION);
        this.log.debug("[" + getClass().getSimpleName() + "::createSecurityService] clusterPartition vale : "
                + clusterPartition);
        if (clusterPartition != null && clusterPartition.length() > 0) {
            properties.put("jnp.partitionName", clusterPartition);
            this.log.debug("[" + getClass().getSimpleName() + "::createSearchService] disable discovery vale : "
                    + rb.getString(ECMENGINE_DISABLE_DISCOVERY));
            properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_DISABLE_DISCOVERY));
        }

        // Get an initial context
        InitialContext jndiContext = new InitialContext(properties);
        log.debug("[" + getClass().getSimpleName() + "::createSecurityService] context istanziato");

        // Get a reference to the Bean
        Object ref = jndiContext.lookup(ECMENGINE_SECURITY_JNDI_NAME);

        // Get a reference from this to the Bean's Home interface
        EcmEngineSecurityHome home = (EcmEngineSecurityHome) PortableRemoteObject.narrow(ref,
                EcmEngineSecurityHome.class);

        // Create an Adder object from the Home interface
        return home.create();

    } catch (Throwable e) {
        this.log.error("[" + getClass().getSimpleName() + "::createSecurityService] "
                + "Impossibile l'EJB di security: " + e.getMessage());
        throw e;
    } finally {
        this.log.debug("[" + getClass().getSimpleName() + "::createSecurityService] END ");
    }
}

From source file:it.doqui.index.ecmengine.client.engine.EcmEngineDirectDelegateImpl.java

protected EcmEngineMassiveBusinessInterface createMassiveService() throws Throwable {
    this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] BEGIN ");

    Properties properties = new Properties();

    // Caricamento del file contenenti le properties su cui fare il binding
    rb = ResourceBundle.getBundle(ECMENGINE_PROPERTIES_FILE);

    // Caricamento delle proprieta' su cui fare il binding all'oggetto di business delle funzionalita'
    // implementate per la ricerca.
    try {//  w w w . jav a 2 s.c  o  m
        this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] P-Delegata di massive.");

        this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] context factory vale : "
                + rb.getString(ECMENGINE_CONTEXT_FACTORY));
        properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_CONTEXT_FACTORY));
        this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] url to connect vale : "
                + rb.getString(ECMENGINE_URL_TO_CONNECT));
        properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_URL_TO_CONNECT));

        // Controllo che la property cluster partition sia valorizzata per capire se
        // sto lavorando in una configurazione in cluster oppure no
        String clusterPartition = rb.getString(ECMENGINE_CLUSTER_PARTITION);
        this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] clusterPartition vale : "
                + clusterPartition);
        if (clusterPartition != null && clusterPartition.length() > 0) {
            properties.put("jnp.partitionName", clusterPartition);
            this.log.debug(
                    "[" + getClass().getSimpleName() + "::createMassiveService] disable discovery vale : "
                            + rb.getString(ECMENGINE_DISABLE_DISCOVERY));
            properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_DISABLE_DISCOVERY));
        }

        // Get an initial context
        InitialContext jndiContext = new InitialContext(properties);
        log.debug("[" + getClass().getSimpleName() + "::createMassiveService] context istanziato");

        // Get a reference to the Bean
        Object ref = jndiContext.lookup(ECMENGINE_MASSIVE_JNDI_NAME);

        // Get a reference from this to the Bean's Home interface
        EcmEngineMassiveHome home = (EcmEngineMassiveHome) PortableRemoteObject.narrow(ref,
                EcmEngineMassiveHome.class);

        // Create an Adder object from the Home interface
        return home.create();

    } catch (Throwable e) {
        this.log.error("[" + getClass().getSimpleName() + "::createMassiveService] "
                + "Impossibile l'EJB di security: " + e.getMessage());
        throw e;
    } finally {
        this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] END ");
    }
}

From source file:org.enhydra.jdbc.pool.StandardXAPoolDataSource.java

public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception {

    super.getObjectInstance(refObj, name, nameCtx, env);
    Reference ref = (Reference) refObj;
    InitialContext ictx = new InitialContext(env);
    this.setTransactionManagerName((String) ref.get("transactionManagerName").getContent());
    if (this.transactionManagerName != null) {
        try {/* www .  j  a v  a 2 s.c  om*/
            this.setTransactionManager((TransactionManager) ictx.lookup(this.transactionManagerName));
        } catch (NamingException e) {
            // ignore, TransactionManager might be set later enlisting the XAResouce on the Transaction
        }
    }

    this.setDataSource((XADataSource) ictx.lookup(this.dataSourceName));
    log.debug("StandardXAPoolDataSource:getObjectInstance: instance created");
    return this;
}

From source file:it.doqui.index.ecmengine.client.engine.EcmEngineDirectDelegateImpl.java

protected EcmEngineManagementBusinessInterface createManagementService() throws Throwable {
    this.log.debug("[" + getClass().getSimpleName() + "::createManagementService] BEGIN ");
    Properties properties = new Properties();

    /* Caricamento del file contenenti le properties su cui fare il binding */
    rb = ResourceBundle.getBundle(ECMENGINE_PROPERTIES_FILE);

    /*/*from  w  w w  .  j av a  2  s .  com*/
    * Caricamento delle proprieta' su cui fare il binding all'oggetto di business delle funzionalita'
    * implementate per il management.
    */
    try {
        this.log.debug(
                "[" + getClass().getSimpleName() + "::createManagementService] P-Delegata di backoffice.");

        this.log.debug("[" + getClass().getSimpleName() + "::createManagementService] context factory vale : "
                + rb.getString(ECMENGINE_CONTEXT_FACTORY));
        properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_CONTEXT_FACTORY));
        this.log.debug("[" + getClass().getSimpleName() + "::createManagementService] url to connect vale : "
                + rb.getString(ECMENGINE_URL_TO_CONNECT));
        properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_URL_TO_CONNECT));

        /* Controllo che la property cluster partition sia valorizzata per capire se
         * sto lavorando in una configurazione in cluster oppure no */
        String clusterPartition = rb.getString(ECMENGINE_CLUSTER_PARTITION);
        this.log.debug("[" + getClass().getSimpleName() + "::createManagementService] clusterPartition vale : "
                + clusterPartition);
        if (clusterPartition != null && clusterPartition.length() > 0) {
            properties.put("jnp.partitionName", clusterPartition);
            this.log.debug(
                    "[" + getClass().getSimpleName() + "::createManagementService] disable discovery vale : "
                            + rb.getString(ECMENGINE_DISABLE_DISCOVERY));
            properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_DISABLE_DISCOVERY));
        }

        // Get an initial context
        InitialContext jndiContext = new InitialContext(properties);
        log.debug("[" + getClass().getSimpleName() + "::createManagementService] context istanziato");

        // Get a reference to the Bean
        Object ref = jndiContext.lookup(ECMENGINE_MANAGEMENT_JNDI_NAME);

        // Get a reference from this to the Bean's Home interface
        EcmEngineManagementHome home = (EcmEngineManagementHome) PortableRemoteObject.narrow(ref,
                EcmEngineManagementHome.class);

        // Create an Adder object from the Home interface
        return home.create();

    } catch (Throwable e) {
        this.log.error("[" + getClass().getSimpleName() + "::createManagementService] "
                + "Impossibile istanziare la P-Delegata di management: " + e.getMessage());
        throw e;
    } finally {
        this.log.debug("[" + getClass().getSimpleName() + "::createManagementService] END ");
    }
}

From source file:com.opensymphony.module.propertyset.database.JDBCPropertySet.java

public void init(Map config, Map args) {
    // args/*  w  w  w . j a v a2  s. co m*/
    globalKey = (String) args.get("globalKey");

    // config  --> modified by chirs chen  2007-07-03
    try {
        InitialContext initCtx = new InitialContext();
        Context context = (Context) initCtx.lookup("java:comp/env");
        ds = (DataSource) context.lookup((String) config.get("datasource"));
    } catch (Exception e) {
        log.fatal("Could not get DataSource", e);
    }

    tableName = (String) config.get("table.name");
    colGlobalKey = (String) config.get("col.globalKey");
    colItemKey = (String) config.get("col.itemKey");
    colItemType = (String) config.get("col.itemType");
    colString = (String) config.get("col.string");
    colDate = (String) config.get("col.date");
    colData = (String) config.get("col.data");
    colFloat = (String) config.get("col.float");
    colNumber = (String) config.get("col.number");
}

From source file:eu.learnpad.simulator.mon.probe.GlimpseAbstractProbe.java

/**
 * This method setup a {@link TopicConnection} object.
 * /*from   ww w.  ja  v  a 2 s  .  com*/
 * @param initConn the InitialContext object generated using the method {@link #initConnection(Properties, boolean)}.
 * @param settings can be generated automatically using {@link Manager#createProbeSettingsPropertiesObject(String, String, String, String, String, String, boolean, String, String)}
 * @param probeChannel
 * @param settings
 * @param debug
 * @return a {@link TopicPublisher} object
 * @throws NamingException
 * @throws JMSException
 */
protected TopicPublisher createConnection(InitialContext initConn, String probeChannel, Properties settings,
        boolean debug) throws NamingException, JMSException {
    if (debug)
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating ConnectionFactory with settings ");
    TopicConnectionFactory connFact = (TopicConnectionFactory) initConn
            .lookup(settings.getProperty("connectionFactoryNames"));
    if (debug) {
        DebugMessages.ok();
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating TopicConnection ");
    }
    connection = connFact.createTopicConnection();
    if (debug) {
        DebugMessages.ok();
        DebugMessages.line();
    }
    if (debug) {
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Creating Session ");
    }
    publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    if (debug) {
        DebugMessages.ok();
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Looking up for channel ");
    }
    connectionTopic = (Topic) initContext.lookup(probeChannel);
    if (debug) {
        DebugMessages.ok();
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Creating Publisher ");
    }
    return tPub = publishSession.createPublisher(connectionTopic);
}