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:de.dmxcontrol.model.ShutterModel.java

public void setValue(int value) {
    shutter[0] = value;// ww  w .ja v a2 s .  c om
    try {
        SendData("Shutter", "boolean", value != 0);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    notifyListener();
}

From source file:ch.icclab.cyclops.persistence.client.InfluxDBClient.java

public TSDBData getData(String query) {
    JSONArray resultArray;/*from  w  w  w.j a  v  a  2 s  .c  o  m*/
    JSONObject resultObj;
    TSDBData dataObj = null;
    Representation output;
    ObjectMapper mapper = new ObjectMapper();

    Client client = new Client(Protocol.HTTP);
    ClientResource cr = new ClientResource(url);

    cr.addQueryParameter("q", query);
    cr.addQueryParameter("u", username);
    cr.addQueryParameter("p", password);
    cr.get(MediaType.APPLICATION_JSON);
    output = cr.getResponseEntity();

    try {
        resultArray = new JSONArray(output.getText());
        if (!resultArray.isNull(0)) {
            resultObj = new JSONObject();
            resultObj = (JSONObject) resultArray.get(0);
            dataObj = mapper.readValue(resultObj.toString(), TSDBData.class);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return dataObj;
}

From source file:org.jboss.aerogear.android.ReadFilter.java

/**
 * @return a URL encoded query which represents the values set in this object.
 *//*from ww  w.  j a va  2  s  .  c  om*/
public String getQuery() {
    StringBuilder queryBuilder = new StringBuilder("?");
    String amp = "";

    if (limit != null && limit != Integer.MAX_VALUE) {
        queryBuilder.append(amp).append("limit=").append(limit);
        amp = "&";
    }

    if (offset != null && offset > 0) {
        queryBuilder.append(amp).append("offset=").append(offset);
        amp = "&";
    }

    if (where != null && where.length() > 0) {
        try {
            queryBuilder.append(amp).append(preparePathParam());
        } catch (UnsupportedEncodingException ex) {
            Log.e(TAG, "UTF-8 isn't supported on this platform", ex);
            throw new RuntimeException(ex);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        amp = "&";
    }

    return ("".equals(amp)) ? "" : queryBuilder.toString();
}

From source file:com.lukasz.chat.Pusher.java

private void sendSubscribeMessage(PusherChannel channel) {
    if (!isConnected())
        return;/*from w w w.jav a 2s  . c o  m*/

    try {
        String eventName = PUSHER_EVENT_SUBSCRIBE;

        JSONObject eventData = new JSONObject();
        eventData.put("channel", channel.getName());

        if (channel.isPrivate()) {
            String authInfo = authenticate(channel.getName());
            eventData.put("auth", authInfo);
        }

        sendEvent(eventName, eventData, null);

        Log.d(LOG_TAG, "subscribed to channel " + channel.getName());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.lukasz.chat.Pusher.java

private void sendUnsubscribeMessage(PusherChannel channel) {
    if (!isConnected())
        return;/*from  w w w  .j  a va  2s .c om*/

    try {
        String eventName = PUSHER_EVENT_UNSUBSCRIBE;

        JSONObject eventData = new JSONObject();
        eventData.put("channel", channel.getName());

        sendEvent(eventName, eventData, null);

        Log.d(LOG_TAG, "unsubscribed from channel " + channel.getName());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:org.openhab.habdroid.model.OpenHABWidget.java

public OpenHABWidget(OpenHABWidget parent, JSONObject widgetJson) {
    this.parent = parent;
    this.children = new ArrayList<OpenHABWidget>();
    this.mappings = new ArrayList<OpenHABWidgetMapping>();
    try {/*w  w  w  .j  a v  a2 s. c o m*/
        if (widgetJson.has("item")) {
            this.setItem(new OpenHABItem(widgetJson.getJSONObject("item")));
        }
        if (widgetJson.has("linkedPage")) {
            this.setLinkedPage(new OpenHABLinkedPage(widgetJson.getJSONObject("linkedPage")));
        }
        if (widgetJson.has("mappings")) {
            JSONArray mappingsJsonArray = widgetJson.getJSONArray("mappings");
            for (int i = 0; i < mappingsJsonArray.length(); i++) {
                JSONObject mappingObject = mappingsJsonArray.getJSONObject(i);
                OpenHABWidgetMapping mapping = new OpenHABWidgetMapping(mappingObject.getString("command"),
                        mappingObject.getString("label"));
                mappings.add(mapping);
            }
        }
        if (widgetJson.has("type"))
            this.setType(widgetJson.getString("type"));
        if (widgetJson.has("widgetId"))
            this.setId(widgetJson.getString("widgetId"));
        if (widgetJson.has("label"))
            this.setLabel(widgetJson.getString("label"));
        if (widgetJson.has("icon"))
            this.setIcon(widgetJson.getString("icon"));
        if (widgetJson.has("url"))
            this.setUrl(widgetJson.getString("url"));
        if (widgetJson.has("minValue"))
            this.setMinValue((float) widgetJson.getDouble("minValue"));
        if (widgetJson.has("maxValue"))
            this.setMaxValue((float) widgetJson.getDouble("maxValue"));
        if (widgetJson.has("step"))
            this.setStep((float) widgetJson.getDouble("step"));
        if (widgetJson.has("refresh"))
            this.setRefresh(widgetJson.getInt("refresh"));
        if (widgetJson.has("period"))
            this.setPeriod(widgetJson.getString("period"));
        if (widgetJson.has("service"))
            this.setService(widgetJson.getString("service"));
        if (widgetJson.has("height"))
            this.setHeight(widgetJson.getInt("height"));
        if (widgetJson.has("iconcolor"))
            this.setIconColor(widgetJson.getString("iconcolor"));
        if (widgetJson.has("labelcolor"))
            this.setLabelColor(widgetJson.getString("labelcolor"));
        if (widgetJson.has("valuecolor"))
            this.setValueColor(widgetJson.getString("valuecolor"));
        if (widgetJson.has("encoding"))
            this.setEncoding(widgetJson.getString("encoding"));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    if (widgetJson.has("widgets")) {
        try {
            JSONArray childWidgetJsonArray = widgetJson.getJSONArray("widgets");
            for (int i = 0; i < childWidgetJsonArray.length(); i++) {
                new OpenHABWidget(this, childWidgetJsonArray.getJSONObject(i));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    this.parent.addChildWidget(this);
}

From source file:com.df.app.carsWaiting.CarsWaitingListActivity.java

/**
 * //from w w  w  .  j ava  2s  .  c o  m
 * @param result
 */
private void fillInData(String result) {
    try {
        JSONArray jsonArray = new JSONArray(result);

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);

            CarsWaitingItem item = new CarsWaitingItem();
            item.setPlateNumber(jsonObject.getString("plateNumber"));
            item.setExteriorColor(jsonObject.getString("exteriorColor"));
            item.setCarType(jsonObject.getString("licenseModel"));
            item.setDate(jsonObject.getString("createDate"));
            item.setCarId(jsonObject.getInt("carId"));
            item.setJsonObject(jsonObject);

            data.add(item);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    adapter.notifyDataSetChanged();

    startNumber = data.size() + 1;

    if (data.size() == 0) {
        footerView.setVisibility(View.GONE);
    } else {
        footerView.setVisibility(View.VISIBLE);
    }

    //        for(int i = 0; i < data.size(); i++)
    //            swipeListView.closeAnimate(i);

    //        // 0, ??(?
    //        if(data.size() == 0) {
    //            DeleteFiles.deleteFiles(AppCommon.photoDirectory);
    //            DeleteFiles.deleteFiles(AppCommon.savedDirectory);
    //        }
}

From source file:com.norman0406.slimgress.API.Interface.Interface.java

public void request(final Handshake handshake, final String requestString, final Location playerLocation,
        final JSONObject requestParams, final RequestResult result) throws InterruptedException {
    if (!handshake.isValid() || handshake.getXSRFToken().length() == 0)
        throw new RuntimeException("handshake is not valid");

    new Thread(new Runnable() {
        public void run() {

            // create post
            String postString = mApiBaseURL + mApiRequest + requestString;
            HttpPost post = new HttpPost(postString);

            // set additional parameters
            JSONObject params = new JSONObject();
            if (requestParams != null) {
                if (requestParams.has("params"))
                    params = requestParams;
                else {
                    try {
                        params.put("params", requestParams);

                        // add persistent request parameters
                        if (playerLocation != null) {
                            String loc = String.format("%08x,%08x", playerLocation.getLatitude(),
                                    playerLocation.getLongitude());
                            params.getJSONObject("params").put("playerLocation", loc);
                            params.getJSONObject("params").put("location", loc);
                        }/*  ww w.  j  a v  a  2s  . co  m*/
                        params.getJSONObject("params").put("knobSyncTimestamp", getCurrentTimestamp());

                        JSONArray collectedEnergy = new JSONArray();

                        // TODO: add collected energy guids

                        params.getJSONObject("params").put("energyGlobGuids", collectedEnergy);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            } else {
                try {
                    params.put("params", null);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            try {
                StringEntity entity = new StringEntity(params.toString(), "UTF-8");
                entity.setContentType("application/json");
                post.setEntity(entity);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            // set header
            post.setHeader("Content-Type", "application/json;charset=UTF-8");
            post.setHeader("Accept-Encoding", "gzip");
            post.setHeader("User-Agent", "Nemesis (gzip)");
            post.setHeader("X-XsrfToken", handshake.getXSRFToken());
            post.setHeader("Host", mApiBase);
            post.setHeader("Connection", "Keep-Alive");
            post.setHeader("Cookie", "SACSID=" + mCookie);

            // execute and get the response.
            try {
                HttpResponse response = null;
                String content = null;

                synchronized (Interface.this) {
                    response = mClient.execute(post);
                    assert (response != null);

                    if (response.getStatusLine().getStatusCode() == 401) {
                        // token expired or similar
                        //isAuthenticated = false;
                        response.getEntity().consumeContent();
                    } else {
                        HttpEntity entity = response.getEntity();

                        // decompress gzip if necessary
                        Header contentEncoding = entity.getContentEncoding();
                        if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip"))
                            content = decompressGZIP(entity);
                        else
                            content = EntityUtils.toString(entity);

                        entity.consumeContent();
                    }
                }

                // handle request result
                if (content != null) {
                    JSONObject json = new JSONObject(content);
                    RequestResult.handleRequest(json, result);
                }
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

From source file:com.axinom.drm.quickstart.activity.SampleChooserActivity.java

private void makeMoviesRequest() {
    JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, API_CATALOG, null,
            new Response.Listener<JSONArray>() {
                @Override//w  w w .  j a va2 s  .c o m
                public void onResponse(JSONArray response) {
                    // Adding video URLs and names to lists from json array response.
                    for (int i = 0; i < response.length(); i++) {
                        try {
                            JSONObject jsonObject = response.getJSONObject(i);
                            mVideoUrls.add(jsonObject.getString("url"));
                            mVideoNames.add(jsonObject.getString("name"));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    ArrayAdapter adapter = new ArrayAdapter<String>(getApplicationContext(),
                            android.R.layout.simple_list_item_1, mVideoNames) {
                        @Override
                        public View getView(int position, View convertView, ViewGroup parent) {
                            View view = super.getView(position, convertView, parent);
                            TextView textView = (TextView) view.findViewById(android.R.id.text1);
                            textView.setTextColor(Color.BLACK);
                            return view;
                        }
                    };
                    mListView.setAdapter(adapter);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(TAG, "Movies json was not loaded with error: " + error.getMessage());
                }
            });
    BaseApp.requestQueue.add(request);
}

From source file:com.seanmadden.net.fast.FastInterpretype.java

public FastInterpretype() {

    BufferedReader reader;// w  w  w  .j  a  va2s .c om
    try {
        reader = new BufferedReader(new FileReader(filename));
        String line = "", jsonData = "";
        while ((line = reader.readLine()) != null) {
            jsonData += line;
        }
        config = new JSONObject(jsonData);
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
        System.out.println("Configuration not found!  Preloading settings.");
        try {
            config.put("SerialPort", "COM1");
            config.put("SerialBaud", 19200);
            config.put("SerialParity", 0);
            config.put("SerialBits", 8);
            config.put("SerialStopBits", 1);
            config.put("StringBreakLength", 50);
            config.put("OperatorName", "Operator");
            FileWriter writer = new FileWriter(filename);
            config.write(writer);
            writer.flush();
            writer.close();
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    si = new SerialInterface(config);
    si.open();
    si.addObserver(this);
    mw = new MainWindow(this);
    si.sendRawDataToPort(DataPacket.generateClearConvoPayload());
    String username = JOptionPane.showInputDialog("What is your name?");
    si.sendRawDataToPort(DataPacket.generateSignedOnPayload(username));
    mw.acceptText(username + " (you) has signed on.\n");
    mw.setLocalUserName(username);
    try {
        config.put("OperatorName", username);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    mw.validate();
    mw.setVisible(true);
}