KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > servlets > responders > ResponderMESSAGE


1 /******************************************************************************
2  * ResponderMESSAGE.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

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