Example usage for org.json JSONException getMessage

List of usage examples for org.json JSONException getMessage

Introduction

In this page you can find the example usage for org.json JSONException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.baroq.pico.google.PlayServices.java

@Override
public void onPlayersLoaded(int statusCode, PlayerBuffer buffer) {
    JSONObject json = new JSONObject();
    try {/*  www.  j  a  v a2 s .c  o  m*/
        json.put("type", PLAYER_LOADED);
        json.put("statusCode", statusCode);
        switch (statusCode) {
        case GamesClient.STATUS_OK:
            // if data was successfully loaded and is up-to-date.
            JSONArray players = new JSONArray();
            JSONObject player;
            for (int i = 0, l = buffer.getCount(); i < l; i++) {
                Player p = buffer.get(i);
                player = new JSONObject();
                player.put("displayName", p.getDisplayName());
                if (p.hasHiResImage()) {
                    Uri uri = p.getHiResImageUri();
                    player.put("hiResImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                }
                if (p.hasIconImage()) {
                    Uri uri = p.getIconImageUri();
                    player.put("iconImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                }
                player.put("playerId", p.getPlayerId());
                player.put("retrievedTimestamp", p.getRetrievedTimestamp());
                players.put(player);
            }
            json.put("list", players);
            break;
        case GamesClient.STATUS_INTERNAL_ERROR:
            // if an unexpected error occurred in the service 
            break;
        case GamesClient.STATUS_NETWORK_ERROR_STALE_DATA:
            // if the device was unable to communicate with the network. In this case, the operation is not retried automatically.
            break;
        case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
            // need to reconnect GamesClient
            mHelper.reconnectClients(clientTypes);
            break;
        case GamesClient.STATUS_LICENSE_CHECK_FAILED:
            // The game is not licensed to the user. Further calls will return the same code.
            break;
        default:
            // error
            break;
        }
    } catch (JSONException ex) {
        Log.e(TAG, "PLAYER_LOADED [" + statusCode + "] exception: " + ex.getMessage());
        return;
    }

    buffer.close();
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
    pluginResult.setKeepCallback(true);
    connectionCB.sendPluginResult(pluginResult);
}

From source file:com.baroq.pico.google.PlayServices.java

@Override
public void onAchievementsLoaded(int statusCode, AchievementBuffer buffer) {
    JSONObject json = new JSONObject();
    try {/*  www  .  j  a  v a 2 s  .  co  m*/
        json.put("type", GAME_ACHIEVEMENT_LOADED);
        json.put("statusCode", statusCode);
        switch (statusCode) {
        case GamesClient.STATUS_OK:
            // if data was successfully loaded and is up-to-date
            JSONArray achievements = new JSONArray();
            JSONObject achievement;
            Achievement a;
            for (int i = 0, l = buffer.getCount(); i < l; i++) {
                a = buffer.get(i);
                achievement = new JSONObject();
                achievement.put("achievementId", a.getAchievementId());
                achievement.put("description", a.getDescription());
                achievement.put("lastUpdatedTimestamp", a.getLastUpdatedTimestamp());
                achievement.put("name", a.getName());
                achievement.put("achievementId", a.getPlayer().getPlayerId());
                achievement.put("state", a.getState());
                achievement.put("type", a.getType());
                if (Achievement.TYPE_INCREMENTAL == a.getType()) {
                    achievement.put("currentSteps", a.getCurrentSteps());
                    achievement.put("totalSteps", a.getTotalSteps());
                    achievement.put("formattedCurrentSteps", a.getFormattedCurrentSteps());
                    achievement.put("formattedTotalSteps", a.getFormattedTotalSteps());
                }
                Uri uri = a.getRevealedImageUri();
                if (null != uri)
                    achievement.put("revealedImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                uri = a.getUnlockedImageUri();
                if (null != uri)
                    achievement.put("unlockedImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                achievements.put(achievement);
            }
            json.put("list", achievements);
            break;
        case GamesClient.STATUS_NETWORK_ERROR_NO_DATA:
            // A network error occurred while attempting to retrieve fresh data, and no data was available locally.
            break;
        case GamesClient.STATUS_INTERNAL_ERROR:
            // if an unexpected error occurred in the service 
            break;
        case GamesClient.STATUS_NETWORK_ERROR_STALE_DATA:
            // if the device was unable to communicate with the network. In this case, the operation is not retried automatically.
            break;
        case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
            // need to reconnect GamesClient
            mHelper.reconnectClients(clientTypes);
            break;
        case GamesClient.STATUS_LICENSE_CHECK_FAILED:
            // The game is not licensed to the user. Further calls will return the same code.
            break;
        default:
            // error
            break;
        }
    } catch (JSONException ex) {
        Log.e(TAG, "GAME_ACHIEVEMENT_LOADED [" + statusCode + "] exception: " + ex.getMessage());
        return;
    }

    buffer.close();
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
    pluginResult.setKeepCallback(true);
    connectionCB.sendPluginResult(pluginResult);
}

From source file:com.baroq.pico.google.PlayServices.java

@Override
public void onAchievementUpdated(int statusCode, String achievementId) {
    JSONObject json = new JSONObject();
    try {//from   w w w . j  av  a2 s.c o m
        json.put("type", GAME_ACHIEVEMENT_UPDATED);
        json.put("statusCode", statusCode);
        switch (statusCode) {
        case GamesClient.STATUS_OK:
            // if data was successfully loaded and is up-to-date 
            json.put("achievementId", achievementId);
            break;
        case GamesClient.STATUS_NETWORK_ERROR_NO_DATA:
            // A network error occurred while attempting to retrieve fresh data, and no data was available locally.
            break;
        case GamesClient.STATUS_INTERNAL_ERROR:
            // if an unexpected error occurred in the service 
            break;
        case GamesClient.STATUS_NETWORK_ERROR_STALE_DATA:
            // if the device was unable to communicate with the network. In this case, the operation is not retried automatically.
            break;
        case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
            // need to reconnect GamesClient
            mHelper.reconnectClients(clientTypes);
            break;
        case GamesClient.STATUS_LICENSE_CHECK_FAILED:
            // The game is not licensed to the user. Further calls will return the same code.
            break;
        default:
            // error
            break;
        }
    } catch (JSONException ex) {
        Log.e(TAG, "GAME_ACHIEVEMENT_UPDATED [" + statusCode + "] exception: " + ex.getMessage());
        return;
    }

    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
    pluginResult.setKeepCallback(true);
    connectionCB.sendPluginResult(pluginResult);
}

From source file:com.baroq.pico.google.PlayServices.java

@Override
public void onLeaderboardMetadataLoaded(int statusCode, LeaderboardBuffer leaderboard) {
    JSONObject json = new JSONObject();
    try {// ww w  . j  ava2s  .com
        json.put("type", GAME_LEADERBOARD_METADATA_LOADED);
        json.put("statusCode", statusCode);
        switch (statusCode) {
        case GamesClient.STATUS_OK:
            // if data was successfully loaded and is up-to-date.
            JSONArray list = new JSONArray();
            JSONObject obj;
            JSONArray vList;
            JSONObject v;
            Leaderboard lb;
            ArrayList<LeaderboardVariant> variants;
            LeaderboardVariant variant;
            int i, l, j, k;
            for (i = 0, l = leaderboard.getCount(); i < l; i++) {
                obj = new JSONObject();
                lb = leaderboard.get(i);
                obj.put("displayName", lb.getDisplayName());
                Uri uri = lb.getIconImageUri();
                if (null != uri)
                    obj.put("iconImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                obj.put("leaderboardId", lb.getLeaderboardId());
                obj.put("scoreOrder", lb.getScoreOrder());
                variants = lb.getVariants();
                vList = new JSONArray();
                for (j = 0, k = variants.size(); j < k; j++) {
                    v = new JSONObject();
                    variant = variants.get(i);
                    v.put("collection", variant.getCollection());
                    v.put("numScores", variant.getNumScores());
                    v.put("timeSpan", variant.getTimeSpan());
                    v.put("hasPlayerInfo", variant.hasPlayerInfo());
                    if (variant.hasPlayerInfo()) {
                        v.put("displayPlayerRank", variant.getDisplayPlayerRank());
                        v.put("displayPlayerScore", variant.getDisplayPlayerScore());
                        v.put("playerRank", variant.getPlayerRank());
                        v.put("rawPlayerScore", variant.getRawPlayerScore());
                    }
                    vList.put(v);
                    obj.put("variants", vList);
                }
                list.put(obj);
            }
            json.put("leaderboard", list);
            break;
        case GamesClient.STATUS_INTERNAL_ERROR:
            // if an unexpected error occurred in the service 
            break;
        case GamesClient.STATUS_NETWORK_ERROR_STALE_DATA:
            // if the device was unable to communicate with the network. in this case, the operation is not retried automatically.
            break;
        case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
            // need to reconnect GamesClient
            mHelper.reconnectClients(clientTypes);
            break;
        case GamesClient.STATUS_LICENSE_CHECK_FAILED:
            // the game is not licensed to the user. further calls will return the same code.
            break;
        default:
            // error
            break;
        }
    } catch (JSONException ex) {
        Log.e(TAG, "game_leaderboard_scores_loaded [" + statusCode + "] exception: " + ex.getMessage());
        return;
    }

    leaderboard.close();
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
    pluginResult.setKeepCallback(true);
    connectionCB.sendPluginResult(pluginResult);
}

From source file:com.baroq.pico.google.PlayServices.java

@Override
public void onLeaderboardScoresLoaded(int statusCode, LeaderboardBuffer leaderboard,
        LeaderboardScoreBuffer scores) {
    JSONObject json = new JSONObject();
    try {//from w ww .j a v  a2s. com
        json.put("type", GAME_LEADERBOARD_SCORES_LOADED);
        json.put("statusCode", statusCode);
        switch (statusCode) {
        case GamesClient.STATUS_OK:
            // if data was successfully loaded and is up-to-date.
            JSONArray list = new JSONArray();
            JSONObject obj;
            JSONArray vList;
            JSONObject v;
            Leaderboard lb;
            ArrayList<LeaderboardVariant> variants;
            LeaderboardVariant variant;
            int i, l, j, k;
            for (i = 0, l = leaderboard.getCount(); i < l; i++) {
                obj = new JSONObject();
                lb = leaderboard.get(i);
                obj.put("displayName", lb.getDisplayName());
                Uri uri = lb.getIconImageUri();
                if (null != uri)
                    obj.put("iconImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                obj.put("leaderboardId", lb.getLeaderboardId());
                obj.put("scoreOrder", lb.getScoreOrder());
                variants = lb.getVariants();
                vList = new JSONArray();
                for (j = 0, k = variants.size(); j < k; j++) {
                    v = new JSONObject();
                    variant = variants.get(i);
                    v.put("collection", variant.getCollection());
                    v.put("numScores", variant.getNumScores());
                    v.put("timeSpan", variant.getTimeSpan());
                    v.put("hasPlayerInfo", variant.hasPlayerInfo());
                    if (variant.hasPlayerInfo()) {
                        v.put("displayPlayerRank", variant.getDisplayPlayerRank());
                        v.put("displayPlayerScore", variant.getDisplayPlayerScore());
                        v.put("playerRank", variant.getPlayerRank());
                        v.put("rawPlayerScore", variant.getRawPlayerScore());
                    }
                    vList.put(v);
                    obj.put("variants", vList);
                }
                list.put(obj);
            }
            json.put("leaderboard", list);
            LeaderboardScore lbs;
            for (i = 0, l = scores.getCount(); i < l; i++) {
                obj = new JSONObject();
                lbs = scores.get(i);
                obj.put("displayRank", lbs.getDisplayRank());
                obj.put("displayScore", lbs.getDisplayScore());
                obj.put("rank", lbs.getRank());
                obj.put("rawScore", lbs.getRawScore());
                obj.put("scoreHolderPlayerId", lbs.getScoreHolder().getPlayerId());
                obj.put("scoreHolderDisplayName", lbs.getScoreHolderDisplayName());
                Uri uri = lbs.getScoreHolderHiResImageUri();
                if (null != uri)
                    obj.put("scoreHolderHiResImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                uri = lbs.getScoreHolderIconImageUri();
                if (null != uri)
                    obj.put("scoreHolderIconImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
                obj.put("timestampMillis", lbs.getTimestampMillis());
                list.put(obj);
            }
            json.put("scores", list);
            break;
        case GamesClient.STATUS_INTERNAL_ERROR:
            // if an unexpected error occurred in the service 
            break;
        case GamesClient.STATUS_NETWORK_ERROR_STALE_DATA:
            // if the device was unable to communicate with the network. in this case, the operation is not retried automatically.
            break;
        case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
            // need to reconnect GamesClient
            mHelper.reconnectClients(clientTypes);
            break;
        case GamesClient.STATUS_LICENSE_CHECK_FAILED:
            // the game is not licensed to the user. further calls will return the same code.
            break;
        default:
            // error
            break;
        }
    } catch (JSONException ex) {
        Log.e(TAG, "game_leaderboard_scores_loaded [" + statusCode + "] exception: " + ex.getMessage());
        return;
    }

    leaderboard.close();
    scores.close();
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
    pluginResult.setKeepCallback(true);
    connectionCB.sendPluginResult(pluginResult);
}

From source file:com.baroq.pico.google.PlayServices.java

@Override
public void onScoreSubmitted(int statusCode, SubmitScoreResult result) {
    JSONObject json = new JSONObject();
    try {//from w ww .j  av  a 2 s.com
        json.put("type", GAME_SCORES_SUBMITTED);
        json.put("statusCode", statusCode);
        switch (statusCode) {
        case GamesClient.STATUS_OK:
            // if data was successfully loaded and is up-to-date.
            json.put("leaderboardId", result.getLeaderboardId());
            json.put("playerId", result.getPlayerId());
            json.put("resultStatusCode", result.getStatusCode());
            SubmitScoreResult.Result timeResult = result.getScoreResult(LeaderboardVariant.TIME_SPAN_ALL_TIME);
            JSONObject r = new JSONObject();
            r.put("formattedScore", timeResult.formattedScore);
            r.put("newBest", timeResult.newBest);
            r.put("rawScore", timeResult.rawScore);
            json.put("timeResult", r);
            timeResult = result.getScoreResult(LeaderboardVariant.TIME_SPAN_WEEKLY);
            r = new JSONObject();
            r.put("formattedScore", timeResult.formattedScore);
            r.put("newBest", timeResult.newBest);
            r.put("rawScore", timeResult.rawScore);
            json.put("weekly", r);
            timeResult = result.getScoreResult(LeaderboardVariant.TIME_SPAN_DAILY);
            r = new JSONObject();
            r.put("formattedScore", timeResult.formattedScore);
            r.put("newBest", timeResult.newBest);
            r.put("rawScore", timeResult.rawScore);
            json.put("daily", r);
            break;
        case GamesClient.STATUS_INTERNAL_ERROR:
            // if an unexpected error occurred in the service 
            break;
        case GamesClient.STATUS_NETWORK_ERROR_OPERATION_DEFERRED:
            // if the device is offline or was otherwise unable to post the score to the server. The score was stored locally and will be posted to the server the next time the device is online and is able to perform a sync (no further action is required from the client).
            break;
        case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
            // need to reconnect GamesClient
            mHelper.reconnectClients(clientTypes);
            break;
        case GamesClient.STATUS_LICENSE_CHECK_FAILED:
            // The game is not licensed to the user. Further calls will return the same code.
            break;
        default:
            // error
            break;
        }
    } catch (JSONException ex) {
        Log.e(TAG, "GAME_SCORES_SUBMITTED [" + statusCode + "] exception: " + ex.getMessage());
        return;
    }

    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
    pluginResult.setKeepCallback(true);
    connectionCB.sendPluginResult(pluginResult);
}

From source file:com.adisayoga.earthquake.ui.SocialConnectActivity.java

/**
 * Tampilkan informasi Facebook sebagai tanda user telah login.
 *///from   w w w  .j  a  v a 2s . c o m
private void showFacebookInfo() {
    facebookLoginStatus.setText(R.string.loading);

    // Tampilkan nama user yang login
    runner.request("me", new BaseRequestListener() {
        @Override
        public void onComplete(String response, Object state) {
            try {
                Log.d(TAG, "Response: " + response.toString());
                JSONObject json = Util.parseJson(response);
                final String name = json.getString("name");

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        facebookLoginStatus.setText(getText(R.string.welcome) + " " + name);
                    }
                });

            } catch (JSONException e) {
                Log.w(TAG, "JSON Error pada response");

            } catch (FacebookError e) {
                Log.w(TAG, "Facebook Error: " + e.getMessage());
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        facebookLoginStatus.setText(R.string.facebook_error);
                    }
                });
            }
        }

        @Override
        public void onIOException(IOException e, Object state) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    facebookLoginStatus.setText(R.string.network_error);
                }
            });
            super.onIOException(e, state);
        }
    });
}

From source file:org.akvo.flow.api.parser.json.SurveyedLocaleParser.java

public SurveyedLocalesResponse parseResponse(String response) {
    final List<SurveyedLocale> surveyedLocales = new ArrayList<SurveyedLocale>();
    String error = null;//from w  ww  . j a va  2  s .  co m
    try {
        JSONObject jResponse = new JSONObject(response);
        JSONArray jSurveyedLocales = jResponse.getJSONArray(Attrs.SURVEYED_LOCALE_DATA);
        for (int i = 0; i < jSurveyedLocales.length(); i++) {
            JSONObject jSurveyedLocale = jSurveyedLocales.getJSONObject(i);
            SurveyedLocale surveyedLocale = parseSurveyedLocale(jSurveyedLocale);
            surveyedLocales.add(surveyedLocale);
        }
    } catch (JSONException e) {
        // Something went wrong in the parsing. We consider this invalid data,
        // and will stop the sync, to avoid storing corrupted data.
        PersistentUncaughtExceptionHandler.recordException(e);
        Log.e(TAG, e.getMessage(), e);
        error = "Invalid JSON response";
    }

    return new SurveyedLocalesResponse(surveyedLocales, error);
}

From source file:web.ObelixWebServer.java

/**
 * Start Obelix Web Server./*from  w ww .ja v a 2  s. com*/
 */
public final void run() {

    try {

        port(this.webPort);
        ObelixWebAuth.enableCORS("*", "*", "*");
        ObelixWebAuth.requireValidToken();

        // All users, items, relationships

        get("/*/*/*/users/all", "application/json", (request, response) -> this.graphDb.getAllUserIds(),
                new JsonTransformer());

        get("/*/*/*/items/all", "application/json", (request, response) -> this.itemsGraph.getAll(),
                new JsonTransformer());

        get("/*/*/*/relationships/all", "application/json",
                (request, response) -> this.graphDb.getRelationships(), new JsonTransformer());

        // clean the relationships for users
        get("/*/*/*/users/:userID/relationships/clean/:max", "application/json", (request,
                response) -> this.graphDb.cleanRelationships(request.params("userID"), request.params("max")));

        get("/*/*/*/users/clean-all-relationships/:max", "application/json",
                (request, response) -> this.graphDb.cleanAllRelationships(request.params("max")),
                new JsonTransformer());

        // Recommendations
        get("/*/*/*/users/:userID/relationships/:depth", "application/json", (request, response) -> this.graphDb
                .getRelationships(request.params("userID"), request.params("depth"), null, null, false),
                new JsonTransformer());

        get("/*/*/*/users/:userID/all-relationships", "application/json", (request, response) -> this.graphDb
                .getRelationships(request.params("userID"), "4", null, null, false), new JsonTransformer());

        get("/*/*/*/users/:userID/relationships/:depth/:since/:until", "application/json",
                (request, response) -> this.graphDb.getRelationships(request.params("userID"),
                        request.params("depth"), request.params("since"), request.params("until"), false),
                new JsonTransformer());

        get("/*/*/*/users/:userID/recommend/:depth", "application/json",
                (request, response) -> this.obelixRecommender.recommend(request.params("userID"),
                        request.params("depth")),
                new JsonTransformer());

        get("/*/*/*/users/:userID/recommend", "application/json", (request, response) -> this.obelixRecommender
                .recommend(request.params("userID"), recommendationDepth), new JsonTransformer());

        get("/*/*/*/users/:userID/recommend/:depth/:since/:until/:importanceFactor", "application/json",
                (request, response) -> this.obelixRecommender.recommend(request.params("userID"),
                        request.params("depth"), request.params("since"), request.params("until"),
                        request.params("importanceFactor")),
                new JsonTransformer());

        // Settings for search

        get("/*/*/*/settings", "application/json", (request, response) -> settings(), new JsonTransformer());

        exception(ObelixNodeNotFoundException.class, (e, request, response) -> {
            LOGGER.error(e.getMessage());
            response.status(STATUS_CODE_NOT_FOUND);
            response.body("User or item not found");
        });

        // Search result logger

        post("/*/*/*/log/search", (request, response) -> {
            try {
                new Jedis("localhost", REDIS_PORT_NUMBER).lpush("obelix-server::log::search::result",
                        new JSONObject(request.body()).toString());
                return "OK";
            } catch (JSONException e) {
                response.status(STATUS_CODE_NOT_FOUND);
                response.body("Bad request, we need json data");
                return response;
            }
        });

        post("/*/*/*/log/pageview", (request, response) -> {
            try {
                new Jedis("localhost", REDIS_PORT_NUMBER).lpush("obelix-server::log::page::view",
                        new JSONObject(request.body()).toString());
                return "OK";
            } catch (JSONException e) {
                response.status(STATUS_CODE_NOT_FOUND);
                response.body("Bad request, we need json data");
                return response;
            }
        });

    } catch (Exception e) {
        LOGGER.error("ObelixWebServer Exception", e);
    }
}

From source file:net.dv8tion.jda.core.requests.WebSocketClient.java

protected void handleEvent(JSONObject raw) {
    String type = raw.getString("t");
    long responseTotal = api.getResponseTotal();

    if (type.equals("GUILD_MEMBER_ADD"))
        ((GuildMembersChunkHandler) getHandler("GUILD_MEMBERS_CHUNK"))
                .modifyExpectedGuildMember(raw.getJSONObject("d").getLong("guild_id"), 1);
    if (type.equals("GUILD_MEMBER_REMOVE"))
        ((GuildMembersChunkHandler) getHandler("GUILD_MEMBERS_CHUNK"))
                .modifyExpectedGuildMember(raw.getJSONObject("d").getLong("guild_id"), -1);

    //If initiating, only allows READY, RESUMED, GUILD_MEMBERS_CHUNK, GUILD_SYNC, and GUILD_CREATE through.
    // If we are currently chunking, we don't allow GUILD_CREATE through anymore.
    if (initiating && !(type.equals("READY") || type.equals("GUILD_MEMBERS_CHUNK") || type.equals("RESUMED")
            || type.equals("GUILD_SYNC") || (!chunkingAndSyncing && type.equals("GUILD_CREATE")))) {
        //If we are currently GuildStreaming, and we get a GUILD_DELETE informing us that a Guild is unavailable
        // convert it to a GUILD_CREATE for handling.
        JSONObject content = raw.getJSONObject("d");
        if (!chunkingAndSyncing && type.equals("GUILD_DELETE") && content.has("unavailable")
                && content.getBoolean("unavailable")) {
            type = "GUILD_CREATE";
            raw.put("t", "GUILD_CREATE").put("jda-field",
                    "This event was originally a GUILD_DELETE but was converted to GUILD_CREATE for WS init Guild streaming");
        } else {/*from  w w  w  .j  a v  a 2 s  .  co  m*/
            LOG.debug("Caching " + type + " event during init!");
            cachedEvents.add(raw);
            return;
        }
    }
    //
    //        // Needs special handling due to content of "d" being an array
    //        if(type.equals("PRESENCE_REPLACE"))
    //        {
    //            JSONArray presences = raw.getJSONArray("d");
    //            LOG.trace(String.format("%s -> %s", type, presences.toString()));
    //            PresenceUpdateHandler handler = new PresenceUpdateHandler(api, responseTotal);
    //            for (int i = 0; i < presences.length(); i++)
    //            {
    //                JSONObject presence = presences.getJSONObject(i);
    //                handler.handle(presence);
    //            }
    //            return;
    //        }

    JSONObject content = raw.getJSONObject("d");
    LOG.trace(String.format("%s -> %s", type, content.toString()));

    try {
        switch (type) {
        //INIT types
        case "READY":
            //LOG.debug(String.format("%s -> %s", type, content.toString())); already logged on trace level
            processingReady = true;
            handleIdentifyRateLimit = false;
            sessionId = content.getString("session_id");
            if (!content.isNull("_trace"))
                updateTraces(content.getJSONArray("_trace"), "READY", WebSocketCode.DISPATCH);
            handlers.get("READY").handle(responseTotal, raw);
            break;
        case "RESUMED":
            if (!processingReady) {
                initiating = false;
                ready();
            }
            if (!content.isNull("_trace"))
                updateTraces(content.getJSONArray("_trace"), "RESUMED", WebSocketCode.DISPATCH);
            break;
        default:
            SocketHandler handler = handlers.get(type);
            if (handler != null)
                handler.handle(responseTotal, raw);
            else
                LOG.debug("Unrecognized event:\n" + raw);
        }
    } catch (JSONException ex) {
        LOG.warn("Got an unexpected Json-parse error. Please redirect following message to the devs:\n\t"
                + ex.getMessage() + "\n\t" + type + " -> " + content);
        LOG.log(ex);
    } catch (Exception ex) {
        LOG.log(ex);
    }
}