[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: HTTPAPI (Web Service) sending an XML string as an input parameter to a web service 'brackets'
- From: Elbert Cook <emcook@xxxxxxxxx>
- To: HTTPAPI and FTPAPI Projects <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
- Subject: Re: HTTPAPI (Web Service) sending an XML string as an input parameter to a web service 'brackets'
- Date: Sat, 14 Nov 2009 19:40:29 -0800 (PST)
Don't you need a HTTP_setCCSIDs in your code?
Example:
Soap =
'<?xml version="1.0" encoding="UTF-8"?>+
<soapenv:Envelope +
// stuff goes here
</soapenv:Envelope>';
HTTP_setCCSIDs(1208: 0); // CCSID 1208 = UTF-8
----- Original Message ----
From: Kevin Groninga <kevin@xxxxxxxxx>
To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx
Sent: Sat, November 14, 2009 6:20:57 PM
Subject: HTTPAPI (Web Service) sending an XML string as an input parameter to a web service 'brackets'
Well, I gotta say that I'm really a novice at this and although I read over
your response several times and tried several other variations, I'm still
not have any luck whatsoever. This is my first foray into working with web
services from an RPG and as luck would have it, I've come across this
problem with the straight bracket [] characters.
I've tried literally hundreds of different variations of encodings, and
parameters and keep failing.
So I thought I might forward you my source code and see if you could help
define how I would code this RPG as UCS2 and then convert to UTF-8 before
using HTTPAPI.
*-------------------------------------------------------------------------
*
* Name . . . : MQS1036R
* Text . . . : Web service, send Ship Confirmation / Pick In
* Author . . : Kevin Groninga
* Date . . . : 11/11/2009
*
*-------------------------------------------------------------------------
* Parameters
*
* p1036iTmStamp - in - record timestamp
* p1036oSuccess - out - count, success
* p1036oFailure - out - count, failure
* p1036oRsnCde - out - reason code
*
*-------------------------------------------------------------------------
* Modifications
*
* Date Pgmr Project/Task
* mm/dd/yyyy <Pgmr> <CMS Project Code>-(optional desc)
* This notation explains the modifications.
*
*-------------------------------------------------------------------------
H DFTACTGRP(*NO) BNDDIR('HTTPAPI':'QC2LE')
* ship confirmations / pick in messages
Fpckshpz1 if e k disk
* web server profile
Fwssrv if e k disk
* options
Foptions if e k disk
* entry parameters
D MQS1036R PR ExtPgm('MQS1036R')
D p1036iTmStamp Z const
D p1036oSuccess 3 0
D p1036oFailure 3 0
D p1036oRsnCde 256A
D MQS1036R PI
D p1036iTmStamp Z const
D p1036oSuccess 3 0
D p1036oFailure 3 0
D p1036oRsnCde 256A
/copy libhttp/qrpglesrc,httpapi_h
* incoming xml, start
D StartOfElement PR
D UserData * value
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D attrs * dim(32767)
D const options(*varsize)
* incoming xml, end
D EndOfElement PR
D UserData * value
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 65535A varying const
D attrs * dim(32767)
D const options(*varsize)
* incoming XML, response variables
D incValue s 32767A varying
D incReasonCode s 256A varying
D incReasonCod1 s 256A varying
D incReasonCod2 s 256A varying
* web service
D SOAP s 32766A varying
D rc s 10I 0
* work
D wksID s like(srsid) inz(3)
D wkqs# s like(ctlqs#) inz(9106)
* web server, URL
D srvServerURL s 128
D srvServiceURL s 256
D srvBindingURL s 256
D srvUsername s 32
D srvPassword s 32
* web service SOAP, substitution variables
D varXMLMsg s 32767A varying
* web service SOAP, response attribute counters
D cntSuccess s 3 0
D cntFailure s 3 0
/free
// if no parameters received, exit
if ( %parms < 1 );
return;
endif;
// reset output parms
p1036oSuccess = 0;
p1036oFailure = 0;
p1036oRsnCde = '';
// load shipment confirmation / pick in XML message
chain p1036iTmStamp pckshpz1;
if %found(pckshpz1);
varXMLMsg = shxmlmsg;
endif;
// load server URL, user, password
chain wksID wssrv;
if %found(wssrv);
srvServerURL = srsurl;
srvUsername = srusnm;
srvPassword = srpwd;
endif;
// load Web Service URL
srvServiceURL = %trim(srvServerURL) +
'/CWDirectCPService/services/CWPickIn';
// load Binding URL
srvBindingURL = '';
// reset incoming and response variables
incValue = '';
incReasonCode = '';
incReasonCod1 = '';
incReasonCod2 = '';
cntSuccess = 0;
cntFailure = 0;
// Note: http_debug(*ON/*OFF) can be used to turn debugging
// on and off. When debugging is turned on, diagnostic
// info is written to an IFS file named
// /tmp/httpapi_debug.txt
chain wkqs# options;
if %found(options) and (ctlqst = 'Y');
http_debug(*ON);
endif;
// Note: http_XmlStripCRLF(*ON/*OFF) controls whether or not
// the XML parser removes CR and LF characters from the
// XML data that's passed to your 'Incoming' procedure.
http_XmlStripCRLF(*ON);
// load SOAP request statement with text expected by web service
// - substitute variables for 'XML Message' info
SOAP =
'<?xml version="1.0" encoding="UTF-8"?>'
+ '<soapenv:Envelope'
+ ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"'
+ ' xmlns:dom="http://dom.w3c.org">'
+ '<soapenv:Header/>'
+ '<soapenv:Body>'
+ '<dom:performAction>'
+ '<![CDATA[' // <== Here's those pesky straight brackets
+ %trim(varXMLMsg)
+ ']]>' // <== Here's those pesky straight brackets
+ '</dom:performAction>'
+ '</soapenv:Body>'
+ '</soapenv:Envelope>';
// post SOAP request to web service
rc = http_url_post_xml(%trim(srvServiceURL)
: %addr(SOAP) + 2
: %len(SOAP)
: %paddr(StartOfElement)
: %paddr(EndOfElement)
: *NULL
: HTTP_TIMEOUT
: HTTP_USERAGENT
: 'text/xml;charset=UTF-8'
: %trim(srvBindingURL));
// process web service response
if (rc <> 1);
// unexpected response code
// commented out - if left in, when in batch mode, job ended
// - default failure count and reason code
// http_crash();
cntFailure = cntFailure + 1;
incReasonCode = 'NO CONNECT';
endif;
// if CWPickIn update successful,
// - action as required
if cntSuccess >= 1;
endif;
// if CWPickIn update failed,
// - action as required
if cntFailure >= 1;
endif;
// load output parameters
p1036oSuccess = cntSuccess;
p1036oFailure = cntFailure;
p1036oRsnCde = incReasonCode;
// exit
*inlr = *on;
/end-free
*--------------------------------------------------------------------
* Parse incoming XML response, start ... see EXAMPLE16
*--------------------------------------------------------------------
P StartOfElement B
D StartOfElement PI
D UserData * value
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D attrs * dim(32767)
D const options(*varsize)
/free
/end-free
P E
*--------------------------------------------------------------------
* Parse incoming XML response, end ... see EXAMPLE16
*--------------------------------------------------------------------
P EndOfElement B
D EndOfElement PI
D UserData * value
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 65535A varying const
D attrs * dim(32767)
D const options(*varsize)
/free
if name = 'Message';
incValue = %trim(value);
select;
when incValue = 'OK';
cntSuccess = cntSuccess + 1;
other;
cntFailure = cntFailure + 1;
incReasonCode = %trim(incValue);
if %scan('<Message':incValue) <> *zero;
incReasonCod1 = %trim(%subst(incValue:1:
(%scan('<Message':incValue) - 1)));
incReasonCod2 = %trim(%subst(incValue:
(%scan('</Message>':incValue) +
10)));
incReasonCode = %trim(incReasonCod1) + ' ' +
%trim(incReasonCod2);
endif;
endsl;
endif;
/end-free
P E
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------