KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > service > exe > OutstandingRequest


1 package org.jbpm.bpel.service.exe;
2
3 import java.io.Serializable JavaDoc;
4
5 import javax.jms.*;
6 import javax.xml.namespace.QName JavaDoc;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.w3c.dom.Element JavaDoc;
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 /**
17  * @author Alejandro Guízar
18  * @version $Revision: 1.6 $ $Date: 2005/05/12 21:26:31 $
19  */

20 public class OutstandingRequest {
21   
22   private Destination replyTo;
23   private String JavaDoc correlationID;
24   
25   private Receiver receiver;
26   
27   private static final Log log = LogFactory.getLog(OutstandingRequest.class);
28   
29   public OutstandingRequest(Destination replyTo, String JavaDoc 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 JavaDoc messageElement, QName JavaDoc 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 JavaDoc) messageElement);
48       responseMsg.setJMSCorrelationID(correlationID);
49       // set the fault name, if any
50
if (faultName != null) {
51         responseMsg.setStringProperty(BpelEndpointHandler.FAULT_NAME_PROP, faultName.toString());
52       }
53       // send the response
54
producer.send(responseMsg);
55       log.debug("sent response: " + BpelEndpointHandler.messageToString(responseMsg));
56       /* session.commit(); */
57     }
58     catch (JMSException e) {
59       log.error(e);
60       throw new RuntimeException JavaDoc("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