KickJava   Java API By Example, From Geeks To Geeks.

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


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