Operating System - OpenVMS

Calling a HTTP service from COBOL

Go to solution
Richard J Maher
Trusted Contributor

Calling a HTTP service from COBOL


I need to access a remote Parts Inventory system from my VMS COBOL program. The remote system publishes itself as a http(s) service that requires me to send it a GET request with my Part Number in the URL, and it will return Stock-on-Hand. (either as responseTest or responseXML)

What is HP's recommended and supported mechanism for achieving this through COBOL or a.n.other 3GL?

Cheers Richard Maher
Steven Schweda
Honored Contributor

Re: Calling a HTTP service from COBOL

> What is HP's recommended and supported
> mechanism [...]

Ask HP?

If all you want is a method which works,
irregardful of who recommends it, you could
do any of several things. The simplest would
probably be to spawn a wget or cURL command,
or to use the appropriate functions in the
cURL library.


I'm pretty ignorant of COBOL, but I assume
that one could do all the required TCP/IP
stuff for an HTTP transaction using System
Services (QIO and friends). I've stuck with
the C RTL for such things, but I gather that
many things are possible.


> [...] a.n.other [...]

Honored Contributor

Re: Calling a HTTP service from COBOL

Consider a COBOL2002 compliant or an OO COBOL compiler, if you can find one with sufficient support for what you need. There are COBOL compilers around with XML PARSE and XML GENERATE support, though platform support can (does) vary (widely).

Calling into libcurl/libwget or another library, or into libwww/SAX/libxml2 or other such could be a feasible approach, depending on the construction. This is basic mixed-language programming.

An extension of this and a rather more "HLL-ish" approach would be to pre-process the COBOL2002 syntax and embed the requisite calls for what you need here.

Further upwards in scale, to graft a front-end onto LLVM or another available tool-chain, but that's a rather larger project than a pre-processor. (Either would be an interesting project. Tying a COBOL front-end onto LLVM would be very interesting.)

Also OpenCOBOL, which provides a COBOL to C translator, or perhaps the Raincode XMLBoost XML stuff, or mayhap Microfocus has a compiler and tools in this area.

There are add-on packages for some platforms, though I've not seen one for OpenVMS. (This could easily turn into another market for your products, too.)

The best solution here depends on local requirements, and on the details of the XML processing. AJAX here, apparently, though there may well be other paths into the data.

As for any HP recommendations or support considerations, or around HP support or plans for COBOL 2000 (if the compiler isn't there yet), those would be best discussed directly with an HP representative.
Steven Schweda
Honored Contributor

Re: Calling a HTTP service from COBOL

> [...] libcurl/libwget [...]

I believe that libcurl exists, but there is
no wget library. Wget is approximately a
Richard J Maher
Trusted Contributor

Re: Calling a HTTP service from COBOL

Hi Steven, Hoff

Thanks for the replies.

("a.n.other" is just another way of pronouncing "another". IOW, could be any VMS 3GL, Basic, C, Pascal, Fortran, COBOL, PL/I, ADA and so on. . .)

I guess I'm just a bit mystified that, in this day and age of the WEB with the ascendancy of RESTful services and the prevasiveness of AJAX-esque/httpRequest style RPCs in general, that the VMS "solution" involves spawning a process and using cURL :-(

I had rather hoped for something more along the lines of: -


An XHR$ RTL with one routine per Ajax method (open, send[w] etc) and the object attributes implemented with item lists. Sounds reasonably useful, no?

Look, I don't know how much it'd cost to develop, but I'm guessing it'd be far less than what HP has already seen booked to the gSOAP port (Baring any sort of Bear Sterns approach to open and timely declarations :-)

VMS 3GL access to Ajax *and* SOAP, knocked off in one simple user-mode RTL!

If only there was someone available with extensive HTTP, SSL, TCP/IP and (unfortunately C) knowledge available that wasn't adverse to being paid handsomely for undertaking such a challenge?

Cheers Richard Maher
Steven Schweda
Honored Contributor

Re: Calling a HTTP service from COBOL

> [...] the VMS "solution" involves spawning
> a process and using cURL :-(

So use libcurl. I don't, but it sure sounds
like what you seek.

Knowing nothing, it does not amaze me that
code to deal with XML is distinct from code
to do an HTTP fetch.

> [...] (Baring any sort [...]

You want them naked?
Honored Contributor

Re: Calling a HTTP service from COBOL

Locating a C++ source code implementation of the XMLHttpRequest call is pretty easy, based on a quick look around. This code would require porting to OpenVMS, and (to make it easier for COBOL) some sort of a wrapper.

The particular code located was GPL2. Locating an implementation with a BSD, MIT or similar license (if that is requirement here) would require some more time digging around, or would require some custom coding time.

libwget is around. May well be a wrapper around the tool and specific to Python, I (clearly) haven't looked carefully.

Barring your ability to locate somebody for this project, it seems you might well be learning C or C++.

Richard J Maher
Trusted Contributor

Re: Calling a HTTP service from COBOL

Hi All,

Ok, does anyone have a libCurl example for retrieving data from a page such as: -

(Called from any VMS 3GL that tickles your fancy)

Cheers Richard Maher

PS. Am I really on my own here in thinking this core infrastructure technology is something that should be bundled with VMS?

DCE/RPC, ONC/RPC, BridgeWorks, WSIT, AXIS2, AXIS2/C, gSOAP, GlassFish - all "YES!". But any sort of simple Ajax http request - an emphatic "NO!"?

I though AJAX was all the rage at Bootcamp?

Oh well, looks like we finally got IPsec; thank God for small mercies!

Full steam ahead.
Robert Gezelter
Honored Contributor

Re: Calling a HTTP service from COBOL


>If only there was someone available with >extensive HTTP, SSL, TCP/IP and (unfortunately >C) knowledge available that wasn't adverse to >being paid handsomely for undertaking such a >challenge?

Having written direct TCP code on more than a few occasions, and with the existing cURL port, I am not sure what "solution" you are seeking. Certainly, the mechanisms to make such an interface accessible to COBOL written procedures (at least within constraints similar to the rest of the IO system and run-time library) are not particularly difficult.

- Bob Gezelter, http://www.rlgsc.com
Honored Contributor

Re: Calling a HTTP service from COBOL

{{not particularly difficult}}

A couple of days of design and code and debug for this, I'd think, for wrapping specific parts of libcurl for COBOL for this task. (And I'd tend to avoid itemlists with COBOL; COBOL can call APIs using itemlists, but that's more work and more code.)

Porting the XMLHttpRequest C++ stuff would take a look at the source code to determine its dependencies and the difficulty of porting the code. Probably a larger project, but probably with a bigger payback.

Straight TCP socket traffic is simple (once you realize it is a byte stream and not datagrams), and I'd not expect substantial dependencies in the XMLHttpRequest code -- dependencies that could be swapped out for libpcap or $qio[w] calls, if the dependencies are not avoidable and not present in the base OS.

(And if you're in this area, you'll probably also need to install either the Xerces/Xalan stuff, or libxml2. My preference has been for the latter library, and there are ports around of both.)

I've occasionally commented on a lack of (integrated or add-on) libraries and RTLs for various common purposes (and I and others have ported a few of these over), though your application requirements and your customer requirements here are best addressed directly with representatives of HP.