-
1. Re: Javax.naming.reference ClassCast exception on EJB local lookup from within Jboss6 container
wdfink May 28, 2016 5:16 PM (in response to ion_mayank)Did you really use JBoss AS6.0 ? This is quite old and I recommend to migrate to WildFly.
For JBossAS6 you might have problems to get appropriate answers
But you might show the complete stacktrace and the client invocaion code here
-
2. Re: Javax.naming.reference ClassCast exception on EJB local lookup from within Jboss6 container
ion_mayank May 30, 2016 1:16 AM (in response to wdfink)Hello Wolf-Dieter Fink,
Thanks for having a look and replying.
Please find the stacktrace:
06:01:15,598 INFO [STDOUT] Exception occurred: java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.company.ejb.ABCManagerLocal
06:01:16,338 ERROR [STDERR] java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.company.ejb.ABCManagerLocal
06:01:16,448 ERROR [STDERR] at com.company.utility.provider.EJBLocalProvider.getABCManager(EJBLocalProvider.java:565)
06:01:16,453 ERROR [STDERR] at com.company.ejb.AppRegistration.handleNotification(AppRegistration.java:291)
06:01:16,458 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor425.invoke(Unknown Source)
06:01:16,464 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
06:01:16,469 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
06:01:16,474 ERROR [STDERR] at org.jboss.mx.notification.NotificationListenerProxy.invoke(NotificationListenerProxy.java:154)
06:01:16,479 ERROR [STDERR] at $Proxy1399.handleNotification(Unknown Source)
06:01:16,484 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:257)
06:01:16,490 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport$SendNotifJob.run(NotificationBroadcasterSupport.java:322)
06:01:16,495 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport$1.execute(NotificationBroadcasterSupport.java:307)
06:01:16,500 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:229)
06:01:16,506 ERROR [STDERR] at org.jboss.bootstrap.impl.base.server.AbstractServer.sendNotificationWithCurrentTimeUserData(AbstractServer.java:791)
06:01:16,511 ERROR [STDERR] at org.jboss.bootstrap.impl.base.server.AbstractServer.sendStartJmxNotification(AbstractServer.java:768)
06:01:16,517 ERROR [STDERR] at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:420)
06:01:16,522 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)
Problem is occurring when we are invoking EJB3 from MBean (you can see MBean is starting its own thread from stacktrace). I feel problem is Jboss6 is considering this invocation as a client invocation even though call is made from within the Jboss6 server. Also as I said in my previous post both MBean and EJB are deployed in same Jar file within an ear.
We are not upgrading the server as this is a financial product where performance in milliseconds matters. We tried to migrate it to Jboss7 3 yrs back but our not able to match current performance.
Any pointers or help would be appreciated.
-
3. Re: Javax.naming.reference ClassCast exception on EJB local lookup from within Jboss6 container
ion_mayank May 30, 2016 3:26 AM (in response to ion_mayank)Hi,
UPDATE:
I used EJB service extension feature on my MBean and then used EJB injection using @EJB.
When I am injecting EJB now it is able to find the correct proxy and javax.naming.reference problem is not coming.
However my MBean is now not able to find the EJB classes and throws the following exception on casting:
java.lang.RuntimeException: Specified calling class, com.company.ejb.ABCManagerLocal could not be found for java.net.URLClassLoader@77827284
I guess classloader for Mbean and EJB are different but unable to understand how to pass EJB classes in classpath of MBean.
-
4. Re: Javax.naming.reference ClassCast exception on EJB local lookup from within Jboss6 container
ion_mayank May 30, 2016 3:45 AM (in response to ion_mayank)Hi,
UPDATE:
I used EJB service extension feature on my MBean and then used EJB injection using @EJB.
When I am injecting EJB now it is able to find the correct proxy and javax.naming.reference problem is not coming.
However my MBean is now not able to find the EJB classes and throws the following exception on casting:
java.lang.RuntimeException: Specified calling class, com.company.ejb.ABCManagerLocal could not be found for java.net.URLClassLoader@77827284
I guess classloader for Mbean and EJB are different but unable to understand how to pass EJB classes in classpath of MBean.
StackTrace:
08:38:50,926 ERROR [STDERR] java.lang.RuntimeException: Specified calling class, com.company.ejb.ABCManagerLocal could not be found for java.net.URLClassLoader@375e9756
08:38:50,941 ERROR [STDERR] at org.jboss.ejb3.common.lang.SerializableMethod.getClassFromName(SerializableMethod.java:311)
08:38:50,945 ERROR [STDERR] at org.jboss.ejb3.common.lang.SerializableMethod.getClassType(SerializableMethod.java:282)
08:38:50,948 ERROR [STDERR] at org.jboss.ejb3.common.lang.SerializableMethod.toMethod(SerializableMethod.java:233)
08:38:50,956 ERROR [STDERR] at org.jboss.ejb3.common.lang.SerializableMethod.toMethod(SerializableMethod.java:220)
08:38:50,958 ERROR [STDERR] at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:178)
08:38:50,959 ERROR [STDERR] at $Proxy1399.isIntegration(Unknown Source)
08:38:50,960 ERROR [STDERR] at com.company.ejb.AppRegistration.handleNotification(AppRegistration.java:282)
08:38:50,961 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor423.invoke(Unknown Source)
08:38:50,962 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
08:38:50,963 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
08:38:50,964 ERROR [STDERR] at org.jboss.mx.notification.NotificationListenerProxy.invoke(NotificationListenerProxy.java:154)
08:38:50,965 ERROR [STDERR] at $Proxy1400.handleNotification(Unknown Source)
08:38:50,966 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:257)
08:38:50,967 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport$SendNotifJob.run(NotificationBroadcasterSupport.java:322)
08:38:50,968 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport$1.execute(NotificationBroadcasterSupport.java:307)
08:38:50,969 ERROR [STDERR] at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:229)
08:38:50,970 ERROR [STDERR] at org.jboss.bootstrap.impl.base.server.AbstractServer.sendNotificationWithCurrentTimeUserData(AbstractServer.java:791)
08:38:50,972 ERROR [STDERR] at org.jboss.bootstrap.impl.base.server.AbstractServer.sendStartJmxNotification(AbstractServer.java:768)
08:38:50,973 ERROR [STDERR] at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:420)
08:38:50,974 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)
08:38:50,976 ERROR [STDERR] Caused by: java.lang.ClassNotFoundException: com.company.ejb.ABCManagerLocal
08:38:50,977 ERROR [STDERR] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
08:38:50,979 ERROR [STDERR] at java.security.AccessController.doPrivileged(Native Method)
08:38:50,980 ERROR [STDERR] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
08:38:50,981 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
08:38:50,982 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
08:38:50,983 ERROR [STDERR] at java.lang.Class.forName0(Native Method)
08:38:50,984 ERROR [STDERR] at java.lang.Class.forName(Class.java:247)
08:38:50,985 ERROR [STDERR] at org.jboss.ejb3.common.classloader.util.PrimitiveClassLoadingUtil.loadClass(PrimitiveClassLoadingUtil.java:99)
08:38:50,986 ERROR [STDERR] at org.jboss.ejb3.common.lang.SerializableMethod.getClassFromName(SerializableMethod.java:307)
08:38:50,987 ERROR [STDERR] ... 19 more
-
5. Re: Javax.naming.reference ClassCast exception on EJB local lookup from within Jboss6 container
ion_mayank May 31, 2016 3:49 AM (in response to ion_mayank)Hello,
I have been able to move further with this. Giving the solution (kind of a hack) for other if they are still using Jboss6
MBean is not able to find any class which is not still loaded to load in JVM and throws ClassnotFoundException.
To resolve this, I added a static reference variable in the MBean to do the lookup (you will need to add any other lookup as well if it is still not loaded)
Jboss6 loads the static references and static blocks before starting any application specific thred or a MBean thread. In its own Jboss server thread it loads these lookup classes without an error.
Later when the Mbean thread runs it is able to find the class already loaded and do not try to load the class again.
This solved the problem however running static initializer blocks before loaded all components also leads to a problem of loading something with uninitialized data like data caches which results in other issues.