Hello everyone,
I have a node in my process that I want to wait on a jms message. I'm using the following code:
package ch.siesa.beyondfibre.jbpm.customer.delete;
import javax.jms.*;
import javax.naming.*;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
public class WaitAction implements ActionHandler, MessageListener{
private static final long serialVersionUID = 1L;
Context jndiContext = null;
ExecutionContext executionContext = null;
TopicConnectionFactory topicConnectionFactory = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicSubscriber topicSubscriber = null;
public void execute(ExecutionContext ctx) throws Exception {
System.out.println("Subscribing node to JMS topic...");
this.executionContext = ctx;
jndiContext = new InitialContext();
topicConnectionFactory = (TopicConnectionFactory)jndiContext.lookup("TopicConnectionFactory");
topic = (Topic) jndiContext.lookup("topic/testTopic");
topicConnection = topicConnectionFactory.createTopicConnection();
topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topicSubscriber = topicSession.createSubscriber(topic);
topicSubscriber.setMessageListener(this);
topicConnection.start();
System.out.println("Subscription ok, waiting !");
}
public void onMessage(Message message) {
executionContext.leaveNode("success");
}
}
It is however throwing an exception:
11:09:44,983 ERROR [GraphElement] action threw exception: This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6
javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6
I have two questions :
- Is there a workaround this exception ?
- Isn't there a simpler way to have a node wait for a message ?
Thanking you all in advance :)
Regards