Search in sources :

Example 51 with JsonObject

use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.

the class FromJsonDecoder method decodeMessage.

public IBigBlueButtonMessage decodeMessage(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (PubSubPingMessage.PUBSUB_PING.equals(messageName)) {
                Gson gson = new Gson();
                PubSubPingMessage msg = gson.fromJson(message, PubSubPingMessage.class);
                return msg;
            } else if (PubSubPongMessage.PUBSUB_PONG.equals(messageName)) {
                Gson gson = new Gson();
                PubSubPongMessage msg = gson.fromJson(message, PubSubPongMessage.class);
                return msg;
            } else if (StartCustomPollRequestMessage.START_CUSTOM_POLL_REQUEST.equals(messageName)) {
                Gson gson = new Gson();
                StartCustomPollRequestMessage msg = gson.fromJson(message, StartCustomPollRequestMessage.class);
                return msg;
            } else {
                // System.out.println("Unknown message name=[" + messageName + "]");
                return null;
            }
        }
    }
    System.out.println("Invalid message format");
    return null;
}
Also used : PubSubPongMessage(org.bigbluebutton.common.messages.PubSubPongMessage) PubSubPingMessage(org.bigbluebutton.common.messages.PubSubPingMessage) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) StartCustomPollRequestMessage(org.bigbluebutton.common.messages.StartCustomPollRequestMessage) JsonParser(com.google.gson.JsonParser)

Example 52 with JsonObject

use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.

the class AllowUserToShareDesktopReply method fromJson.

public static AllowUserToShareDesktopReply fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (NAME.equals(messageName)) {
                if (payload.has(TIMESTAMP) && payload.has(MEETING_ID) && payload.has(USER_ID) && payload.has(ALLOWED)) {
                    Long timestamp = payload.get(TIMESTAMP).getAsLong();
                    String meetingId = payload.get(MEETING_ID).getAsString();
                    String userId = payload.get(USER_ID).getAsString();
                    Boolean allowed = payload.get(ALLOWED).getAsBoolean();
                    return new AllowUserToShareDesktopReply(meetingId, userId, allowed, timestamp);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 53 with JsonObject

use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.

the class AssignPresenterRequestMessage method fromJson.

public static AssignPresenterRequestMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (ASSIGN_PRESENTER_REQUEST.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.NEW_PRESENTER_ID) && payload.has(Constants.NEW_PRESENTER_NAME) && payload.has(Constants.ASSIGNED_BY)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String newPresenterId = payload.get(Constants.NEW_PRESENTER_ID).getAsString();
                    String newPresenterName = payload.get(Constants.NEW_PRESENTER_NAME).getAsString();
                    String assignedBy = payload.get(Constants.ASSIGNED_BY).getAsString();
                    return new AssignPresenterRequestMessage(meetingId, newPresenterId, newPresenterName, assignedBy);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 54 with JsonObject

use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.

the class GetChatHistoryReplyMessage method fromJson.

public static GetChatHistoryReplyMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (GET_CHAT_HISTORY_REPLY.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.CHAT_HISTORY) && payload.has(Constants.REQUESTER_ID)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String requesterId = payload.get(Constants.REQUESTER_ID).getAsString();
                    JsonArray history = (JsonArray) payload.get(Constants.CHAT_HISTORY);
                    Util util = new Util();
                    ArrayList<Map<String, Object>> chatHistory = util.extractChatHistory(history);
                    return new GetChatHistoryReplyMessage(meetingId, requesterId, chatHistory);
                }
            }
        }
    }
    return null;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) HashMap(java.util.HashMap) JsonParser(com.google.gson.JsonParser)

Example 55 with JsonObject

use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.

the class GetChatHistoryRequestMessage method fromJson.

public static GetChatHistoryRequestMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (GET_CHAT_HISTORY_REQUEST.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.REPLY_TO) && payload.has(Constants.REQUESTER_ID)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    String replyTo = payload.get(Constants.REPLY_TO).getAsString();
                    String requesterId = payload.get(Constants.REQUESTER_ID).getAsString();
                    return new GetChatHistoryRequestMessage(meetingId, requesterId, replyTo);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonObject (com.google.gson.JsonObject)1417 JsonElement (com.google.gson.JsonElement)389 JsonArray (com.google.gson.JsonArray)293 JsonParser (com.google.gson.JsonParser)285 JsonPrimitive (com.google.gson.JsonPrimitive)137 Gson (com.google.gson.Gson)91 Test (org.junit.Test)81 HashMap (java.util.HashMap)79 Map (java.util.Map)78 ArrayList (java.util.ArrayList)77 IOException (java.io.IOException)66 Test (org.testng.annotations.Test)61 InputStreamReader (java.io.InputStreamReader)38 JsonParseException (com.google.gson.JsonParseException)27 File (java.io.File)25 List (java.util.List)21 HttpResponse (org.apache.http.HttpResponse)21 JsonReader (com.google.gson.stream.JsonReader)19 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 InputStream (java.io.InputStream)19