Search in sources :

Example 1 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class TomEEInjectionEnricher method getAppContext.

private AppContext getAppContext(final Class<?> clazz) {
    final String clazzName = clazz.getName();
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    if (deployment != null && deployment.get() != null) {
        final BeanContext context = containerSystem.getBeanContext(deployment.get().getDescription().getName() + "_" + clazzName);
        if (context != null) {
            return context.getModuleContext().getAppContext();
        }
    }
    final List<AppContext> appContexts = containerSystem.getAppContexts();
    final ClassLoader loader = clazz.getClassLoader();
    for (final AppContext app : appContexts) {
        final BeanContext context = containerSystem.getBeanContext(app.getId() + "_" + clazzName);
        if (context != null) {
            // in embedded mode we have deployment so we dont go here were AppLoader would just be everywhere
            if (context.getBeanClass().getClassLoader() == loader) {
                return app;
            }
        }
    }
    if (deployment != null && deployment.get() != null && deployment.get().getDescription().testable() && !isJunitComponent(clazz)) /*app context will be found by classloader, no need to log anything there*/
    {
        Logger.getLogger(TomEEInjectionEnricher.class.getName()).log(Level.WARNING, "Failed to find AppContext for: " + clazzName);
    }
    return null;
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) AppContext(org.apache.openejb.AppContext)

Example 2 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class InitContextFactory method getInitialContext.

@SuppressWarnings("unchecked")
@Override
public Context getInitialContext(final Hashtable env) throws javax.naming.NamingException {
    if (!OpenEJB.isInitialized()) {
        initializeOpenEJB(env);
    }
    final String user = (String) env.get(Context.SECURITY_PRINCIPAL);
    final String pass = (String) env.get(Context.SECURITY_CREDENTIALS);
    final String realmName = (String) env.get("openejb.authentication.realmName");
    if (user != null && pass != null) {
        try {
            final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class);
            final Object identity;
            if (realmName == null) {
                identity = securityService.login(user, pass);
            } else {
                identity = securityService.login(realmName, user, pass);
            }
            securityService.associate(identity);
        } catch (final LoginException e) {
            throw (AuthenticationException) new AuthenticationException("User could not be authenticated: " + user).initCause(e);
        }
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    Context context = containerSystem.getJNDIContext();
    context = (Context) context.lookup("openejb/local");
    return context;
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Context(javax.naming.Context) AuthenticationException(javax.naming.AuthenticationException) SecurityService(org.apache.openejb.spi.SecurityService) LoginException(javax.security.auth.login.LoginException)

Example 3 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class ContextualJndiReference method lookup.

private Object lookup(final String s) throws NamingException {
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final Context jndiContext = containerSystem.getJNDIContext();
    try {
        if (s.startsWith("java:") | s.startsWith("openejb:")) {
            return jndiContext.lookup(s);
        } else {
            return jndiContext.lookup("openejb/Resource/" + s);
        }
    } catch (final NameNotFoundException e) {
        return jndiContext.lookup("java:module/" + Strings.lastPart(getClassName(), '.'));
    } catch (final NamingException e) {
        throw (NamingException) new NamingException("could not look up " + s).initCause(e);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException)

Example 4 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class openejbURLContextFactory method getContext.

public static Context getContext() throws NamingException {
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final Context context = (Context) containerSystem.getJNDIContext().lookup("openejb");
    return context;
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Context(javax.naming.Context)

Example 5 with ContainerSystem

use of org.apache.openejb.spi.ContainerSystem in project tomee by apache.

the class ApplicationPropertiesTest method testOverrideAdd.

public void testOverrideAdd() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        SystemInstance.get().getProperties().put("fooApp.color", "orange");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Aggregations

ContainerSystem (org.apache.openejb.spi.ContainerSystem)64 Assembler (org.apache.openejb.assembler.classic.Assembler)31 BeanContext (org.apache.openejb.BeanContext)22 HashMap (java.util.HashMap)20 Map (java.util.Map)19 File (java.io.File)17 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)13 Context (javax.naming.Context)12 EjbJar (org.apache.openejb.jee.EjbJar)11 StatelessBean (org.apache.openejb.jee.StatelessBean)11 AppContext (org.apache.openejb.AppContext)10 AppInfo (org.apache.openejb.assembler.classic.AppInfo)10 Properties (java.util.Properties)9 EjbModule (org.apache.openejb.config.EjbModule)9 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)9 ArrayList (java.util.ArrayList)8 NamingException (javax.naming.NamingException)8 WebContext (org.apache.openejb.core.WebContext)8 InitialContext (javax.naming.InitialContext)7 NameNotFoundException (javax.naming.NameNotFoundException)6