[jbpm-commits] JBoss JBPM SVN: r3328 - in jbpm3/trunk/modules: core/src/main/resources and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Dec 11 05:32:08 EST 2008
Author: thomas.diesler at jboss.com
Date: 2008-12-11 05:32:08 -0500 (Thu, 11 Dec 2008)
New Revision: 3328
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java
jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml
jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java
Log:
Fix JNDI comp references to JbpmDS and UserTransaction
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java 2008-12-11 08:52:50 UTC (rev 3327)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/jta/JtaDbPersistenceServiceFactory.java 2008-12-11 10:32:08 UTC (rev 3328)
@@ -48,41 +48,47 @@
*
* @author Tom Baeyens
*/
-public class JtaDbPersistenceServiceFactory extends DbPersistenceServiceFactory {
+public class JtaDbPersistenceServiceFactory extends DbPersistenceServiceFactory
+{
private static final long serialVersionUID = 1L;
private UserTransaction userTransaction;
- public JtaDbPersistenceServiceFactory() {
+ public JtaDbPersistenceServiceFactory()
+ {
setCurrentSessionEnabled(true);
setTransactionEnabled(false);
}
-
- public Service openService() {
+
+ public Service openService()
+ {
return new JtaDbPersistenceService(this);
}
- public UserTransaction getUserTransaction() {
- if (userTransaction == null) {
+ public UserTransaction getUserTransaction()
+ {
+ if (userTransaction == null)
+ {
String jndiName = getConfiguration().getProperty("jta.UserTransaction");
- if (jndiName == null) {
+ if (jndiName == null)
+ {
/*
- * EJB 2.1 section 20.9 The container must make the UserTransaction interface available to the
- * enterprise beans that are allowed to use this interface (only session and message-
- * driven beans with bean-managed transaction demarcation are allowed to use this
- * interface) in JNDI under the name java:comp/UserTransaction.
- * J2EE 1.4 section 4.2.1.1 The J2EE platform must provide an object implementing the
- * UserTransaction interface to all web components. The platform must publish the
- * UserTransaction object in JNDI under the name java:comp/UserTransaction.
+ * EJB 2.1 section 20.9 The container must make the UserTransaction interface available to the enterprise beans that are allowed to use this interface (only
+ * session and message- driven beans with bean-managed transaction demarcation are allowed to use this interface) in JNDI under the name
+ * java:comp/UserTransaction. J2EE 1.4 section 4.2.1.1 The J2EE platform must provide an object implementing the UserTransaction interface to all web
+ * components. The platform must publish the UserTransaction object in JNDI under the name java:comp/UserTransaction.
*/
jndiName = "java:comp/UserTransaction";
}
- try {
- userTransaction = (UserTransaction) new InitialContext().lookup(jndiName);
- } catch (NamingException e) {
- throw new JbpmException("could not retrieve user transaction with name "+jndiName, e);
+ try
+ {
+ userTransaction = (UserTransaction)new InitialContext().lookup(jndiName);
}
+ catch (NamingException e)
+ {
+ throw new JbpmException("could not retrieve user transaction with name " + jndiName, e);
+ }
}
return userTransaction;
}
Modified: jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml 2008-12-11 08:52:50 UTC (rev 3327)
+++ jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml 2008-12-11 10:32:08 UTC (rev 3328)
@@ -1,11 +1,12 @@
<!-- DataSource properties (begin) ===
- <property name="hibernate.connection.datasource">java:comp/env/jdbc/JbpmDataSource</property>
+ <property name="hibernate.connection.datasource">java:JbpmDS</property>
==== DataSource properties (end) -->
<!-- JTA transaction properties (begin) ===
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
+ <property name="jta.UserTransaction">UserTransaction</property>
==== JTA transaction properties (end) -->
<!-- CMT transaction properties (begin) ===
Modified: jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java 2008-12-11 08:52:50 UTC (rev 3327)
+++ jbpm3/trunk/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java 2008-12-11 10:32:08 UTC (rev 3328)
@@ -94,20 +94,24 @@
* @author Tom Baeyens
* @author Alejandro Guizar
*/
-public class CommandListenerBean implements MessageDrivenBean, MessageListener {
+public class CommandListenerBean implements MessageDrivenBean, MessageListener
+{
private static final long serialVersionUID = 1L;
-
+
MessageDrivenContext messageDrivenContext = null;
LocalCommandService commandService;
Connection jmsConnection;
Destination deadLetterQueue;
- public void onMessage(Message message) {
- try {
+ public void onMessage(Message message)
+ {
+ try
+ {
// extract command from message
Command command = extractCommand(message);
- if (command == null) {
+ if (command == null)
+ {
discard(message);
return;
}
@@ -115,40 +119,54 @@
Object result = commandService.execute(command);
// send a response back if a "reply to" destination is set
Destination replyTo = message.getJMSReplyTo();
- if (replyTo != null && (result instanceof Serializable || result == null)) {
- sendResult((Serializable) result, replyTo, message.getJMSMessageID());
+ if (replyTo != null && (result instanceof Serializable || result == null))
+ {
+ sendResult((Serializable)result, replyTo, message.getJMSMessageID());
}
}
- catch (JMSException e) {
+ catch (JMSException e)
+ {
messageDrivenContext.setRollbackOnly();
log.error("could not process message " + message, e);
}
}
- protected Command extractCommand(Message message) throws JMSException {
+ protected Command extractCommand(Message message) throws JMSException
+ {
Command command = null;
- if (message instanceof ObjectMessage) {
+ if (message instanceof ObjectMessage)
+ {
log.debug("deserializing command from jms message...");
ObjectMessage objectMessage = (ObjectMessage)message;
Serializable object = objectMessage.getObject();
- if (object instanceof Command) {
- command = (Command) object;
- } else {
- log.warn("ignoring object message cause it isn't a command '"+object+"'"+(object!=null ? " ("+object.getClass().getName()+")" : ""));
+ if (object instanceof Command)
+ {
+ command = (Command)object;
}
- } else {
- log.warn("ignoring message '"+message+"' cause it isn't an ObjectMessage ("+message.getClass().getName()+")");
+ else
+ {
+ log.warn("ignoring object message cause it isn't a command '" + object + "'" + (object != null ? " (" + object.getClass().getName() + ")" : ""));
+ }
}
+ else
+ {
+ log.warn("ignoring message '" + message + "' cause it isn't an ObjectMessage (" + message.getClass().getName() + ")");
+ }
return command;
}
- private void discard(Message message) throws JMSException {
- if (deadLetterQueue == null) {
+ private void discard(Message message) throws JMSException
+ {
+ if (deadLetterQueue == null)
+ {
// lookup dead letter queue
- try {
+ try
+ {
Context initial = new InitialContext();
- deadLetterQueue = (Destination) initial.lookup("java:comp/env/jms/DeadLetterQueue");
- } catch (NamingException e) {
+ deadLetterQueue = (Destination)initial.lookup("java:comp/env/jms/DeadLetterQueue");
+ }
+ catch (NamingException e)
+ {
log.debug("failed to retrieve dead letter queue, rejecting message: " + message);
messageDrivenContext.setRollbackOnly();
return;
@@ -156,54 +174,70 @@
}
// send message to dead letter queue
Session jmsSession = createSession();
- try {
+ try
+ {
jmsSession.createProducer(deadLetterQueue).send(message);
- } finally {
+ }
+ finally
+ {
jmsSession.close();
}
}
- private void sendResult(Serializable result, Destination destination, String correlationId) throws JMSException {
+ private void sendResult(Serializable result, Destination destination, String correlationId) throws JMSException
+ {
log.debug("sending result " + result + " to " + destination);
Session jmsSession = createSession();
- try {
+ try
+ {
Message resultMessage = jmsSession.createObjectMessage(result);
resultMessage.setJMSCorrelationID(correlationId);
jmsSession.createProducer(destination).send(resultMessage);
- } finally {
+ }
+ finally
+ {
jmsSession.close();
}
}
- private Session createSession() throws JMSException {
- if (jmsConnection == null) {
+ private Session createSession() throws JMSException
+ {
+ if (jmsConnection == null)
+ {
// lookup factory and create jms connection
- try {
+ try
+ {
Context initial = new InitialContext();
- ConnectionFactory jmsConnectionFactory = (ConnectionFactory) initial.lookup("java:comp/env/jms/JbpmConnectionFactory");
+ ConnectionFactory jmsConnectionFactory = (ConnectionFactory)initial.lookup("java:comp/env/jms/JbpmConnectionFactory");
jmsConnection = jmsConnectionFactory.createConnection();
}
- catch (NamingException e) {
+ catch (NamingException e)
+ {
throw new EJBException("error retrieving jms connection factory", e);
}
}
/*
- * if the connection supports xa, the session will be transacted, else the
- * session will auto acknowledge; in either case no explicit transaction
- * control must be performed - see ejb 2.1 - 17.3.5
+ * if the connection supports xa, the session will be transacted, else the session will auto acknowledge; in either case no explicit transaction control must be
+ * performed - see ejb 2.1 - 17.3.5
*/
return jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
- public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) {
+ public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext)
+ {
this.messageDrivenContext = messageDrivenContext;
}
- public void ejbRemove() {
- if (jmsConnection != null) {
- try {
+ public void ejbRemove()
+ {
+ if (jmsConnection != null)
+ {
+ try
+ {
jmsConnection.close();
- } catch (JMSException e) {
+ }
+ catch (JMSException e)
+ {
log.debug("failed to close jms connection", e);
}
jmsConnection = null;
@@ -213,14 +247,20 @@
messageDrivenContext = null;
}
- public void ejbCreate() {
- try {
+ public void ejbCreate()
+ {
+ try
+ {
Context initial = new InitialContext();
- LocalCommandServiceHome commandServiceHome = (LocalCommandServiceHome) initial.lookup("java:comp/env/ejb/LocalCommandServiceBean");
+ LocalCommandServiceHome commandServiceHome = (LocalCommandServiceHome)initial.lookup("java:comp/env/ejb/LocalCommandServiceBean");
commandService = commandServiceHome.create();
- } catch (NamingException e) {
+ }
+ catch (NamingException e)
+ {
throw new EJBException("error retrieving command service home", e);
- } catch (CreateException e) {
+ }
+ catch (CreateException e)
+ {
throw new EJBException("error creating command service", e);
}
}
More information about the jbpm-commits
mailing list