Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unable to rollback in a Bean Managed Message Driven Bean

85 views
Skip to first unread message

John Favre

unread,
Mar 21, 2001, 10:45:57 AM3/21/01
to
I posted this under the ejb20 group and thought I would also post it here.
I am trying to have a Bean Managed MDB, because I want to be able to
rollback(replay) messages. I haven't been successful in accomplishing this
yet.
1. Is this allowed?
2. Whenever I rollback a message recieved, it is lost. I think it should be
put back onto the queue to be processed again. Is this correct and if so is
this a known problem in Weblogic 6.0?

Here are the parts of my code and xml descriptors.

ejb-jar.xml:
<ejb-jar>
<enterprise-beans>
<message-driven>
<ejb-name>Consumer</ejb-name>
<ejb-class>Consumer</ejb-class>
<transaction-type>Bean</transaction-type>
<message-driven-destination>
<jms-destination-type>javax.jms.Queue</jms-destination-type>
</message-driven-destination>
</message-driven>
</enterprise-beans>
<ejb-jar>

Consumer.java:

.....

public void onMessage(Message msg) {
try {
messageContext.getUserTransaction().begin();
} catch(SystemException e) {
e.printStackTrace();
return;
} catch(NotSupportedException e) {
e.printStackTrace();
return;
}

// Some condition that is undesirable.
if (something bad) {
try {
messageContext.getUserTransaction().rollback();
} catch(SystemException se) {
e.printStackTrace();
return;
}
}

// Processed successfully
try {
messageContext.getUserTransaction().commit();
} catch(JMSException e) {
e.printStackTrace();

try {
messageContext.getUserTransaction().rollback();
} catch(SystemException se) {
e.printStackTrace();
}
} catch(SystemException e) {
e.printStackTrace();

try {
messageContext.getUserTransaction().rollback();
} catch(SystemException se) {
e.printStackTrace();
}
} catch(HeuristicRollbackException e) {
e.printStackTrace();

try {
messageContext.getUserTransaction().rollback();
} catch(SystemException se) {
e.printStackTrace();
}
} catch(HeuristicMixedException e) {
e.printStackTrace();

try {
messageContext.getUserTransaction().rollback();
} catch(SystemException se) {
e.printStackTrace();
}
} catch(RollbackException e) {
e.printStackTrace();

try {
messageContext.getUserTransaction().rollback();
} catch(SystemException se) {
e.printStackTrace();
}
}
}

Thanks

Tom Barnes

unread,
Mar 21, 2001, 11:08:32 AM3/21/01
to John Favre
It looks like your code starts a transaction inside the onMessage() --
so the message can not part of that transaction (it has already been
delivered to you).

The way to do what you want is to have the MDB generate the transaction
for you via a container managed transaction. In this case the message will
participate in the transaction. Configure your DD to follow this example:

<ejb-jar>
<enterprise-beans>

<message-driven>
<ejb-name>TxAccountMDBean</ejb-name>
<ejb-class>weblogic.qa.tests.ejb20.message.TxAccountMDBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
</message-driven-destination>
<security-identity>
<run-as-specified-identity>
<role-name>foo</role-name>
</run-as-specified-identity>
</security-identity>
</message-driven>

</enterprise-beans>

<assembly-descriptor>
<container-transaction>

<method>
<ejb-name>TxAccountMDBean</ejb-name>
<method-name>onMessage()</method-name>
</method>

<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

</ejb-jar>

To rollback the transaction:

UserTransaction ut = weblogic.transaction.TXHelper.getUserTransaction();
ut.setRollbackOnly();

John Favre

unread,
Mar 21, 2001, 3:18:17 PM3/21/01
to
I changed to a container managed bean and it seems to work however when I
call setRollBackOnly() the program throws an AppSetRollBackOnlyException and
pages of exception data follow which will fill up my logging. Is this
normal to get this exception and if so is there a way to stop it from
happenning?


"Tom Barnes" <dev....@not.my.address.com> wrote in message
news:3AB8D200...@not.my.address.com...

Steve Felts

unread,
Mar 21, 2001, 3:48:26 PM3/21/01
to
You are the fourth person in this group to complain about this.
This is fixed in Silversword (by just not printing the stack trace).
I will check into putting this fix in the next rolling patch.

"John Favre" <John...@amciwireless.com> wrote in message news:3ab9...@newsgroups.bea.com...

Tom Gerber

unread,
Mar 21, 2001, 4:17:07 PM3/21/01
to
What the hell is "silversword"? and what SP will this be fixed in?

Is what John put below mean that this is expected/correct behavior? and
WL is printing the stack trace and the fix/patch is simply to not print
the stack trace?

Tom

Tom Barnes

unread,
Mar 21, 2001, 5:33:05 PM3/21/01
to t...@nexterna.com
John --

Are you seeing stuff in the log or just on the console? I'm assuming
the latter, but if your seeing stuff in the log can respond with what it is?

More below.

Tom

Tom Gerber wrote:

> What the hell is "silversword"? and what SP will this be fixed in?
>

Oops. Codeword for a future release. Steve is investigating putting
the fix in a "rolling patch" -- which is contains all patches that
occur after the last SP. These come out fairly frequently.

>
> Is what John put below mean that this is expected/correct behavior? and
> WL is printing the stack trace and the fix/patch is simply to not print
> the stack trace?
>

John is getting the expected behavior, and yes he is running afoul of
a printStackTrace(). And yes the fix is just to remove the printStackTrace().

Steve Felts

unread,
Mar 21, 2001, 6:10:41 PM3/21/01
to
What is Silversword?
See "BEA readies WebLogic 'SilverSword' " at http://www.the451.com.

"Tom Gerber" <t...@nexterna.com> wrote in message news:3AB91A53...@nexterna.com...

Steve Felts

unread,
Mar 22, 2001, 8:22:27 AM3/22/01
to
I am assuming that the problem you are seeing is a stack trace for a RollbackException
is printing in your log file although processing continues normally
(I don't think there is such a thing as an AppSetRollBackOnlyException).

This problem (CR043640) has been fixed in the rolling patch ("a collection of bug fixes between
service packs") for WLS 6.0 SP1. These are intended to be issued on about a monthly basis.
If you need it sooner, contact support and ask for an emergency patch (formerly known as one-off patch).


"Tom Gerber" <t...@nexterna.com> wrote in message news:3AB91A53...@nexterna.com...

Tom Gerber

unread,
Mar 22, 2001, 8:51:16 AM3/22/01
to
I made it into work before John (I work with him).

Here is the stack trace we are getting in our logs:

####<Mar 19, 2001 4:27:01 PM CST> <Warning> <EJB> <jfavre> <myserver>
<ExecuteThread-9> <> <17:10c6b9ae408e3828> <000000> <The MessageDriven
Bean threw an Exception in onMessage()>
java.lang.IllegalStateException: Message-driven beans are not allowed to
call getRollbackOnly()
at
weblogic.ejb20.internal.MessageDrivenEJBContextImpl.setRollbackOnly(MessageDrivenEJBContextImpl.java:49)
at com.nexterna.transmit.OPTransmitEJB.onMessage(OPTransmitEJB.java:273)
at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:92)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:1858)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:1817)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.Kernel.execute(Kernel.java:250)
at weblogic.jms.client.JMSSession.pushEnvelope(JMSSession.java:1749)
at weblogic.jms.client.JMSCallback.pushEnvelope(JMSCallback.java:69)
at weblogic.jms.frontend.FESession.execute(FESession.java:1826)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
####<Mar 19, 2001 4:27:01 PM CST> <Warning> <EJB> <jfavre> <myserver>
<ExecuteThread-9> <> <17:10c6b9ae408e3828> <000000> <The MessageDriven
Bean threw an Exception in onMessage()>
javax.transaction.NotSupportedException: Another transaction is
associated with this thread. Existing tx =
transaction=(IdHash=1319634,Xid=17:10c6b9ae408e3828,Status=Marked
rollback. [Reason =
weblogic.transaction.internal.AppSetRollbackOnlyException],numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds
since begin=0,seconds
left=30,activeThread=Thread[ExecuteThread-9,5,Thread Group for Queue:
'default'],ServerResourceInfo[JMS_MyJMSJDBCStore]=(state=started,assigned=none),SCInfo[myserver]=(state=active))
at
weblogic.transaction.internal.TransactionManagerImpl.begin(TransactionManagerImpl.java:150)
at
weblogic.transaction.internal.ServerTransactionManagerImpl.begin(ServerTransactionManagerImpl.java:187)
at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:70)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:1858)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:1817)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.Kernel.execute(Kernel.java:250)
at weblogic.jms.client.JMSSession.pushEnvelope(JMSSession.java:1749)
at weblogic.jms.client.JMSCallback.pushEnvelope(JMSCallback.java:69)
at weblogic.jms.frontend.FESession.execute(FESession.java:1826)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

I will ask John to post the DD for this.

Thanks

John Favre

unread,
Mar 22, 2001, 11:06:08 AM3/22/01
to
Tom,

I am only seeing this on the console and the error looks like:

weblogic.transaction.internal.AppSetRollbackOnlyException
at
weblogic.transaction.internal.TransactionImpl.setRollbackOnly(TransactionImp
l.java:403)
at
weblogic.ejb20.internal.BaseEJBContext.setRollbackOnly(BaseEJBContext.java:2
46)
at
weblogic.ejb20.internal.MessageDrivenEJBContextImpl.setRollbackOnly(MessageD
rivenEJBContextImpl.java:52)
at
com.nexterna.transmit.OPTransmitEJB.onMessage(OPTransmitEJB.java:165)

at weblogic.ejb20.internal.MDListener.execute(MDListener.java:221)
at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:175)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:1929)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:1888)


at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.Kernel.execute(Kernel.java:250)

at weblogic.jms.client.JMSSession.pushEnvelope(JMSSession.java:1776)


at weblogic.jms.client.JMSCallback.pushEnvelope(JMSCallback.java:69)
at weblogic.jms.frontend.FESession.execute(FESession.java:1826)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

--------------- nested within: ------------------
weblogic.transaction.RollbackException: Unknown reason - with nested
exception:
[weblogic.transaction.internal.AppSetRollbackOnlyException]
at
weblogic.transaction.internal.TransactionImpl.throwRollbackException(Transac
tionImpl.java:1248)
at
weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransaction
Impl.java:218)
at
weblogic.transaction.internal.TransactionManagerImpl.commit(TransactionManag
erImpl.java:208)
at weblogic.ejb20.internal.MDListener.execute(MDListener.java:233)
at weblogic.ejb20.internal.MDListener.onMessage(MDListener.java:175)
at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:1929)
at weblogic.jms.client.JMSSession.execute(JMSSession.java:1888)


at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.Kernel.execute(Kernel.java:250)

at weblogic.jms.client.JMSSession.pushEnvelope(JMSSession.java:1776)


at weblogic.jms.client.JMSCallback.pushEnvelope(JMSCallback.java:69)
at weblogic.jms.frontend.FESession.execute(FESession.java:1826)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

The other error Tom Gerber sent is something else I already fixed.

John

"Tom Barnes" <dev....@not.my.address.com> wrote in message

news:3AB92C21...@not.my.address.com...

Steve Felts

unread,
Mar 22, 2001, 2:51:54 PM3/22/01
to
The two of you are getting different traces. Tom Gerber is getting

<ExecuteThread-9> <> <17:10c6b9ae408e3828> <000000> <The MessageDriven
Bean threw an Exception in onMessage()>
java.lang.IllegalStateException: Message-driven beans are not allowed to
call getRollbackOnly()
at
weblogic.ejb20.internal.MessageDrivenEJBContextImpl.setRollbackOnly(MessageDrivenEJBContextImpl.java:49)
at com.nexterna.transmit.OPTransmitEJB.onMessage(OPTransmitEJB.java:273)

This means that you are using the EJBContext to call set RollbackOnly. I'm not sure exactly
how you are doing that but it's wrong. Since you are using message driven beans, you need to use the
MessageDrivenContext instead of the EJBContext. This context is set and used in your MDB as shown in
the following partial MDB.

private MessageDrivenContext context;

public void setMessageDrivenContext(MessageDrivenContext mycontext) {
context = mycontext;
}
public void onMessage(Message msg) {
try { // some logic
}
catch(Exception e) {
System.out.println("MDB doing rollback");
context.setRollbackOnly();
}
}
When you do this, you get the exception printed to the screen that John reported:
weblogic.transaction.internal.AppSetRollbackOnlyException
at weblogic.transaction.internal.TransactionImpl.setRollbackOnly(TransactionImpl.java:403)
at weblogic.ejb20.internal.BaseEJBContext.setRollbackOnly(BaseEJBContext.java:246)
at weblogic.ejb20.internal.MessageDrivenEJBContextImpl.setRollbackOnly(MessageDrivenEJBContextImpl.java:52)

This is noise. The noise is gone in the next rolling patch (CR043640).


"Tom Gerber" <t...@nexterna.com> wrote in message news:3ABA0354...@nexterna.com...

0 new messages