Search in sources :

Example 6 with NoInitialContextException

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

the class OSGiInitialContextFactoryBuilder method getInitialContext.

public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
    Activator.getAugmenterInvoker().augmentEnvironment(environment);
    BundleContext context = Utils.getBundleContext(environment, InitialContext.class);
    if (context == null) {
        throw new NoInitialContextException("The calling code's BundleContext could not be determined.");
    }
    Activator.getAugmenterInvoker().unaugmentEnvironment(environment);
    return ContextHelper.getInitialContext(context, environment);
}
Also used : NoInitialContextException(javax.naming.NoInitialContextException) BundleContext(org.osgi.framework.BundleContext)

Example 7 with NoInitialContextException

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

the class ContextHelper method getInitialContext.

public static Context getInitialContext(BundleContext context, Hashtable<?, ?> environment) throws NamingException {
    final Bundle jndiBundle = FrameworkUtil.getBundle(ContextHelper.class);
    // if we are outside OSGi (like in our unittests) then we would get Null back here, so just make sure we don't.
    if (jndiBundle != null) {
        BundleContext jndiBundleContext = Utils.doPrivileged(jndiBundle::getBundleContext);
        if (!jndiBundleContext.getClass().equals(context.getClass())) {
            // the context passed in must have come from a child framework
            // use the parent context instead
            context = jndiBundleContext;
        }
    }
    ContextProvider provider = getContextProvider(context, environment);
    if (provider != null) {
        return new DelegateContext(context, provider);
    } else {
        String contextFactoryClass = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY);
        if (contextFactoryClass == null) {
            return new DelegateContext(context, environment);
        } else {
            throw new NoInitialContextException("Unable to find the InitialContextFactory " + contextFactoryClass + ".");
        }
    }
}
Also used : NoInitialContextException(javax.naming.NoInitialContextException) Bundle(org.osgi.framework.Bundle) BundleContext(org.osgi.framework.BundleContext)

Aggregations

NoInitialContextException (javax.naming.NoInitialContextException)7 InitialContext (javax.naming.InitialContext)5 NamingException (javax.naming.NamingException)3 Properties (java.util.Properties)2 Context (javax.naming.Context)2 BundleContext (org.osgi.framework.BundleContext)2 Hashtable (java.util.Hashtable)1 ConnectionFactory (javax.jms.ConnectionFactory)1 JMSException (javax.jms.JMSException)1 NameNotFoundException (javax.naming.NameNotFoundException)1 Reference (javax.naming.Reference)1 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)1 Bundle (org.osgi.framework.Bundle)1