01: package org.claros.chat.ajax;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05:
06: import javax.servlet.ServletException;
07: import javax.servlet.http.HttpServlet;
08: import javax.servlet.http.HttpServletRequest;
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.claros.chat.controllers.TrafficController;
12: import org.claros.chat.threads.ChatSender;
13: import org.jivesoftware.smack.XMPPConnection;
14:
15: public class Sender extends HttpServlet {
16:
17: /**
18: *
19: */
20: private static final long serialVersionUID = 6152899787081101689L;
21:
22: /**
23: * Constructor of the object.
24: */
25: public Sender() {
26: super ();
27: }
28:
29: /**
30: * The doGet method of the servlet. <br>
31: *
32: * This method is called when a form has its tag value method equals to get.
33: *
34: * @param request the request send by the client to the server
35: * @param response the response send by the server to the client
36: * @throws ServletException if an error occurred
37: * @throws IOException if an error occurred
38: */
39: public void doGet(HttpServletRequest request,
40: HttpServletResponse response) throws ServletException,
41: IOException {
42: response.setHeader("Expires", "-1");
43: response.setHeader("Pragma", "no-cache");
44: response.setHeader("Cache-control", "no-cache");
45:
46: response.setContentType("text/html");
47: PrintWriter out = response.getWriter();
48:
49: String user = request.getParameter("user");
50: String msg = request.getParameter("msg");
51:
52: msg = new String(msg.getBytes("iso-8859-9"), "utf-8");
53:
54: XMPPConnection conn = (XMPPConnection) request.getSession()
55: .getAttribute("conn");
56: if (conn != null) {
57: String xmppUser = conn.getUser();
58: if (xmppUser != null) {
59: ChatSender sender = TrafficController
60: .getSender(xmppUser);
61: sender.sendMessage(user, msg);
62: }
63: }
64: out.print("ok");
65: out.flush();
66: out.close();
67: }
68:
69: /**
70: * The doPost method of the servlet. <br>
71: *
72: * This method is called when a form has its tag value method equals to post.
73: *
74: * @param request the request send by the client to the server
75: * @param response the response send by the server to the client
76: * @throws ServletException if an error occurred
77: * @throws IOException if an error occurred
78: */
79: public void doPost(HttpServletRequest request,
80: HttpServletResponse response) throws ServletException,
81: IOException {
82: doGet(request, response);
83: }
84: }
|