Could not enlist in transaction on entering meta-aware objec
s0d0 Nov 23, 2006 4:10 AMHi,
I'm are using Sonic Software JCA Adapter for JBoss.
When I'm trying to create XA Session I got error:
10:57:11,316 ERROR [STDERR] javax.jms.JMSException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: Error enlisting resource in transaction=TransactionImple < jts, afd0212:8c43:456561b4:12 >) 10:57:11,317 ERROR [STDERR] at com.sonicsw.sonicmq.j2ee.jmsra.impl.sonic.SonicXAConnectionAdapter.createXASession(SonicXAConnectionAdapter.java:72) 10:57:11,317 ERROR [STDERR] at fi.logiasoftware.test.MessageSenderBase.openConnection(MessageSenderBase.java:148) 10:57:11,317 ERROR [STDERR] at fi.logiasoftware.test.TestBean.doSomethingElse(TestBean.java:59) 10:57:11,317 ERROR [STDERR] at fi.logiasoftware.test.TestBean.doSomething(TestBean.java:46) 10:57:11,318 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 10:57:11,318 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 10:57:11,319 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 10:57:11,319 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585) 10:57:11,319 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112) 10:57:11,319 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166) 10:57:11,320 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) 10:57:11,320 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,320 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) 10:57:11,320 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,320 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:46) 10:57:11,321 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,321 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79) 10:57:11,321 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191) 10:57:11,321 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,321 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76) 10:57:11,322 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,322 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62) 10:57:11,322 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,322 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77) 10:57:11,322 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102) 10:57:11,323 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,323 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47) 10:57:11,323 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,323 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) 10:57:11,323 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 10:57:11,325 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:263) 10:57:11,325 ERROR [STDERR] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106) 10:57:11,326 ERROR [STDERR] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82) 10:57:11,327 ERROR [STDERR] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828) 10:57:11,327 ERROR [STDERR] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681) 10:57:11,327 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358) 10:57:11,327 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:398) 10:57:11,328 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
Server hangs (won't shutdown without killing) after this exception.
Here is simple test code:
package fi.logiasoftware.test;
import java.util.HashMap;
import javax.annotation.Resource;
import javax.ejb.EJBException;
import javax.ejb.Init;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.jms.JMSException;
import org.jboss.annotation.ejb.LocalBinding;
import org.jboss.annotation.ejb.RemoteBinding;
import com.sonicsw.sonicmq.j2ee.jmsra.sonicra.SonicConnection;
@Stateless
@RemoteBinding(jndiBinding = "Test")
@LocalBinding(jndiBinding = "TestLocal")
@Remote(Test.class)
@Local(Test.class)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class TestBean extends MessageSenderBase implements Test {
private @Resource
javax.ejb.TimerService timerService;
private void thisWillFail() throws JMSException {
System.out.println("I will fail");
throw new JMSException("thisWillFail");
}
private void thisWillSucceed() {
System.out.println("I did succeed");
}
public void doSomething() {
doSomethingElse();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void doSomethingElse() {
SonicConnection conn = null;
HashMap<Object, Object> m = new HashMap<Object,Object>();
m.put("property1", "value1");
try {
conn = openConnection();
sendMessage(conn, "Test message", m, "SonicJMS/Queues/Queue20");
//thisWillFail();
thisWillSucceed();
} catch (JMSException e) {
e.printStackTrace();
throw new EJBException(e);
} finally {
shutdownConnection(conn);
}
}
}
package fi.logiasoftware.test;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import javax.annotation.Resource;
import javax.ejb.EJBException;
import javax.ejb.SessionContext;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.XAConnection;
import javax.jms.XASession;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
import com.sonicsw.sonicmq.j2ee.jmsra.sonicra.SonicConnection;
import com.sonicsw.sonicmq.j2ee.jmsra.sonicra.SonicConnectionFactory;
public class MessageSenderBase {
private final static String CONNECTION_FACTORY = "java:/SonicJMS/default/XAQueueConnectionFactory";
public final static int UNKNOWN_TXN_TYPE = -1;
public final static int XA_TXN_TYPE = 1;
public final static int NON_XA_TXN_TYPE = 2;
private int m_txnType = UNKNOWN_TXN_TYPE;
protected XASession xaSession = null;
protected Session session = null;
protected @Resource
SessionContext sessionCtx;
Logger logger = Logger
.getLogger("fi.logiasoftware.messageserver.services.backend.MessageSenderBase");
public void sendTextMessage(String msg, HashMap properties,
SonicConnection conn, javax.jms.Destination destination) throws JMSException {
MessageProducer producer = null;
producer = session.createProducer(destination);
TextMessage textMessage = session.createTextMessage();
textMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
textMessage.setJMSExpiration(0);
textMessage.setBooleanProperty("JMS_SonicMQ_preserveUndelivered", true);
textMessage.setBooleanProperty("JMS_SonicMQ_notifyUndelivered", true);
Set set = properties.keySet();
Iterator it = set.iterator();
logger.debug("Setting properties");
while (it.hasNext()) {
String propertyName = (String) it.next();
Object o = properties.get(propertyName);
if (o instanceof String) {
String propertyValue = (String) properties.get(propertyName);
textMessage.setStringProperty(propertyName, propertyValue);
} else if (o instanceof Integer) {
Integer propertyValue = (Integer) properties.get(propertyName);
textMessage.setIntProperty(propertyName, propertyValue
.intValue());
} else if (o instanceof Boolean) {
Boolean propertyValue = (Boolean) properties.get(propertyName);
textMessage.setBooleanProperty(propertyName, propertyValue);
}
}
logger.debug("Setting text");
textMessage.setText(msg);
logger.debug("sending message");
producer.send(textMessage);
}
private int getAppServerTxnType() {
// Only need to determine this once per bean activation. It will not
// change unless the bean is redeployed with a different deployment
// descriptor.
if (sessionCtx != null && m_txnType == UNKNOWN_TXN_TYPE) {
try {
sessionCtx.getRollbackOnly();
m_txnType = XA_TXN_TYPE;
} catch (IllegalStateException ise) {
m_txnType = NON_XA_TXN_TYPE;
}
}
return m_txnType;
}
private Queue getQueue(String jndiName) {
try {
InitialContext iniCtx = new InitialContext();
Queue q = (Queue) iniCtx.lookup(jndiName);
return q;
} catch (NamingException ne) {
throw new EJBException(ne);
}
}
public void sendMessage(SonicConnection conn, String msg, HashMap properties, String queueName)
throws JMSException {
Queue queue = getQueue(queueName);
sendTextMessage(msg, properties, conn, queue);
}
public SonicConnection openConnection() {
SonicConnection conn = null;
InitialContext iniCtx = null;
Object ref = null;
try {
iniCtx = new InitialContext();
ref = iniCtx.lookup(CONNECTION_FACTORY);
} catch (NamingException e) {
throw new EJBException(e);
}
try {
SonicConnectionFactory cf = (SonicConnectionFactory) ref;
conn = (SonicConnection) cf.getConnection();
conn.start();
int txnType = getAppServerTxnType();
logger.debug("Checking server transaction type");
if (txnType == XA_TXN_TYPE && conn instanceof XAConnection) {
logger.debug("Creating xasession");
xaSession = ((XAConnection) conn).createXASession();
session = xaSession.getSession();
logger.debug("XAsession created");
} else {
// Create the JMS session directly from the connection
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
if (conn == null)
throw new EJBException("could not connect to JMS queue: "
+ CONNECTION_FACTORY + ", message cannot be sent and will be lost!");
return conn;
} catch(JMSException e) {
e.printStackTrace();
throw new EJBException(e);
} finally {
if(conn != null) {
try {
conn.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
}
}
public void shutdownConnection(SonicConnection conn) {
Logger logger = Logger
.getLogger("fi.logiasoftware.messageserver.services.backend.MessageSenderBean");
if (conn != null) {
int txnType = getAppServerTxnType();
try {
if(session != null)
session.close();
if (txnType == XA_TXN_TYPE && conn instanceof XAConnection) {
if(xaSession != null)
xaSession.close();
}
conn.close();
} catch (JMSException jmse) {
logger.warn("Could not close JMS connection. Reason: "
+ jmse.getMessage());
}
}
}
}