public void onMessage (Message omessage)
{
ProcessInstance instance = null;
ProcessManagerBean pmb = new ProcessManagerBean();
pmb.setSessionContext(null);
try
{
System.out.println ("MessageProcessor::onMessage() called..");
MapMessage message = (MapMessage)omessage;
String instanceId = message.getString("instance");
String msg = message.getString("message");
String str_payload = message.getString("payload");
ByteArrayInputStream bis = new ByteArrayInputStream(str_payload.getBytes("ISO-8859-1"));
Object payload = GlobalContext.deserialize(bis, String.class);
instance = pmb.getProcessInstance(instanceId);
if(instance.isRunning("")){ // if STOP signaled, don't execute anymore.
//review: message would effect only one instance. it is not common in BPEL
instance.getProcessDefinition().fireMessage(msg, instance, payload);
pmb.applyChanges();
}
}
catch(Throwable e)
{
System.out.println("MessageProcessorBean::onMessage(): fail to process message. Reason:[" + e.getMessage() + "]. try to redeliver... ");
//e.printStackTrace();
try {
pmb.cancelChanges();
} catch (RemoteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ejbContext.setRollbackOnly();
}finally{
try {
pmb.remove();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoveException e) {
// TODO Auto-generated catch block