1 package example; 2 3 import java.util.logging.Logger ; 4 5 import java.io.PrintWriter ; 6 import java.io.IOException ; 7 8 import javax.servlet.GenericServlet ; 9 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 = 17 Logger.getLogger(MessageServlet.class.getName()); 18 19 private MessageSender _sender; 20 private int _count; 21 22 25 public void setSender(MessageSender sender) 26 { 27 _sender = sender; 28 } 29 30 33 public void service(ServletRequest request, ServletResponse response) 34 throws IOException , ServletException 35 { 36 String message = "sample message: " + _count++; 37 38 response.setContentType("text/html"); 39 40 PrintWriter out = response.getWriter(); 41 out.println("message: " + message + "<br>"); 42 43 log.info("sending: " + message); 44 45 _sender.send(null, message); 46 47 log.info("complete send"); 48 49 out.println("received message: " + MyListener.getLastMessage() + "<br>"); 50 } 51 } 52 | Popular Tags |