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.microsoft.office365.starter.models.O365CalendarModel.java

private String getErrorMessage(String result) {
    String errorMessage = "";
    try {// w  ww.  j  ava2  s  . co m

        // Gets the JSON object out of the result string
        String responsejSON = result.substring(result.indexOf("{"), result.length());

        JSONObject jObject = new JSONObject(responsejSON);
        JSONObject error = (JSONObject) jObject.get("error");
        errorMessage = error.getString("message");

    } catch (JSONException e) {
        e.printStackTrace();
        errorMessage = e.getMessage();
    }
    return errorMessage;
}

From source file:com.mobeelizer.java.connection.MobeelizerConnectionServiceImpl.java

@Override
public MobeelizerAuthenticateResponse authenticate(final String login, final String password,
        final String deviceType, final String deviceToken) {
    try {/*w  w  w . j a  v a 2  s  . co m*/

        String url;
        if (deviceType != null && deviceToken != null) {
            url = getUrl("/authenticate", "deviceToken", deviceToken, "deviceType", deviceType);
        } else {
            url = getUrl("/authenticate");
        }
        HttpGet request = new HttpGet(url);

        setHeaders(request, true, false);

        request.setHeader("mas-user-name", login);
        request.setHeader("mas-user-password", password);

        MobeelizerOperationStatus<String> content = executeAndGetContent(request);
        if (content.getError() != null) {
            return new MobeelizerAuthenticateResponseImpl(null, null, content.getError());
        }
        JSONObject json = new JSONObject(content.getContent());

        return new MobeelizerAuthenticateResponseImpl(json.getString("role"), json.getString("instanceGuid"),
                null);
    } catch (JSONException e) {
        return new MobeelizerAuthenticateResponseImpl(null, null,
                MobeelizerOperationErrorImpl.exception(new IOException(e.getMessage())));
    }
}

From source file:com.mobeelizer.java.connection.MobeelizerConnectionServiceImpl.java

@Override
public MobeelizerOperationError sendRemoteNotification(final String device, final String group,
        final List<String> users, final Map<String, String> notification) {
    try {//w ww.ja v  a 2 s  .co  m
        JSONObject object = new JSONObject();
        StringBuilder logBuilder = new StringBuilder();
        logBuilder.append("try to send remote notification ").append(notification).append(" to");
        if (device != null) {
            object.put("device", device);
            logBuilder.append(" device: ").append(device);
        }
        if (group != null) {
            object.put("group", group);
            logBuilder.append(" group: ").append(group);
        }
        if (users != null) {
            object.put("users", new JSONArray(users));
            logBuilder.append(" users: ").append(users);
        }
        if (device == null && group == null && users == null) {
            logBuilder.append(" everyone");
        }
        object.put("notification", new JSONObject(notification));
        delegate.logInfo(logBuilder.toString());
        return executePostAndGetContent("/push", object).getError();
    } catch (JSONException e) {
        return MobeelizerOperationErrorImpl.other(e.getMessage());
    }
}

From source file:com.mobeelizer.java.connection.MobeelizerConnectionServiceImpl.java

private MobeelizerOperationStatus<String> executeAndGetContent(final HttpRequestBase request) {
    HttpClient client = httpClient();//from w  w w .  ja v a 2 s .  c  o  m

    InputStream is = null;
    Reader reader = null;

    if (!delegate.isNetworkAvailable()) {
        return new MobeelizerOperationStatus<String>(MobeelizerOperationErrorImpl.missingConnectionError());
    }

    delegate.setProxyIfNecessary(request);

    MobeelizerOperationError error = null;

    try {
        HttpResponse response = client.execute(request);

        int status = response.getStatusLine().getStatusCode();

        HttpEntity entity = response.getEntity();
        if (entity == null) {
            return new MobeelizerOperationStatus<String>(MobeelizerOperationErrorImpl.connectionError());
        }
        is = entity.getContent();
        Writer writer = new StringWriter();
        char[] buffer = new char[1024];
        reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        int n;
        while ((n = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, n);
        }
        String content = writer.toString().trim();

        if (status == HttpStatus.SC_OK) {
            return new MobeelizerOperationStatus<String>(content);
        } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR && content.trim().length() > 0) {
            JSONObject json = new JSONObject(content);
            error = MobeelizerOperationErrorImpl.serverError(json);
        } else {
            error = MobeelizerOperationErrorImpl.connectionError(status);
        }

    } catch (JSONException e) {
        error = MobeelizerOperationErrorImpl.exception(e);
    } catch (IOException e) {
        error = MobeelizerOperationErrorImpl.exception(e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                delegate.logDebug(e.getMessage());
            }
        }
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                delegate.logDebug(e.getMessage());
            }
        }
        client.getConnectionManager().shutdown();
    }
    return new MobeelizerOperationStatus<String>(error);
}

From source file:org.o3project.ocnrm.odenos.driver.AbstractDriver.java

private void onFlowProcess(final String networkId, final Flow flow, String action) {
    seqNo = SEQNO_PREFIX + mf.requestNoToString();
    logger.info(seqNo + "\t" + "onFlowProcess Strat");

    NetworkInterface networkIf = networkInterfaces().get(networkId);
    BasicFlow targetFlow = getFlow(networkIf, flow.getFlowId());

    logger.debug(seqNo + "\t" + "Status:" + flow.getStatus());
    targetFlow.setStatus(FlowObject.FlowStatus.ESTABLISHING.toString());

    try {//from   w  ww  .j a v a2  s  .com
        flowMessageManager(networkIf, networkId, action, targetFlow, seqNo);
    } catch (JSONException e) {
        logger.error(seqNo + "\t" + "get JSONException.");
        e.printStackTrace();
        return;
    } catch (IOException e) {
        logger.error(seqNo + "\t" + "get IOException.");
        e.printStackTrace();
        return;
    } catch (Exception e) {
        logger.error(seqNo + "\t" + "get Exception: " + e.getMessage());
        e.printStackTrace();
        return;
    }
    logger.info(seqNo + "\t" + "onFlowProcess End");
}

From source file:org.uiautomation.ios.server.servlet.IOSServlet.java

private Response getResponse(WebDriverLikeRequest request) {
    long start = System.currentTimeMillis();
    String command = "";
    WebDriverLikeCommand wdlc = null;//from  w  w w .j  av  a2 s . c om
    try {
        wdlc = request.getGenericCommand();
        Handler h = CommandMapping.get(wdlc).createHandler(getDriver(), request);
        command = wdlc.method() + "\t " + wdlc.path();
        return h.handleAndRunDecorators();
    } catch (WebDriverException we) {
        Response response = new Response();
        if (wdlc.isSessionLess()) {
            response.setSessionId("");
        } else {
            response.setSessionId(request.getSession());
        }

        response.setStatus(errorCodes.toStatusCode(we));

        try {
            JSONObject o = serializeException(we);
            response.setValue(o);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return response;
    } catch (Exception e) {
        throw new WebDriverException("bug." + e.getMessage(), e);
    } finally {
        String message = ((System.currentTimeMillis() - start) + "ms.\t" + command);
        log.info(message);
    }
}

From source file:com.cubusmail.user.UserAccountDao.java

/**
 * @param preferencesJson/*from w w  w  . j  a  va  2 s .  c  om*/
 * @param preferences
 */
private void json2Preferences(String preferencesJson, Preferences preferences) {

    try {
        JSONObject object = new JSONObject(preferencesJson);
        Field[] fields = Preferences.class.getFields();
        if (fields != null) {
            for (Field field : fields) {
                Object value = object.has(field.getName()) ? object.get(field.getName()) : null;
                if (value != null) {
                    if (value instanceof Integer) {
                        field.setInt(preferences, ((Integer) value).intValue());
                    } else if (value instanceof Boolean) {
                        field.setBoolean(preferences, ((Boolean) value).booleanValue());
                    } else if (value instanceof String) {
                        field.set(preferences, value);
                    }
                }
            }
        }
    } catch (JSONException e) {
        logger.error(e.getMessage(), e);
    } catch (NumberFormatException e) {
        logger.error(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        logger.error(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.clipsmonitor.gui.MapGeneratorTopComponent.java

private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveButtonActionPerformed
    int retrival = save.showSaveDialog(this);
    if (retrival == JFileChooser.APPROVE_OPTION) {
        try {/*from   ww  w .ja  v  a2  s  .  c  o  m*/
            String output = model.SaveFiles(save.getSelectedFile());
            model.log(output);
        } catch (JSONException ex) {
            Exceptions.printStackTrace(ex);
            model.error(ex.getMessage());
        }
    }
    updateLogArea();
}

From source file:com.atolcd.alfresco.AuditFilter.java

/**
 * @param request//from   w w  w  .jav  a2s .  c o  m
 * @param userId
 * @param siteId
 * @param componentId
 * @param objectId
 * @return
 * @throws JSONException
 * @throws URIException
 * @throws UnsupportedEncodingException
 */
private String getNodeRefRemoteCall(HttpServletRequest request, String userId, String siteId,
        String componentId, String objectId) throws JSONException, URIException, UnsupportedEncodingException {
    Connector connector;
    try {
        connector = FrameworkUtil.getConnector(request.getSession(true), userId,
                AlfrescoUserFactory.ALFRESCO_ENDPOINT_ID);
        // <url>/share-stats/slingshot/details/{siteId}/{componentId}/{objectId}</url>
        Response resp = connector.call("/share-stats/slingshot/details/" + siteId + "/" + componentId + "/"
                + URLEncoder.encode(objectId, "UTF-8"));

        if (resp.getStatus().getCode() == Status.STATUS_OK) {
            try {
                JSONObject json = new JSONObject(resp.getResponse());
                if (json.has("nodeRef")) {
                    return (String) json.get("nodeRef");
                }
            } catch (JSONException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.getMessage(), e);
                }
            }
        }
    } catch (ConnectorServiceException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
    }

    return objectId;
}

From source file:com.phonegap.ContactManager.java

/**
 * Executes the request and returns PluginResult.
 * /* w ww .j  a v a2s  .  c om*/
 * @param action       The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @param callbackId   The callback id used when calling back into JavaScript.
 * @return             A PluginResult object with a status and message.
 */
public PluginResult execute(String action, JSONArray args, String callbackId) {
    if (contactAccessor == null) {
        contactAccessor = ContactAccessor.getInstance(webView, ctx);
    }
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    try {
        if (action.equals("search")) {
            JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
            return new PluginResult(status, res, "navigator.service.contacts.cast");
        } else if (action.equals("save")) {
            return new PluginResult(status, contactAccessor.save(args.getJSONObject(0)));
        } else if (action.equals("remove")) {
            if (contactAccessor.remove(args.getString(0))) {
                return new PluginResult(status, result);
            } else {
                JSONObject r = new JSONObject();
                r.put("code", 2);
                return new PluginResult(PluginResult.Status.ERROR, r);
            }
        }
        return new PluginResult(status, result);
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}