eclipse-ee4j / openmq

OpenMQ
https://projects.eclipse.org/projects/ee4j.openmq/
Other
48 stars 33 forks source link

java.lang.ClassCastException: com.sun.messaging.jms.ra.TemporaryQueue cannot be cast to com.sun.messaging.Destination #238

Open glassfishrobot opened 11 years ago

glassfishrobot commented 11 years ago

According to http://docs.oracle.com/cd/E26576_01/doc.312/e24945/client-design-and-features.htm#gkvyk I want to set a EventListener to get notified on consumer events. The code runs inside Glassfish. Stripped down I basically do the following:

public void onMessage( final Message msg ) {

    javax.jms.Queue tempQueue = tempQueue = ( javax.jms.Queue )msg.getJMSReplyTo();
    com.sun.messaging.jms.notification.EventListener eventListener = new MyEventListener( queueInfo );
    connection.setConsumerEventListener( ( Destination )queue, eventListener );
}

This ends up with the following exception:

java.lang.ClassCastException: com.sun.messaging.jms.ra.TemporaryQueue cannot be cast to com.sun.messaging.Destination
        at com.macd.xconnect.ejbeans.implementation.queueregistry.QueueRegistryBean.addConsumerListener(QueueRegistryBean.java:234)
        at com.macd.xconnect.ejbeans.implementation.queueregistry.QueueRegistryBean.rebind(QueueRegistryBean.java:200)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
        at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
        at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
        at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
        at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
        at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
        at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
        at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
        at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
        at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
        at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
        at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
        at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:89)
        at $Proxy269.rebind(Unknown Source)
        at com.macd.xconnect.ejbeans.implementation.queueregistry.QueueRegistryMDB.onMessage(QueueRegistryMDB.java:99)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
        at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4180)
        at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5368)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
        at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1099)
        at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:81)
        at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:171)
        at $Proxy301.onMessage(Unknown Source)
        at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:260)
        at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:114)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

As far as I can see from available javadocs com.sun.messaging.Destination is a superclass of com.sun.messaging.jms.ra.TemporaryQueue.

Environment

Glassfish: 3.1.2.2

Affected Versions

[4.5.2]

glassfishrobot commented 6 years ago
glassfishrobot commented 11 years ago

@glassfishrobot Commented Reported by cplaetzinger

glassfishrobot commented 11 years ago

@glassfishrobot Commented @nigeldeakin said: It appears that the consumer event feature is only available when using the Java SE client (i.e. when using com.sun.messaging.jms.Connection). JMSRA's implementations of Connection do not have a setConsumerEventListener method. So this is not a bug but a missing feature.

glassfishrobot commented 11 years ago

@glassfishrobot Commented @nigeldeakin said: As for why you got that ClassCastException: I suspect it was because the com.sun.messaging.Destination class being used by your MDB was loaded using a different class loader from the one used by the resource adapter (which created the com.sun.messaging.jms.ra.TemporaryQueue). So Java didn't recognise one as a supertype of the other.

How did you get your MDB to compile the reference to com.sun.messaging.Destination? Did you include imq.jar in your application?

Nigel

glassfishrobot commented 11 years ago

@glassfishrobot Commented cplaetzinger said: Hi Nigel,

in reply to your first comment: Should I create a new issue requesting this feature or will you do so?

Regarding the your second comment: yes. We have some Glassfish jars including imqjmsra.jar in the classpath for compiling our application. But we do not package it/deploy it. Is there a workaround to get rid of the ClassCastException?

Many thanks Christian

glassfishrobot commented 11 years ago

@glassfishrobot Commented @nigeldeakin said: Please create a new feature request (e.g. "Add support for consumer event listeners in JMSRA".

Even if you are able to work around the TemporaryQueue class cast problem you will not be able to cast your connection to a com.sun.messaging.jms.Connection (which is the only class that implements setConsumerEventListener), since the resource adapter uses a completely different implementation class.

Nigel

glassfishrobot commented 11 years ago

@glassfishrobot Commented cplaetzinger said: Created #239 requesting support for consumer event listeners in JMSRA.

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA MQ-238