01: package example;
02:
03: import java.util.logging.Logger;
04:
05: import java.io.PrintWriter;
06: import java.io.IOException;
07:
08: import javax.servlet.GenericServlet;
09: import javax.servlet.ServletRequest;
10: import javax.servlet.ServletResponse;
11: import javax.servlet.ServletException;
12:
13: import com.caucho.services.message.MessageSender;
14:
15: public class MessageServlet extends GenericServlet {
16: private static final Logger log = Logger
17: .getLogger(MessageServlet.class.getName());
18:
19: private MessageSender _sender;
20: private int _count;
21:
22: /**
23: * Sends the message.
24: */
25: public void setSender(MessageSender sender) {
26: _sender = sender;
27: }
28:
29: /**
30: * Sends the message.
31: */
32: public void service(ServletRequest request, ServletResponse response)
33: throws IOException, ServletException {
34: String message = "sample message: " + _count++;
35:
36: response.setContentType("text/html");
37:
38: PrintWriter out = response.getWriter();
39: out.println("message: " + message + "<br>");
40:
41: log.info("sending: " + message);
42:
43: _sender.send(null, message);
44:
45: log.info("complete send");
46:
47: out.println("received message: " + MyListener.getLastMessage()
48: + "<br>");
49: }
50: }
|