How to Debug HTTPAPI RPG Programs
If you are using the IBM i HTTPAPI (LIBHTTP) opensource utilities, you already realize how easy it is to talk to an internet web service from within your IBM i RPG programs but sometimes even the best-laid plans go wrong. This is when you need to learn how about the “debug HTTPAPI webservices” function.
Assuming you are here to learn about
- Webservice programming on IBM i System or
- How RPGLE talks to websites or
- Randomly looking for pictures of naked ladies but somehow found yourself here…
Then you have come to the right place. So, lets look at how to debug an RPGLE program, specifically using the HTTPAPI opensource library (also confusingly called “libhttp”) and it’s existing service program procedures.
This sounds daunting but, if you have a passing knowledge of RPGLE then it’s insanely easy with HTTPAPI’s beautiful logging functions.
You may not have realized that after you have run your program, you will have a beautiful log of the entire webservice process stored in an IFS file in your temporary folder — assuming you are running in debug mode of course.
So , in your program make sure you are turning on debug:
// 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 /if defined(DEBUGGING) http_debug(*ON); /endif
and then after you have ran it you can see the results by typing: dsplnk ‘/tmp/httpapi_debug.txt’
You will see a gloriously detailed log that looks something like this:
************Beginning of data**************HTTPAPI Ver 1.24 released 2012-01-23 OS/400 Ver V7R1M0 New iconv() objects set, PostRem=819. PostLoc=0. ProtRem=819. ProtLoc=0 http_url_post(): entered http_persist_open(): entered http_long_ParseURL(): entered DNS resolver retrans: 2 DNS resolver retry : 2 DNS resolver options: x'00000136' DNS default domain: NICKLITTEN.COM DNS server found: 10.14.54.230 DNS server found: 10.517.54.222 https_init(): entered ------------------------------------------------------------------------------------- Dump of local-side certificate information: ------------------------------------------------------------------------------------- Dump of server-side certificate information: ------------------------------------------------------------------------------------- Cert Validation Code = 6000 -----BEGIN CERTIFICATE----- MIIFNTCCBB2gAwIBAgIETBxPvjANBgkqhkiG9w0BAQUFADCBsTELMAkGA1UEBhMC ... blah blah blah lots of certificate gubbins ... 4Icw1U5mtZ9rVmEOyN3/g+fY0o2iypwIvBHc1LAHN1WFLpmFrwl/oyjT4cHb9eMA -----END CERTIFICATE----- Serial Number: 4C:1?:4F:?? Common Name: *.authorize.net Country: US Country: US State/Province: Washington Locality: Bellevue Org Unit: Authorize.Net Org: Authorize.net Issuer CN: Entrust Certification Authority - L1C Issuer Country: US Issuer Org: Entrust, Inc. Issuer Org Unit: (c) 2009 Entrust, Inc., OU=www.entrust.net/rpa is incorporated by reference Version: 3 not before: 20120228133909 Unknown Field: 13:39:09 28-02-2012 not after: 20140228210940 Unknown Field: 21:09:40 28-02-2014 pub key alg: 1.2.840.113549.1.1.5 Protocol Used: TLS Version 1 http_persist_post(): entered http_persist_req(POST) entered. http_persist_req(POST) entered. http_long_ParseURL(): entered do_oper(POST): entered There are 0 cookies in the cache POST /soap/v1/Service.asmx HTTP/1.1 Host: apitest.authorize.net User-Agent: http-api/1.24 Content-Type: text/xml SOAPAction: https://api.authorize.net/soap/v1/AuthenticateTest... blah blah blah Content-Length: 449 senddoc(): entered <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://w recvresp(): entered HTTP/1.1 200 OK Date: Thu, 23 Jan 2014 15:09:04 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET ... and much much more.
You can see the full SOAP string that you sent and also the full reply you received back.
Debugging RPG has never been so easy.
This is one happy RPG programmer 🙂