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;
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations