Hi Eric,
feel free to ask on Weld ML, irc, gitter or forums -
http://weld.cdi-spec.org/community
And if possible provide a simple test app/reproducer.
Martin
Dne 18.4.2017 v 00:01 Stuart Douglas napsal(a):
It sounds like a class loading problem. You likely have two copies
of
ejbs.LoginManager, and somehow you are using the wrong one. If you
look at the output of
System.out.println(LoginManager.class.getClassLoader()) and
System.out.println(CDI.current().select(clazz).get().getClass().getClassLoader())
it should give you a clue.
This is not an Undertow issue.
Stuart
On Fri, Apr 14, 2017 at 11:52 AM, Eric B <ebenzacar(a)gmail.com> wrote:
> I posted this problem on StackOverflow, but after doing more research, I'm
> not sure if this is a Weld, JBoss/WildFly or undertow issue. Or whether its
> a framework issue, or how the framework is being used. If this is not the
> correct list, can you please let me know which list/group I should be
> directing the issue to?
>
> I'm running into a strange problem and error message that I do not
> understand. I'm running my application on JBoss 7 EAP.
>
> Caused by: java.lang.ClassCastException: Cannot cast
> ejbs.LoginManager$417755913$Proxy$_$$_Weld$EnterpriseProxy$ to
> ejbs.LoginManager
>
> I'm trying to programatically retrieve an EJB from the CDI context by using
> its interface and am getting this error message. I've created a sample
> proof-of-concept that is trying to retrieve EJB beans from the CDI context
>
> public <T> T getSesionBean(Class<T> clazz, String name) {
> Properties properties = new Properties();
>
> try {
> InitialContext initContext = new InitialContext();
>
> return clazz.cast(CDI.current().select(clazz).get());
> } catch (Exception e) {
> // TODO Auto-generated catch block
> throw new RuntimeException(e);
> }
> }
>
> It is being called as:
>
> LoginManager login = getSesionBean(LoginManager.class);
>
> with my EJB defined as:
>
> @Stateless(name="LoginManager")
> @Local(LoginManager.class)
> @LocalBinding(jndiBinding="LoginManager")
> public class LoginManagerBean implements LoginManager {
> ...
> ...
> ...
> }
>
> I don't understand it. I'm expecting the bean being retrieved from the
> context to be a proxy. Shouldn't it be castable to my interface? Otherwise,
> how am I supposed to retrieve it?
>
> More interestingly, this does not seem to be a consistent error; sometimes
> the code works fine. Sometimes it fails. I haven't been able to determine
> what makes it work or throw an exception.
>
> I found a related issue here, but not sure if this is the same problem
> and/or which version of Weld is used in JB7EAP. I'm including the following
> dependency in my application:
>
> <dependency>
> <groupId>org.wildfly</groupId>
> <artifactId>wildfly-ejb-client-bom</artifactId>
> <version>10.1.0.Final</version>
> <type>pom</type>
> </dependency>
>
> Am I doing something completely wrong? If this is a Weld bug, can I use a
> different proxy system than Weld? Is this even configurable in undertow?
>
>
> Thanks,
>
>
> Eric
>
>
> _______________________________________________
> undertow-dev mailing list
> undertow-dev(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/undertow-dev
_______________________________________________
undertow-dev mailing list
undertow-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/undertow-dev
--
Martin Kouba
Senior Software Engineer
Red Hat, Czech Republic