×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Greg,
So you have EBCDIC XML data, and you want to convert it to UTF-8 and
then base64 encode it? That's certainly doable, but I've never seen a
web service that wants it done that way. But, assuming that's what you
need, then your code would look as follows. I will add comments to
explain what each line does:
// tell httpapi to translate from job ccsid (0) to UTF-8 (1208) or
vice-versa
http_setCCSIDs( 1208: 0 );
// Translate xmlData to UTF-8 using a pointer to dynamic memory
utflen = HTTP_xlatedyn( %len(xmlData)
: %addr(xmlData:*DATA)
: TO_ASCII
: p_xmlDataUTF );
// Set output field to max length -- this is important to avoid RPG
// erasing the data when the length is set later
%len(xmlData64) = %len(xmlData64:*MAX);
// Convert UTF-8 string to base64
b64len = base64_encode( p_xmlDataUTF
: utflen
: %addr(xmlData64:*DATA)
: %len(xmlData64:*MAX) );
// Set length to only what was needed for the base64 data
%len(xmlData64) = b64len;
// Free up the dynamic string, we're done with it
dealloc p_xmlDataUTF;
You might consider making xmlData64 larger (utf-8 can make strings longer, as some special characters can take up multiple bytes. then, base64 encoding it will also make it 33% longer.) So if your input data can be up to 2048 characters (which is very small for an xml doc) then the max size of the output of this routine would be 10924 bytes. It's unlikely that it'd be that large, but there's no reason not to account for the worst case scenario. (Especially since you're only talking about appeox 10k, a tiny piece of memory by today's standards.)
Good luck!
On 5/16/19 2:36 PM, Greg Wilburn wrote:
Is this the easiest way to Base64 encode and XML document (either in an RPG variable or on the IFS) for use in a SOAP web service?
I've used Scott's BASE64R4 service program for smaller things like API keys, etc.
I've been trying to mock-up a test scenario, and I'm not getting the results I expected - pretty sure I'm doing something wrong with the varchar fields. The code I'm copying was using much smaller fixed length fields.
xmlData and xmlData64 are both varchar(2048)... however the data is nowhere near that large (utflen=710).
http_setCCSIDs( 1208: 0 );
utflen = HTTP_xlatedyn( %len(%trim(xmlData))
: %addr(xmlData)
: TO_ASCII
: p_xmlDataUTF );
b64len = base64_encode( p_xmlDataUTF
: utflen
: %addr(xmlData64)
: %size(xmlData64) );
dealloc p_xmlDataUTF;
My resulting data in xmlData64 does not match the online encoders.
Thanks,
Greg
As an Amazon Associate we earn from qualifying purchases.