Hi,
I'm using glassfish 9.1_01 (build b09-fcs). I implemented a simple interceptor which is invoked around all my EJBs' methods and reports exceptions thrown by these methods. The interceptor is injected with SessionContext. It all worked fine until I added a message-driven bean to my application. An InjectionException is thrown when trying to create my MDB because Glassfish seems to be attempting to inject MessageDrivenContext instead of SessionContext to my interceptor's sessionContext field. Here's the interceptor's code:
public class ExceptionReporter {
@Resource
SessionContext sessionContext;
String createMessage(final InvocationContext invocation) {
...
}
@AroundInvoke
public Object reportException(final InvocationContext invocation) throws Exception {
try {
return invocation.proceed();
} catch (final Exception ex) {
log.error(createMessage(invocation), ex);
throw ex;
}
}
}
And here's the MDB's code:
@MessageDriven(mappedName = BusinessConstants.JMS_QUEUE_1_NAME, name = BusinessConstants.SEND_EMAIL_MDB_NAME, description = BusinessConstants.SEND_EMAIL_MDB_DESCRIPTION, activationConfig = {_at_ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "true")})
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class SendEmailBean implements MessageListener {
@EJB(name = BusinessConstants.MAILING_SERVICE_NAME)
IMailingServiceLocal mailingService;
@Resource
MessageDrivenContext mdc;
public void onMessage(Message message) {
processMessage(message);
}
private void processMessage(Message message) {
...
}
}
The interceptor is configured to be invoked around all EJB's methods - here's my ejb-jar.xml descriptor:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="
http://java.sun.com/xml/ns/javaee"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0">
<interceptors>
<interceptor>
<interceptor-class>
com.camasoft.mb.share.intercept.ExceptionReporter
</interceptor-class>
</interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>
com.camasoft.mb.share.intercept.ExceptionReporter
</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
Now this is what I get when glassfish tries to create my message-driven bean:
[#|2008-02-22T07:26:43.494+0100|SEVERE|sun-appserver9.1|javax.enterprise.system.container.ejb.mdb|_ThreadID=43;_ThreadName=p: thread-pool-1; w: 200;_RequestID=3503171f-f143-4f1f-bc0a-1
9e35f73ee39;|com.sun.enterprise.InjectionException
com.sun.enterprise.InjectionException: Exception attempting to inject Env-Prop: com.camasoft.mb.share.intercept.ExceptionReporter/sessionContext_at_Field-Injec Resource. Class name =
com.camasoft.mb.share.intercept.ExceptionReporter Field name=sessionContext_at_java.lang.String_at_com.camasoft.mb.share.intercept.ExceptionReporter/sessionContext@@ into class com.camasoft
.mb.share.intercept.ExceptionReporter
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:387)
at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:206)
at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:127)
at com.sun.ejb.containers.MessageBeanContainer.createMessageDrivenEJB(MessageBeanContainer.java:713)
at com.sun.ejb.containers.MessageBeanContainer.access$100(MessageBeanContainer.java:109)
at com.sun.ejb.containers.MessageBeanContainer$MessageBeanContextFactory.create(MessageBeanContainer.java:492)
at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:199)
at com.sun.ejb.containers.MessageBeanContainer._getContext(MessageBeanContainer.java:555)
at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:1675)
at com.sun.ejb.containers.MessageBeanContainer.beforeMessageDelivery(MessageBeanContainer.java:1008)
at com.sun.ejb.containers.MessageBeanListenerImpl.beforeMessageDelivery(MessageBeanListenerImpl.java:70)
at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:159)
at $Proxy2006.onMessage(Unknown Source)
at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:76)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Caused by: java.lang.IllegalArgumentException: Can not set javax.ejb.SessionContext field com.camasoft.mb.share.intercept.ExceptionReporter.sessionContext to com.sun.ejb.containers.Mes
sageBeanContextImpl
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
at java.lang.reflect.Field.set(Field.java:657)
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:338)
... 15 more
|#]
Is this behavior caused by some specification restrictions or am I doing something wrong?
Best regards,
Olaf
[Message sent by forum member 'olafos' (olafos)]
http://forums.java.net/jive/thread.jspa?messageID=260374