use of org.apache.webbeans.config.WebBeansContext in project tomee by apache.
the class EmbeddedTomEEContainer method stopCdiContexts.
private void stopCdiContexts(final String name) {
try {
final HttpSession session = SESSIONS.remove(name);
if (session != null) {
final WebBeansContext wbc = container.getAppContexts(container.getInfo(name).appId).getWebBeansContext();
if (wbc != null && wbc.getBeanManagerImpl().isInUse()) {
wbc.getContextsService().startContext(RequestScoped.class, null);
wbc.getContextsService().startContext(SessionScoped.class, session);
wbc.getContextsService().startContext(ConversationScoped.class, null);
}
}
} catch (final Exception e) {
// no-op
}
}
use of org.apache.webbeans.config.WebBeansContext in project tomee by apache.
the class WebappBeanManagerTest method containerEventsShouldntGoUp.
@Test
public void containerEventsShouldntGoUp() {
final WebappWebBeansContext ctx = new WebappWebBeansContext(Collections.<Class<?>, Object>emptyMap(), new Properties(), new WebBeansContext());
final WebappBeanManager wbm = new WebappBeanManager(ctx) {
@Override
public BeanManagerImpl getParentBm() {
throw new IllegalStateException("shouldn't be called");
}
};
wbm.fireEvent(new GProcessProducer(null, null), true);
wbm.fireEvent(new GProcessProducerField(null, null, null), true);
wbm.fireEvent(new GProcessProducerMethod(null, null, null), true);
wbm.fireEvent(new GProcessInjectionTarget(null, null), true);
wbm.fireEvent(new GProcessBean(null, null), true);
wbm.fireEvent(new GProcessAnnotatedType(null), true);
wbm.fireEvent(new GProcessSessionBean(null, null, null, null), true);
wbm.fireEvent(new AfterBeanDiscoveryImpl(ctx), true);
wbm.fireEvent(new AfterDeploymentValidationImpl(wbm), true);
wbm.fireEvent(new BeforeBeanDiscoveryImpl(ctx), true);
wbm.fireEvent(new BeforeShutdownImpl(), true);
}
use of org.apache.webbeans.config.WebBeansContext in project tomee by apache.
the class WebbeansContextInEmbeddedModeTest method checkWebbeansContext.
@Test
public void checkWebbeansContext() {
final WebBeansContext ctx1 = WebBeansContext.currentInstance();
final List<AppContext> appCtxs = SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts();
assertEquals(1, appCtxs.size());
final WebBeansContext ctx2 = appCtxs.iterator().next().getWebBeansContext();
assertSame(ctx1, ctx2);
}
use of org.apache.webbeans.config.WebBeansContext in project tomee by apache.
the class SingleApplicationComposerRunner method composerInject.
private static void composerInject(final Object target) throws IllegalAccessException {
WebBeansContext wbc = null;
try {
wbc = WebBeansContext.currentInstance();
} catch (final IllegalStateException ise) {
// no-op
}
if (wbc != null) {
OWBInjector.inject(wbc.getBeanManagerImpl(), target, null);
}
final Object app = APP.get();
final Class<?> aClass = target.getClass();
for (final Field f : aClass.getDeclaredFields()) {
if (f.isAnnotationPresent(RandomPort.class)) {
for (final Field field : app.getClass().getDeclaredFields()) {
if (field.getType() == f.getType()) {
if (!field.isAccessible()) {
field.setAccessible(true);
}
if (!f.isAccessible()) {
f.setAccessible(true);
}
final Object value = field.get(app);
f.set(target, value);
break;
}
}
} else if (f.isAnnotationPresent(Application.class)) {
if (!f.isAccessible()) {
f.setAccessible(true);
}
f.set(target, app);
}
}
final Class<?> superclass = aClass.getSuperclass();
if (superclass != Object.class) {
composerInject(superclass);
}
}
use of org.apache.webbeans.config.WebBeansContext in project tomee by apache.
the class WebContext method newWeakableInstance.
public <T> Instance newWeakableInstance(final Class<T> beanClass) throws OpenEJBException {
final WebBeansContext webBeansContext = getWebBeansContext();
final ConstructorInjectionBean<Object> beanDefinition = getConstructorInjectionBean(beanClass, webBeansContext);
CreationalContext<Object> creationalContext;
final Object o;
if (webBeansContext == null) {
creationalContext = null;
try {
o = beanClass.newInstance();
} catch (final InstantiationException | IllegalAccessException e) {
throw new OpenEJBException(e);
}
} else {
creationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(beanDefinition);
o = beanDefinition.create(creationalContext);
}
// Create bean instance
final Context unwrap = InjectionProcessor.unwrap(getInitialContext());
final InjectionProcessor injectionProcessor = new InjectionProcessor(o, injections, unwrap);
final Object beanInstance;
try {
beanInstance = injectionProcessor.createInstance();
if (webBeansContext != null) {
final InjectionTargetBean<Object> bean = InjectionTargetBean.class.cast(beanDefinition);
bean.getInjectionTarget().inject(beanInstance, creationalContext);
if (shouldBeReleased(bean.getScope())) {
creationalContexts.put(beanInstance, creationalContext);
}
}
} catch (final OpenEJBException oejbe) {
if (creationalContext != null) {
creationalContext.release();
}
throw oejbe;
}
return new Instance(beanInstance, creationalContext);
}
Aggregations