private void fireServerCreated(final ClassLoader oldLoader) { final Object ctx = AppFinder.findAppContextOrWeb(oldLoader, new AppFinder.Transformer<Object>() { @Override public Object from(final AppContext appCtx) { return appCtx; } @Override public Object from(final WebContext webCtx) { return webCtx; } }); final AppContext appCtx = AppContext.class.isInstance(ctx) ? AppContext.class.cast(ctx) : WebContext.class.cast(ctx).getAppContext(); WebContext webContext = appCtx == ctx ? null : WebContext.class.cast(ctx); if (webContext == null && appCtx.getWebContexts().size() == 1 && appCtx.getWebContexts().get(0).getClassLoader() == oldLoader) { webContext = appCtx.getWebContexts().get(0); } SystemInstance.get().fireEvent(new ServerCreated(server, appCtx, webContext, this.context)); }
public static <T> Collection<T> findByTypeForContext(final String context, final Class<T> type) { final WebAppBuilder builder = SystemInstance.get().getComponent(WebAppBuilder.class); if (!LightweightWebAppBuilder.class.isInstance(builder)) { return Collections.emptyList(); } for (final AppContext app : SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts()) { for (final WebContext web : app.getWebContexts()) { if (web.getContextRoot().replace("/", "").equals(context.replace("/", ""))) { final Collection<Object> potentials = LightweightWebAppBuilder.class.cast(builder).listenersFor(web.getContextRoot()); if (potentials == null) { return Collections.emptyList(); } final Collection<T> filtered = new ArrayList<>(potentials.size()); for (final Object o : potentials) { if (type.isInstance(o)) { filtered.add(type.cast(o)); } } return filtered; } } } return Collections.emptyList(); }
@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); } OpenEJBSecurityListener.requests.remove(); // can be a not container thread so clean it up 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); }
for (final WebContext w : appCtx.getWebContexts()) { final Object instance = w.getBindings().get(noJavaPrefix); if (instance != null) {
private static WebContext findWebContext(final String path) { // TODO: this is a poor impl, would need registration of app etc to be better and have a rooter for (final AppContext app : SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts()) { for (final WebContext web : app.getWebContexts()) { if (path.startsWith(web.getContextRoot()) || path.startsWith('/' + web.getContextRoot())) { return web; } } } return null; }
@Override public void close() throws IOException { try { final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class); if (sessionManager != null) { for (final WebContext web : appCtx.getWebContexts()) { sessionManager.destroy(web); } } } catch (final Throwable e) { // no-op } } });
public OpenEJBAsyncContext(final HttpServletRequest request, final ServletResponse response, final String contextPath) { if (es == null) { synchronized (OpenEJBAsyncContext.class) { // we don't care since impl is not really thread safe, just here for testing if (es == null) { init(); } } } this.request = request; this.contextPath = contextPath; if (contextPath != null) { for (final AppContext app : SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts()) { for (final WebContext web : app.getWebContexts()) { if (web.getContextRoot().replace("/", "").equals(contextPath.replace("/", ""))) { this.context = web; break; } } } } this.response = response; this.socket = Socket.class.cast(request.getAttribute("openejb_socket")); this.event = new AsyncEvent(this, request, response); INITIALIZED.add(this); }
public static <T> T findAppContextOrWeb(final ClassLoader cl, final Transformer<T> transformer) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { final ClassLoader appContextClassLoader = appContext.getClassLoader(); if (appContextClassLoader.equals(cl) || (cl != null && cl.equals(appContextClassLoader))) { // CxfContainerLoader is not symmetric return transformer.from(appContext); } for (final WebContext web : appContext.getWebContexts()) { final ClassLoader webClassLoader = web.getClassLoader(); if (webClassLoader.equals(cl) || (cl != null && cl.equals(webClassLoader))) { return transformer.from(web); } } } return null; }
@Override public void run() { try { final Object sessionManager = SystemInstance.get().getComponent( ParentClassLoaderFinder.Helper.get().loadClass("org.apache.openejb.server.httpd.session.SessionManager") ); if (sessionManager != null) { final Class<?>[] paramTypes = {WebContext.class}; for (final WebContext web : appContext.getWebContexts()) { Reflections.invokeByReflection(sessionManager, "destroy", paramTypes, new Object[]{web}); } } } catch (final Throwable e) { // no-op } } });
private String findPrefix() { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { if (appContext.getClassLoader().equals(loader)) { return appContext.getId(); } for (final WebContext web : appContext.getWebContexts()) { if (web.getClassLoader().equals(loader)) { return appContext.getId(); } } } if (1 == containerSystem.getAppContexts().size()) { return containerSystem.getAppContexts().iterator().next().getId(); } return null; }
private String findPrefix() { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { if (appContext.getClassLoader().equals(loader)) { return appContext.getId(); } for (final WebContext web : appContext.getWebContexts()) { if (web.getClassLoader().equals(loader)) { return appContext.getId(); } } } if (1 == containerSystem.getAppContexts().size()) { return containerSystem.getAppContexts().iterator().next().getId(); } return null; }
public static <T> T findAppContextOrWeb(final ClassLoader cl, final Transformer<T> transformer) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { final ClassLoader appContextClassLoader = appContext.getClassLoader(); boolean found = false; if (appContextClassLoader.equals(cl) || (cl != null && cl.equals(appContextClassLoader))) { // CxfContainerLoader is not symmetric final T from = transformer.from(appContext); found = true; if (from != null) { return from; } } for (final WebContext web : appContext.getWebContexts()) { final ClassLoader webClassLoader = web.getClassLoader(); if (webClassLoader.equals(cl) || (cl != null && cl.equals(webClassLoader))) { return transformer.from(web); } } if (found) { // for cases where app and webapp share the same classloader break; } } return null; }
@Override public void init(final ServletConfig servletConfig) throws ServletException { final String contextRoot = servletConfig.getServletContext().getContextPath(); final String context = contextRoot == null || contextRoot.equals("") ? "" : contextRoot.substring(1); app = SystemInstance.get().getComponent(ContainerSystem.class).getAppContext(context); if (app == null) { // could be if we skip EE integration, fake an app app = new AppContext(context, SystemInstance.get(), servletConfig.getServletContext().getClassLoader(), new IvmContext(), new IvmContext(), true); app.set(GovernanceApplicationScopedService.class, new GovernanceApplicationScopedService(app.getId())); final WebContext webContext = new WebContext(app); webContext.setContextRoot(context); webContext.setHost(servletConfig.getServletContext().getServletContextName()); app.getWebContexts().add(webContext); } super.init(servletConfig); SystemInstance.get().fireEvent( new ServerCreated( server, app, app.getWebContexts().iterator().next(), contextRoot)); app = null; }
private static String findAppName(final WebBeansContext webBeansContext) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { if (appContext.getWebBeansContext() == webBeansContext) { return appContext.getId(); } for (final WebContext web : appContext.getWebContexts()) { if (web.getWebbeansContext() == webBeansContext) { // ear return web.getId(); } } } return "defaultDelegate"; }
private static String findAppName(final WebBeansContext webBeansContext) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); for (final AppContext appContext : containerSystem.getAppContexts()) { if (appContext.getWebBeansContext() == webBeansContext) { return appContext.getId(); } for (final WebContext web : appContext.getWebContexts()) { if (web.getWebbeansContext() == webBeansContext) { // ear return web.getId(); } } } return "defaultDelegate"; }
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; }
public static Context getContext() { final ThreadContext callContext = ThreadContext.getThreadContext(); if (callContext == null) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); final ClassLoader current = Thread.currentThread().getContextClassLoader(); final Context globalContext = containerSystem.getJNDIContext(); if (current == null) { return globalContext; } for (final AppContext appContext : containerSystem.getAppContexts()) { for (final WebContext web : appContext.getWebContexts()) { // more specific first if (current.equals(web.getClassLoader())) { return new ContextHandler(web.getJndiEnc()); } } if (current.equals(appContext.getClassLoader())) { return new ContextHandler(appContext.getAppJndiContext()); } } return globalContext; } final BeanContext di = callContext.getBeanContext(); if (di != null) { return di.getJndiEnc(); } else { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); return containerSystem.getJNDIContext(); } }
public static Context getContext() { final ThreadContext callContext = ThreadContext.getThreadContext(); if (callContext == null) { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); final ClassLoader current = Thread.currentThread().getContextClassLoader(); final Context globalContext = containerSystem.getJNDIContext(); if (current == null) { return globalContext; } for (final AppContext appContext : containerSystem.getAppContexts()) { for (final WebContext web : appContext.getWebContexts()) { // more specific first if (current.equals(web.getClassLoader())) { return new ContextHandler(web.getJndiEnc()); } } if (current.equals(appContext.getClassLoader())) { return new ContextHandler(appContext.getAppJndiContext()); } } return globalContext; } final BeanContext di = callContext.getBeanContext(); if (di != null) { return di.getJndiEnc(); } else { final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); return containerSystem.getJNDIContext(); } }
error = t; for (final WebContext web : appContext.getWebContexts()) { try { OWBInjector.inject(web.getWebBeansContext().getBeanManagerImpl(), inputTestInstance, null);
error = t; for (final WebContext web : appContext.getWebContexts()) { if (web.getWebBeansContext() == null) { continue;