Search in sources :

Example 71 with Context

use of javax.naming.Context in project spring-framework by spring-projects.

the class SimpleNamingContext method createSubcontext.

@Override
public Context createSubcontext(String name) {
    String subcontextName = this.root + name;
    if (!subcontextName.endsWith("/")) {
        subcontextName += "/";
    }
    Context subcontext = new SimpleNamingContext(subcontextName, this.boundObjects, this.environment);
    bind(name, subcontext);
    return subcontext;
}
Also used : Context(javax.naming.Context)

Example 72 with Context

use of javax.naming.Context in project spring-framework by spring-projects.

the class JmsTemplateTests method createTemplate.

private JmsTemplate createTemplate() {
    JmsTemplate template = new JmsTemplate();
    JndiDestinationResolver destMan = new JndiDestinationResolver();
    destMan.setJndiTemplate(new JndiTemplate() {

        @Override
        protected Context createInitialContext() {
            return jndiContext;
        }
    });
    template.setDestinationResolver(destMan);
    template.setSessionTransacted(useTransactedTemplate());
    return template;
}
Also used : Context(javax.naming.Context) JndiTemplate(org.springframework.jndi.JndiTemplate) JndiDestinationResolver(org.springframework.jms.support.destination.JndiDestinationResolver)

Example 73 with Context

use of javax.naming.Context in project spring-framework by spring-projects.

the class SimpleNamingContext method createSubcontext.

@Override
public Context createSubcontext(String name) {
    String subcontextName = this.root + name;
    if (!subcontextName.endsWith("/")) {
        subcontextName += "/";
    }
    Context subcontext = new SimpleNamingContext(subcontextName, this.boundObjects, this.environment);
    bind(name, subcontext);
    return subcontext;
}
Also used : Context(javax.naming.Context)

Example 74 with Context

use of javax.naming.Context in project liquibase by liquibase.

the class MultiTenantSpringLiquibase method resolveDataSources.

private void resolveDataSources() throws NamingException {
    Context context = new InitialContext();
    int lastIndexOf = jndiBase.lastIndexOf("/");
    String jndiRoot = jndiBase.substring(0, lastIndexOf);
    String jndiParent = jndiBase.substring(lastIndexOf + 1);
    Context base = (Context) context.lookup(jndiRoot);
    NamingEnumeration<NameClassPair> list = base.list(jndiParent);
    while (list.hasMoreElements()) {
        NameClassPair entry = list.nextElement();
        String name = entry.getName();
        String jndiUrl;
        if (entry.isRelative()) {
            jndiUrl = jndiBase + "/" + name;
        } else {
            jndiUrl = name;
        }
        Object lookup = context.lookup(jndiUrl);
        if (lookup instanceof DataSource) {
            dataSources.add((DataSource) lookup);
            log.debug("Added a data source at " + jndiUrl);
        } else {
            log.info("Skipping a resource " + jndiUrl + " not compatible with DataSource.");
        }
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameClassPair(javax.naming.NameClassPair) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource)

Example 75 with Context

use of javax.naming.Context in project gitblit by gitblit.

the class GitblitContext method lookupBaseFolderFromJndi.

private String lookupBaseFolderFromJndi() {
    try {
        // try to lookup JNDI env-entry for the baseFolder
        InitialContext ic = new InitialContext();
        Context env = (Context) ic.lookup("java:comp/env");
        return (String) env.lookup("baseFolder");
    } catch (NamingException n) {
        logger.error("Failed to get JNDI env-entry: " + n.getExplanation());
    }
    return null;
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServletContext(javax.servlet.ServletContext) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Aggregations

Context (javax.naming.Context)507 InitialContext (javax.naming.InitialContext)250 Test (org.junit.Test)173 NamingException (javax.naming.NamingException)156 DataSource (javax.sql.DataSource)72 Properties (java.util.Properties)67 Connection (java.sql.Connection)62 NameNotFoundException (javax.naming.NameNotFoundException)52 UserTransaction (javax.transaction.UserTransaction)48 SQLException (java.sql.SQLException)46 IOException (java.io.IOException)44 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)44 Statement (java.sql.Statement)42 Name (javax.naming.Name)38 Hashtable (java.util.Hashtable)35 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)27 BeanContext (org.apache.openejb.BeanContext)27 Binding (javax.naming.Binding)25 Reference (javax.naming.Reference)25 NotContextException (javax.naming.NotContextException)23