cancel
Showing results for 
Search instead for 
Did you mean: 

Error processing JSON input for Create operations.

avishek_gorai2
Participant
0 Kudos

Hi,

We are trying to give JSON as input to a Gateway services Create method and the same is failing in Gateway with RABAX ERROR. On checking ST22 logs found the following error 'Error while parsing an XML stream: 'BOM / charset detection failed'.'

We tried to pass this as input from REST client with the following headers along with the X-CSRF token in the header:

Content-Type : application/json; charset=utf-8

Accept: application/json

The same operation was tried from a SAPUI5 application where we set the model type as JSON [new sap.ui.model.odata.ODataModel( sServiceUrl ,  true,  "User",  "Pwd"); ] and got the same error in ST22. Whereas the same operation worked from SAPUI5 when model was XML [new sap.ui.model.odata.ODataModel( sServiceUrl ,  false,  "User",  "Pwd"); ].

The Gateway system in SP06 and is able to output JSON.

Any pointers to resolve the issue will be highly appreciated.

Thanks,

Avishek

Accepted Solutions (0)

Answers (3)

Answers (3)

AshwinDutt
Active Contributor
0 Kudos

Hello Avishek,

Your Body would be like this : Sample Body ->

{

"ManuCompany":"ABCD",

"RequestNo":"TEST",

"RequestItmno":"0001",

"FromPackage":"YY0025",

"ToPackage":"XX0025",

"Quantity":"1",

"BaseUnit":"TON"

}

Please make sure you maintain the below headers correctly :

Content-Type - application/json ( To specify your content in body is in JSON format )

Accept - application/json ( To get reaponse in JSON )

x-csrf-token : <Value Which You have Fetched via a GET>

With the above you should be easily accomplish CREATE without any parsing error.

Regards,

Ashwin

Pavan_Golesar
Active Participant
0 Kudos

Hi ,

With your said guidelines... I followed them But I am still facing the same issue...

Can you help?

Regs,

Pavan G

Message was edited by: Pavan Golesar

kammaje_cis
Active Contributor
0 Kudos

Avishesk,

There was a similar thread earlier.

http://scn.sap.com/thread/3396852

Ensure that you have not passed $forma tin the URI. Also I do not think you need to pass charset=utf8.

Thanks

Krishna

avishek_gorai2
Participant
0 Kudos

Hi Krishna, Aakash,

I have tried all of these (no $format in URL, chatset=utf8 in ContentType) and the UI5 code snippet given by Aakash. All of them are throwing the same error.

When I try from a SAPUI5 application, the same code works when oModel is set to XML while it fails when it is set to JSON. Please find the HTTP sniffer traces for both instances (when running the UI5 application).

I even tried from a REST client using various headers and still get the same error. It fails in line 40 of the Constructor method of class CL_SXML_STRING_WRITER in Gateway system.

Payload Trace with XML format:

Payload trace with JSON format in oModel (this is failing at Gateway)

Not sure if our Gateway system has some issues. Any pointers to find this.

Regards,

Avishek.

avishek_gorai2
Participant
0 Kudos

Hi All,

On further debuging found out that the problem could be in reading the JSON from a kernal module. We idntified a place where a Kernal module to read the next node of JSON in called and the error (CSXML_PARSE_ERROR) is raised after this point, the path to the kernal module is CL_SXML_READER~IF_SXML_READER~NEXT_NODE~fxkmsrd_next_node (also find the RSKMETH report's trace for the Kernal module below).

Request some help from the forum experts to validate if the Kernal module is not upto date or any other pointers to resolve this issue...

Also please find below the runtime trace for a call trying to POST JSON data format:

Appreciate any help on this.

Thanks,

Avishek

kammaje_cis
Active Contributor
0 Kudos

Avishek,

Can you try with this request body? That is without 'd'.

{

      "Name": "Avishek",

      "Greeting": "HelloAvishek"

}

Thanks

Krishna

avishek_gorai2
Participant
0 Kudos

Hi Krishna,

Tried it (even had tried the same earlier), system is giving the same error.

Regards,

Avishek.

kammaje_cis
Active Contributor
0 Kudos

one more thing.

Ensure that the name of the properties match those in the metadata. "name" given as "Name" can give this error.

Thanks

Krishna

avishek_gorai2
Participant
0 Kudos

hi Krishna,

The properties seem to be correct, I have copied them from the respose itself and the same issue/error repeats for all services, so I fear this is a sytem issue.

Many thanks for your follow up and response.

Regards,

Avishek.

kammaje_cis
Active Contributor
0 Kudos

I feel that somewhere it is not recognizing the input as json. This is because the control going to xml class (CL_SXML_READER~IF_SXML_READER~NEXT_NODE) instead of json classes.

Former Member
0 Kudos

Hi Avishek,

did you find a solution in the meantime? We are having the same issue currently.

Kind Regards

Thomas

former_member195242
Active Participant
0 Kudos

Hi Avishek,

Looks like there's an error in your JSON request body. It is possible to do a POST request with JSON request body. When you are doing it from Rest Client, you just need to provide a header "Content-type = application/json".

I am not sure how you are providing the request from SAPUI5, but as I do, it works for me. Here is a sample code:

     var oData = {};

     oData.P1 = "abc";

     oData.P2 = "def";

     oData.P3 = "ghi";    //P1,P2,P3 are the properties of the entity in model

       

     oModel.create(sServiceUrl", oData, null, function(oData,response){ }, function(oError){ });

Best regards,

Aakash

avishek_gorai2
Participant
0 Kudos

Hi Akash,

I'll try your code snippet in an UI5 application. Wanted to confirm if you use JSON as the data type while declaring the OData model in UI5 [new sap.ui.model.odata.ODataModel( sServiceUrl ,  true,  "User",  "Pwd"); ] using the second parameter as true.

Sample JSON Input:

{"d":{"BusinessPartnerID":"0200000000","Role":"01","EmailAddress":"abs@xyz.com","PhoneNumber":"012345678","FaxNumber":"","WebAddress":"http://www.xyz.com","CompanyName":"ABC","LegalForm":"LT","CurrencyCode":"INR","City":"Gotham","PostalCode":"12345","Street":"Wall street","Building":"12","Country":"IN","AddressType":"02","AddressValStartDate":null,"AddressValEndDate":null,"CreatedBy":"0000000033","CreatedAt":"/Date(1365173193000)/","ChangedBy":"0000000033","ChangedAt":"/Date(1365173193000)/",}}

Appreciate your help on this.

Regards,

Avishek.

avishek_gorai2
Participant
0 Kudos

Even trying a simpler application with the following JSON input and getting the same error from Gateway system

{

  "d": {

        "Name": "Avishek",

        "Greeting": "HelloAvishek"

      }

}

former_member195242
Active Participant
0 Kudos

Hi Avishek,

Yes I use JSON as data type ( value true ) while creating the model, the same way as you have mentioned. I hope you are using the exact property names in the json request. Did you try the way I have specified?

Best regards,

Aakash