0

I am getting 400 Bad Request when trying this :

 List<Object> list = new ArrayList<Object>();
 Object[]  mongodata = restTemplate.getForObject(mongourl,Object[].class,fileName);
                 list = Arrays.asList(mongodata);
System.out.println("\n MONGODATA \n"+list);

where mongourl is the url for calling mongodb, filename is "EC001.TXT". The data that will be returned is :

[
    {
        "_id": {
            "$oid": "5e141d337d7558rd1f2e91c8"
        },
        "data": [
            {
                "payload": [
                    {
                        "DATA001": "ECE,100,MATH,99,PHY,90",
                        "DATA002": 1
                    }
                ]
            },
            {
                "payload2": [
                    {
                        "SFTPHOST": "test.host",
                        "SFTPPASSWORD": "test.password",
                        "SFTPUSERNAME": "test.username",
                        "FILETYPE": "TEST",
                        "FILENAME": "EC001.TXT",
                        "SFTPPATH": "TEST.path"
                    }
                ]
            }
        ],
        "_etag": {
            "$oid": "5e141d33d6018000083f312b"
        }
    }
]
Thira
  • 81
  • 1
  • 9
  • you are getting 400 along with above data as response.. ? – Ganesh Feb 04 '20 at 07:19
  • @ganesh045: no. i am getting only 400. the data i checked in postman – Thira Feb 04 '20 at 07:25
  • And the endpoints in postman and this code snippet are the same? – A. Wolf Feb 04 '20 at 07:46
  • @A.Wolf : Yes. I copied it from postman – Thira Feb 04 '20 at 08:26
  • There are some differences, or you wouldn't receive 400 :) can you add both endpoint to your question? Then we'll investigate more in depth. – A. Wolf Feb 04 '20 at 08:35
  • Got it. It was something wrong with the url. In postman, we need not give the variables in the url as a string but we need to do it in Java. That was what threw this error. Made the variables a string separately and then added it to the url and it worked. – Thira Feb 04 '20 at 09:33

1 Answers1

0

It was something wrong with the url. In postman, we need not give the variables in the url as a string but we need to do it in Java. That was what threw this error. Made the variables a string separately and then added it to the url and it worked.

Thira
  • 81
  • 1
  • 9