Page 1 of 1

DBCS data in JSON request to Rest API webservice

Posted: Sat May 06, 2023 10:41 am
by Preethi
Hi Scott,

We are sending JSON request with DBCS data to Rest API webservice. This is not working and we are seeing junk data and this is not working.
The same request and code is working fine for English characters. We are also sending PDF attachment with the request.

The input IFS file has ccsid as 1208. http_mfd_encoder_addvar_s API adds junk data to IFS file. Appreciate any help to fix this issue

code -
D metainfo S 500C

http_mfd_encoder_addvar_s(enc: 'metadata'
: %TRIM(metainfo)
: 'application/json');

Metainfo has the below data
{
"attributes": {
"Store Name": "表外漢字"
"Store Country": "JP",
"Address": "〒181–0013 東京都三鷹市下連雀1丁目1−83",
}
}

HTTPAPI version used - 1.45
Regards,
Preethi

Re: DBCS data in JSON request to Rest API webservice

Posted: Sun May 07, 2023 2:56 pm
by Scott Klement
Stop converting the data to ebcdic....

Re: DBCS data in JSON request to Rest API webservice

Posted: Mon May 08, 2023 3:14 am
by Preethi
Do you mean not to use ccsid 1208?

Re: DBCS data in JSON request to Rest API webservice

Posted: Mon May 08, 2023 7:48 pm
by Scott Klement
No. CCSID 1208 is UTF-8 -- that's perfectly fine.

The problem is that you're calling http_mfd_encoder_addvar_s(), which accepts an EBCDIC character string as it's parameter. So when you pass your UCS-2 field (metainfo) to it, RPG is automatically converting from UCS-2 to EBCDIC.

Would it be possible to use http_mfd_encoder_addstmf to add the JSON file directly from the IFS?

Re: DBCS data in JSON request to Rest API webservice

Posted: Wed May 10, 2023 3:48 pm
by Preethi
Yes the DBCS characters are changed to EBCDIC and the Kanji characters are corrupt. I think the problem is with the procedure http_mfd_encoder_addvar_s where peValue is declared as character field

P http_mfd_encoder_addvar_s...
P B export
D http_mfd_encoder_addvar_s...
D PI 1N
D peEncoder * value
D peVariable 50A varying value
D peValue 256A varying value >>>>>> Character field
D peContType 32767a varying const

The procedure http_mfd_encoder_addvar translate the data to ASCII

c eval p_LD = peData
c callp http_xlate(peDataSize: wwLD: TO_ASCII) >>> Conversion to ASCII
c callp write(dsMfd_fd : p_LD: peDataSize)
c callp http_xlate(peDataSize: wwLD: TO_EBCDIC)

Do you have any suggestion on how to resolve this problem.

Re: DBCS data in JSON request to Rest API webservice

Posted: Wed May 10, 2023 4:05 pm
by Preethi
I am using http_mfd_encoder_addstmf to attach PDF. I am able to add the PDF in IFS file with CCSID 1208 and 819. I just tried to use IFS file with CCSID 1399 for Kanji characters to work but this corrupted the PDF file.

IFS File with CCSID 1399 - JSON request with Kanji characters is populated but file is corrupted.
IFS File with CCSID 1208 - JSON request with Kanji characters is corrupt but file is attached properly.

I am not sure how to proceed.

Re: DBCS data in JSON request to Rest API webservice

Posted: Wed May 10, 2023 4:53 pm
by Preethi
"Would it be possible to use http_mfd_encoder_addstmf to add the JSON file directly from the IFS?"

The restapi accepts 1 file and 1 metadata in json format.

Re: DBCS data in JSON request to Rest API webservice

Posted: Wed May 10, 2023 5:51 pm
by Preethi
Your suggestion to include json as file worked... I will keep you posted if I see any other issue

Thank you so much!