2 import org.opensrf.net.xmpp.XMPPMessage;
3 import org.opensrf.util.*;
6 import java.util.Iterator;
11 public static void processXMPPMessage(XMPPMessage msg) throws MethodException {
13 if(msg == null) return;
15 //System.out.println(msg.getBody());
17 /** fetch this session from the cache */
18 Session ses = Session.findCachedSession(msg.getThread());
21 /** inbound client request, create a new server session */
25 /** parse the JSON message body, which should result in a list of OpenSRF messages */
29 msgList = new JSONReader(msg.getBody()).readArray();
30 } catch(JSONException e) {
36 Iterator itr = msgList.iterator();
38 OSRFObject obj = null;
39 long start = new Date().getTime();
41 /** cycle through the messages and push them up the stack */
42 while(itr.hasNext()) {
44 /** Construct a Message object from the parsed generic OSRFObject */
45 obj = (OSRFObject) itr.next();
50 obj.getInt("threadTrace"),
51 obj.getString("type"),
57 /** LOG the duration */
60 private static void processOSRFMessage(Session ses, Message msg) throws MethodException {
62 Logger.debug("received id=" + msg.getId() +
63 " type=" + msg.getType() + " payload=" + msg.getPayload());
65 if( ses instanceof ClientSession )
66 processResponse((ClientSession) ses, msg);
68 processRequest((ServerSession) ses, msg);
72 * Process a server response
74 private static void processResponse(ClientSession session, Message msg) throws MethodException {
75 String type = msg.getType();
77 if(msg.RESULT.equals(type)) {
78 session.pushResponse(msg);
82 if(msg.STATUS.equals(type)) {
84 OSRFObject obj = (OSRFObject) msg.getPayload();
85 Status stat = new Status(obj.getString("status"), obj.getInt("statusCode"));
86 int statusCode = stat.getStatusCode();
87 String status = stat.getStatus();
91 session.setRequestComplete(msg.getId());
94 session.setRequestComplete(msg.getId());
95 throw new MethodException(status);
101 * Process a client request
103 private static void processRequest(ServerSession session, Message msg) {