Requesting comment on WELD-2062
by Benjamin Confino
Hello
A while back this issue was raised:
https://issues.jboss.org/browse/WELD-2062
I have recently encountered a similar issue in which an update to a
servlet does not take effect.
I have verified the solution proposed in WELD-2062 manually. By using my
eclipse debugger I was able to modify a variable and force
AnnotatedTypeIdentifier.equals() to return false, this resolved the issue.
My questions is, does AnnotatedTypeIdentifier.equals() need to be modified
to use the class instead of the className as suggested in WELD-2062 or is
this an integration issue where websphere has failed to provide the
required information?
Regards
Benjamin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
8 years, 3 months
ApplicationScoped event fires on service invocation
by Benjamin Confino
We have a user scenario where we wishes to replace @Singleton @Startup EJB
beans with CDI beans. This was attempted by observing the
ApplicationScoped initialization event to trigger the replacement code.
However, the event was fired only after the service invocation, which was
too late. Apparently OWB fires this event much earlier.
The CDI spec states:
The application context is provided by a built-in context object for the
built-in scope type
@ApplicationScoped. The application scope is active:
• during the service() method of any servlet in the web application,
during the doFilter()
method of any servlet filter and when the container calls any
ServletContextListener,
HttpSessionListener, AsyncListener or ServletRequestListener,
• during any Java EE web service invocation,
• during any remote method invocation of any EJB, during any asynchronous
method invocation
of any EJB, during any call to an EJB timeout method and during message
delivery to any EJB
message-driven bean,
• when the disposer method or @PreDestroy callback of any bean with any
normal scope other
than @ApplicationScoped is called, and
• during @PostConstruct callback of any bean.
The application context is shared between all servlet requests, web
service invocations, EJB
remote method invocations, EJB asynchronous method invocations, EJB
timeouts and message
deliveries to message-driven beans that execute within the same
application. The application
context is destroyed when the application is shut down.
An event with qualifier @Initialized(ApplicationScoped.class) is fired
when the application
context is initialized and an event with qualifier
@Destroyed(ApplicationScoped.class) is fired
when the application is destroyed. The event payload is:
• the ServletContext if the application is a web application deployed to a
Servlet container, or
• any java.lang.Object for other types of application.
How do you interpret "initialized"? Does it mean the event is fired only
after the context is active?
Is it possible to make the event firing a bit earlier, say around
AfterDeploymentValidation?
Below is the app to demonstrate the timing along with the server.xml:
And here is the results of running it
[AUDIT ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT ] CWWKE0100I: This product is licensed for development, and
limited production use. The full license terms can be viewed here:
https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/lic...
[AUDIT ] CWWKZ0058I: Monitoring dropins for applications.
---> ApplicationScopedExtension, AfterDeploymentValidation event received,
before looking up and touching @ApplicationScoped dummy bean
---> ApplicationScopedDummyBean, @PostConstruct init method called
---> ApplicationScopedExtension, after looking up and touching
@ApplicationScoped dummy bean
[AUDIT ] CWWKT0016I: Web application available (default_host):
http://localhost:9080/70383.180.846.test-application/
---> ApplicationScopedObserverBean, observed
@Initialized(ApplicationScoped.class) event.
[AUDIT ] CWWKZ0001I: Application 70383.180.846.test-application started
in 1.165 seconds.
[AUDIT ] CWWKF0012I: The server installed the following features:
[jsp-2.3, ejbLite-3.2, managedBeans-1.0, jsf-2.2, beanValidation-1.1,
servlet-3.1, ssl-1.0, jndi-1.0, jsonp-1.0, appSecurity-2.0, jdbc-4.1,
jaxrs-2.0, jaxrsClient-2.0, el-3.0, json-1.0, cdi-1.2, distributedMap-1.0,
webProfile-7.0, websocket-1.1, jpa-2.1].
[AUDIT ] CWWKF0011I: The server defaultServer is ready to run a smarter
planet.
As you can see, the ApplicationScopedDummyBean, @PostConstruct init method
called proves that the applicationContext was active before the event was
fired. Why is this applicationscoped initialization event not fired
earlier?
Regards
Benjamin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
8 years, 4 months
Proper way to get to EnhancedAnnotatedConstructor (CDI autofactories implementation)
by Jan-Willem Gmelig Meyling
Hello everyone,
I am in the process of patching the softwaremill-common CDI extensions [1] from Weld 1.1 to Weld 2.x. I am currently working on their extension for autofactories. I stumbled upon the following piece of code I would like to migrate:
CurrentInjectionPoint currentInjectionPoint = Container.instance().services().get(CurrentInjectionPoint.class);
currentInjectionPoint.push(ConstructorInjectionPoint.of(bean, (WeldConstructor<T>) createdTypeData.getCreatedTypeConstructor()));
instance = newInstance(parameters);
currentInjectionPoint.pop();
Source: [2]
I see how the pop should now be invoked on the `ThreadLocalStackReference` returned by the push method. I have also found the InjectionPointFactory#createConstructorInjectionPoint(Bean, Class, EnhancedAnnotatedConstructor, BeanManagerImpl) method [3]. Now I am wondering how I can get to the `EnhancedAnnotatedConstructor`, as the approach I am currently using feels plain wrong.
My code:
CurrentInjectionPoint currentInjectionPoint = Container.instance().services().get(CurrentInjectionPoint.class);
Class<?> declaringComponentClass = (Class<T>) createdTypeData.getCreatedTypeConstructor().getBaseType();
BeanManagerImpl manager = ((BeanManagerProxy) beanManager).delegate();
EnhancedAnnotatedConstructor<T> constructor = (EnhancedAnnotatedConstructor<T>) manager
.createEnhancedAnnotatedType(declaringComponentClass)
.getEnhancedConstructors()
.stream().findAny().get();
ConstructorInjectionPoint<T> actualInjectionPoint = InjectionPointFactory.instance()
.createConstructorInjectionPoint(bean, declaringComponentClass, constructor, manager);
ThreadLocalStackReference<InjectionPoint> ref = currentInjectionPoint.push(actualInjectionPoint);
instance = newInstance(parameters);
My code is also available on Github at [4]. My question is also posted on Stackoverflow [5], so points will be awarded for the answer.
Thanks in advance!
Jan-Willem Gmelig Meyling
[1] https://github.com/softwaremill/softwaremill-common/tree/master/softwarem... <https://github.com/softwaremill/softwaremill-common/tree/master/softwarem...>
[2] https://github.com/softwaremill/softwaremill-common/blob/master/softwarem... <https://github.com/softwaremill/softwaremill-common/blob/master/softwarem...>
[3] http://javadox.com/org.jboss.weld.servlet/weld-servlet/2.3.1.Final/org/jb... <http://javadox.com/org.jboss.weld.servlet/weld-servlet/2.3.1.Final/org/jb...>
[4] https://github.com/JWGmeligMeyling/cdi-autofactories/blob/8346cf269d73a8b... <https://github.com/JWGmeligMeyling/cdi-autofactories/blob/8346cf269d73a8b...>
[5] http://stackoverflow.com/questions/38436110/proper-way-to-get-enhancedann... <http://stackoverflow.com/questions/38436110/proper-way-to-get-enhancedann...>
8 years, 4 months