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.atolcd.alfresco.ProxyAuditFilter.java

private String getNodeRefRemoteCall(HttpServletRequest request, String userId, String siteId,
        String componentId, String objectId) throws JSONException, URIException, UnsupportedEncodingException {
    Connector connector;/*w ww  .j a  v  a  2 s .c  o m*/

    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:de.dan_nrw.android.scroid.dao.wallpapers.parsing.JsonWallpaperParser.java

@Override
public List<Wallpaper> parse(String data) throws ParseException {
    try {/*from  ww  w .ja v a2 s.  c  o m*/
        JSONArray array = new JSONArray(data);
        List<Wallpaper> wallpapers = new ArrayList<Wallpaper>();

        for (int i = 0; i < array.length(); i++) {
            JSONObject jsonWallpaper = array.getJSONObject(i);

            wallpapers.add(new Wallpaper(jsonWallpaper.getString("id"), jsonWallpaper.getString("title"),
                    URI.create(jsonWallpaper.getString("thumburl")),
                    URI.create(jsonWallpaper.getString("previewurl")),
                    URI.create(jsonWallpaper.getString("url")), jsonWallpaper.getString("text")));
        }

        return wallpapers;
    } catch (JSONException ex) {
        throw new ParseException(ex.getMessage(), 0);
    }
}

From source file:com.google.identitytoolkit.RpcHelper.java

@VisibleForTesting
JSONObject checkGitkitException(String response) throws GitkitClientException, GitkitServerException {
    try {// w  w w.j a va2  s . c  o  m
        JSONObject result = new JSONObject(response);
        if (!result.has("error")) {
            return result;
        }
        // Error handling
        JSONObject error = result.getJSONObject("error");
        String code = error.optString("code");
        if (code != null) {
            if (code.startsWith("4")) {
                // 4xx means client input error
                throw new GitkitClientException(error.optString("message"));
            } else {
                throw new GitkitServerException(error.optString("message"));
            }
        }
    } catch (JSONException e) {
        log.warning("Server response exception: " + e.getMessage());
    }
    throw new GitkitServerException("null error code from Gitkit server");
}

From source file:com.nebel_tv.content.services.MediaItemServiceTest.java

/**
 * Test of getMediaItem request of service IvaWrapperWeb (remote server).
 *
 * @param url Service URL//from   ww  w  .j a va 2s .c  o  m
 */
public void testServiceRequest(String url) {
    try {
        String response = IOUtils.toString(new URL(url));
        assertTrue(response != null && !response.isEmpty());

        JSONObject jsonItem = new JSONObject(response);
        testJsonMediaItem(jsonItem);
    } catch (JSONException e) {
        fail("JSON parsing failed" + e.getMessage());
    } catch (IOException e) {
        fail("Web service request failed " + e.getMessage());
    }
}

From source file:com.nolanofra.test.lazyLoader.MainActivity.java

private ArrayList<Video> getVideos(String url) {
    ArrayList<Video> videos = new ArrayList<Video>();

    String jsonString = executeGet(url);

    JSONTokener tokener = new JSONTokener(jsonString);

    JSONObject objectMain = null;/*from   w ww .j av  a 2 s.  c  om*/

    try {
        objectMain = new JSONObject(tokener);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    JSONObject data = null;
    JSONArray itemsArray = null;
    try {
        data = objectMain.getJSONObject("data");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    try {
        itemsArray = data.getJSONArray("items");

        for (int i = 0; i < itemsArray.length(); i++) {
            JSONObject videoRoot = itemsArray.getJSONObject(i);
            JSONObject video = videoRoot.getJSONObject("video");
            Video v = new Video();
            v.title = video.getString("title");
            if (!video.isNull("description"))
                v.description = video.getString("description");
            if (!video.isNull("thumbnail")) {
                JSONObject thumbnail = video.getJSONObject("thumbnail");
                v.thumbnailHQDefault = thumbnail.getString("hqDefault");
                v.thumbnailSQDefault = thumbnail.getString("sqDefault");
            }

            videos.add(v);
        }
    } catch (Exception e) {
        Log.d("error", e.getMessage());
    }

    return videos;
}

From source file:com.tune.reporting.base.endpoints.AdvertiserReportCohortBase.java

/**
 * Parse response and gather job identifier.
 *
 * @param response @see TuneServiceResponse
 *
 * @return String Report Job Id on Export queue.
 * @throws TuneServiceException If service fails to handle post request.
 * @throws TuneSdkException If error within SDK.
 * @throws IllegalArgumentException Invalid parameter.
 *//*from   www  .j a v  a2  s  .c o  m*/
public static String parseResponseReportJobId(final TuneServiceResponse response)
        throws TuneServiceException, TuneSdkException, IllegalArgumentException {
    if (null == response) {
        throw new IllegalArgumentException("Parameter 'response' is not defined.");
    }

    JSONObject jdata = (JSONObject) response.getData();
    if (null == jdata) {
        throw new TuneServiceException("Report request failed to get export data.");
    }

    if (!jdata.has("job_id")) {
        throw new TuneSdkException(String.format("Export data does not contain report 'jobId', response: %s",
                response.toString()));
    }

    String reportJobId = null;
    try {
        reportJobId = jdata.getString("job_id");
    } catch (JSONException ex) {
        throw new TuneSdkException(ex.getMessage(), ex);
    } catch (Exception ex) {
        throw new TuneSdkException(ex.getMessage(), ex);
    }

    if ((null == reportJobId) || reportJobId.isEmpty()) {
        throw new TuneSdkException(
                String.format("Export response 'jobId' is not defined, response: %s", response.toString()));
    }

    return reportJobId;
}

From source file:com.tune.reporting.base.endpoints.AdvertiserReportCohortBase.java

/**
 * Parse response and gather report url.
 *
 * @param response @see TuneServiceResponse
 *
 * @return String Report URL download from Export queue.
 * @throws TuneSdkException If error within SDK.
 * @throws TuneServiceException If service fails to handle post request.
 *//* w ww  .j a  va 2s  . co  m*/
public static String parseResponseReportUrl(final TuneServiceResponse response)
        throws TuneSdkException, TuneServiceException {
    if (null == response) {
        throw new IllegalArgumentException("Parameter 'response' is not defined.");
    }

    JSONObject jdata = (JSONObject) response.getData();
    if (null == jdata) {
        throw new TuneServiceException("Report export response failed to get data.");
    }

    if (!jdata.has("url")) {
        throw new TuneSdkException(
                String.format("Export data does not contain report 'url', response: %s", response.toString()));
    }

    String reportUrl = null;
    try {
        reportUrl = jdata.getString("url");
    } catch (JSONException ex) {
        throw new TuneSdkException(ex.getMessage(), ex);
    } catch (Exception ex) {
        throw new TuneSdkException(ex.getMessage(), ex);
    }

    if ((null == reportUrl) || reportUrl.isEmpty()) {
        throw new TuneSdkException(
                String.format("Export response 'url' is not defined, response: %s", response.toString()));
    }

    return reportUrl;
}

From source file:com.dedipower.portal.android.TicketLanding.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ticketlanding);
    final ListView list = (ListView) findViewById(R.id.TicketList);

    final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....",
            true);//from  w  ww .  j  a  va2s .  co  m
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                OpenTicketsAdaptor adapter = new OpenTicketsAdaptor(TicketLanding.this, listOfTickets,
                        API.SessionID);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                TicketAPI = API.PortalQuery("tickets", "none");
                Success = TicketAPI.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured.";
                Success = "false";
            }

            if (Success.equals("false")) {
                try {
                    ErrorMessage = TicketAPI.getString("msg");
                } catch (JSONException e) {
                    ErrorMessage = "A JSON parsing error prevented an exact error message to be determined.";
                }
            } else {
                Log.i("APIFuncs", TicketAPI.toString());
                try {
                    Tickets = TicketAPI.getJSONArray("tickets");
                    ErrorMessage = "";
                } catch (JSONException e) {
                    ErrorMessage = "There are no open tickets for your account.";
                }

                //OK lets actually do something useful
                //ListView list = (ListView)findViewById(R.id.TicketList);
                //List<OpenTickets> listOfTickets = new ArrayList<OpenTickets>();
                int TicketCount = Tickets.length();

                if (TicketCount == 0) {
                    ErrorMessage = "There are no open tickets for your account.";
                    handler.sendEmptyMessage(0);
                    return;
                }

                for (int i = 0; i < TicketCount; i++) {
                    JSONObject CurrentTicket = null;
                    try {
                        CurrentTicket = Tickets.getJSONObject(i);
                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }
                    try {
                        listOfTickets.add(new OpenTickets(CurrentTicket.getString("status"),
                                CurrentTicket.getInt("id"), CurrentTicket.getString("server"),
                                CurrentTicket.getString("email"), CurrentTicket.getString("subject"),
                                CurrentTicket.getInt("createdat"), CurrentTicket.getInt("lastupdate"), false));
                        //CurrentTicket.getBoolean("subscriber")));
                    } catch (JSONException e) {
                        Log.e("APIFuncs", e.getMessage());
                    }
                }
            }

            handler.sendEmptyMessage(0);
        }
    };

    dataPreload.start();
}

From source file:rom.relurori.hanblocks.db.spreadsheet.AbstractGetNameTask.java

@Override
protected Void doInBackground(Void... params) {
    Log.d(TAG, "doInBackground");
    try {/*from w w w  .ja  va2  s.  c o  m*/
        // do work on server
        fetchNameFromProfileServer();
        //fetchSpreadsheetListFromServer();
    } catch (IOException ex) {
        onError("Following Error occured, please try again. " + ex.getMessage(), ex);
    } catch (JSONException e) {
        onError("Bad response: " + e.getMessage(), e);
    }
    return null;
}

From source file:com.app.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject //from   ww w  . j  a v a  2 s.c om
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", false);
    }

    final WebView parent = this.webView;

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            //LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            //LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            //LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);

            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(cordova.getActivity());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            /*
            ImageButton back = new ImageButton((Context) ctx);
            back.getBackground().setAlpha(0);
            back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goBack();
            }
            });
            back.setId(1);
            try {
            back.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setLayoutParams(backParams);
                    
            ImageButton forward = new ImageButton((Context) ctx);
            forward.getBackground().setAlpha(0);
            forward.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goForward();
            }
            });
            forward.setId(2);
            try {
            forward.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
            }               
            forward.setLayoutParams(forwardParams);
            */

            /*
            edittext = new EditText((Context) ctx);
            edittext.setOnKeyListener(new View.OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  navigate(edittext.getText().toString());
                  return true;
                }
                return false;
            }
            });
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setLayoutParams(editParams);
            */
            //edittext = new EditText((Context) ctx);
            //edittext.setVisibility(View.GONE);

            LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.FILL_PARENT, 1.0f);
            TextView title = new TextView(cordova.getActivity());
            title.setId(1);
            title.setLayoutParams(titleParams);
            title.setGravity(Gravity.CENTER_VERTICAL);
            title.setTypeface(null, Typeface.BOLD);

            ImageButton close = new ImageButton(cordova.getActivity());
            close.getBackground().setAlpha(0);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });
            close.setId(4);
            try {
                close.setImageBitmap(loadDrawable("plugins/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setLayoutParams(closeParams);

            childWebView = new WebView(cordova.getActivity());
            childWebView.getSettings().setJavaScriptEnabled(true);
            childWebView.getSettings().setBuiltInZoomControls(true);
            WebViewClient client = new ChildBrowserClient(parent, ctx, title/*, edittext*/);
            childWebView.setWebViewClient(client);
            childWebView.loadUrl(url);
            childWebView.setId(5);
            childWebView.setInitialScale(0);
            childWebView.setLayoutParams(wvParams);
            childWebView.requestFocus();
            childWebView.requestFocusFromTouch();

            //toolbar.addView(back);
            //toolbar.addView(forward);
            //toolbar.addView(edittext);
            toolbar.addView(close);
            toolbar.addView(title);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(childWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;
            lp.verticalMargin = 0f;
            lp.horizontalMargin = 0f;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}