Search in sources :

Example 66 with JsonParser

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

the class MeetingClientMessageSender method handleMeetingMessage.

public void handleMeetingMessage(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();
            switch(messageName) {
                case DisconnectUserMessage.DISCONNECT_USER:
                    DisconnectUserMessage m = DisconnectUserMessage.fromJson(message);
                    if (m != null) {
                        processDisconnectUserMessage(m);
                    }
                    break;
                case DisconnectAllUsersMessage.DISCONNECT_All_USERS:
                    DisconnectAllUsersMessage daum = DisconnectAllUsersMessage.fromJson(message);
                    if (daum != null) {
                        processDisconnectAllUsersMessage(daum);
                    }
                    break;
                case MeetingEndedMessage.MEETING_ENDED:
                    MeetingEndedMessage mem = MeetingEndedMessage.fromJson(message);
                    if (mem != null) {
                        processMeetingEndedMessage(mem);
                    }
                    break;
                case MeetingEndingMessage.MEETING_ENDING:
                    MeetingEndingMessage me = MeetingEndingMessage.fromJson(message);
                    if (me != null) {
                        processMeetingEndingMessage(me);
                    }
                    break;
                case MeetingHasEndedMessage.MEETING_HAS_ENDED:
                    MeetingHasEndedMessage mhem = MeetingHasEndedMessage.fromJson(message);
                    if (mhem != null) {
                        processMeetingHasEndedMessage(mhem);
                    }
                    break;
                case MeetingStateMessage.MEETING_STATE:
                    MeetingStateMessage msm = MeetingStateMessage.fromJson(message);
                    if (msm != null) {
                        processMeetingStateMessage(msm);
                    }
                    break;
                case NewPermissionsSettingMessage.NEW_PERMISSIONS_SETTING:
                    NewPermissionsSettingMessage npsm = NewPermissionsSettingMessage.fromJson(message);
                    if (npsm != null) {
                        processNewPermissionsSettingMessage(npsm);
                    }
                    break;
                case MeetingMutedMessage.MEETING_MUTED:
                    MeetingMutedMessage mmm = MeetingMutedMessage.fromJson(message);
                    if (mmm != null) {
                        processMeetingMutedMessage(mmm);
                    }
                    break;
                case UserLockedMessage.USER_LOCKED:
                    UserLockedMessage ulm = UserLockedMessage.fromJson(message);
                    if (ulm != null) {
                        processUserLockedMessage(ulm);
                    }
                    break;
            }
        }
    }
}
Also used : DisconnectAllUsersMessage(org.bigbluebutton.common.messages.DisconnectAllUsersMessage) MeetingEndingMessage(org.bigbluebutton.common.messages.MeetingEndingMessage) MeetingHasEndedMessage(org.bigbluebutton.common.messages.MeetingHasEndedMessage) DisconnectUserMessage(org.bigbluebutton.common.messages.DisconnectUserMessage) MeetingEndedMessage(org.bigbluebutton.common.messages.MeetingEndedMessage) MeetingMutedMessage(org.bigbluebutton.common.messages.MeetingMutedMessage) MeetingStateMessage(org.bigbluebutton.common.messages.MeetingStateMessage) JsonObject(com.google.gson.JsonObject) UserLockedMessage(org.bigbluebutton.common.messages.UserLockedMessage) NewPermissionsSettingMessage(org.bigbluebutton.common.messages.NewPermissionsSettingMessage) JsonParser(com.google.gson.JsonParser)

Example 67 with JsonParser

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

the class PollingClientMessageSender method handlePollMessage.

public void handlePollMessage(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();
            switch(messageName) {
                case PollStartedMessage.POLL_STARTED:
                    processPollStartedMessage(message);
                    break;
                case PollStoppedMessage.POLL_STOPPED:
                    processPollStoppedMessage(message);
                    break;
                case PollShowResultMessage.POLL_SHOW_RESULT:
                    processPollShowResultMessage(message);
                    break;
                case UserVotedPollMessage.USER_VOTED_POLL:
                    processUserVotedPollMessage(message);
                    break;
            }
        }
    }
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 68 with JsonParser

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

the class CaptionClientMessageSender method handleCaptionMessage.

public void handleCaptionMessage(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();
            switch(messageName) {
                case SendCaptionHistoryReplyMessage.SEND_CAPTION_HISTORY_REPLY:
                    SendCaptionHistoryReplyMessage sch = SendCaptionHistoryReplyMessage.fromJson(message);
                    if (sch != null) {
                        processSendCaptionHistoryReplyMessage(sch);
                    }
                    break;
                case UpdateCaptionOwnerMessage.UPDATE_CAPTION_OWNER:
                    UpdateCaptionOwnerMessage uco = UpdateCaptionOwnerMessage.fromJson(message);
                    if (uco != null) {
                        processUpdateCaptionOwnerMessage(uco);
                    }
                    break;
                case EditCaptionHistoryMessage.EDIT_CAPTION_HISTORY:
                    EditCaptionHistoryMessage ech = EditCaptionHistoryMessage.fromJson(message);
                    if (ech != null) {
                        processEditCaptionHistoryMessage(ech);
                    }
                    break;
            }
        }
    }
}
Also used : UpdateCaptionOwnerMessage(org.bigbluebutton.common.messages.UpdateCaptionOwnerMessage) JsonObject(com.google.gson.JsonObject) SendCaptionHistoryReplyMessage(org.bigbluebutton.common.messages.SendCaptionHistoryReplyMessage) EditCaptionHistoryMessage(org.bigbluebutton.common.messages.EditCaptionHistoryMessage) JsonParser(com.google.gson.JsonParser)

Example 69 with JsonParser

use of com.google.gson.JsonParser in project iosched by google.

the class RemoteJsonHelper method fetchJsonFromPublicURL.

public static JsonObject fetchJsonFromPublicURL(String urlStr) throws IOException {
    URL url = new URL(urlStr);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    // 30 seconds
    connection.setReadTimeout(1000 * 30);
    int response = connection.getResponseCode();
    if (response < 200 || response >= 300) {
        throw new IllegalArgumentException("Unexpected HTTP response [" + response + "] at URL: " + urlStr);
    }
    InputStream stream = connection.getInputStream();
    JsonReader reader = new JsonReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
    return (JsonObject) new JsonParser().parse(reader);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JsonReader(com.google.gson.stream.JsonReader) JsonObject(com.google.gson.JsonObject) URL(java.net.URL) JsonParser(com.google.gson.JsonParser)

Example 70 with JsonParser

use of com.google.gson.JsonParser in project iosched by google.

the class VendorAPIEntityFetcher method fetch.

@Override
public JsonElement fetch(Enum<?> entityType, Map<String, String> params) throws IOException {
    StringBuilder urlStr = new StringBuilder(BASE_URL);
    urlStr.append(entityType.name());
    if (params != null && !params.isEmpty()) {
        urlStr.append("?");
        for (Map.Entry<String, String> param : params.entrySet()) {
            urlStr.append(param.getKey()).append("=").append(param.getValue()).append("&");
        }
        urlStr.deleteCharAt(urlStr.length() - 1);
    }
    URL url = new URL(urlStr.toString());
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("URL requested: " + url);
    }
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    // 30 seconds
    connection.setReadTimeout(1000 * 30);
    connection.setRequestProperty("code", Config.CMS_API_CODE);
    connection.setRequestProperty("apikey", Config.CMS_API_KEY);
    InputStream stream = connection.getInputStream();
    JsonReader reader = new JsonReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
    return new JsonParser().parse(reader);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JsonReader(com.google.gson.stream.JsonReader) Map(java.util.Map) URL(java.net.URL) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonParser (com.google.gson.JsonParser)356 JsonObject (com.google.gson.JsonObject)285 JsonElement (com.google.gson.JsonElement)105 JsonArray (com.google.gson.JsonArray)57 IOException (java.io.IOException)43 Gson (com.google.gson.Gson)40 InputStreamReader (java.io.InputStreamReader)32 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 Map (java.util.Map)18 Type (java.lang.reflect.Type)15 JsonReader (com.google.gson.stream.JsonReader)12 Test (org.junit.Test)12 URL (java.net.URL)11 AssetManager (android.content.res.AssetManager)10 InputStream (java.io.InputStream)10 GsonBuilder (com.google.gson.GsonBuilder)9 UserType (com.glitchcog.fontificator.bot.UserType)8 EmojiType (com.glitchcog.fontificator.emoji.EmojiType)8 JsonParseException (com.google.gson.JsonParseException)8