[EJB/JBoss] - StatelessSession -> DAO leaves open transactions
by wcydaip
I've been using a pretty simple setup where a StatelessSession bean coordinates calls to various DAO's to perform inserts and updates. I began noticing a while back that many of my apps connections leave open transactions and am begining to wonder if I've misunderstood something about the transactional manager and the way it handles its exception handling.
I use JBossAS 4.0.2 on a W2K machine running against W2K SQLServer.
The session beans are setup to utilize the containers CMT.
| public void updatePersonInfoInTemp(int personId, ArrayList tests)throws GeneralFailureException{
| RegistrationDAO dao = new RegistrationDAO();
| try {
| TestInfo test = null;
| for(int i=0; i<tests.size();i++){
| test = (TestInfo)tests.get(i);
| dao.updatePersonInfoInTemp(test.getSessionId(), test.getTestCode(), personId);
| }
| } catch (SQLException e) {
| // context.setRollbackOnly(); // is this needed?
| throw new GeneralFailureException(e.getMessage());
| } catch (NamingException e) {
| // context.setRollbackOnly(); // is this needed?
| throw new GeneralFailureException(e.getMessage());
| }
| }
|
Exception classes:
| public class GeneralFailureException extends EventException{
|
| private Throwable t;
|
| public GeneralFailureException(String s) {
| super(s);
| }
|
| public GeneralFailureException(String s, Throwable t) {
| super(s);
| this.t = t;
| }
|
| public String getThrowable() {
| return ("Received throwable with Message: "+ t.getMessage());
| }
| }
| public class EventException extends Exception
| implements java.io.Serializable {
|
| public EventException() {}
|
| public EventException(String str) {
| super(str);
| }
| }
|
The DAO's don't do anything special except throw the indicated error when encountered, such as:
| public void updatePersonInfoInTemp(int sessionId, String testCode, int personId)throws SQLException, NamingException{
| logger.debug("entering updatePersonInfoInTemp");
| Connection con = null;
| PreparedStatement ps = null;
| ResultSet rs = null;
| try {
| con = getConnection(AppHelper.SC_DEFAULT_DS_CON);
| try {
| ps = con.prepareStatement(
| "UPDATE TempTest SET PersonID = ? " +
| "WHERE SessionID = ? AND TestCode = ?");
|
| int count = 1;
| ps.setInt(count++, personId);
| ps.setInt(count++, sessionId);
| ps.setString(count++, testCode);
|
| ps.executeUpdate();
| } catch (SQLException ex) {
| logger.error(ex);
| throw ex;
| }
| } finally {
| AppHelper.closeResultSet(rs);
| AppHelper.closeStatement(ps);
| AppHelper.releaseConnection(con);
| }
| logger.debug("leaving updatePersonInfoInTemp");
| }
|
Is there something that I'm doing that would cause transactions to be left open?
Thanks for any help.
Graham
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977969#3977969
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977969
19 years, 8 months
[EJB/JBoss] - configuring remote topic host and port
by sridummy
Hi
Im using Jboss4.0.3SP1, Im very new to JMS&MDB's. I have written a MDB and a client which subscribes the msgs. I have to connect to the remote Topic which is in Seebeyond very old version and didnt have jndi.
The following is the code which i implemented for connecting to remote topic and ejb-jar.xml, jboss.xml
Im unable to listen to the messages after deploying the jar file.
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicPublisher;
import javax.jms.*;
import javax.ejb.*;
import javax.jms.TopicSession;
import javax.jms.TextMessage;
import com.seebeyond.jms.client.STCTopicConnectionFactory;
import com.seebeyond.jms.message.STCBytesMessage;
import com.seebeyond.jms.message.STCTextMessage;
/**
* @ejb.bean name="MyMBD1"
* display-name="Name for MyMBD1"
* description="Description for MyMBD1"
* destination-type="javax.jms.Topic"
* acknowledge-mode="Auto-acknowledge"
*/
public class MyMBD1 implements MessageDrivenBean, MessageListener {
MessageDrivenContext context = null;
String topicName = "etXMLShipmentOrder";
TopicConnectionFactory tcf = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicSubscriber topicSubscriber = null;
STCBytesMessage message = null;
InputStreamReader inputStreamReader = null;
char answer = '\0';
String hostName = "egludev07";
int port = 24820;
public MyMBD1() {
super();
System.out.println("Topic name is " + topicName);
// TODO Auto-generated constructor stub
}
public void setMessageDrivenContext(MessageDrivenContext context)
throws EJBException {
this.context = context;
System.out.println("Insdie setMessageDrivenContext ");
}
public void ejbRemove() throws EJBException {
System.out.println("ejbRemove ");
context = null;
if (topicConnection != null) {
try {
System.out.println("... Closing connection ...");
topicSession.commit();
topicConnection.close();
}catch(JMSException e){
System.out.println("Inside ejbRemove catch block ");
e.printStackTrace();
}
}
}
public void onMessage(Message message) {
System.out.println("onMessage");
STCTextMessage msg = null;
//final int MAX_MESSAGE_SIZE = 60;
try {
if (message instanceof TextMessage) {
msg = (STCTextMessage) message;
System.out.println(
"... Reading message: " + msg.getText());
} else {
System.out.println(
"Message of wrong type: "
+ message.getClass().getName());
}
topicSession.commit();
} catch (Exception e) {
System.out.println(
" JMSException in onMessage(): " + e.toString());
} catch (Throwable te) {
System.out.println(
"Exception in onMessage():" + te.getMessage());
}
}
/**
* Default create method
*
* @throws CreateException
*/
public void ejbCreate() {
System.out.println("Inside ejbCreate ");
try {
tcf = new STCTopicConnectionFactory(hostName, port);
topicConnection = tcf.createTopicConnection();
topicConnection.start();
topicSession =
topicConnection.createTopicSession(
true,
Session.AUTO_ACKNOWLEDGE);
topic = topicSession.createTopic(topicName);
topicSubscriber = topicSession.createDurableSubscriber(topic,"EAI_TEST_DURABLE");
} catch (Exception e){
System.out.println("Inside ejbCreateException Block "+e.getMessage());
e.getStackTrace();
}
}
}
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar >
<enterprise-beans>
<message-driven>
<ejb-name>MyMDB1</ejb-name>
<ejb-class>com.eagle.mdb.MyMBD1</ejb-class>
<transaction-type>Container</transaction-type>
<acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
</message-driven-destination>
<resource-ref>
<res-ref-name>jms/JmsXA</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
</enterprise-beans>
</ejb-jar>
jboss.xml
<?xml version="1.0" encoding="UTF-8"?>
<enterprise-beans>
<message-driven>
<ejb-name>MyMDB1</ejb-name>
<destination-jndi-name>topic/testTopic</destination-jndi-name>
<resource-ref>
<res-ref-name>jms/JmsXA</res-ref-name>
<jndi-name>TopicConnectionFactory</jndi-name>
</resource-ref>
</message-driven>
</enterprise-beans>
For my senario, pls guide me. Its very urgent.
Thanks in Advance
Sri
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977963#3977963
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977963
19 years, 8 months
[EJB/JBoss] - configuring remote topic host and port
by sridummy
Hi
Im using Jboss4.0.3SP1, Im very new to JMS&MDB's. I have written a MDB and a client which subscribes the msgs. I have to connect to the remote Topic which is in Seebeyond very old version and didnt have jndi.
The following is the code which i implemented for connecting to remote topic and ejb-jar.xml, jboss.xml
Im unable to listen to the messages after deploying the jar file.
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicPublisher;
import javax.jms.*;
import javax.ejb.*;
import javax.jms.TopicSession;
import javax.jms.TextMessage;
import com.seebeyond.jms.client.STCTopicConnectionFactory;
import com.seebeyond.jms.message.STCBytesMessage;
import com.seebeyond.jms.message.STCTextMessage;
/**
* @ejb.bean name="MyMBD1"
* display-name="Name for MyMBD1"
* description="Description for MyMBD1"
* destination-type="javax.jms.Topic"
* acknowledge-mode="Auto-acknowledge"
*/
public class MyMBD1 implements MessageDrivenBean, MessageListener {
MessageDrivenContext context = null;
String topicName = "etXMLShipmentOrder";
TopicConnectionFactory tcf = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicSubscriber topicSubscriber = null;
STCBytesMessage message = null;
InputStreamReader inputStreamReader = null;
char answer = '\0';
String hostName = "egludev07";
int port = 24820;
public MyMBD1() {
super();
System.out.println("Topic name is " + topicName);
// TODO Auto-generated constructor stub
}
public void setMessageDrivenContext(MessageDrivenContext context)
throws EJBException {
this.context = context;
System.out.println("Insdie setMessageDrivenContext ");
}
public void ejbRemove() throws EJBException {
System.out.println("ejbRemove ");
context = null;
if (topicConnection != null) {
try {
System.out.println("... Closing connection ...");
topicSession.commit();
topicConnection.close();
}catch(JMSException e){
System.out.println("Inside ejbRemove catch block ");
e.printStackTrace();
}
}
}
public void onMessage(Message message) {
System.out.println("onMessage");
STCTextMessage msg = null;
//final int MAX_MESSAGE_SIZE = 60;
try {
if (message instanceof TextMessage) {
msg = (STCTextMessage) message;
System.out.println(
"... Reading message: " + msg.getText());
} else {
System.out.println(
"Message of wrong type: "
+ message.getClass().getName());
}
topicSession.commit();
} catch (Exception e) {
System.out.println(
" JMSException in onMessage(): " + e.toString());
} catch (Throwable te) {
System.out.println(
"Exception in onMessage():" + te.getMessage());
}
}
/**
* Default create method
*
* @throws CreateException
*/
public void ejbCreate() {
System.out.println("Inside ejbCreate ");
try {
tcf = new STCTopicConnectionFactory(hostName, port);
topicConnection = tcf.createTopicConnection();
topicConnection.start();
topicSession =
topicConnection.createTopicSession(
true,
Session.AUTO_ACKNOWLEDGE);
topic = topicSession.createTopic(topicName);
topicSubscriber = topicSession.createDurableSubscriber(topic,"EAI_TEST_DURABLE");
} catch (Exception e){
System.out.println("Inside ejbCreateException Block "+e.getMessage());
e.getStackTrace();
}
}
}
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar >
<enterprise-beans>
<message-driven>
<ejb-name>MyMDB1</ejb-name>
<ejb-class>com.eagle.mdb.MyMBD1</ejb-class>
<transaction-type>Container</transaction-type>
<acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
</message-driven-destination>
<resource-ref>
<res-ref-name>jms/JmsXA</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
</enterprise-beans>
</ejb-jar>
jboss.xml
<?xml version="1.0" encoding="UTF-8"?>
<enterprise-beans>
<message-driven>
<ejb-name>MyMDB1</ejb-name>
<destination-jndi-name>topic/testTopic</destination-jndi-name>
<resource-ref>
<res-ref-name>jms/JmsXA</res-ref-name>
<jndi-name>TopicConnectionFactory</jndi-name>
</resource-ref>
</message-driven>
</enterprise-beans>
For my senario, pls guide me. Its very urgent.
Thanks in Advance
Sri
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977962#3977962
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977962
19 years, 8 months
[Beginners Corner] - configuring remote topic host and port
by sridummy
Hi
Im using Jboss4.0.3SP1, Im very new to JMS&MDB's. I have written a MDB and a client which subscribes the msgs. I have to connect to the remote Topic which is in Seebeyond very old version and didnt have jndi.
The following is the code which i implemented for connecting to remote topic and ejb-jar.xml, jboss.xml
Im unable to listen to the messages after deploying the jar file.
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicPublisher;
import javax.jms.*;
import javax.ejb.*;
import javax.jms.TopicSession;
import javax.jms.TextMessage;
import com.seebeyond.jms.client.STCTopicConnectionFactory;
import com.seebeyond.jms.message.STCBytesMessage;
import com.seebeyond.jms.message.STCTextMessage;
/**
* @ejb.bean name="MyMBD1"
* display-name="Name for MyMBD1"
* description="Description for MyMBD1"
* destination-type="javax.jms.Topic"
* acknowledge-mode="Auto-acknowledge"
*/
public class MyMBD1 implements MessageDrivenBean, MessageListener {
MessageDrivenContext context = null;
String topicName = "etXMLShipmentOrder";
TopicConnectionFactory tcf = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicSubscriber topicSubscriber = null;
STCBytesMessage message = null;
InputStreamReader inputStreamReader = null;
char answer = '\0';
String hostName = "egludev07";
int port = 24820;
public MyMBD1() {
super();
System.out.println("Topic name is " + topicName);
// TODO Auto-generated constructor stub
}
public void setMessageDrivenContext(MessageDrivenContext context)
throws EJBException {
this.context = context;
System.out.println("Insdie setMessageDrivenContext ");
}
public void ejbRemove() throws EJBException {
System.out.println("ejbRemove ");
context = null;
if (topicConnection != null) {
try {
System.out.println("... Closing connection ...");
topicSession.commit();
topicConnection.close();
}catch(JMSException e){
System.out.println("Inside ejbRemove catch block ");
e.printStackTrace();
}
}
}
public void onMessage(Message message) {
System.out.println("onMessage");
STCTextMessage msg = null;
//final int MAX_MESSAGE_SIZE = 60;
try {
if (message instanceof TextMessage) {
msg = (STCTextMessage) message;
System.out.println(
"... Reading message: " + msg.getText());
} else {
System.out.println(
"Message of wrong type: "
+ message.getClass().getName());
}
topicSession.commit();
} catch (Exception e) {
System.out.println(
" JMSException in onMessage(): " + e.toString());
} catch (Throwable te) {
System.out.println(
"Exception in onMessage():" + te.getMessage());
}
}
/**
* Default create method
*
* @throws CreateException
*/
public void ejbCreate() {
System.out.println("Inside ejbCreate ");
try {
tcf = new STCTopicConnectionFactory(hostName, port);
topicConnection = tcf.createTopicConnection();
topicConnection.start();
topicSession =
topicConnection.createTopicSession(
true,
Session.AUTO_ACKNOWLEDGE);
topic = topicSession.createTopic(topicName);
topicSubscriber = topicSession.createDurableSubscriber(topic,"EAI_TEST_DURABLE");
} catch (Exception e){
System.out.println("Inside ejbCreateException Block "+e.getMessage());
e.getStackTrace();
}
}
}
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar >
<enterprise-beans>
<message-driven>
<ejb-name>MyMDB1</ejb-name>
<ejb-class>com.eagle.mdb.MyMBD1</ejb-class>
<transaction-type>Container</transaction-type>
<acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
</message-driven-destination>
<resource-ref>
<res-ref-name>jms/JmsXA</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
</enterprise-beans>
</ejb-jar>
jboss.xml
<?xml version="1.0" encoding="UTF-8"?>
<enterprise-beans>
<message-driven>
<ejb-name>MyMDB1</ejb-name>
<destination-jndi-name>topic/testTopic</destination-jndi-name>
<resource-ref>
<res-ref-name>jms/JmsXA</res-ref-name>
<jndi-name>TopicConnectionFactory</jndi-name>
</resource-ref>
</message-driven>
</enterprise-beans>
For my senario, pls guide me. Its very urgent.
Thanks in Advance
Sri
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977960#3977960
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977960
19 years, 8 months