KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > clientapi > CallbackReceiver


1 package org.apache.axis2.clientapi;
2
3 import org.apache.axis2.addressing.miheaders.RelatesTo;
4 import org.apache.axis2.context.MessageContext;
5 import org.apache.axis2.engine.AxisFault;
6 import org.apache.axis2.engine.MessageReceiver;
7 import org.apache.axis2.soap.SOAPEnvelope;
8
9 import java.util.HashMap JavaDoc;
10
11 public class CallbackReceiver implements MessageReceiver {
12
13     public static String JavaDoc SERVIC_NAME = "ClientService";
14
15     private HashMap JavaDoc callbackstore;
16
17     public CallbackReceiver() {
18         callbackstore = new HashMap JavaDoc();
19     }
20
21     public void addCallback(String JavaDoc MsgID, Callback callback) {
22         callbackstore.put(MsgID, callback);
23     }
24
25     public void invoke(String JavaDoc MsgID, SOAPEnvelope result) {
26
27     }
28     /* (non-Javadoc)
29      * @see org.apache.axis2.engine.MessageReceiver#recieve(org.apache.axis2.context.MessageContext)
30      */

31     public void recieve(MessageContext messgeCtx) throws AxisFault {
32         //TODO find the related message ID and call the callback
33
RelatesTo relatesTO = messgeCtx.getMessageInformationHeaders().getRelatesTo();
34
35         String JavaDoc messageID = relatesTO.getValue();
36         Callback callback = (Callback) callbackstore.get(messageID);
37         AsyncResult result = new AsyncResult(messgeCtx);
38         if (callback != null) {
39             callback.onComplete(result);
40             callback.setComplete(true);
41         }else{
42             throw new AxisFault("The Callback realtes to MessageID "+ messageID + " is not found");
43         }
44     }
45
46 }
47
Popular Tags