Client is not authorized while inserting objects into collection in a loop

0 votes

Hi,

We are getting an error randomly saying "Client is not authorized". Below is what we are doing:

1. Getting the json objects from one app in a jsonArray

2. Initialize app42 wtih other app using the correct apiKey and secreKey.

3. Then we have a loop that inserts objects from the jsonArray into a collection.

It works fine for some of the objects so apikey and secretkey are correct, then it randomly gives the exception as given below:

{"app42Fault":{"httpErrorCode":401,"appErrorCode":1401,"message":"UnAuthorized Access","details":"Client is not authorized"}}

Note : We have replay attack protect as DISABLED, still we have the issue. Please help.

related to an answer for: Error : "Client is not authorized"
asked Mar 25, 2016 in Java by jitesh.h.lalwani (20 points)

1 Answer

0 votes
Hi Jitesh,

 

Could you please share the complete logs and the code snippet in which you are working on. It will help us to provide better support to you.

Regards,

Himanshu Sharma
answered Mar 25, 2016 by hs00105 (2,005 points)
Please see the code below:
public static boolean insertObjectsIntoCollection(JSONArray jsonArray, String dbName, String collectionName) throws JSONException, InterruptedException{
        JSONObject jsonObj;
        boolean result = false;

        for (int i = 0; jsonArray != null && i < jsonArray.length(); i++) {
            jsonObj = jsonArray.getJSONObject(i);
            result = App42Utilities.insertJSONObject(dbName, collectionName, jsonObj);
            if(!result){
                return result;
            }
        }
        return true;
    }

AppUtilities.insertJSONDocument just has following code:
try {
            App42Log.setDebug(true);
            storageService.insertJSONDocument(dbName,collectionName,jsonObject);
        } catch (App42Exception e) {
            System.out.println("Not inserted object :: " + jsonObject.getString("title"));
            //e.printStackTrace();
        }

I will post logs in next comment.
Json String : {"app42":{"storage":{"jsonDoc":{"releaseDetails":[{"releaseDate":"2015-10-02T00:00:00.000Z","country":"US"}],"genre":["Drama","Sci-Fi"],"trailer":"https://youtu.be/Ue4PCI0NamI","starcast":[{"characterName":"Mark Watney","actorName":"Matt Damon"},{"characterName":"Melissa Lewis","actorName":"Jessica Chastain"},{"characterName":"Teddy Sanders","actorName":"Jeff Daniels"},{"characterName":"Rick Martinez","actorName":"Michael Peña"},{"characterName":"Annie Montrose","actorName":"Kristen Wiig"},{"characterName":"Mitch Henderson","actorName":"Sean Bean"},{"characterName":"Beth Johanssen","actorName":"Kate Mara"},{"characterName":"Vincent Kapoor","actorName":"Chiwetel Ejiofor"},{"characterName":"Rich Purnell","actorName":"Donald Glover"}],"recentlyReleased":"N","editorChoice":"N","carouselType":"details","comingSoon":"N","insertDate":"1/9/2016","updateDate":"1/9/2016","newTrailer":"N","oscarWinner":"N","title":"The Martian","username":"kush747@gmail.com","carouselMovie":"N","facts":[],"background":"Comedy","poster":"http://cdn.shephertz.com/repository/files/bdd80d43a10e63f9977032785de20f0f6cb7087e487e56e0c2d8f7ae086cbced/eb5fddc181261ca47b8e2785afce2a6fa4e7da9b/The Martian.jpg","synopsis":"Presumed dead, Mark Watney is left alone on Mars during a NASA mission. Now, he must overcome overwhelming odds to survive alone on a deserted planet.","writers":["Drew Goddard","Andy Weir"],"directors":["Ridley Scott"],"producers":["Ridley Scott","Aditya Sood","Michael Schaefer","Simon Kinberg","Teresa Kelly","Mark Huffam"],"carouselImage":""}}}}
Post URL is https://api.shephertz.com/cloud/1.0/storage/insert/dbName/ONFRIDAY/collectionName/MOVIES?
 Setting Header value : signature : K%2B605Ust9jCO1oheyz6BuEsCb70%3D
 Setting Header value : version : 1.0
 Setting Header value : SDKName : Java
 Setting Header value : timeStamp : 2016-03-25T19:48:13.451Z
 Setting Header value : apiKey : ae0cfe7c26c81db40bcecfb4f75039e9965a265ea0f35af2294d7eb3d7c7ca26
App42Exception : {"app42Fault":{"httpErrorCode":401,"appErrorCode":1401,"message":"UnAuthorized Access","details":"Client is not authorized"}}
Hi Jitesh,

Thanks for sharing this details, but its not complete logs and complete code snippet. Could you please share complete logs like where you initialize App42 instance and where you build service and how? Also, the complete logs of method. Please share with us at support@shephertz.com . It will help us to provide better support to you.

Regards,
Himanshu Sharma
Could you please explain what do you mean by complete log of method and how can i get them? I got the above logs by using App42Log.setDebug(true)
Hi,

Complete logs means the logs which you get at the time of having success in inserting a JSON document. It will help us to debug the issue.

Regards.
Himanshu Sharma
Hi Jitesh,

I hope this issue has been resolved. Please let me know in case you still have any concerns.

Regards,
Himanshu Sharma
I'm thinking everyone has this issue.  I just released my game a few days ago and starting receiving this error yesterday when people couldn't get into my game.
Hi User,

The issue which Jitesh is facing is because of non-english character in description,  which can be easily resolved by encoding string into base64 before inserting into JSON document. If you face any other issue related to this then please let me know.  I will be happy to help you!!!.

Regards,
Himanshu Sharma
Hi, thats correct.

Now the problem is we stored the string "Michael Peña" (just an example) without encoding it in to Base64, and it is stored and shown correctly on the dashboard.

But while fetching this object, it doesn't give this value correctly, and thus when we take the object from one collection and try to insert in another, it fails.

And now we have like 22 big json objects that are problematic. Is there an easy way to copy them into destination collection without reinserting them with encoding?
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
...