This the snip from config.xml:
<JMSConnectionFactory JNDIName="jms/XATopicConnectionFactory"
Name="XA Topic Connection Factory" Targets="jmsServer"
TransactionTimeout="0" UserTransactionsEnabled="true"
XAConnectionFactoryEnabled="true" XAServerEnabled="true"/>
and code causing the exception (in a servlet):
ctx = new InitialContext();
factory = (TopicConnectionFactory)
ctx.lookup("jms/XATopicConnectionFactory");
conn = factory.createTopicConnection();
session = conn.createTopicSession(true,
Session.AUTO_ACKNOWLEDGE);
System.out.println("Transacted session? " +
session.getTransacted());
topic = (Topic) ctx.lookup(TOPIC);
TopicPublisher publisher;
TextMessage mMsg;
for (int i=1; i<5; i++){
mMsg = session.createTextMessage( "Message No. " + i);
publisher = session.createPublisher(topic);
publisher.publish(mMsg);
if (i==3){
session.commit();
}
}
session.rollback();
Weblogic's complain:
*********false
weblogic.jms.common.IllegalStateException: No transaction
at weblogic.jms.client.JMSXASession.commit(JMSXASession.java:59)
at
test.jms.transaction.xa.XATransactionTestServlet.doGet(XATransactionT
estServlet.java:167)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:945)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:332)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:242)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:5363)
at
weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
eManager.java:721)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:3043)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2466)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)
As per the JMS spec, XASessions can not be transacted, and the transacted
flag is ignored. I think you are creating an XASession unawares as you are
actually
getting an XAConnection from createTopicConnection, and then in turn
using this XAConnection to create the session. This behavior is caused
by the "XAServerEnabled" flag. Either don't use an XA factory at all or set
this
particular flag to false.
For more on "transacted sessions" vs. "user transaction aware sessions" (which,
despite
the unfortunate similarity in names, are significantly different) see the JMS
FAQ.
Tom