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.francetelecom.clara.cloud.commons.JndiAwarePropertyPlaceholderConfigurer.java

/**
 * Resolve the given placeholder using the given properties. Default
 * implementation simply checks for an environment entry for a corresponding
 * property key./*from  www  .j a v  a 2  s .  c  o  m*/
 * <p>
 * Subclasses can override this for customized placeholder-to-key mappings
 * or custom resolution strategies, possibly just using the given lookup as
 * a fallback.
 * 
 * @param placeholder
 *            the placeholder to resolve
 * @return the resolved value, of <code>null</code> if none
 */
protected String resolveJndiProperty(String placeholder) {
    InitialContext initialContext = null;
    try {
        initialContext = new InitialContext();
        try {

            String prefix;
            if (resourceRef) {
                prefix = "java:comp/env/";
            } else {
                prefix = "";
            }
            return (String) initialContext.lookup(prefix + placeholder);
        } catch (NameNotFoundException e) {
            return null;
        } catch (NamingException e) {
            return null;
        }
    } catch (NamingException e) {
        throw new RuntimeException(e);
    } finally {
        if (initialContext != null) {
            try {
                initialContext.close();
            } catch (NamingException e) {
            }
        }
    }
}

From source file:gov.nih.nci.ess.ae.service.query.service.globus.resource.QueryResourceBase.java

public QueryResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }//from  www.  jav a2 s  . c  om
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/Query";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (QueryResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}

From source file:edu.duke.cabig.c3pr.grid.studyservice.service.globus.resource.StudyServiceResourceBase.java

public StudyServiceResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }//w  ww.  j  ava2  s . c  om
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/StudyService";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (StudyServiceResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}

From source file:gov.nih.nci.ccts.grid.service.globus.resource.LabConsumerServiceResourceBase.java

public LabConsumerServiceResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }/*from w w  w.  ja v a 2s.  c  om*/
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/LabConsumerService";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (LabConsumerServiceResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}

From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsDataSourceFactory.java

/**
 * Retrieval of a DataSource as a JNDI resource
 * //from  www  .  j av  a 2s  .c  om
 * Lookup the DataSource, which will be backed by a pool that the application server provides. DataSource instances
 * are also a good candidate for caching as an instance variable, as JNDI lookups can be expensive as well.
 * 
 * @param dsName
 *          JNDI resource name
 * @return DataSource
 */
public static DataSource getJNDIDataSource(String dsName) {
    SitoolsDataSource foundDataSource = dataSources.get(dsName);
    if (foundDataSource != null) {
        return foundDataSource;
    }

    DataSource ds = null;
    try {
        InitialContext ctx = new InitialContext();

        ds = (DataSource) ctx.lookup(dsName);
        JDBCDataSource jdbcDS = new JDBCDataSource();
        jdbcDS.setName(dsName);
        dataSources.put(dsName, new SitoolsDataSource(jdbcDS, ds, null));

    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ds;
}

From source file:gov.nih.nci.ess.ae.service.protocol.service.globus.resource.AEProtocolResourceBase.java

public AEProtocolResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }// w ww .ja  v a 2s  . c  o m
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/AEProtocol";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (AEProtocolResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}

From source file:gov.nih.nci.ess.ae.service.management.service.globus.resource.ManagementResourceBase.java

public ManagementResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }//from   w  w  w .j  ava  2 s .co m
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/Management";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (ManagementResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}

From source file:gov.nih.nci.ess.ae.service.aeassociate.service.globus.resource.AEAssociateResourceBase.java

public AEAssociateResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }/*from w w  w .  j  a  v  a2 s.  c o m*/
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/AEAssociate";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (AEAssociateResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}

From source file:edu.duke.cabig.c3pr.grid.registrationservice.service.globus.resource.RegistrationServiceResourceBase.java

public RegistrationServiceResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }//from   ww w. j  av  a 2 s.  c o  m
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/RegistrationService";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (RegistrationServiceResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}

From source file:gov.nih.nci.ess.ae.service.aeadvancedquery.service.globus.resource.AEAdvancedQueryResourceBase.java

public AEAdvancedQueryResourceConfiguration getConfiguration() {
    if (this.configuration != null) {
        return this.configuration;
    }//  ww  w  .ja  v  a2  s  . c  o  m
    MessageContext ctx = MessageContext.getCurrentContext();

    String servicePath = ctx.getTargetService();
    servicePath = servicePath.substring(0, servicePath.lastIndexOf("/"));
    servicePath += "/AEAdvancedQuery";

    String jndiName = Constants.JNDI_SERVICES_BASE_NAME + servicePath + "/configuration";
    logger.debug("Will read configuration from jndi name: " + jndiName);
    try {
        Context initialContext = new InitialContext();
        this.configuration = (AEAdvancedQueryResourceConfiguration) initialContext.lookup(jndiName);
    } catch (Exception e) {
        logger.error("when performing JNDI lookup for " + jndiName + ": " + e, e);
    }

    return this.configuration;
}