Search code examples
javaejbwebsphereinterceptor

WAS 7.0.0.23 - default interceptors in MDB with activation spec throws classcastexception


I am facing an issue with Interceptors for MDB in Websphere. I configured defaultInterceptor for MDBs with ActivationSpec and not listerner port in WAS 7.0.0.23. I am getting ClassCastException. The same configration works for SessionBean.

<assembly-descriptor><interceptor-binding>
<ejb-name>*</ejb-name>
    <interceptor-class>com.LoggingInterceptor</interceptor-class>
</interceptor-binding></assembly-descriptor>

Exception: LocalExceptio E CNTR0019E: EJB threw an unexpected (non-declared) exception during invocation of method "onMessage". Exception data: javax.ejb.EJBException: Injection failure; nested exception is: java.lang.IllegalArgumentException: java.lang.ClassCastException

http://www-01.ibm.com/support/docview.wss?uid=swg1PM53989 This link says that this issue will occur only if we use listener port - but we are using Activation Spec.

Appreciate you help.


Solution

  • This error message is poor, but it means you have method injection, but the target type (of the lookup) does not match the type in your code. For example, if you have:

    @Resource
    public void setQueue(QueueConnectionFactory qcf) { ... }
    

    ...but you've specified a binding for this resource that points at a data source, then you will get a ClassCastException. I suggest removing all injections (likely from your interceptor or its superclasses, since the error only occurs when you add it) and then slowly re-add them until you've found the problem.