Theo Kouwenhoven
asked on
HTTPPOSTCLOB in RPGLE
Hi experts,
I recently discovered the "SYSTOOLS.HTTPPOSTCLOB" to consume webservices
As long as I give the right input to the WS, it works fine, but I can't figureout how to catch errors.
e.g. I send a wrong ZipCode a Zipcode-service to get an address.
If I do that in SoapUI I get the information:
result : GDATA_DATA CHAR(8000000) NOT ADDRESSABLE
SQLCODE = -4302
SQLSTATE = '38000'
SQL Diagnostics data:
I recently discovered the "SYSTOOLS.HTTPPOSTCLOB" to consume webservices
As long as I give the right input to the WS, it works fine, but I can't figureout how to catch errors.
e.g. I send a wrong ZipCode a Zipcode-service to get an address.
If I do that in SoapUI I get the information:
{"errors": [{
"status": "400",
"title": "Bad Request",
"detail": "postalcode has the wrong format. It should be: 9999XX"
}]}
If i do the same request with SYSTOOLS.HTTPPOSTCLOB, the response is empty (I assume null),result : GDATA_DATA CHAR(8000000) NOT ADDRESSABLE
SQLCODE = -4302
SQLSTATE = '38000'
SQL Diagnostics data:
....5...10...15...20...25...30...35...40...45...50...55...60
1 'COMMAND_FUNCTION=VALUES INTO;COMMAND_FUNCTION_CODE=-66;DB2_N'
61 'UMBER_CONNECTIONS=+1;DB2_SQL_ATTR_CONCURRENCY=R;DB2_SQL_ATTR'
121 '_CURSOR_CAPABILITY=R;DB2_SQL_ATTR_CURSOR_HOLD=N;DB2_SQL_ATTR'
181 '_CURSOR_ROWSET=N;DB2_SQL_ATTR_CURSOR_SCROLLABLE=N;DB2_SQL_AT'
241 'TR_CURSOR_SENSITIVITY=S;DB2_SQL_ATTR_CURSOR_TYPE=F;MORE=N;NU'
301 'MBER=+1;CLASS_ORIGIN=ISO 9075;CONDITION_NUMBER=+1;DB2_MESSAG'
361 'E_ID=SQL4302;DB2_MESSAGE_ID1=CPF503E;DB2_MODULE_DETECTING_ER'
421 'ROR=QSQVALUE;DB2_ORDINAL_TOKEN_1=SYSTOOLS.HTTPPOSTCLOB;DB2_O'
481 'RDINAL_TOKEN_2=HTTPP00013;DB2_ORDINAL_TOKEN_3=java.net.Malfo'
541 'rmedURLException:no protocol: '
601 ' '
661 ' '
721 ' ;DB2_RETUR'
781 'NED_SQLCODE=-4302;DB2_TOKEN_COUNT=+3;DB2_TOKEN_STRING=SYSTOO'
841 'LS.HTTPPOSTCLOB■HTTPP00013■java.net.MalformedURLException:no'
901 ' protocol: '
961 ' '
1021 ' '
ASKER
Hi Gary,
The URL, and Header of the Post are retrieved from a file, so for all calls the same.
The body of the call are 3 parmeters passed to the program (so the structure is identical for all 3 calls
Body: {"PostalCode": "0123AA", "HouseNumber": "2", "Addition": " "}
This is wrong because Postalcodes never start with zero.
Her I get the Json error-string in soapUI (as in the question).
Body: {"PostalCode": "9999AA", "HouseNumber": "2", "Addition": " "}
This is wrong because Postalcode 9999AA doesn't exist (format is right).
Her I get the remark <Empty JSON content>.
Body: {"PostalCode": "1071XX", "HouseNumber": "1", "Addition": " "}
This is a valid adres so I get the JSON string:
[{"City":"AMSTERDAM","Post alCode":"1 071XX","St reet":"Mus eumstraat" ,"HouseNum ber":1,"Fo rmattedAdd ress":["Mu seumstraat 1 ","1071XX AMSTERDAM"],"geo":{"lat":5 2.359944," long1":4.8 85389,"rdx Coordinate ":120816.3 73,"rdyCoo rdinate":4 85901.503} }]
In the RPG program I only get response on the last one.
I don't have access to the AS400 right now, but i saw that the response on the first 2 request has a Null result.
The result var is a SQLCLOB and I'm not sure if this type of var. can hold a null value
(I suppose i have to define that someware???)
The URL, and Header of the Post are retrieved from a file, so for all calls the same.
The body of the call are 3 parmeters passed to the program (so the structure is identical for all 3 calls
Body: {"PostalCode": "0123AA", "HouseNumber": "2", "Addition": " "}
This is wrong because Postalcodes never start with zero.
Her I get the Json error-string in soapUI (as in the question).
Body: {"PostalCode": "9999AA", "HouseNumber": "2", "Addition": " "}
This is wrong because Postalcode 9999AA doesn't exist (format is right).
Her I get the remark <Empty JSON content>.
Body: {"PostalCode": "1071XX", "HouseNumber": "1", "Addition": " "}
This is a valid adres so I get the JSON string:
[{"City":"AMSTERDAM","Post
In the RPG program I only get response on the last one.
I don't have access to the AS400 right now, but i saw that the response on the first 2 request has a Null result.
The result var is a SQLCLOB and I'm not sure if this type of var. can hold a null value
(I suppose i have to define that someware???)
So, as you probably know, these tools are written in Java and implemented as IBM i DB2 Stored Procedures. So when a problem occurs, you get Java errors. Here is the relevant part of the GET DIAGNOSTICS that you provided:
DB2_TOKEN_STRING=SYSTOOLS. HTTPPOSTCL OB■HTTPP00 013■java.n et.Malform edURLExcep tion:no protocol
This is a Java error that typically happens when the URL is missing a protocol (http://, https://), for example, incorrectly passing:
URL = www.mydomain.com
instead of
URL = http://www.mydomain.com
This would normally happen before the actual HTTP operation even occurs. That is why I am focusing on the instead of the result. In any of the three examples you posted, you should get back a response. Is there any chance that something is happening in your code that is causing a problem with the url?
DB2_TOKEN_STRING=SYSTOOLS.
This is a Java error that typically happens when the URL is missing a protocol (http://, https://), for example, incorrectly passing:
URL = www.mydomain.com
instead of
URL = http://www.mydomain.com
This would normally happen before the actual HTTP operation even occurs. That is why I am focusing on the instead of the result. In any of the three examples you posted, you should get back a response. Is there any chance that something is happening in your code that is causing a problem with the url?
ASKER
Hi Gary,
In all 3 cases, I use the same program with the folowing steps:
1. Get URL from file
2. Get XML-header from file
3. Compose JSON data with Posalcode-Parm, Housnumber-Parm and Addition-parm.
Stap 1 and 2 are retrieved with fixed-data key so will give always the same data (I checked that)
Stap 3 = a simple concatination of text en variable
Body = '{"PostalCode": "' + %trim(P#PostC) + '", '
+ '"HouseNumber": "' + %trim(P#Hsn) + '", '
+ '"Addition": "' + %trim(P#Addit) + '"}';
Then getting the data with SQL SET
EXEC SQL SET :gData = SYSTOOLS.HTTPPOSTCLOB(:URL , :Head, :Body);
If the URL would be wrong, I wouldnt receive data on an existing Postalcode (and i do)
if it is an URL problem for the other two call's I expect to get the same Diagnostics data,
but the response is not the same.
For the non-existing code I get a null-value string in SoapUI, so I can imagine that I get an error on the response because the CLOB probably doesn't accept *null
But the false formated code returns usefull errordata in SoapUI (see question)
Dump0123.txt
Dump9999.txt
Dump_OK.txt
In all 3 cases, I use the same program with the folowing steps:
1. Get URL from file
2. Get XML-header from file
3. Compose JSON data with Posalcode-Parm, Housnumber-Parm and Addition-parm.
Stap 1 and 2 are retrieved with fixed-data key so will give always the same data (I checked that)
Stap 3 = a simple concatination of text en variable
Body = '{"PostalCode": "' + %trim(P#PostC) + '", '
+ '"HouseNumber": "' + %trim(P#Hsn) + '", '
+ '"Addition": "' + %trim(P#Addit) + '"}';
Then getting the data with SQL SET
EXEC SQL SET :gData = SYSTOOLS.HTTPPOSTCLOB(:URL
If the URL would be wrong, I wouldnt receive data on an existing Postalcode (and i do)
if it is an URL problem for the other two call's I expect to get the same Diagnostics data,
but the response is not the same.
For the non-existing code I get a null-value string in SoapUI, so I can imagine that I get an error on the response because the CLOB probably doesn't accept *null
But the false formated code returns usefull errordata in SoapUI (see question)
Dump0123.txt
Dump9999.txt
Dump_OK.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Gary,
Dump999 is a non existing postalcode, the first one was a wrong formatted code.
On non existing I don't get a response, on the wrong formatted I expect a error string.
I'm just testing and have to decide what option we choose to develop this kind of programs.
The call to SYSTOOLS.HTTPPOSTCLOB is in a RPG program and the body is fixed defined.
the idea is to compose the body with XMLDOCUMENT(... XMLELEMENT etc.
(while trying this, my conclusion is that is is a lot of work and the result doesn't look very programers friendly)
I did try the WSDL2RPG from Thomas Raddatz, bud this is also hard to maintain
Yesterday I fond out that there is a wsdl2ws.sh on the IFS and saw that a Service program is generated.
I will also investigate this option.
If you have a other or preferred solution, please let me know.
Dump999 is a non existing postalcode, the first one was a wrong formatted code.
On non existing I don't get a response, on the wrong formatted I expect a error string.
I'm just testing and have to decide what option we choose to develop this kind of programs.
The call to SYSTOOLS.HTTPPOSTCLOB is in a RPG program and the body is fixed defined.
the idea is to compose the body with XMLDOCUMENT(... XMLELEMENT etc.
(while trying this, my conclusion is that is is a lot of work and the result doesn't look very programers friendly)
I did try the WSDL2RPG from Thomas Raddatz, bud this is also hard to maintain
Yesterday I fond out that there is a wsdl2ws.sh on the IFS and saw that a Service program is generated.
I will also investigate this option.
If you have a other or preferred solution, please let me know.
Please provide the working and nonworking httpgetclob call you are executing (replace private info, of course), plus contents of the parameters you are passing for a working call and the nonworking call.