Example usage for org.json JSONException printStackTrace

List of usage examples for org.json JSONException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:nl.hnogames.domoticzapi.Parsers.LanguageParser.java

@Override
public void parseResult(String result) {
    try {/*from  w  w w.j  av  a2s  .  c  o  m*/
        Language language = new Language(new JSONObject(result));
        receiver.onReceiveLanguage(language);
    } catch (JSONException e) {
        Log.e(TAG, "LanguageParser JSON exception");
        e.printStackTrace();
        receiver.onError(e);
    }
}

From source file:com.github.akinaru.rfdroid.bluetooth.BluetoothCustomManager.java

private void dispatchRFdroid(BluetoothDevice device, int rssi, final byte[] scanRecord) {

    if (scanningList.containsKey(device.getAddress())) {

        if (adListener != null && measurement.getBtDevice() != null
                && measurement.getBtDevice().getDeviceAddress().equals(device.getAddress())) {

            long ts = new Date().getTime();
            measurement.getHistoryList().add(ts);
            adListener.onADframeReceived(ts, measurement.getHistoryList());
        }//  w  w  w.  j  a  v a2  s .co m
    } else {
        Log.i(TAG, "found a RFdroid");

        List<ADStructure> structures = ADPayloadParser.getInstance().parse(scanRecord);

        int advInterval = -1;

        for (ADStructure structure : structures) {

            if (structure instanceof ADManufacturerSpecific) {

                ADManufacturerSpecific data = (ADManufacturerSpecific) structure;

                if (data.getData().length == 9) {

                    byte[] name = new byte[7];
                    System.arraycopy(data.getData(), 0, name, 0, 7);

                    String nameStr = new String(name);
                    if (nameStr.equals("RFdroid")) {
                        advInterval = (data.getData()[7] << 8) + (data.getData()[8] & 0xFF);
                        Log.i(TAG, "current scan interval : " + advInterval);
                    }
                }
            }
        }

        if (advInterval != -1) {

            scanningList.put(device.getAddress(), device);

            if (!measurement.isSelectionningDevice())
                measurement.setBtDevice(new BluetoothObject(device.getAddress(), device.getName(),
                        (int) (advInterval * 0.625)));

            try {
                JSONObject object = new JSONObject();
                object.put(JsonConstants.BT_ADDRESS, device.getAddress());
                object.put(JsonConstants.BT_DEVICE_NAME, device.getName());
                object.put(JsonConstants.BT_ADVERTISING_INTERVAL, (int) (advInterval * 0.625));

                ArrayList<String> deviceInfo = new ArrayList<>();
                deviceInfo.add(object.toString());

                broadcastUpdateStringList(BluetoothEvents.BT_EVENT_DEVICE_DISCOVERED, deviceInfo);

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

}

From source file:com.github.akinaru.rfdroid.bluetooth.BluetoothCustomManager.java

private void dispatchBtDevices(BluetoothDevice device, int rssi, final byte[] scanRecord) {

    if (scanningList.containsKey(device.getAddress())) {

        if (adListener != null && measurement.getBtDevice() != null
                && measurement.getBtDevice().getDeviceAddress().equals(device.getAddress())) {

            long ts = new Date().getTime();
            measurement.getHistoryList().add(ts);
            adListener.onADframeReceived(ts, measurement.getHistoryList());
        }//from w  w w.  ja v  a2s . co  m
    } else {

        Log.i(TAG, "found a new Bluetooth device : " + device.getName() + " : " + device.getAddress());

        scanningList.put(device.getAddress(), device);

        try {
            JSONObject object = new JSONObject();
            object.put(JsonConstants.BT_ADDRESS, device.getAddress());
            object.put(JsonConstants.BT_DEVICE_NAME, device.getName());
            object.put(JsonConstants.BT_ADVERTISING_INTERVAL, -1);

            ArrayList<String> deviceInfo = new ArrayList<>();
            deviceInfo.add(object.toString());

            broadcastUpdateStringList(BluetoothEvents.BT_EVENT_DEVICE_DISCOVERED, deviceInfo);

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush.java

private boolean registerWithUserId(final String userId) {

    if (isInitialized == true) {
        if (MFPPushUtils.validateString(userId) && MFPPushUtils.validateString(clientSecret)) {

            MFPPushUrlBuilder builder = new MFPPushUrlBuilder(applicationId);
            String path = builder.getDeviceIdUrl(regId);
            MFPPushInvoker invoker = MFPPushInvoker.newInstance(appContext, path, Request.GET, clientSecret);
            invoker.setJSONRequestBody(null);

            invoker.setResponseListener(new ResponseListener() {
                @Override/* ww w  . j a v a 2  s. c o  m*/
                public void onSuccess(Response response) {
                    try {
                        String retDeviceId = (new JSONObject(response.getResponseText())).getString(DEVICE_ID);
                        String retToken = (new JSONObject(response.getResponseText())).getString(TOKEN);
                        String userIdFromResponse = (new JSONObject(response.getResponseText()))
                                .getString(USER_ID);

                        if (!(retDeviceId.equals(regId)) || !(retToken.equals(deviceToken))
                                || !(userId.equals(userIdFromResponse))) {
                            deviceId = retDeviceId;
                            MFPPushUtils.storeContentInSharedPreferences(appContext, applicationId, DEVICE_ID,
                                    deviceId);

                            hasRegisterParametersChanged = true;
                            updateTokenCallback(deviceToken, userId);
                        } else {
                            deviceId = retDeviceId;
                            isTokenUpdatedOnServer = true;
                            MFPPushUtils.storeContentInSharedPreferences(appContext, applicationId, DEVICE_ID,
                                    deviceId);
                            registerResponseListener.onSuccess(response.toString());
                        }
                    } catch (JSONException e1) {
                        logger.error(
                                "MFPPush:verifyDeviceRegistrationWithUserId() - Exception caught while parsing JSON response.");
                        e1.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Response response, Throwable throwable, JSONObject jsonObject) {
                    // Device is not registered.
                    isNewRegistration = true;
                    updateTokenCallback(deviceToken, userId);
                }
            });
            invoker.execute();
        } else {

            String error = "Error while registration - Please verify your UserId and ClientSecret value";
            logger.error(
                    "MFPPush:verifyDeviceRegistrationWithUserId() - Please verify your UserId and ClientSecret value");
            System.out.print("MFPPush:verifyDeviceRegistrationWithUserId() - " + error);
        }
    } else {
        String error = "Error while registration -. Not initialized MFPPush";
        logger.error(
                "MFPPush:verifyDeviceRegistrationWithUserId() - Error while registration -. Not initialized MFPPush");
        System.out.print("MFPPush:verifyDeviceRegistrationWithUserId() - " + error);
    }

    return true;
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush.java

private boolean register() {

    if (isInitialized) {
        MFPPushUrlBuilder builder = new MFPPushUrlBuilder(applicationId);
        String path = builder.getDeviceIdUrl(regId);
        MFPPushInvoker invoker = MFPPushInvoker.newInstance(appContext, path, Request.GET, clientSecret);
        invoker.setJSONRequestBody(null);

        invoker.setResponseListener(new ResponseListener() {
            @Override//  ww w. j  a  v  a 2s  .co m
            public void onSuccess(Response response) {
                try {
                    String retDeviceId = (new JSONObject(response.getResponseText())).getString(DEVICE_ID);
                    String retToken = (new JSONObject(response.getResponseText())).getString(TOKEN);
                    String userIdFromResponse = (new JSONObject(response.getResponseText())).getString(USER_ID);

                    if (!(retDeviceId.equals(regId)) || !(retToken.equals(deviceToken))
                            || !(userIdFromResponse.equals("anonymous"))) {
                        deviceId = retDeviceId;
                        MFPPushUtils.storeContentInSharedPreferences(appContext, applicationId, DEVICE_ID,
                                deviceId);

                        hasRegisterParametersChanged = true;
                        updateTokenCallback(deviceToken, null);
                    } else {
                        deviceId = retDeviceId;
                        isTokenUpdatedOnServer = true;
                        MFPPushUtils.storeContentInSharedPreferences(appContext, applicationId, DEVICE_ID,
                                deviceId);
                        registerResponseListener.onSuccess(response.toString());
                    }
                } catch (JSONException e1) {
                    logger.error(
                            "MFPPush:VerifyDeviceRegistration() - Exception caught while parsing JSON response.");
                    e1.printStackTrace();
                }
            }

            @Override
            public void onFailure(Response response, Throwable throwable, JSONObject jsonObject) {
                // Device is not registered.
                isNewRegistration = true;
                updateTokenCallback(deviceToken, null);
            }
        });
        invoker.execute();

    } else {
        String error = "Error while registration -. Not initialized MFPPush";
        logger.error(
                "MFPPush:verifyDeviceRegistrationWithUserId() - Error while registration -. Not initialized MFPPush");
    }
    return true;
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush.java

private void getSenderIdFromServerAndRegisterInBackground(final String userId) {
    MFPPushUrlBuilder builder = new MFPPushUrlBuilder(applicationId);
    String path = builder.getSettingsUrl();
    MFPPushInvoker invoker = MFPPushInvoker.newInstance(appContext, path, Request.GET, clientSecret);
    logger.debug(//from  w ww  .  ja  va  2 s . co  m
            "MFPPush: getSenderIdFromServerAndRegisterInBackground() - The url for getting gcm configuration is: "
                    + path);
    invoker.setJSONRequestBody(null);

    invoker.setResponseListener(new ResponseListener() {

        @Override
        public void onSuccess(Response response) {
            logger.debug(
                    "MFPPush: getSenderIdFromServerAndRegisterInBackground() - success retrieving senderId from server");
            String senderId = null;
            try {
                senderId = (String) (new JSONObject(response.getResponseText())).get(SENDER_ID);
            } catch (JSONException e) {
                logger.error(
                        "MFPPush: getSenderIdFromServerAndRegisterInBackground() - Failure while parsing JSON object for "
                                + "retrieving senderId");
                e.printStackTrace();
            }

            if (senderId == null) {
                errorString = "MFPPush: getSenderIdFromServerAndRegisterInBackgound() - SenderId is not configured in the backend application.";
                registerResponseListener.onFailure(new MFPPushException(errorString));
            } else {
                gcmSenderId = senderId;
                MFPPushUtils.storeContentInSharedPreferences(appContext, applicationId, SENDER_ID, gcmSenderId);
                registerInBackground(userId);
            }
        }

        @Override
        public void onFailure(Response response, Throwable throwable, JSONObject object) {
            logger.error(
                    "MFPPush: getSenderIdFromServerAndRegisterInBackground() - Error while getting senderId from push server.");
            errorString = null;
            statusCode = 0;
            if (response != null) {
                errorString = response.getResponseText();
                statusCode = response.getStatus();
            } else if (errorString == null && throwable != null) {
                errorString = throwable.toString();
            } else if (errorString == null && object != null) {
                errorString = object.toString();
            }
            registerResponseListener.onFailure(new MFPPushException(errorString, statusCode));
        }
    });

    invoker.execute();
}

From source file:com.citrus.sdk.payment.NetbankingOption.java

@Override
public String getSavePaymentOptionObject() {
    JSONObject object = null;/*from   w  ww .  j a va 2 s  .  com*/
    try {
        object = new JSONObject();
        JSONArray paymentOptions = new JSONArray();

        JSONObject option = new JSONObject();
        option.put("owner", "");
        option.put("bank", bankName);
        option.put("type", "netbanking");
        paymentOptions.put(option);

        object.put("paymentOptions", paymentOptions);
        object.put("type", "payment");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return object.toString();
}

From source file:com.aliyun.openservices.odps.console.commands.logview.GetTaskDetailsAction.java

private List<FuxiJob> loadJobsFromStream(InputStream in) throws ODPSConsoleException {
    JSONTokener tokener = new JSONTokener(new BufferedReader(new InputStreamReader(in)));
    try {/* w w  w . java2  s  . co m*/
        JSONObject obj = new JSONObject(tokener);
        ArrayList<FuxiJob> jobs = new ArrayList<FuxiJob>();
        JSONObject mapReduceJson;
        try {
            mapReduceJson = obj.getJSONObject("mapReduce");
        } catch (JSONException e) {
            return jobs;
        }
        JSONArray jobsJson = mapReduceJson.getJSONArray("jobs");
        for (int i = 0; i < jobsJson.length(); i++) {
            jobs.add(getFuxiJobFromJson(jobsJson.getJSONObject(i)));
        }
        return jobs;
    } catch (JSONException e) {
        e.printStackTrace();
        throw new ODPSConsoleException("Bad json format");
    }
}

From source file:com.sepgil.ral.UpdateNodeTask.java

@Override
public HttpRequestBase getHttpRequest(String url) {
    HttpPost post = new HttpPost(url);

    try {/*from   w  w  w .ja  v a  2  s. co  m*/
        StringEntity enity = new StringEntity(mNode.getJSON(), HTTP.UTF_8);
        post.setEntity(enity);
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return post;
}

From source file:com.example.ehrtemplateviewerexample.TemplateViewerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {//from  ww  w  . ja  va  2 s.  c om
        ArchetypeSchemaProvider asp = new ArchetypeSchemaProvider(getApplicationContext(),
                "archetypes.properties", "archetypes");
        this.tp = new TemplateProvider(getApplicationContext(),
                WidgetProvider.parseFileToString(getApplicationContext(), "ecg_bp_template.json"), asp,
                LANGUAGE);
        this.buildArchetypeFragments();
        this.setupButtonsListener();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}