Example usage for org.json JSONException getCause

List of usage examples for org.json JSONException getCause

Introduction

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

Prototype

public Throwable getCause() 

Source Link

Usage

From source file:com.ibm.iot.android.iotstarter.utils.MqttHandler.java

/**
 * Process incoming messages to the MQTT client.
 *
 * @param topic       The topic the message was received on.
 * @param mqttMessage The message that was received
 * @throws Exception  Exception that is thrown if the message is to be rejected.
 *///www. j  a v a  2 s .c o m
@Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
    Log.d(TAG, ".messageArrived() entered");

    int receiveCount = app.getReceiveCount();
    app.setReceiveCount(++receiveCount);
    String runningActivity = app.getCurrentRunningActivity();
    if (runningActivity != null && runningActivity.equals(IoTFragment.class.getName())) {
        Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT);
        actionIntent.putExtra(Constants.INTENT_DATA, Constants.INTENT_DATA_RECEIVED);
        context.sendBroadcast(actionIntent);
    }

    String payload = new String(mqttMessage.getPayload());
    Log.d(TAG, ".messageArrived - Message received on topic " + topic + ": message is " + payload);
    // TODO: Process message
    try {
        // send the message through the application logic
        MessageConductor.getInstance(context).steerMessage(payload, topic);
    } catch (JSONException e) {
        Log.e(TAG, ".messageArrived() - Exception caught while steering a message", e.getCause());
        e.printStackTrace();
    }
}

From source file:org.openqa.selenium.safari.SafariDriverCommandExecutor.java

@Override
public synchronized Response execute(Command command) {
    if (!server.isRunning() && DriverCommand.QUIT.equals(command.getName())) {
        Response itsOkToQuitMultipleTimes = new Response();
        itsOkToQuitMultipleTimes.setStatus(ErrorCodes.SUCCESS);
        return itsOkToQuitMultipleTimes;
    }//from   w ww.  ja v a 2 s.c  om

    checkState(connection != null, "Executor has not been started yet");

    // On quit(), the SafariDriver's browser extension simply returns a stub success
    // response, so we can short-circuit the process and just return that here.
    // The SafarIDriver's browser extension doesn't do anything on qu
    // There's no need to wait for a response when quitting.
    if (DriverCommand.QUIT.equals(command.getName())) {
        Response response = new Response(command.getSessionId());
        response.setStatus(ErrorCodes.SUCCESS);
        response.setState(ErrorCodes.SUCCESS_STRING);
        return response;
    }

    try {
        SafariCommand safariCommand = new SafariCommand(command);
        String rawJsonCommand = new BeanToJsonConverter().convert(serialize(safariCommand));
        ListenableFuture<String> futureResponse = connection.send(rawJsonCommand);

        JSONObject jsonResponse = new JSONObject(futureResponse.get());
        Response response = new JsonToBeanConverter().convert(Response.class,
                jsonResponse.getJSONObject("response").toString());
        if (response.getStatus() == ErrorCodes.SUCCESS) {
            checkArgument(safariCommand.getId().equals(jsonResponse.getString("id")),
                    "Response ID<%s> does not match command ID<%s>", jsonResponse.getString("id"),
                    safariCommand.getId());
        }

        return response;
    } catch (JSONException e) {
        throw new JsonException(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new WebDriverException(e);
    } catch (ExecutionException e) {
        throw Throwables.propagate(e.getCause());
    }
}

From source file:com.ibm.pickmeup.utils.MqttHandler.java

@Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
    Log.d(TAG, ".messageArrived() entered");
    String payload = new String(mqttMessage.getPayload());
    Log.d(TAG, ".messageArrived - Message received on topic " + topic + ": message is " + payload);
    try {//from w  w w .j ava  2 s  . c  o m
        // send the message through the application logic
        MessageConductor.getInstance(context).steerMessage(payload, topic);
    } catch (JSONException e) {
        Log.e(TAG, ".messageArrived() - Exception caught while steering a message", e.getCause());
        e.printStackTrace();
    }
}

From source file:com.ibm.iot.android.iotstarter.utils.MyIoTCallbacks.java

/**
 * Process incoming messages to the MQTT client.
 *
 * @param topic       The topic the message was received on.
 * @param mqttMessage The message that was received
 * @throws Exception  Exception that is thrown if the message is to be rejected.
 *///from w w  w. j a va  2  s . c  om
@Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
    Log.d(TAG, ".messageArrived() entered");

    int receiveCount = app.getReceiveCount();
    app.setReceiveCount(++receiveCount);
    //String runningActivity = app.getCurrentRunningActivity();
    //if (runningActivity != null && runningActivity.equals(IoTPagerFragment.class.getName())) {
    Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT);
    actionIntent.putExtra(Constants.INTENT_DATA, Constants.INTENT_DATA_RECEIVED);
    context.sendBroadcast(actionIntent);
    //}

    String payload = new String(mqttMessage.getPayload());
    Log.d(TAG, ".messageArrived - Message received on topic " + topic + ": message is " + payload);
    // TODO: Process message
    try {
        // send the message through the application logic
        MessageConductor.getInstance(context).steerMessage(payload, topic);
    } catch (JSONException e) {
        Log.e(TAG, ".messageArrived() - Exception caught while steering a message", e.getCause());
        e.printStackTrace();
    }
}

From source file:tech.salroid.filmy.tmdb_account.AddRating.java

private void parseMarkedResponse(JSONObject response) {

    try {//from  ww  w.  j  a  v a2  s.  c  o m
        int status_code = response.getInt("status_code");

        if (status_code == 1) {

            CustomToast.show(context, "Your rating has been added.", false);

            mBuilder.setContentText("Movie rating done.")
                    // Removes the progress bar
                    .setProgress(0, 0, false);
            mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
            mNotifyManager.cancel(NOTIFICATION_ID);

        } else if (status_code == 12) {

            CustomToast.show(context, "Rating updated.", false);

            mBuilder.setContentText("Rating updated.")
                    // Removes the progress bar
                    .setProgress(0, 0, false);
            mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
            mNotifyManager.cancel(NOTIFICATION_ID);
        }

    } catch (JSONException e) {
        Log.d("webi", e.getCause().toString());

        mBuilder.setContentText("Can't add rating.")
                // Removes the progress bar
                .setProgress(0, 0, false);
        mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
        mNotifyManager.cancel(NOTIFICATION_ID);

        CustomToast.show(context, "Can't add rating.", false);
    }

}

From source file:com.googlecode.jsfFlex.phaseListener.ObjectServiceRequestDataRetrieverFlusher.java

@Override
void retrieveFlushData(FacesContext context, String componentId, String methodToInvoke)
        throws ServletException, IOException {

    JSONObject methodResult = null;/*  w  w w.j  a va 2 s  .c  om*/

    try {
        methodResult = JSONObject.class
                .cast(invokeResourceMethod(context, componentId, methodToInvoke, null, null));
    } catch (Exception methodInvocationException) {
        throw new ServletException(methodInvocationException);
    }

    HttpServletResponse response = HttpServletResponse.class.cast(context.getExternalContext().getResponse());
    response.setContentType(XML_CONTENT_TYPE);

    StringBuilder responseContent = new StringBuilder();
    responseContent.append(XML_HEAD);

    try {
        responseContent.append(JSONConverter.convertJSONObjectToXMLString(methodResult));
    } catch (JSONException jsonException) {
        throw new ServletException(ERROR_CONVERTING_JSON_OBJECT_TO_XML, jsonException.getCause());
    }

    _log.info("Flushing content : " + responseContent.toString());

    Writer writer = response.getWriter();
    writer.write(responseContent.toString());
    writer.flush();

}

From source file:tech.salroid.filmy.tmdb_account.UnMarkingWatchList.java

private void parseMarkedResponse(JSONObject response) {

    if (listener != null)
        listener.unmarked(position);//from  w  w  w .  j  a  v a2 s . c  om

    try {
        int status_code = response.getInt("status_code");

        if (status_code == 13) {
            CustomToast.show(context, "Movie removed from watchlist.", false);
        } else {
            CustomToast.show(context, "Can't remove from watchlist.", false);
        }

    } catch (JSONException e) {
        Log.d("webi", e.getCause().toString());
        CustomToast.show(context, "Can't remove from watchlist.", false);
    }

}

From source file:com.soomla.util.JSONFactory.java

public T create(JSONObject jsonObject, String packageName) {

    if (jsonObject == null) {
        // warn//from  ww w  .  jav  a2s.c o m
        return null;
    }

    T t = null;
    try {
        //            SoomlaUtils.LogDebug(TAG, jsonObject.toString());
        String className = jsonObject.getString(com.soomla.data.JSONConsts.SOOM_CLASSNAME);
        Class<? extends T> clazz = (Class<? extends T>) Class.forName(packageName + "." + className);
        SoomlaUtils.LogDebug(TAG, "creating with: " + packageName + "." + className);
        if (clazz != null) {
            final Constructor<? extends T> jsonCtor = clazz.getDeclaredConstructor(JSONObject.class);
            t = jsonCtor.newInstance(jsonObject);
        } else {
            SoomlaUtils.LogError(TAG, "unknown class name:" + className);
        }

    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG, "fromJSONObject JSONException:" + e.getMessage());
    } catch (InstantiationException e) {
        SoomlaUtils.LogError(TAG, "fromJSONObject InstantiationException:" + e.getMessage());
    } catch (IllegalAccessException e) {
        SoomlaUtils.LogError(TAG, "fromJSONObject IllegalAccessException:" + e.getMessage());
    } catch (NoSuchMethodException e) {
        SoomlaUtils.LogError(TAG, "fromJSONObject no JSONObject constructor found:" + e.getMessage());
    } catch (InvocationTargetException e) {
        SoomlaUtils.LogError(TAG, "fromJSONObject InvocationTargetException:" + e.getMessage());
        SoomlaUtils.LogError(TAG, "fromJSONObject InvocationTargetException[cause]:" + e.getCause());
    } catch (ClassNotFoundException e) {
        SoomlaUtils.LogError(TAG, "fromJSONObject ClassNotFoundException:" + e.getMessage());
    }

    return t;
}

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static void handleJSONException(final JSONException e) throws ApiException {
    if (AppContext.DEBUG) {
        Log.e(ApiParser.TAG, e.getMessage());
    }/*from  w  w  w .  j a  v a  2  s  . c o m*/
    throw new ApiException(ResponseCode.ERROR_JSON_EXCEPTION, e.getMessage(), e.getCause());
}

From source file:com.imaginea.mongodb.controllers.TroubleShootController.java

/**
 * Handles a GET Request at path mViewer/admin for changing the logger level
 *
 * @param request  Request made by user/*from ww  w  .  ja  v  a 2s.  c om*/
 * @param response
 * @throws ServletException ,IOException,IllegalArgumentException
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, IllegalArgumentException {

    response.setContentType("application/x-json");
    PrintWriter out = response.getWriter();
    JSONObject respObj = new JSONObject();

    String loggerLevel = request.getParameter("level");

    try {

        if (!logLevels.containsKey(loggerLevel)) {
            JSONObject error = new JSONObject();
            error.put("code", ErrorCodes.LOGGING_LEVEL_UNDEFINED);
            error.put("message", "Undefined Logging level");
            JSONObject temp = new JSONObject();
            temp.put("error", error);
            respObj.put("response", temp);

        } else {

            Level newLevel = logLevels.get(loggerLevel);

            Logger rootLogger = LogManager.getRootLogger(); // To get the
            // Root Logger

            String oldLevel = rootLogger.getEffectiveLevel().toString();
            rootLogger.setLevel(newLevel);

            JSONObject temp = new JSONObject();
            temp.put("result", "Logger Level Changed from " + oldLevel + " to " + rootLogger.getLevel());
            respObj.put("response", temp);
        }
        out.write(respObj.toString());
        out.close();
    } catch (JSONException e) {
        throw new ServletException("Error forming JSON Object in Servlet", e.getCause());
    }

}