1 package org.jbpm.bpel.service.exe; 2 3 import java.io.Serializable ; 4 5 import javax.jms.*; 6 import javax.xml.namespace.QName ; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 import org.w3c.dom.Element ; 11 12 import org.jbpm.bpel.messager.MessagerSession; 13 import org.jbpm.bpel.service.def.BpelEndpointHandler; 14 import org.jbpm.bpel.service.def.Receiver; 15 16 20 public class OutstandingRequest { 21 22 private Destination replyTo; 23 private String correlationID; 24 25 private Receiver receiver; 26 27 private static final Log log = LogFactory.getLog(OutstandingRequest.class); 28 29 public OutstandingRequest(Destination replyTo, String correlationID) { 30 this.replyTo = replyTo; 31 this.correlationID = correlationID; 32 } 33 34 public Receiver getReceiver() { 35 return receiver; 36 } 37 38 public void setReceiver(Receiver receiver) { 39 this.receiver = receiver; 40 } 41 42 public void sendReply(Element messageElement, QName faultName, MessagerSession bpelSession) { 43 Session session = bpelSession.getJmsSession(); 44 MessageProducer producer = null; 45 try { 46 producer = session.createProducer(replyTo); 47 Message responseMsg = session.createObjectMessage((Serializable ) messageElement); 48 responseMsg.setJMSCorrelationID(correlationID); 49 if (faultName != null) { 51 responseMsg.setStringProperty(BpelEndpointHandler.FAULT_NAME_PROP, faultName.toString()); 52 } 53 producer.send(responseMsg); 55 log.debug("sent response: " + BpelEndpointHandler.messageToString(responseMsg)); 56 57 } 58 catch (JMSException e) { 59 log.error(e); 60 throw new RuntimeException ("could not send message", e); 61 } 62 finally { 63 if (producer != null) { 64 try { 65 producer.close(); 66 } 67 catch (JMSException e) { 68 log.warn(e); 69 } 70 } 71 } 72 } 73 } 74 | Popular Tags |