× 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.



Scott,

I was going to just write it to a file because I couldn't get the larger variable working with CGIDEV2. Based on the web service sample, the SOAP envelope (below), including the "filename" and "passphrase" should not be base64 encoded, while the XML message is encoded. So I wasn't sure how to go about that.

Since the max size of the SOAP message is 10MB, maybe I should focus on getting this to work w/out using a streamfile.

My problem is this:

I'm using CGIDEV2 to build my XML document. So GetHtmlBufferP() allows me to access the data without writing it to the IFS. In the CGIDEV2 example of GetHtmlBufferP, it shows a variable of size of 32767 (but I know it is "expandable").
When I make my xmlData variable larger that 32K (i.e.16MB), I lose the first two characters of the data. I also get an "out of range" message with HTTP_xlatedyn().

// This is CGIDEV2 OutBuffer Definition
// dcl-s xmlData varchar(65535) based(xmlbufferP); *** THIS WORKS ***
dcl-s xmlData varchar(16773100) based(xmlbufferP);
dcl-ds xmlBufferInfo;
xmlBufferP pointer;
xmlBufferLen uns(10);
end-ds;

I'm sure this has to do with the 4-byte offset for the larger variable, but I'm not sure how I account for that.

Greg

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Tuesday, May 21, 2019 8:01 PM
To: rpg400-l@xxxxxxxxxxxxxxxxxx
Subject: Re: Base64 Encoding

Greg,

Please consider using the newer functions rather than the old http_url_xxx routines.

I don't really understand why you want to put your data into a file (I guess so you can handle larger than 16mb files...  that's about the only thing I can think of?).  If so, its just a matter of base64 encoding it, then writing it to the IFS.

Not really sure what you're asking, I guess.


On 5/21/19 12:32 PM, Greg Wilburn wrote:
As a follow up to my earlier post...

I have this code working (the UTF-8 translation was not necessary). But I'm anticipating a possible issue once the size of the XML payload gets larger. I'm basically keeping everything in memory, and posting to the web service.

The problem occurs when my XML payload gets very large... I would like to write the XML Payload to a file, base64 encode that, then post the SOAP message. Given the current process below, how can I combine the base64 encoded data with the SOAP Header/Envelope, filename and passphrase? I would like to use HTTP_URL_POST_STMF.

One other point is that I will likely have to hit this same web service with other data.

Currently working process:

1. Use CGIDEV2 to create the XML payload (using a template for the
structure) 2. Instead of using WrtHtmlToStmf, I use GetHtmlBufferP to
get the pointer to my XML data 3. Base64 encode the XML payload buffer
(xmlData64) 4. Post the SOAP message (including the filename and
passphrase) using HTTP_URL_POST

SOAP=
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";'+
' xmlns:tem="http://tempuri.org/";>'+
'<soapenv:Header/>'+
'<soapenv:Body>'+
'<tem:UploadFile>'+
'<tem:f>' + xmlData64 + '</tem:f>'+
'<tem:fileName>' + filename + '</tem:fileName>'+
'<tem:passphrase>' + passphrase + '</tem:passphrase>'+
'</tem:UploadFile>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';

rc = http_url_post( URL
: %addr(SOAP: *data)
: %len(%trimr(SOAP))
: ResponseStmf
: HTTP_TIMEOUT
: HTTP_USERAGENT
: HTTP_CONTTYPE);

if rc <> 1;
httperror = http_error();
endif;



-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxxxxxxxx] On Behalf
Of Scott Klement
Sent: Friday, May 17, 2019 2:30 AM
To: rpg400-l@xxxxxxxxxxxxxxxxxx
Subject: Re: Base64 Encoding

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
--
Scott Klement
http://www.scottklement.com

--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a
message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

--
Scott Klement
http://www.scottklement.com

--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.