01: /******************************************************************************
02: * ResponderMESSAGE.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.util.Properties;
07: import javax.servlet.ServletConfig;
08: import javax.servlet.ServletOutputStream;
09: import javax.servlet.ServletException;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12: import org.openlaszlo.compiler.Canvas;
13: import org.openlaszlo.connection.*;
14: import org.apache.log4j.Logger;
15:
16: public final class ResponderMESSAGE extends ResponderConnection {
17: private static Logger mLogger = Logger
18: .getLogger(ResponderMESSAGE.class);
19:
20: protected void respondImpl(HttpServletRequest req,
21: HttpServletResponse res, Application app, int serial,
22: String username) throws IOException {
23: String to = req.getParameter("to");
24: String msg = req.getParameter("msg"); // msg: XML message
25: String range = req.getParameter("range");
26:
27: if (to == null || to.equals("")) {
28: respondWithErrorSWF(res,
29: /* (non-Javadoc)
30: * @i18n.test
31: * @org-mes="missing 'to' parameter"
32: */
33: org.openlaszlo.i18n.LaszloMessages.getMessage(
34: ResponderMESSAGE.class.getName(), "051018-41"));
35: return;
36: }
37: if (msg == null) {
38: respondWithErrorSWF(res,
39: /* (non-Javadoc)
40: * @i18n.test
41: * @org-mes="missing 'msg' parameter"
42: */
43: org.openlaszlo.i18n.LaszloMessages.getMessage(
44: ResponderMESSAGE.class.getName(), "051018-52"));
45: return;
46: }
47:
48: mLogger.debug("to='" + to + "',msg='" + msg + "',range='"
49: + range + "',s=" + serial);
50:
51: // Wrap it around resultset so serial number is always '0'. This makes
52: // sure it fools it into believing the local dataset got the right data.
53: StringBuffer xmlResult = new StringBuffer();
54: String wrapper = "<resultset s=\"0\">" + msg + "</resultset>";
55:
56: ConnectionGroup group = app.getConnectionGroup();
57: int count = group.sendMessage(to, wrapper, range, xmlResult);
58:
59: if (count > 0) {
60: respondWithStatusSWF(res, HttpServletResponse.SC_OK,
61: "message sent", xmlResult.toString(), serial);
62: } else {
63: String m =
64: /* (non-Javadoc)
65: * @i18n.test
66: * @org-mes="message not sent: no one specified connected " + "(range: " + p[0] + ")"
67: */
68: org.openlaszlo.i18n.LaszloMessages.getMessage(
69: ResponderMESSAGE.class.getName(), "051018-77",
70: new Object[] { range });
71: respondWithErrorSWF(res, m);
72: }
73: }
74: }
|