diff options
author | Ugnich Anton | 2012-11-04 22:49:10 +0700 |
---|---|---|
committer | Ugnich Anton | 2012-11-04 22:49:10 +0700 |
commit | 1c70f9be446a5002d33e18f344429f3b75cb3a48 (patch) | |
tree | 951e0b25ef8e124ff81e95e4ade3b84b919d1f14 /src/com/juick/jabber/ws | |
parent | 35e57155cada91682f7cf0bb9c6afa25c570e7af (diff) |
Logging
Diffstat (limited to 'src/com/juick/jabber/ws')
-rw-r--r-- | src/com/juick/jabber/ws/Main.java | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/src/com/juick/jabber/ws/Main.java b/src/com/juick/jabber/ws/Main.java index 95008259..9107c408 100644 --- a/src/com/juick/jabber/ws/Main.java +++ b/src/com/juick/jabber/ws/Main.java @@ -40,9 +40,9 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; import java.util.Iterator; import java.util.Properties; -import java.util.Vector; /** * @@ -52,9 +52,9 @@ public class Main implements XmppListener, MessageListener { Connection sql; XmppConnection xmpp; - Vector<SocketSubscribed> sockReplies = new Vector<SocketSubscribed>(); - Vector<SocketSubscribed> sockMessages = new Vector<SocketSubscribed>(); - Vector<SocketSubscribed> sockAll = new Vector<SocketSubscribed>(); + ArrayList<SocketSubscribed> sockReplies = new ArrayList<SocketSubscribed>(); + ArrayList<SocketSubscribed> sockMessages = new ArrayList<SocketSubscribed>(); + ArrayList<SocketSubscribed> sockAll = new ArrayList<SocketSubscribed>(); Selector sel; public static void main(String[] args) { @@ -83,7 +83,7 @@ public class Main implements XmppListener, MessageListener { } public void setupXmppComponent(String password) { - xmpp = new XmppConnectionComponent(new JID("ws.juick.com"), password, "127.0.0.1", 5347, false); + xmpp = new XmppConnectionComponent(new JID("", "ws.juick.com", ""), password, "127.0.0.1", 5347, false); xmpp.addListener((XmppListener) this); xmpp.addListener((MessageListener) this); xmpp.start(); @@ -114,10 +114,10 @@ public class Main implements XmppListener, MessageListener { while (true) { sel.select(); - System.out.println("ONE"); +// System.out.println("ONE"); Iterator it = sel.selectedKeys().iterator(); while (it.hasNext()) { - System.out.println("TWO"); +// System.out.println("TWO"); SelectionKey selKey = (SelectionKey) it.next(); it.remove(); if (selKey.isAcceptable()) { @@ -127,7 +127,7 @@ public class Main implements XmppListener, MessageListener { sChannel.configureBlocking(false); sChannel.register(sel, SelectionKey.OP_READ); } else if (selKey.isReadable()) { - System.out.println("THREE"); +// System.out.println("THREE"); SocketChannel sChannel = (SocketChannel) selKey.channel(); ByteBuffer buf = ByteBuffer.allocate(10240); try { @@ -140,19 +140,19 @@ public class Main implements XmppListener, MessageListener { wsHandshake(sChannel, buf); } else { System.out.println(sChannel.socket().getRemoteSocketAddress().toString() + " INVALID FRAME"); - System.out.println("FOUR"); +// System.out.println("FOUR"); sChannel.close(); selKey.cancel(); } } else { sChannel.close(); selKey.cancel(); - System.out.println("SIX"); +// System.out.println("SIX"); } } catch (IOException e) { System.err.println(e); sChannel.close(); - System.out.println("FIVE"); +// System.out.println("FIVE"); selKey.cancel(); } } @@ -201,10 +201,8 @@ public class Main implements XmppListener, MessageListener { // Cookies int UID = 0; - + String hash = null; if (hCookie != null) { - String hash = null; - String cookies[] = hCookie.split("; "); for (int i = 0; i < cookies.length; i++) { String cookie[] = cookies[i].split("=", 2); @@ -213,15 +211,12 @@ public class Main implements XmppListener, MessageListener { break; } } - if (hash != null) { UID = com.juick.server.UserQueries.getUIDbyHash(sql, hash); } } - // URL - String loc[] = hLocation.split("/"); int MID = 0; if (hLocation.equals("/my") && UID > 0) { @@ -250,7 +245,7 @@ public class Main implements XmppListener, MessageListener { return; } - System.out.println(sock.socket().getRemoteSocketAddress().toString() + " HANDSHAKE (UID=" + UID + ", MID=" + MID + ")"); + System.out.println(sock.socket().getRemoteSocketAddress().toString() + " HANDSHAKE (Hash=" + hash + "; UID = " + UID + "; MID = " + MID + ")"); Long lSecNum1 = calcSecKeyNum(hSecWebSocketKey1); Long lSecNum2 = calcSecKeyNum(hSecWebSocketKey2); @@ -347,6 +342,7 @@ public class Main implements XmppListener, MessageListener { public void onMessage(com.juick.xmpp.Message msg) { JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS); if (jmsg != null) { + System.err.println("MID=" + jmsg.MID + "; RID=" + jmsg.RID); if (jmsg.RID == 0) { onJuickMessagePost(jmsg); } else { @@ -359,15 +355,15 @@ public class Main implements XmppListener, MessageListener { String json = "{" + "\"mid\":" + jmsg.MID + "," + "\"user\":{" + "\"uid\":" + jmsg.User.UID + "," + "\"uname\":\"" + encloseJSON(jmsg.User.UName) + "\"}," - + "\"timestamp\":\"" + jmsg.Timestamp + "\"," + + "\"timestamp\":\"" + jmsg.TimestampString + "\"," + "\"body\":\"" + encloseJSON(jmsg.Text) + "\""; - if (jmsg.tags.size() > 0) { + if (jmsg.Tags.size() > 0) { json += ",\"tags\":["; - for (int i = 0; i < jmsg.tags.size(); i++) { + for (int i = 0; i < jmsg.Tags.size(); i++) { if (i > 0) { json += ","; } - json += "\"" + encloseJSON((String) jmsg.tags.get(i)) + "\""; + json += "\"" + encloseJSON((String) jmsg.Tags.get(i)) + "\""; } json += "]"; } @@ -453,6 +449,7 @@ public class Main implements XmppListener, MessageListener { try { out.rewind(); ss.sock.write(out); + System.err.println(" --->" + ss.sock.socket().getRemoteSocketAddress()); } catch (IOException e) { sockAll.remove(i); try { @@ -463,8 +460,6 @@ public class Main implements XmppListener, MessageListener { } } - - } private void onJuickMessageReply(com.juick.Message jmsg) { @@ -473,7 +468,7 @@ public class Main implements XmppListener, MessageListener { + "\"rid\":" + jmsg.RID + "," + "\"replyto\":" + jmsg.ReplyTo + "," + "\"user\":{" + "\"uid\":" + jmsg.User.UID + "," + "\"uname\":\"" + encloseJSON(jmsg.User.UName) + "\"}," - + "\"timestamp\":\"" + jmsg.Timestamp + "\"," + + "\"timestamp\":\"" + jmsg.TimestampString + "\"," + "\"body\":\"" + encloseJSON(jmsg.Text) + "\"" + "}"; @@ -489,6 +484,7 @@ public class Main implements XmppListener, MessageListener { try { out.rewind(); ss.sock.write(out); + System.err.println(" --->" + ss.sock.socket().getRemoteSocketAddress()); } catch (IOException e) { sockReplies.remove(i); try { |