DBCS data in JSON request to Rest API webservice

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
Preethi
Posts: 11
Joined: Mon Apr 10, 2023 1:00 pm

DBCS data in JSON request to Rest API webservice

Post 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
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: DBCS data in JSON request to Rest API webservice

Post by Scott Klement »

Stop converting the data to ebcdic....
Preethi
Posts: 11
Joined: Mon Apr 10, 2023 1:00 pm

Re: DBCS data in JSON request to Rest API webservice

Post by Preethi »

Do you mean not to use ccsid 1208?
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: DBCS data in JSON request to Rest API webservice

Post 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?
Preethi
Posts: 11
Joined: Mon Apr 10, 2023 1:00 pm

Re: DBCS data in JSON request to Rest API webservice

Post 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.
Preethi
Posts: 11
Joined: Mon Apr 10, 2023 1:00 pm

Re: DBCS data in JSON request to Rest API webservice

Post 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.
Preethi
Posts: 11
Joined: Mon Apr 10, 2023 1:00 pm

Re: DBCS data in JSON request to Rest API webservice

Post 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.
Preethi
Posts: 11
Joined: Mon Apr 10, 2023 1:00 pm

Re: DBCS data in JSON request to Rest API webservice

Post 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!
Post Reply