Search in sources :

Example 86 with InitialContext

use of javax.naming.InitialContext in project aries by apache.

the class InitialContextTest method testURLContextErrorPropagation.

@Test
public void testURLContextErrorPropagation() throws Exception {
    ObjectFactory of = new ObjectFactory() {

        public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
            throw new Exception("doh");
        }
    };
    registerURLObjectFactory(of, "test");
    ic = initialContext();
    try {
        ic.lookup("test:something");
        Assert.fail("Expected NamingException");
    } catch (NamingException ne) {
        assertNotNull(ne.getCause());
        assertEquals("doh", ne.getCause().getMessage());
    }
}
Also used : InitialLdapContext(javax.naming.ldap.InitialLdapContext) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) BundleContext(org.osgi.framework.BundleContext) LdapContext(javax.naming.ldap.LdapContext) ObjectFactory(javax.naming.spi.ObjectFactory) Hashtable(java.util.Hashtable) NamingException(javax.naming.NamingException) NoInitialContextException(javax.naming.NoInitialContextException) NamingException(javax.naming.NamingException) Name(javax.naming.Name) Test(org.junit.Test)

Example 87 with InitialContext

use of javax.naming.InitialContext in project aries by apache.

the class JndiExtensionTests method testGetBeanManagerThroughJNDI.

public void testGetBeanManagerThroughJNDI() throws Exception {
    Hashtable<String, Object> env = new Hashtable<>();
    env.put(JNDIConstants.BUNDLE_CONTEXT, cdiBundle.getBundleContext());
    InitialContext context = new InitialContext(env);
    BeanManager beanManager = (BeanManager) context.lookup("java:comp/BeanManager");
    assertNotNull(beanManager);
    assertPojoExists(beanManager);
}
Also used : Hashtable(java.util.Hashtable) BeanManager(javax.enterprise.inject.spi.BeanManager) InitialContext(javax.naming.InitialContext)

Example 88 with InitialContext

use of javax.naming.InitialContext in project geode by apache.

the class GemfireSessionManager method registerMBean.

/**
   * Register a bean for statistic gathering purposes
   */
private void registerMBean() {
    mbean = new SessionStatistics();
    try {
        InitialContext ctx = new InitialContext();
        MBeanServer mbs = MBeanServer.class.cast(ctx.lookup("java:comp/env/jmx/runtime"));
        ObjectName oname = new ObjectName(Constants.SESSION_STATISTICS_MBEAN_NAME);
        mbs.registerMBean(mbean, oname);
    } catch (Exception ex) {
        LOG.warn("Unable to register statistics MBean. Error: {}", ex.getMessage());
    }
}
Also used : SessionStatistics(org.apache.geode.modules.session.internal.jmx.SessionStatistics) InitialContext(javax.naming.InitialContext) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CacheClosedException(org.apache.geode.cache.CacheClosedException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 89 with InitialContext

use of javax.naming.InitialContext in project deltaspike by apache.

the class OpenEjbContainerControl method boot.

@Override
public synchronized void boot(Map<?, ?> properties) {
    if (context == null) {
        // this immediately boots the container
        final Properties p = new Properties();
        p.putAll(PROPERTIES);
        if (// override with user config
        properties != null) {
            p.putAll(properties);
        }
        try {
            context = new InitialContext(p);
        } catch (final NamingException e) {
            throw new RuntimeException(e);
        }
        beanManager = WebBeansContext.currentInstance().getBeanManagerImpl();
    }
}
Also used : NamingException(javax.naming.NamingException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) LocalInitialContext(org.apache.openejb.core.LocalInitialContext)

Example 90 with InitialContext

use of javax.naming.InitialContext in project geode by apache.

the class ContextJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    Hashtable table = new Hashtable();
    table.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.geode.internal.jndi.InitialContextFactoryImpl");
    initialContext = new InitialContext(table);
    initialContext.bind("java:gf/env/datasource/oracle", "a");
    gemfireContext = (Context) initialContext.lookup("java:gf");
    envContext = (Context) gemfireContext.lookup("env");
    dataSourceContext = (Context) envContext.lookup("datasource");
}
Also used : Hashtable(java.util.Hashtable) InitialContext(javax.naming.InitialContext) Before(org.junit.Before)

Aggregations

InitialContext (javax.naming.InitialContext)1068 Test (org.junit.Test)325 EJBException (javax.ejb.EJBException)228 Properties (java.util.Properties)213 Context (javax.naming.Context)194 RemoteException (java.rmi.RemoteException)173 TestFailureException (org.apache.openejb.test.TestFailureException)172 NamingException (javax.naming.NamingException)168 AssertionFailedError (junit.framework.AssertionFailedError)168 JMSException (javax.jms.JMSException)167 RemoveException (javax.ejb.RemoveException)66 CreateException (javax.ejb.CreateException)57 DataSource (javax.sql.DataSource)55 Hashtable (java.util.Hashtable)54 Assembler (org.apache.openejb.assembler.classic.Assembler)47 EjbJar (org.apache.openejb.jee.EjbJar)41 NameNotFoundException (javax.naming.NameNotFoundException)40 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)38 Connection (java.sql.Connection)37 StatelessBean (org.apache.openejb.jee.StatelessBean)30