org.apache.webbeans.util.WebBeansUtil Java Examples
The following examples show how to use
org.apache.webbeans.util.WebBeansUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HAAbstractUnitTest.java From HotswapAgent with GNU General Public License v2.0 | 6 votes |
protected void startContainer() { WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader()); //Creates a new container testLifecycle = new HAOpenWebBeansTestLifeCycle(); webBeansContext = WebBeansContext.getInstance(); //Start application try { testLifecycle.startApplication(null); } catch (Exception e) { throw new WebBeansConfigurationException(e); } }
Example #2
Source File: BeginWebBeansListener.java From tomee with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void requestInitialized(final ServletRequestEvent event) { final Object oldContext = ThreadSingletonServiceImpl.enter(this.webBeansContext); if (event != null) { event.getServletRequest().setAttribute(contextKey, oldContext); } try { if (logger.isDebugEnabled()) { logger.debug("Starting a new request : [{0}]", event == null ? "null" : event.getServletRequest().getRemoteAddr()); } if (webBeansContext instanceof WebappWebBeansContext) { // start before child ((WebappWebBeansContext) webBeansContext).getParent().getContextsService().startContext(RequestScoped.class, event); } contextsService.startContext(RequestScoped.class, event); // we don't initialise the Session here but do it lazily if it gets requested // the first time. See OWB-457 } catch (final Exception e) { logger.error(OWBLogConst.ERROR_0019, event == null ? "null" : event.getServletRequest()); WebBeansUtil.throwRuntimeExceptions(e); } }
Example #3
Source File: BeginWebBeansListener.java From tomee with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void sessionCreated(final HttpSessionEvent event) { try { if (logger.isDebugEnabled()) { logger.debug("Starting a session with session id : [{0}]", event.getSession().getId()); } if (webBeansContext instanceof WebappWebBeansContext) { // start before child ((WebappWebBeansContext) webBeansContext).getParent().getContextsService().startContext(SessionScoped.class, event.getSession()); } contextsService.startContext(SessionScoped.class, event.getSession()); } catch (final Exception e) { logger.error(OWBLogConst.ERROR_0020, event.getSession()); WebBeansUtil.throwRuntimeExceptions(e); } }
Example #4
Source File: CdiPlugin.java From tomee with Apache License 2.0 | 5 votes |
public void stop() throws OpenEJBException { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try { // Setting context class loader for cleaning Thread.currentThread().setContextClassLoader(classLoader); // Fire shut down webBeansContext.getBeanManagerImpl().fireEvent(new BeforeShutdownImpl()); // Destroys context webBeansContext.getContextsService().destroy(null); // Free all plugin resources webBeansContext.getPluginLoader().shutDown(); // Clear extensions webBeansContext.getExtensionLoader().clear(); // Delete Resolutions Cache webBeansContext.getBeanManagerImpl().getInjectionResolver().clearCaches(); // Delete AnnotateTypeCache webBeansContext.getAnnotatedElementFactory().clear(); // Clear the resource injection service final CdiResourceInjectionService injectionServices = (CdiResourceInjectionService) webBeansContext.getService(ResourceInjectionService.class); injectionServices.clear(); // Clear singleton list WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader()); } catch (final Exception e) { throw new OpenEJBException(e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
Example #5
Source File: OWBTomcatWebScannerService.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
@Override public void scan() { if (delegate != null) { if (getFinder() == null) { delegate.scan(); } if (finder == null) { finder = getFinder(); } } if (finder != null) { return; } super.scan(); scanGroovy(WebBeansUtil.getCurrentClassLoader()); if (!urls.isEmpty()) { logger.info("OpenWebBeans scanning:"); final String m2 = new File(System.getProperty("user.home", "."), ".m2/repository").getAbsolutePath(); final String base = ofNullable(docBase).orElse("$$$"); final String sharedBase = ofNullable(shared).orElse("$$$"); final String runnerBase = ofNullable(System.getProperty("meecrowave.base")).orElse("$$$"); final String runnerHome = ofNullable(System.getProperty("meecrowave.home")).orElse("$$$"); urls.stream().map(u -> { String shownValue = u // protocol .replace("file://", "") .replace("file:", "") .replace("jar:", "") // URL suffix .replace("!/META-INF/beans.xml", "") .replace("!/", "") // beans.xml .replace("META-INF/beans.xml", ""); // try to make it shorter if (shownValue.startsWith(m2)) { shownValue = "${maven}/" + shownValue.substring(shownValue.replace(File.separatorChar, '/').lastIndexOf('/') + 1); } else if (shownValue.startsWith(base)) { shownValue = "${app}" + shownValue.replace(base, ""); } else if (shownValue.startsWith(sharedBase)) { shownValue = "${shared}" + shownValue.replace(sharedBase, ""); } else if (shownValue.startsWith(runnerBase)) { shownValue = "${base}" + shownValue.replace(runnerBase, ""); } else if (shownValue.startsWith(runnerHome)) { shownValue = "${home}" + shownValue.replace(runnerHome, ""); } return shownValue; }).sorted().forEach(v -> logger.info(" " + v)); if (fileVisitor != null) { urls.stream() .filter(this::isFile) .map(this::toFile) .filter(File::isDirectory) .forEach(fileVisitor); } } urls.clear(); // no more needed filter = null; docBase = null; shared = null; }
Example #6
Source File: WebappBeanManager.java From tomee with Apache License 2.0 | 4 votes |
private boolean isEvent(final Object event) { return !WebBeansUtil.isDefaultExtensionBeanEventType(event.getClass()) && !webappCtx.getWebBeansUtil().isContainerEventType(event); }
Example #7
Source File: OpenEJBLifecycle.java From tomee with Apache License 2.0 | 4 votes |
@Override public void stopApplication(final Object endObject) { logger.debug("OpenWebBeans Container is stopping."); try { // Fire shut down if (WebappBeanManager.class.isInstance(beanManager)) { WebappBeanManager.class.cast(beanManager).beforeStop(); } webBeansContext.getContextsService().endContext(RequestScoped.class, endObject); webBeansContext.getContextsService().endContext(ConversationScoped.class, endObject); webBeansContext.getContextsService().endContext(SessionScoped.class, endObject); webBeansContext.getContextsService().endContext(ApplicationScoped.class, endObject); webBeansContext.getContextsService().endContext(Singleton.class, endObject); // clean up the EL caches after each request ELContextStore elStore = ELContextStore.getInstance(false); if (elStore != null) { elStore.destroyELContextStore(); } this.beanManager.fireEvent(new BeforeShutdownImpl(), true); // this will now even destroy the ExtensionBeans and other internal stuff this.contextsService.destroy(endObject); //Unbind BeanManager if (jndiService != null) { jndiService.unbind(WebBeansConstants.WEB_BEANS_MANAGER_JNDI_NAME); } //Free all plugin resources ((CdiPlugin) webBeansContext.getPluginLoader().getEjbPlugin()).clearProxies(); webBeansContext.getPluginLoader().shutDown(); //Clear extensions webBeansContext.getExtensionLoader().clear(); //Delete Resolutions Cache beanManager.getInjectionResolver().clearCaches(); //Delete AnnotateTypeCache webBeansContext.getAnnotatedElementFactory().clear(); //After Stop //Clear the resource injection service final ResourceInjectionService injectionServices = webBeansContext.getService(ResourceInjectionService.class); if (injectionServices != null) { injectionServices.clear(); } //Comment out for commit OWB-502 //ContextFactory.cleanUpContextFactory(); CdiAppContextsService.class.cast(contextsService).removeThreadLocals(); WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader()); // Clear BeanManager this.beanManager.clear(); // Clear singleton list WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader()); } catch (final Exception e) { logger.error("An error occured while stopping the container.", e); } }