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.soomla.util.JSONFactory.java

public T create(JSONObject jsonObject, String packageName) {

    if (jsonObject == null) {
        // warn/* ww  w .  j ava 2s.  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:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.SystemMonitor.java

private void sendNotification(JSONArray t) {
    new AsyncTask<JSONArray, Void, Void>() {
        @Override/*  w ww  .java 2  s  . co m*/
        protected Void doInBackground(JSONArray... params) {
            JSONArray message = params[0];

            try {

                // Building Parameters
                List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                pairs.add(new BasicNameValuePair("message", message.toString()));
                pairs.add(new BasicNameValuePair("phone", phoneNr));

                JSONObject json = jParser.makeHttpRequest(getString(R.string.send_url), "POST", pairs);

                // check log cat for response
                if (json != null) {
                    String response = json.getString("message");
                    Log.e(SystemMonitor.class.getSimpleName(), "Post Response: " + response);
                } else
                    Log.e(SystemMonitor.class.getSimpleName(), "No Response!!");
            } catch (JSONException e) {
                Log.e(SystemMonitor.class.getSimpleName(), "JSONException: " + e.getMessage());
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void v) {
        }
    }.execute(t, null, null);
}

From source file:de.uni_potsdam.hpi.bpt.promnicat.utilityUnits.transformer.BpmaiJsonToDiagramUnit.java

@Override
public IUnitData<Object> execute(IUnitData<Object> input) throws IllegalTypeException {
    if (input == null) {
        throw new IllegalArgumentException("Got an invalid null pointer input!");
    }/*from w  w w .  ja  va  2s.c o m*/
    if (!(input.getValue() instanceof Representation)) {
        throw new IllegalTypeException(Representation.class, input.getValue().getClass(),
                "Got wrong input type in" + this.getName());
    }
    if (input instanceof IUnitDataProcessMetrics<?>) {
        ((IUnitDataProcessMetrics<?>) input)
                .setModelPath(((Representation) input.getValue()).getOriginalFilePath());
    } else if (input instanceof IUnitDataClassification<?>) {
        ((IUnitDataClassification<?>) input)
                .setModelPath(((Representation) input.getValue()).getOriginalFilePath());
    }

    try {
        String json = ((Representation) input.getValue()).convertDataContentToString();
        Diagram diagram = DiagramBuilder.parseJson(json);
        input.setValue(diagram);
        return input;
    } catch (JSONException e) {
        logger.severe("JSON parsing failed, got message:\n" + e.getMessage());
        input.setValue(null);
        return input;
    }
}

From source file:org.jwebsocket.plugins.sharedobjects.SharedObjectsPlugIn.java

@Override
public void processToken(PlugInResponse aResponse, WebSocketConnector aConnector, Token aToken) {
    String lType = aToken.getType();
    String lNS = aToken.getNS();//from  ww  w .j a  v a 2 s .c om
    String lID = aToken.getString("id");
    String lDataType = aToken.getString("datatype");
    String lValue = aToken.getString("value");

    if (lType != null && (lNS == null || lNS.equals(NS_SHARED_OBJECTS))) {

        Token lResponse = getServer().createResponse(aToken);

        // create
        if (lType.equals("create")) {
            if (log.isDebugEnabled()) {
                log.debug("Processing 'create'...");
            }
            if (!isDataTypeValid(lDataType, aConnector, lResponse)) {
                return;
            }
            if (alreadyExists(lID, aConnector, lResponse)) {
                return;
            }
            sharedObjects.put(lID, string2Object(lDataType, lValue));

            Token lBCT = new Token(lNS, "event");
            lBCT.put("name", "created");
            lBCT.put("id", lID);
            lBCT.put("datatype", lDataType);
            lBCT.put("value", lValue);
            getServer().broadcastToken(aConnector, lBCT);

            // destroy
        } else if (lType.equals("destroy")) {
            if (log.isDebugEnabled()) {
                log.debug("Processing 'destroy'...");
            }
            if (!doesContain(lID, aConnector, lResponse)) {
                return;
            }
            sharedObjects.remove(lID);

            Token lBCT = new Token(lNS, "event");
            lBCT.put("name", "destroyed");
            lBCT.put("id", lID);
            getServer().broadcastToken(aConnector, lBCT);

            // get
        } else if (lType.equals("get")) {
            if (log.isDebugEnabled()) {
                log.debug("Processing 'get'...");
            }
            if (!doesContain(lID, aConnector, lResponse)) {
                return;
            }
            Object lObj = sharedObjects.get(lID);
            lResponse.put("id", lID);
            lResponse.put("result", lObj.toString());

            // put
        } else if (lType.equals("update")) {
            if (log.isDebugEnabled()) {
                log.debug("Processing 'update'...");
            }
            if (!isDataTypeValid(lDataType, aConnector, lResponse)) {
                return;
            }
            sharedObjects.put(lID, string2Object(lDataType, lValue));
            Token lBCT = new Token(lNS, "event");
            lBCT.put("name", "updated");
            lBCT.put("id", lID);
            lBCT.put("datatype", lDataType);
            lBCT.put("value", lValue);
            getServer().broadcastToken(aConnector, lBCT);

            // init
        } else if (lType.equals("init")) {
            if (log.isDebugEnabled()) {
                log.debug("Processing 'init'...");
            }
            Token lBCT = new Token(lNS, "event");
            lBCT.put("name", "init");

            String lData = null;
            try {
                JSONStringer jsonStringer = new JSONStringer();
                // start main object
                jsonStringer.object();
                // iterate through all items (fields) of the token
                Iterator<String> lIterator = sharedObjects.getKeys().iterator();
                while (lIterator.hasNext()) {
                    String lKey = lIterator.next();
                    Object lVal = sharedObjects.get(lKey);
                    if (lVal instanceof Collection) {
                        jsonStringer.key(lKey).array();
                        for (Object item : (Collection) lVal) {
                            jsonStringer.value(item);
                        }
                        jsonStringer.endArray();
                    } else {
                        jsonStringer.key(lKey).value(lVal);
                    }
                }
                // end main object
                jsonStringer.endObject();
                lData = jsonStringer.toString();
            } catch (JSONException ex) {
                log.error(ex.getClass().getSimpleName() + ": " + ex.getMessage());
            }
            lBCT.put("value", lData);
            getServer().sendToken(aConnector, lBCT);

        } else {
            log.warn("Invalid command " + lType + " received...");
            lResponse.put("code", -1);
            lResponse.put("msg", "invalid type '" + lType + "'");
        }

        getServer().sendToken(aConnector, lResponse);
    }

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.harvester.FileHarvestController.java

/**
 * Create a new JSON object/*from  www.  ja v  a 2s.  c  o m*/
 * @param fatalError whether the fatal error flag should be set on this object
 * @return the new JSON object
 */
private JSONObject generateJson(boolean fatalError) {
    JSONObject json = null;
    try {
        json = new JSONObject();
        json.put("fatalError", fatalError);
    } catch (JSONException e) {
        log.error(e.getMessage(), e);
    }
    return json;
}

From source file:org.thaliproject.p2p.btconnectorlib.internal.AbstractBluetoothConnectivityAgent.java

private boolean verifyIdentityStringImp(String bluetoothMacAddress) {
    if (!CommonUtils.isNonEmptyString(mMyIdentityString)) {
        if (CommonUtils.isNonEmptyString(mMyPeerName) && !mMyPeerName.equals(PeerProperties.NO_PEER_NAME_STRING)
                && BluetoothUtils.isValidBluetoothMacAddress(bluetoothMacAddress)) {
            try {
                mMyIdentityString = createIdentityString(mMyPeerName, bluetoothMacAddress);
                Log.i(TAG, "verifyIdentityString: Identity string created: " + mMyIdentityString);
            } catch (JSONException e) {
                Log.e(TAG, "verifyIdentityString: Failed create an identity string: " + e.getMessage(), e);
            }/*from  w  ww .ja v a2 s.com*/
        } else {
            Log.d(TAG,
                    "verifyIdentityString: One or more of the following values are invalid: " + "Peer name: \""
                            + mMyPeerName + "\", Bluetooth MAC address: \"" + bluetoothMacAddress + "\"");
        }
    }

    return (mMyIdentityString != null && mMyIdentityString.length() > 0);
}

From source file:org.thaliproject.p2p.btconnectorlib.internal.AbstractBluetoothConnectivityAgent.java

/**
 * Creates an identity string based on the given arguments.
 *
 * @param peerName The peer name./*from w ww  .  j  av  a  2 s .c o  m*/
 * @param bluetoothMacAddress The Bluetooth MAC address of the peer.
 * @return An identity string or null in case of a failure.
 * @throws JSONException
 */
private String createIdentityString(String peerName, String bluetoothMacAddress) throws JSONException {

    String identityString = null;
    JSONObject jsonObject = new JSONObject();

    try {
        jsonObject.put(JSON_ID_PEER_NAME, peerName);
        jsonObject.put(JSON_ID_PEER_BLUETOOTH_MAC_ADDRESS, bluetoothMacAddress);
        identityString = jsonObject.toString();
    } catch (JSONException e) {
        Log.e(TAG, "createIdentityString: Failed to construct a JSON object (from data " + peerName + " "
                + bluetoothMacAddress + "): " + e.getMessage(), e);
        throw e;
    }

    return identityString;
}

From source file:com.strato.hidrive.api.bll.free.CheckUsernameGateway.java

@Override
protected Request prepareRequest() {
    List<BaseParam<?>> params = new ArrayList<BaseParam<?>>();
    JSONObject json = new JSONObject();
    try {/*  w  ww.ja  v  a 2 s . c o m*/
        json.put("username", this.usernameForCheck);
        json.put("country", this.country);
        json.put("language", this.language);
        json.put("product_name", "HiDriveFree");
        json.put("product", "freemium");
    } catch (JSONException e) {
        if (e != null && e.getMessage() != null) {
            Log.e(getClass().getSimpleName(), e.getMessage());
        }
    }
    params.add(new Param("postdata", json.toString()));
    return new PostRequest("check_username", params);
}

From source file:org.mapsforge.poi.exchange.GeoJsonPoiPrinter.java

@Override
public String print() {
    try {/*from   ww w .  j ava  2s  .c  om*/
        return buildJsonObject(pois).toString(4);
    } catch (JSONException e) {
        throw new RuntimeException(e.getMessage());
    }
}

From source file:org.mapsforge.poi.exchange.GeoJsonPoiPrinter.java

private JSONObject buildJsonObject(Collection<PointOfInterest> pointsOfInterest) {
    JSONObject geoJsonObject = new JSONObject();
    JSONArray geometryCollection = new JSONArray();
    try {/*from w  w w .  j a  v a 2 s. c o m*/
        geoJsonObject.put("type", "FeatureCollection");
        for (PointOfInterest point : pointsOfInterest) {
            geometryCollection.put(pointJsonObject(point));
        }
        geoJsonObject.put("features", geometryCollection);
    } catch (JSONException e) {
        throw new RuntimeException(e.getMessage());
    }
    return geoJsonObject;
}