01: /******************************************************************************
02: * ResponderAGENTMESSAGE.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.util.*;
07: import java.net.*;
08: import javax.servlet.*;
09: import javax.servlet.http.*;
10: import org.openlaszlo.compiler.*;
11: import org.openlaszlo.connection.*;
12: import org.openlaszlo.utils.*;
13: import org.apache.log4j.*;
14:
15: public class ResponderAGENTMESSAGE extends ResponderConnectionAgent {
16: private static boolean mIsInitialized = false;
17: private static Logger mLogger = Logger
18: .getLogger(ResponderAGENTMESSAGE.class);
19:
20: protected void respondAgent(HttpServletRequest req,
21: HttpServletResponse res, ConnectionGroup group)
22: throws IOException {
23: String to = req.getParameter("to");
24: String msg = req.getParameter("msg");
25: String range = req.getParameter("range");
26: String dset = req.getParameter("dset");
27:
28: if (isEmpty(to)) {
29: replyWithXMLStatus(res, "missing 'to' parameter",
30: SC_MISSING_PARAMETER);
31: return;
32: }
33:
34: if (isEmpty(dset)) {
35: replyWithXMLStatus(res, "missing 'dset' parameter",
36: SC_MISSING_PARAMETER);
37: return;
38: }
39:
40: if (msg == null) {
41: replyWithXMLStatus(res, "missing 'msg' parameter",
42: SC_MISSING_PARAMETER);
43: return;
44: }
45:
46: mLogger.debug("to='" + to + "',range='" + range + "', msg='"
47: + msg + "'");
48:
49: // Wrap it around resultset so serial number is always '0'. This makes
50: // sure it fools it into believing the local dataset got the right data.
51: String xml = "<resultset s=\"0\">" + "<root dset=\"" + dset
52: + "\">" + msg + "</root>" + "</resultset>";
53:
54: int count = group.sendMessage(to, xml, range, null);
55:
56: replyWithXMLStatus(res, (count > 0 ? "message sent"
57: : "no one specified connected (range: " + range + ")"));
58: }
59:
60: private boolean isEmpty(String str) {
61: return str == null || str.equals("");
62: }
63: }
|