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:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

private void setRequestHeaders(Request request, JSONObject requestHeadersJson) {
    @SuppressWarnings("unchecked")
    Iterator<String> headersIterator = requestHeadersJson.keys();
    // Convert JSONObject of headers into Header ArrayList
    while (headersIterator.hasNext()) {
        String headerName = headersIterator.next();
        String headerValue;//w w  w. j a  v  a 2s.  c o m
        try {
            headerValue = requestHeadersJson.getString(headerName);
            logger.debug("Jetty set header " + headerName + " = " + headerValue);
            if (!headerName.equalsIgnoreCase("Content-Length")) {
                request.header(headerName, headerValue);
            }
        } catch (JSONException e) {
            logger.error("Error processing request headers: {}", e.getMessage());
        }
    }
}

From source file:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

private void handleCancelEvent(JSONObject data) {
    try {/* w ww .ja v a2  s .  co m*/
        int requestId = data.getInt("id");
        logger.debug("Received cancel for request {}", requestId);
        // Find and abort running request
        if (runningRequests.containsKey(requestId)) {
            Request request = runningRequests.get(requestId);
            request.abort(new InterruptedException());
            runningRequests.remove(requestId);
        }
    } catch (JSONException e) {
        logger.error(e.getMessage());
    }
}

From source file:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

private void handleCommandEvent(JSONObject data) {
    try {//from w w w.j  a v a 2 s  .  c om
        logger.debug("Received command " + data.getString("command") + " for item " + data.getString("item"));
        if (this.listener != null)
            this.listener.sendCommand(data.getString("item"), data.getString("command"));
    } catch (JSONException e) {
        logger.error(e.getMessage());
    }
}

From source file:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

/**
 * This method sends notification to my.openHAB
 *
 * @param userId my.openHAB user id/*from ww w  .j  a v a  2s. c o m*/
 * @param message notification message text
 * @param icon name of the icon for this notification
 * @param severity severity name for this notification
 *
 */

public void sendNotification(String userId, String message, String icon, String severity) {
    if (isConnected()) {
        JSONObject notificationMessage = new JSONObject();
        try {
            notificationMessage.put("userId", userId);
            notificationMessage.put("message", message);
            notificationMessage.put("icon", icon);
            notificationMessage.put("severity", severity);
            socket.emit("notification", notificationMessage);
        } catch (JSONException e) {
            logger.error(e.getMessage());
        }
    } else {
        logger.debug("No connection, notification is not sent");
    }
}

From source file:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

/**
 * This method sends log notification to my.openHAB
 *
 * @param message notification message text
 * @param icon name of the icon for this notification
 * @param severity severity name for this notification
 *
 *//*  ww w . jav a 2 s  . c om*/

public void sendLogNotification(String message, String icon, String severity) {
    if (isConnected()) {
        JSONObject notificationMessage = new JSONObject();
        try {
            notificationMessage.put("message", message);
            notificationMessage.put("icon", icon);
            notificationMessage.put("severity", severity);
            socket.emit("lognotification", notificationMessage);
        } catch (JSONException e) {
            logger.error(e.getMessage());
        }
    } else {
        logger.debug("No connection, notification is not sent");
    }
}

From source file:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

/**
 * This method sends broadcast notification to my.openHAB
 *
 * @param message notification message text
 * @param icon name of the icon for this notification
 * @param severity severity name for this notification
 *
 *///from   w w w. j  a v  a  2  s .c  om

public void sendBroadcastNotification(String message, String icon, String severity) {
    if (isConnected()) {
        JSONObject notificationMessage = new JSONObject();
        try {
            notificationMessage.put("message", message);
            notificationMessage.put("icon", icon);
            notificationMessage.put("severity", severity);
            socket.emit("broadcastnotification", notificationMessage);
        } catch (JSONException e) {
            logger.error(e.getMessage());
        }
    } else {
        logger.debug("No connection, notification is not sent");
    }
}

From source file:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

/**
 * Send SMS to my.openHAB/*from   ww w  .j av  a  2s . c o m*/
 *
 * @param phone number to send notification to
 * @param message text to send
 *
 */

public void sendSMS(String phone, String message) {
    if (isConnected()) {
        JSONObject smsMessage = new JSONObject();
        try {
            smsMessage.put("phone", phone);
            smsMessage.put("message", message);
            socket.emit("sms", smsMessage);
        } catch (JSONException e) {
            logger.error(e.getMessage());
        }
    } else {
        logger.debug("No connection, SMS is not sent");
    }
}

From source file:org.openhab.io.myopenhab.internal.MyOpenHABClient.java

/**
 * Send item update to my.openHAB/*from w w  w .j a  va 2  s .  co m*/
 *
 * @param itemName the name of the item
 * @param itemState updated item state
 *
 */

public void sendItemUpdate(String itemName, String itemState) {
    if (isConnected()) {
        logger.debug("Sending update '{}' for item '{}'", itemState, itemName);
        JSONObject itemUpdateMessage = new JSONObject();
        try {
            itemUpdateMessage.put("itemName", itemName);
            itemUpdateMessage.put("itemStatus", itemState);
            socket.emit("itemupdate", itemUpdateMessage);
        } catch (JSONException e) {
            logger.error(e.getMessage());
        }
    } else {
        logger.debug("No connection, Item update is not sent");
    }
}

From source file:com.eTilbudsavis.etasdk.network.EtaError.java

public JSONObject toJSON() {
    JSONObject o = new JSONObject();
    try {// www  .ja  v a2  s.co  m
        o.put(JsonKey.ID, Json.nullCheck(mId));
        o.put(JsonKey.CODE, Json.nullCheck(mCode));
        o.put(JsonKey.MESSAGE, Json.nullCheck(getMessage()));
        o.put(JsonKey.DETAILS, Json.nullCheck(mDetails));
        o.put(JsonKey.FAILED_ON_FIELD, Json.nullCheck(mFailedOnField));
    } catch (JSONException e) {
        EtaLog.e(TAG, e.getMessage(), e);
    }
    return o;
}

From source file:tap.formatter.JSONFormat.java

@Override
public void writeResult(TableIterator result, OutputStream output, TAPExecutionReport execReport, Thread thread)
        throws TAPException, IOException, InterruptedException {
    try {//from  w  ww .  j  a  v a  2  s.  co m

        // Prepare the output stream for JSON:
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
        JSONWriter out = new JSONWriter(writer);

        // {
        out.object();

        // "metadata": [...]
        out.key("metadata");

        // Write metadata part:
        DBColumn[] columns = writeMetadata(result, out, execReport, thread);

        writer.flush();

        if (thread.isInterrupted())
            throw new InterruptedException();

        // "data": [...]
        out.key("data");

        // Write the data part:
        writeData(result, columns, out, execReport, thread);

        // }
        out.endObject();
        writer.flush();

    } catch (JSONException je) {
        throw new TAPException(je.getMessage(), je);
    }
}