private static String createServiceJmxName(final ClassLoader classLoader) { final AppContext app = AppFinder.findAppContextOrWeb(classLoader, AppFinder.AppContextTransformer.INSTANCE); return app == null ? "application" : app.getId(); }
/** * Generally contexts.get() is enough since we set the current context from a request (see webbeanslistener) * but sometimes matching the classloader is better (manager webapps of tomcat deploys for instance) * so here the algorithm: * 1) try to match with the classloader * 2) if not matched try to use the threadlocal * 3) (shouldn't happen) simply return the biggest webbeancontext * * @param cl the key (generally TCCL) * @return the webbeancontext matching the current context */ public static WebBeansContext get(final ClassLoader cl) { WebBeansContext context = contextByClassLoader.get(cl); if (context != null) { return context; } context = AppFinder.findAppContextOrWeb(cl, AppFinder.WebBeansContextTransformer.INSTANCE); if (context == null) { context = contexts.get(); if (context == null) { // any "guess" algortithm there would break prod apps cause AppFinder failed already, let's try to not try to be more clever than we can throw new IllegalStateException("On a thread without an initialized context nor a classloader mapping a deployed app"); } } else { // some cache to avoid to browse each app each time contextByClassLoader.put(cl, context); } return context; }
public TomEEConfigSource() { final AppContext appContextOrWeb = AppFinder.findAppContextOrWeb(Thread.currentThread().getContextClassLoader(), AppFinder.AppContextTransformer.INSTANCE); if (appContextOrWeb != null) { final List<String> mpIgnoredApps = asList(SystemInstance.get() .getProperty("mp.ignored.apps", "ROOT,docs,host-manager,manager") .split(",")); if (mpIgnoredApps.stream().anyMatch(s -> s.equalsIgnoreCase(appContextOrWeb.getId()))) { configuration.put("geronimo.opentracing.filter.active", "false"); } } }
@Override public ServicesManager find() { final ClassLoader contextClassLoader = unwrap(Thread.currentThread().getContextClassLoader()); final AppContext context = AppFinder.findAppContextOrWeb(contextClassLoader, AppFinder.AppContextTransformer.INSTANCE); if (context != null) { doInit(context); return context.get(ServicesManager.class); } throw new IllegalStateException("Can't find ServiceManager for " + contextClassLoader); }
@Override public void invalidate() { final Object web = AppFinder.findAppContextOrWeb(Thread.currentThread().getContextClassLoader(), AppFinder.AppOrWebContextTransformer.INSTANCE); if (WebContext.class.isInstance(web)) { doInvokeSpecificListeners(WebContext.class.cast(web).getContextRoot()); } else if (AppContext.class.isInstance(web)) { doInvokeSpecificListeners(AppContext.class.cast(web).getId()); } super.invalidate(); }
@Override // avoids the need of org.apache.openejb.server.httpd.EEFilter in embedded mode public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) { setAttribute("openejb_async", "true"); final OpenEJBAsyncContext asyncContext = new OpenEJBAsyncContext(HttpServletRequest.class.cast(servletRequest) /* TODO */, servletResponse, contextPath); asyncContext.internalStartAsync(); asyncStarted = true; final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb( Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE); return webBeansContext != null ? new EEFilter.AsynContextWrapper(asyncContext, servletRequest, webBeansContext) : asyncContext; }
if (AppFinder.findAppContextOrWeb( Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE) == null) { final Iterator<URL> toFilter = urlSet.iterator();
context = AppFinder.findAppContextOrWeb(cl, AppFinder.WebBeansContextTransformer.INSTANCE); if (context == null) { context = contexts.get();
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)); }
private AppContext findAppContext(final InvocationContext ic) { AppContext appContext = null; final ThreadContext tc = ThreadContext.getThreadContext(); if (tc != null && tc.getBeanContext() != null) { appContext = tc.getBeanContext().getModuleContext().getAppContext(); } if (appContext == null) { // we should never enter here for an EJB final ClassLoader loader = Thread.currentThread().getContextClassLoader(); appContext = AppFinder.findAppContextOrWeb(loader, AppFinder.AppContextTransformer.INSTANCE); } if (appContext == null) { LOGGER.warning(GovernanceCodes.TGI_CANT_FIND_APPCONTEXT, "Can't find AppContext for " + Thread.currentThread().getContextClassLoader() + " so method " + ic.getMethod() + " will not get governance activated"); return null; } return appContext; }
if (AppFinder.findAppContextOrWeb( Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE) == null && Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.jsf.ignore-owb", "true"))) {
private static <T> T newInstance(final OpenEjbConfig config, final Class<T> clazz) throws Exception { final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb( Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE); if (webBeansContext == null) { return clazz.newInstance(); } final BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl(); if (!beanManager.isInUse()) { return clazz.newInstance(); } final AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(clazz); final InjectionTarget<T> it = beanManager.createInjectionTarget(annotatedType); final CreationalContext<T> context = beanManager.createCreationalContext(null); final T instance = it.produce(context); it.inject(instance, context); it.postConstruct(instance); config.releasables.add(new Releasable<T>(context, it, instance)); return instance; }
protected HttpListener createPojoWsContainer(final ClassLoader loader, final URL moduleBaseUrl, final PortData port, final String serviceId, final Class target, final Context context, final String contextRoot, final Map<String, Object> bdgs, final ServiceConfiguration services) { final Bus bus = CxfUtil.getBus(); final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader()); try { CxfCatalogUtils.loadOASISCatalog(bus, moduleBaseUrl, "META-INF/jax-ws-catalog.xml"); final PojoWsContainer container = new PojoWsContainer(loader, httpTransportFactory, bus, port, context, target, bdgs, services); container.start(); wsContainers.put(serviceId, container); SystemInstance.get().fireEvent(new ServerCreated( container.getEndpoint().getServer(), AppFinder.findAppContextOrWeb(loader, AppFinder.AppContextTransformer.INSTANCE))); return container; } finally { if (oldLoader != null) { CxfUtil.clearBusLoader(oldLoader); } } }
AppFinder.findAppContextOrWeb(Thread.currentThread().getContextClassLoader(), AppFinder.AppContextTransformer.INSTANCE), providers));
protected HttpListener createPojoWsContainer(ClassLoader loader, URL moduleBaseUrl, PortData port, String serviceId, Class target, Context context, String contextRoot, Map<String, Object> bdgs, ServiceConfiguration services) { Bus bus = CxfUtil.getBus(); final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader()); try { CxfCatalogUtils.loadOASISCatalog(bus, moduleBaseUrl, "META-INF/jax-ws-catalog.xml"); PojoWsContainer container = new PojoWsContainer(loader, newTransportFactory(), bus, port, context, target, bdgs, services); container.start(); wsContainers.put(serviceId, container); SystemInstance.get().fireEvent(new ServerCreated( container.getEndpoint().getServer(), AppFinder.findAppContextOrWeb(loader, AppFinder.AppContextTransformer.INSTANCE))); return container; } finally { if (oldLoader != null) { CxfUtil.clearBusLoader(oldLoader); } } }
final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb( Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE); if (webBeansContext != null) { // cdi
if (AppFinder.findAppContextOrWeb(context.getLoader().getClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE) != null) { final FilterDef asyncOwbFilter = new FilterDef(); asyncOwbFilter.setAsyncSupported("true");
AppContext ctx = appCtx; if (ctx == null) { ctx = AppFinder.findAppContextOrWeb(Thread.currentThread().getContextClassLoader(), AppFinder.AppContextTransformer.INSTANCE); if (ctx == null) { return;
Thread.currentThread().setContextClassLoader(loader); try { final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb( Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE); final BeanManagerImpl bm = webBeansContext == null ? null : webBeansContext.getBeanManagerImpl();