use of org.apache.openejb.AppContext in project tomee by apache.
the class ReloadingLoaderTest method initContext.
@Before
public void initContext() throws LifecycleException {
final OpenEjbConfiguration configuration = new OpenEjbConfiguration();
configuration.facilities = new FacilitiesInfo();
final CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
SystemInstance.get().setComponent(OpenEjbConfiguration.class, configuration);
SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);
SystemInstance.get().setComponent(WebAppEnricher.class, new WebAppEnricher() {
@Override
public URL[] enrichment(final ClassLoader webappClassLaoder) {
return new URL[0];
}
});
parentInstance = new AtomicReference<>(ParentClassLoaderFinder.Helper.get());
loader = new TomEEWebappClassLoader(parentInstance.get()) {
@Override
public ClassLoader getInternalParent() {
return parentInstance.get();
}
@Override
protected void clearReferences() {
// no-op: this test should be reworked to support it but in real life a loader is not stopped/started
}
};
loader.init();
final StandardRoot resources = new StandardRoot();
loader.setResources(resources);
resources.setContext(new StandardContext() {
@Override
public String getDocBase() {
final File file = new File("target/foo");
file.mkdirs();
return file.getAbsolutePath();
}
@Override
public String getMBeanKeyProperties() {
return "foo";
}
{
}
});
resources.start();
loader.start();
info = new AppInfo();
info.appId = "test";
context = new AppContext(info.appId, SystemInstance.get(), loader, new IvmContext(), new IvmContext(), true);
containerSystem.addAppContext(context);
final WebContext webDeployment = new WebContext(context);
webDeployment.setId(context.getId());
webDeployment.setClassLoader(loader);
containerSystem.addWebContext(webDeployment);
}
use of org.apache.openejb.AppContext in project tomee by apache.
the class WsService method start.
@Override
public void start() throws ServiceException {
wsRegistry = SystemInstance.get().getComponent(WsRegistry.class);
if (wsRegistry == null && SystemInstance.get().getComponent(HttpListenerRegistry.class) != null) {
wsRegistry = new OpenEJBHttpWsRegistry();
}
if (portAddressRegistry == null) {
portAddressRegistry = new PortAddressRegistryImpl();
SystemInstance.get().setComponent(PortAddressRegistry.class, portAddressRegistry);
}
containerSystem = (CoreContainerSystem) SystemInstance.get().getComponent(ContainerSystem.class);
portAddressRegistry = SystemInstance.get().getComponent(PortAddressRegistry.class);
assembler = SystemInstance.get().getComponent(Assembler.class);
SystemInstance.get().setComponent(WsService.class, this);
if (assembler != null) {
SystemInstance.get().addObserver(this);
for (final AppInfo appInfo : assembler.getDeployedApplications()) {
final AppContext appContext = containerSystem.getAppContext(appInfo.appId);
deploy(new AssemblerAfterApplicationCreated(appInfo, appContext, null));
}
}
}
use of org.apache.openejb.AppContext in project tomee by apache.
the class TomcatWebAppBuilder method getWebBeansContext.
private WebBeansContext getWebBeansContext(final ContextInfo contextInfo) {
final AppContext appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId);
if (appContext == null) {
return null;
}
WebBeansContext webBeansContext = appContext.getWebBeansContext();
if (webBeansContext == null) {
return null;
}
for (final WebContext web : appContext.getWebContexts()) {
final String stdName = removeFirstSlashAndWar(contextInfo.standardContext.getName());
if (stdName == null) {
continue;
}
final String name = removeFirstSlashAndWar(web.getContextRoot());
if (stdName.equals(name)) {
webBeansContext = web.getWebbeansContext();
if (Contexts.getHostname(contextInfo.standardContext).equals(web.getHost())) {
break;
}
// else loop hoping to find a better matching
}
}
if (webBeansContext == null) {
webBeansContext = appContext.getWebBeansContext();
}
return webBeansContext;
}
use of org.apache.openejb.AppContext in project tomee by apache.
the class ServletContextHandler method invoke.
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
// ITE are handled by Proxys
final Request request = OpenEJBSecurityListener.requests.get();
if (request != null) {
return method.invoke(request.getServletContext(), args);
}
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
final ServletContext c = contexts.get(contextClassLoader);
if (c != null) {
return method.invoke(c, args);
}
// can be a not container thread so clean it up
OpenEJBSecurityListener.requests.remove();
for (final AppContext a : SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts()) {
for (final WebContext w : a.getWebContexts()) {
if (w.getClassLoader() == contextClassLoader) {
// not in CXF so == should be fine
return method.invoke(w.getServletContext(), args);
}
}
}
throw new IllegalStateException("Didnt find a web context for " + contextClassLoader);
}
Aggregations