package org.red5.signalling;

import org.json.JSONException;
import org.json.JSONObject;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
import java.io.IOException;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;


/**
 * 
 * @author Dmitry Bezheckov
 */

@ServerEndpoint("/ws")
public class SignalServer {
	private static final Logger log = Red5LoggerFactory.getLogger(SignalServer.class, "signalling");
	
    @OnOpen
    public void onOpen(Session session) throws IOException {
    	log.info("User connected");
        session.getBasicRemote().sendText("Ok, you are connected");
    }

    @OnMessage
    public String onMessage(String message) {
    	log.info("Got message: " + message);
    	
    	try {
			JSONObject data = new JSONObject(message);
			log.info("Id: " + data.get("ID"));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
        return message + " (from your server)";
    }

    @OnError
    public void onError(Throwable t) {
        t.printStackTrace();
    }

    @OnClose
    public void onClose(Session session) {
    	log.info("User disconnected");
    }
}

@@ -181,24 +181,26 @@
 Exception;%0D%0A
+%0D%0A
 import javax
@@ -1041,66 +1041,57 @@
 %0A%09%09%09
-// TODO Auto-generated catch block%0D%0A%09%09%09e.printStackTrac
+log.error(%22Error parsing JSON %22 + e.getMessag
 e()
+)
 ;%0D%0A%09
@@ -1221,31 +1221,45 @@
     
-    t.printStackTrac
+%09log.error(%22Error %22 + t.getMessag
 e()
+)
 ;%0D%0A 

replace printStackTrace to log.error