Wrong beanmanager retrieved by CDI.current().getBeanManager() in Struts1

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Wrong beanmanager retrieved by CDI.current().getBeanManager() in Struts1

Eric B
I'm running into a really strange behaviour, and I'm not entirely sure where/how to start looking for this or if it is something that I can easily reproduce in a test case (or if it is even worthwhile).

I've got a mutil-war JEE EAR application that uses EJBs, Struts1.  and Struts2.

My EAR is as follows:
EAR
 - root.war
 - ejb.jar
 - web.war
 - ws.war
 - lib/common jars


In one of my war1 web filters, I am sucessfully able to retrieve a bean from the CDI using:
         SessionManager sessionManager = CDI.current().select(SessionManager.class).get()

However, in a Struts1 action, I'm trying to retrieve the same bean from the CDI using:
         SessionManager sessionManager = CDI.current().select(SessionManager.class).get()

but WELD throws and error that it is unable to resolve the SessionManager bean:
org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: Unable to resolve any beans for Type: interface webapp.session.SessionManager; Qualifiers: []


When I dig more into it, I see that CDI.current().getBeanManager() in the filter always returns the beanManager for my ear/web.war deployment.  However, when trying the same call in my Struts 1 Action, instead, it will at times retrieve the bean manager for other deployments, seemingly randomly:
- ear/root.war
- ear/ws.war
- ear/ejb.jar
- ear/web.war

If I retrieve the BeanManager manually from the JNDI, using a JNDI lookup, I am able to retrieve the bean without problems:
BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
Set<Bean<?>> beans = beanManager.getBeans(SessionManager.class);
Bean<?> bean = beanManager.resolve(beans);
CreationalContext<?> context = beanManager.createCreationalContext(bean);
SessionManager sessionManager = (SessionManager) beanManager.getReference(bean, SessionManager.class, context);



So at the end, I'm not entirely sure why CDI.current().getBeanManager() would be retrieving the BeanManager from a different context.  Might this be a bug in Weld, a problem in the container, or something strange that is happening due to the way that Struts1 was designed?  Or do I need to do/add something specific to a config to enable CDI access from within a servlet?

Struts1 is launched as a servlet in the web.xml:
   <servlet>
      <servlet-name>action</servlet-name>
      <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
      <init-param>
         <param-name>config</param-name>
         <param-value>/WEB-INF/struts-config.xml</param-value>
      </init-param>
      <init-param>
         <param-name>chainConfig</param-name>
         <param-value>/WEB-INF/chain-config.xml</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
   </servlet>



Thanks!

Eric






_______________________________________________
wildfly-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/wildfly-dev
Reply | Threaded
Open this post in threaded view
|

Re: Wrong beanmanager retrieved by CDI.current().getBeanManager() in Struts1

Jaikiran Pai-2

On 05/01/18 12:35 AM, Eric B wrote:
>
>
>  However, when trying the same call in my Struts 1 Action, instead, it
> will at times retrieve the bean manager for other deployments,
> seemingly randomly:
>
If it's returning it in a non-deterministic manner then it does sound
like a bug. Is this an application you can share?

P.S: The WildFly user forums https://developer.jboss.org/en/wildfly is a
better place for such questions and the forum infrastructure even allows
you to attach files, unlike this mailing list IIRC.

-Jaikiran
_______________________________________________
wildfly-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/wildfly-dev