Custom Server Code - JSON Error

0 votes

Custom server coding issues.

I have the java code on the server working fine. And I have been able to call it successfully using IOS and swift.

On java however, I am throwing an exception and cannot for the life of me determine why. Help please....

public void fetch (int count, final OnCompleteCallback callback) {
        final CustomCodeService customCodeService = App42API.buildCustomCodeService();
        try {
            
            customCodeService.runJavaCode("Prayerful", null, new App42CallBack() {
                @Override
                public void onSuccess(final Object o) {
                   
                    JSONObject storage = (JSONObject) o;

                    try {
                        JSONObject r = (JSONObject) storage.get("result");

                        callback.onSuccess();
                    } catch (Exception ex) {

                    }
                }

                @Override
                public void onException(final Exception e) {
                    String msg = e.getMessage();  <--------------- Hitting this exception.
                    callback.onException(e);
                }
            });
        } catch (Exception e) {
            
        }
    }

The exception is:

com.shephertz.app42.paas.sdk.android.App42Exception: org.json.JSONException: Value <html><body>404< of type java.lang.String cannot be converted to JSONObject

 

Thoughts? Not sure why I can run it from the UI Console and from Swift just fine but Android is barfing.

asked Apr 17, 2017 in Android by Christian.Henne (11 points)
edited Apr 18, 2017 by Christian.Henne

1 Answer

–1 vote
Hi Christian,

Could you please put a debugger and check where exactly you are getting an exception?

Also, I would suggest instead of doing direct typecast in:

JSONObject storage = (JSONObject) o;

Change this above line of code into:

JSONObject storage = new JSONObject(o); // check if object is a string or not

 

regards,

Himanshu Sharma
answered Apr 18, 2017 by hs00105 (2,005 points)
Please take a look at where the exception is being reported. It is in the OnException() method for runJavaCode. It is NOT as a result of anything inside OnSuccess because it never gets there. Therefore I am assuming it is something within runJavaCode itself. I would check the server logs but it appears there is no way to access any unless this is a scheduled service. The documentation on this is very poor.

Also, look at the exception message. It contains HTML and 404 like something isn't being reached. However, like I said, the server code runs fine from the console and from IOS.
Hi Christian.Henne,

Could you please share the code and your app credentials with us at support@shephertz.com and allow us to test it at our end with your app? it will help us to provide better support to you.

Regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...