All,
I am in need of some assistance in developing my first RPG program to
decode Base64 data.
The requirement is to request a Qualcomm webservice, Event Subscription
Service (ESS), and call the Dequeue2 method which returns message data
that I want to store & use on our IBM i.
Using soapUI I can clearly see the expected response:
<soapenv:Envelope
xmlns:soapenv="[1]http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="[2]http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="[3]http://www.w3.org/2001/XMLSchema"
xmlns:xsi="[4]http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p917:dequeue2Response xmlns:p917="[5]http://websvcs.otswebws">
<dequeue2Return>
<count>3</count>
<transactions>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48dHJhb
kJsb2NrPjx0cmFuIElEPSI3OTM5IiBjb21wYW55SUQ9IlRNVFNXIiBhdXhJRD0iMDA5MzM2
ODM0OCI+PFQuNy4wMS4wPgk8a2V5PjI2NzU3MDQ8L2tleT4JPGV2ZW50VFM+MjAxMi0xMC0
wM1QyMToxMDowNlo8L2V2ZW50VFM+CTxzdGF0dXM+TmV3PC9zdGF0dXM+CTxpbnNwZWN0ZW
RFcXVpcG1lbnQ+dHJhaWxlcjwvaW5zcGVjdGVkRXF1aXBtZW50Pgk8ZXF1aXBtZW50IAkgI
HVuaXRBZGRyZXNzPSIxMDUzNTI3OTMiIAkgIGRldmljZUlEPSIxMDUzNTI3OTMiIAkgIElE
PSIxMDEwIiAJICBlcXVpcFR5cGU9InRyYWN0b3IiIAkgIGFsaWFzPSIxMTAwNjg4IgkgIC8
+CTxwb3NpdGlvbiBsYXQ9IjM1LjkxMjA4MyIgbG9uPSItNzguOTc3MTc2IiBwb3NUUz0iMj
AxMi0xMC0wMlQyMToyNTo0MFoiLz4JPHBvc1R5cGU+MTwvcG9zVHlwZT4JPGlnbml0aW9uU
3RhdHVzPjE8L2lnbml0aW9uU3RhdHVzPgk8dHJpcFN0YXR1cz4wPC90cmlwU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A5MzM2ODM0OCI+PFQuNy4wMy4wPgk8a2V5Pjc0ODAxM
Dwva2V5Pgk8ZXZlbnRUUz4yMDEyLTEwLTAzVDIxOjIwOjA3WjwvZXZlbnRUUz4JPGVxdWlw
bWVudCAJICB1bml0QWRkcmVzcz0iMTA1MzUyNzkzIiAJICBkZXZpY2VJRD0iMTA1MzUyNzk
zIiAJICBJRD0iMTAxMCIgCSAgZXF1aXBUeXBlPSJ0cmFjdG9yIiAJICBhbGlhcz0iMTAxMC
IJICAvPgk8Y29tcGxldGlvbkNvZGU+MzwvY29tcGxldGlvbkNvZGU+CTxjb21wbGV0aW9uU
3RhdHVzPk1lc3NhZ2UgQWNrbm93bGVkZ2VkPC9jb21wbGV0aW9uU3RhdHVzPjwvVC43LjAz
LjA+PC90cmFuPjwvdHJhbkJsb2NrPg==</transactions>
<transactionIdOut>7941</transactionIdOut>
</dequeue2Return>
</p917:dequeue2Response>
</soapenv:Body>
</soapenv:Envelope>
The <transactions> element decoded:
<?xml version="1.0" encoding="UTF-8"?><tranBlock><tran ID="7939"
companyID="XXXXX"
auxID="0093368348"><T.7.01.0> <key>2675704</key> <eventTS>2012-10-03T21
:10:06Z</eventTS> <status>New</status> <inspectedEquipment>trailer</ins
pectedEquipment> <equipment unitAddress="105352793"
deviceID="105352793" ID="1010" equipType="tractor"
alias="1100688" /> <position lat="35.912083" lon="-78.977176"
posTS="2012-10-02T21:25:40Z"/> <posType>1</posType> <ignitionStatus>1</
ignitionStatus> <tripStatus>0</tripStatus> <ltdDistance>0</ltdDistance>
<driverID>DONNIE</driverID> <driverAuthenticated>true</driverAuthentic
ated> <hasDefects>true</hasDefects> <defects> <comments>Trailer is
falling apart</comments> <defect>Coupling (King) Pin</defect>
<defect>Landing Gear</defect> <defect>Brakes</defect>
<defect>Other</defect> <defect>Reefer</defect>
<defect>Doors</defect> </defects></T.7.01.0></tran><tran ID="7940"
companyID="XXXXX"
auxID="0093368348"><T.7.02.0> <key>748010</key> <eventTS>2012-10-03T21:
19:31Z</eventTS> <equipment unitAddress="105352793"
deviceID="105352793" ID="1010" equipType="tractor"
alias="1010"
/> <completionCode>0</completionCode> <completionStatus></completionSta
tus></T.7.02.0></tran><tran ID="7941" companyID="XXXXX"
auxID="0093368348"><T.7.03.0> <key>748010</key> <eventTS>2012-10-03T21:
20:07Z</eventTS> <equipment unitAddress="105352793"
deviceID="105352793" ID="1010" equipType="tractor"
alias="1010"
/> <completionCode>3</completionCode> <completionStatus>Message
Acknowledged</completionStatus></T.7.03.0></tran></tranBlock>
A snippet of documentation on the <transactions> element:
The ESS High-Volume Transaction Block data type is implemented as the
TransactionBlock2 class. It is returned by the [6]ESS High-Volume
Dequeue method. The attributes of an ESS High Volume Transaction Block
are:
Attribute Description
count This integer value contains the number of transactions that are
contained in this block. Choose a host variable large enough for values
up to five digits.
transactionIdOut This long integer value contains the highest
transaction ID returned in the transaction block. Choose a host
variable large enough for values up to 17 digits.
transactions An array of bytes containing the transactions that were
retrieved by this call to dequeue. Choose a host variable large enough
to receive up to 1mb or more worth of bytes in a single call. See the
note below for the format of this byte array.
The transaction block will contain [7]ESS Transactions. Also helpful in
making use of the returned transaction block is the [8]ESS Transaction
Schema.
Note: The <transactions> element is defined in the WSDL as XML data
type xsd:base64Binary. You will need to employ a base64Binary decoder
to translate the transaction data into ASCII or Unicode. Some platforms
have built-in functions to do this. .NET is one such example. Other
platforms will require you download and use a library containing the
base64Binary decoder. A Google search for your platform with the term
"base64 decoder" will likely show several freely available algorithms
for decoding base64Binary data. The algorithm is well defined and
rather simple to replicate.
Once decoded from Base64, the transactions will have a structure
defined here:
* [9]<tranBlock> Structure Definition
I used WSDL2RPG and the attached wsdl to generate service program
ESSSRV02 and rpg program ESSPGM02. The only change made to ESSSRV02
was to add the required soap security header since it is not included
in the provided wsdl. A couple of minor changes to ESSPGM02 and I'm
getting message data. Awesome! Now that I have the data, I am
uncertain of how best to decode the Base64 binary and process the xml
elements with in it.
Here's what element <transactions> looks like in debug:
TRANSACTIONS Ì_%ÎÁÊËÑ?>Á>Ä?ÀÑ>ÅíèãÈÊ/>â%?Ä,ÈÊ/>ñàÄ?_ø/>`ñàè(èëï/ÍÌñàè,Á
`,
ESPGM02 is currently generating error message: Unable to decode
character at position 1. (Char=x'3C')
Questions I've been trying to answer are:
1) How best to decode the <transactions> element
2) Once decoded, will parsing the result be best accomplished with
HTTPAPI procedure: http_parse_xml_string()
Any advice is greatly appreciated.
Thanks in advance,
Donnie
References
1. http://schemas.xmlsoap.org/soap/envelope/
2. http://schemas.xmlsoap.org/soap/encoding/
3. http://www.w3.org/2001/XMLSchema
4. http://www.w3.org/2001/XMLSchema-instance
5. http://websvcs.otswebws/
6. https://intinfo.myqualcomm.com/display/iWebInt/ESS+High-Volume+Dequeue
7. https://intinfo.myqualcomm.com/display/iWebInt/ESS+Transactions
8. https://intinfo.myqualcomm.com/display/iWebInt/Notice+of+Scheduled+ESS+Transaction+Type+Schema+Changes
9. https://intinfo.myqualcomm.com/display/iWebInt/Shared+Complex+Types#SharedComplexTypes-transactionblock
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------