I'm using AS400 and I have been asked to call a web service from the green screen.
How can thisbe this achieved?
Any sample COBOL or CL code would be very helpful.
I'm using AS400 and I have been asked to call a web service from the green screen.
How can thisbe this achieved?
Any sample COBOL or CL code would be very helpful.
I wrote some "middleware" in RPGLE to call a web service (SOAP) and process the XML data returned. Here's the process in a nutshell:
1) Open a socket to the web service
2) Build the XML "payload"
3) Transmit the SOAP request (wrap the payload in a SOAP body and transmit the whole through the socket opened in 1) and save the data sent back by the web service.
4) Parse the XML string returned to me (using the xml-sax BIF)
5) Process that data just like any other data.
I use a lot of stuff from Scott Klement (thank you very much Mr. Klement!):
ERRNO_H
IFS_H
IFSUTIL_H
SOCKET_H
SOCKUTIL_H
I also had to handle converting the data to/from EBCDIC and UTF-8. I think I modeled that process after something Scott wrote as well but I can't remember for sure. Search for iconv to get started on that.
I am not a Cobol programmer, but I can call Java from RPG. Perhaps you can write the web service client in Java (where there are many examples) and call it from Cobol.
I'm not an OS/400 programmer, but I just looked and libCURL seems to have been ported to the AS/400.
Here is a COBOL sample that utilizes libCURL to pull down the latest OpenCOBOL pre-release, using local and server timestamps to avoid any undue traffic. occurlrefresh.cbl
*> **************************************************************
*> * access libcurl to update current OC1.1 source archive
*> **************************************************************
*> Authors: Brian Tiffin, Joseph James Frantz
*> Dates: 22-July-2008, 29-July-2008
*> Purpose: Sample calls to occurl wrapper
*> Wasn't designed to be called a binding
*> Tectonics: cobc -c -Wall occurl.c
*> cobc -x -lcurl occurlrefresh.cbl occurl.o
*> ./occurlrefresh [-v|-q] [url file] [-v|-q url file]
identification division.
program-id. occurlrefresh.
environment division.
input-output section.
data division.
working-storage section.
copy occurlsym.
78 newline value x"0a".
01 args pic x(1024).
01 urlarg pic x(255).
88 urlarg-oc value
'http://www.sim-basis.de/open-cobol-1.1.tar.gz'.
01 filearg pic x(255).
88 filearg-oc value
'open-cobol-1.1.tar.gz'.
01 verbarg pic x(255).
01 argcount pic s9(9) comp-5.
01 verbosity pic 9(9) usage binary value 1.
88 quiet value 0.
88 verbose value 1 thru 2.
88 veryverbose value 2.
local-storage section.
01 curl usage pointer.
01 result pic s9(9) comp-5.
01 curlurl pic x(256).
01 curlfile pic x(256).
01 starttime pic s9(7)v99 comp-5.
01 endtime pic s9(7)v99 comp-5.
01 showtime pic z(6)9.99.
01 modtime usage binary-c-long.
*> Update the OC 1.1 tar if applicable by modification time
procedure division.
*> Pull any command line arguments
accept args from command-line end-accept
unstring args delimited by all spaces
into verbarg urlarg filearg
tallying in argcount
end-unstring
*> no args is still argcount 1
if verbarg equals spaces
subtract 1 from argcount end-subtract
end-if
evaluate argcount
when 0
set urlarg-oc to true
set filearg-oc to true
when 1
evaluate verbarg
when "-q" set quiet to true
when "-v" set veryverbose to true
when other move 1 to verbosity
end-evaluate
set urlarg-oc to true
set filearg-oc to true
when 2
move urlarg to filearg
move verbarg to urlarg
when 3
evaluate verbarg
when "-q" set quiet to true
when "-v" set veryverbose to true
when other move 1 to verbosity
end-evaluate
end-evaluate
*> null terminate the strings for C
string urlarg delimited by space
low-value delimited by size
into curlurl
end-string
string filearg delimited by space
low-value delimited by size
into curlfile
end-string
*> parameters ready
if verbose
display
"file: " function trim(filearg trailing)
" from url: " function trim(urlarg trailing)
end-display
end-if
*> let libcurl do all the hard work
call "occurl_init" returning curl end-call.
*> Set some verbosity options
if verbose
call "occurl_progress" using by value curl
by value verbosity
end-call
end-if
if veryverbose
call "occurl_verbose" using by value curl
by value verbosity
end-call
end-if
*> move zero to modtime, retrieve_file will test local modtime
move 0 to modtime
accept starttime from time end-accept
call "occurl_retrieve_file" using by value curl
by reference curlurl
by reference curlfile
by reference modtime
returning result
end-call
if verbose
accept endtime from time end-accept
subtract
starttime from endtime giving starttime
end-subtract
divide
starttime by 100 giving starttime
end-divide
move starttime to showtime
display newline "Done in " showtime end-display
if result not = 0
display
"result: " result
" - " CURLEMSG(result)
end-display
end-if
end-if
call "occurl_cleanup" using by value curl end-call
stop run giving result
continue.
exit program.
plus a little copybook for cURL status codes and messages, occurlsym.cpy
*> manifest constants for libcurl
*> Usage: COPY occurlsym inside data division
*> Result codes
78 CURLE_OK VALUE 0.
*> Error codes
78 CURLE_UNSUPPORTED_PROTOCOL VALUE 1.
78 CURLE_FAILED_INIT VALUE 2.
78 CURLE_URL_MALFORMAT VALUE 3.
78 CURLE_OBSOLETE4 VALUE 4.
78 CURLE_COULDNT_RESOLVE_PROXY VALUE 5.
78 CURLE_COULDNT_RESOLVE_HOST VALUE 6.
78 CURLE_COULDNT_CONNECT VALUE 7.
78 CURLE_FTP_WEIRD_SERVER_REPLY VALUE 8.
78 CURLE_REMOTE_ACCESS_DENIED VALUE 9.
78 CURLE_OBSOLETE10 VALUE 10.
78 CURLE_FTP_WEIRD_PASS_REPLY VALUE 11.
78 CURLE_OBSOLETE12 VALUE 12.
78 CURLE_FTP_WEIRD_PASV_REPLY VALUE 13.
78 CURLE_FTP_WEIRD_227_FORMAT VALUE 14.
78 CURLE_FTP_CANT_GET_HOST VALUE 15.
78 CURLE_OBSOLETE16 VALUE 16.
78 CURLE_FTP_COULDNT_SET_TYPE VALUE 17.
78 CURLE_PARTIAL_FILE VALUE 18.
78 CURLE_FTP_COULDNT_RETR_FILE VALUE 19.
78 CURLE_OBSOLETE20 VALUE 20.
78 CURLE_QUOTE_ERROR VALUE 21.
78 CURLE_HTTP_RETURNED_ERROR VALUE 22.
78 CURLE_WRITE_ERROR VALUE 23.
78 CURLE_OBSOLETE24 VALUE 24.
78 CURLE_UPLOAD_FAILED VALUE 25.
78 CURLE_READ_ERROR VALUE 26.
78 CURLE_OUT_OF_MEMORY VALUE 27.
78 CURLE_OPERATION_TIMEDOUT VALUE 28.
78 CURLE_OBSOLETE29 VALUE 29.
78 CURLE_FTP_PORT_FAILED VALUE 30.
78 CURLE_FTP_COULDNT_USE_REST VALUE 31.
78 CURLE_OBSOLETE32 VALUE 32.
78 CURLE_RANGE_ERROR VALUE 33.
78 CURLE_HTTP_POST_ERROR VALUE 34.
78 CURLE_SSL_CONNECT_ERROR VALUE 35.
78 CURLE_BAD_DOWNLOAD_RESUME VALUE 36.
78 CURLE_FILE_COULDNT_READ_FILE VALUE 37.
78 CURLE_LDAP_CANNOT_BIND VALUE 38.
78 CURLE_LDAP_SEARCH_FAILED VALUE 39.
78 CURLE_OBSOLETE40 VALUE 40.
78 CURLE_FUNCTION_NOT_FOUND VALUE 41.
78 CURLE_ABORTED_BY_CALLBACK VALUE 42.
78 CURLE_BAD_FUNCTION_ARGUMENT VALUE 43.
78 CURLE_OBSOLETE44 VALUE 44.
78 CURLE_INTERFACE_FAILED VALUE 45.
78 CURLE_OBSOLETE46 VALUE 46.
78 CURLE_TOO_MANY_REDIRECTS VALUE 47.
78 CURLE_UNKNOWN_TELNET_OPTION VALUE 48.
78 CURLE_TELNET_OPTION_SYNTAX VALUE 49.
78 CURLE_OBSOLETE50 VALUE 50.
78 CURLE_PEER_FAILED_VERIFICATION VALUE 51.
78 CURLE_GOT_NOTHING VALUE 52.
78 CURLE_SSL_ENGINE_NOTFOUND VALUE 53.
78 CURLE_SSL_ENGINE_SETFAILED VALUE 54.
78 CURLE_SEND_ERROR VALUE 55.
78 CURLE_RECV_ERROR VALUE 56.
78 CURLE_OBSOLETE57 VALUE 57.
78 CURLE_SSL_CERTPROBLEM VALUE 58.
78 CURLE_SSL_CIPHER VALUE 59.
78 CURLE_SSL_CACERT VALUE 60.
78 CURLE_BAD_CONTENT_ENCODING VALUE 61.
78 CURLE_LDAP_INVALID_URL VALUE 62.
78 CURLE_FILESIZE_EXCEEDED VALUE 63.
78 CURLE_USE_SSL_FAILED VALUE 64.
78 CURLE_SEND_FAIL_REWIND VALUE 65.
78 CURLE_SSL_ENGINE_INITFAILED VALUE 66.
78 CURLE_LOGIN_DENIED VALUE 67.
78 CURLE_TFTP_NOTFOUND VALUE 68.
78 CURLE_TFTP_PERM VALUE 69.
78 CURLE_REMOTE_DISK_FULL VALUE 70.
78 CURLE_TFTP_ILLEGAL VALUE 71.
78 CURLE_TFTP_UNKNOWNID VALUE 72.
78 CURLE_REMOTE_FILE_EXISTS VALUE 73.
78 CURLE_TFTP_NOSUCHUSER VALUE 74.
78 CURLE_CONV_FAILED VALUE 75.
78 CURLE_CONV_REQD VALUE 76.
78 CURLE_SSL_CACERT_BADFILE VALUE 77.
78 CURLE_REMOTE_FILE_NOT_FOUND VALUE 78.
78 CURLE_SSH VALUE 79.
78 CURLE_SSL_SHUTDOWN_FAILED VALUE 80.
78 CURLE_AGAIN VALUE 81.
*> Error strings
01 LIBCURL_ERRORS.
02 CURLEVALUES.
03 FILLER PIC X(30) VALUE "CURLE_UNSUPPORTED_PROTOCOL ".
03 FILLER PIC X(30) VALUE "CURLE_FAILED_INIT ".
03 FILLER PIC X(30) VALUE "CURLE_URL_MALFORMAT ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE4 ".
03 FILLER PIC X(30) VALUE "CURLE_COULDNT_RESOLVE_PROXY ".
03 FILLER PIC X(30) VALUE "CURLE_COULDNT_RESOLVE_HOST ".
03 FILLER PIC X(30) VALUE "CURLE_COULDNT_CONNECT ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_WEIRD_SERVER_REPLY ".
03 FILLER PIC X(30) VALUE "CURLE_REMOTE_ACCESS_DENIED ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE10 ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_WEIRD_PASS_REPLY ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE12 ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_WEIRD_PASV_REPLY ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_WEIRD_227_FORMAT ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_CANT_GET_HOST ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE16 ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_COULDNT_SET_TYPE ".
03 FILLER PIC X(30) VALUE "CURLE_PARTIAL_FILE ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_COULDNT_RETR_FILE ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE20 ".
03 FILLER PIC X(30) VALUE "CURLE_QUOTE_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_HTTP_RETURNED_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_WRITE_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE24 ".
03 FILLER PIC X(30) VALUE "CURLE_UPLOAD_FAILED ".
03 FILLER PIC X(30) VALUE "CURLE_READ_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_OUT_OF_MEMORY ".
03 FILLER PIC X(30) VALUE "CURLE_OPERATION_TIMEDOUT ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE29 ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_PORT_FAILED ".
03 FILLER PIC X(30) VALUE "CURLE_FTP_COULDNT_USE_REST ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE32 ".
03 FILLER PIC X(30) VALUE "CURLE_RANGE_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_HTTP_POST_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CONNECT_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_BAD_DOWNLOAD_RESUME ".
03 FILLER PIC X(30) VALUE "CURLE_FILE_COULDNT_READ_FILE ".
03 FILLER PIC X(30) VALUE "CURLE_LDAP_CANNOT_BIND ".
03 FILLER PIC X(30) VALUE "CURLE_LDAP_SEARCH_FAILED ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE40 ".
03 FILLER PIC X(30) VALUE "CURLE_FUNCTION_NOT_FOUND ".
03 FILLER PIC X(30) VALUE "CURLE_ABORTED_BY_CALLBACK ".
03 FILLER PIC X(30) VALUE "CURLE_BAD_FUNCTION_ARGUMENT ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE44 ".
03 FILLER PIC X(30) VALUE "CURLE_INTERFACE_FAILED ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE46 ".
03 FILLER PIC X(30) VALUE "CURLE_TOO_MANY_REDIRECTS ".
03 FILLER PIC X(30) VALUE "CURLE_UNKNOWN_TELNET_OPTION ".
03 FILLER PIC X(30) VALUE "CURLE_TELNET_OPTION_SYNTAX ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE50 ".
03 FILLER PIC X(30) VALUE "CURLE_PEER_FAILED_VERIFICATION".
03 FILLER PIC X(30) VALUE "CURLE_GOT_NOTHING ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_ENGINE_NOTFOUND ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_ENGINE_SETFAILED ".
03 FILLER PIC X(30) VALUE "CURLE_SEND_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_RECV_ERROR ".
03 FILLER PIC X(30) VALUE "CURLE_OBSOLETE57 ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CERTPROBLEM ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CIPHER ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CACERT ".
03 FILLER PIC X(30) VALUE "CURLE_BAD_CONTENT_ENCODING ".
03 FILLER PIC X(30) VALUE "CURLE_LDAP_INVALID_URL ".
03 FILLER PIC X(30) VALUE "CURLE_FILESIZE_EXCEEDED ".
03 FILLER PIC X(30) VALUE "CURLE_USE_SSL_FAILED ".
03 FILLER PIC X(30) VALUE "CURLE_SEND_FAIL_REWIND ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_ENGINE_INITFAILED ".
03 FILLER PIC X(30) VALUE "CURLE_LOGIN_DENIED ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_NOTFOUND ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_PERM ".
03 FILLER PIC X(30) VALUE "CURLE_REMOTE_DISK_FULL ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_ILLEGAL ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_UNKNOWNID ".
03 FILLER PIC X(30) VALUE "CURLE_REMOTE_FILE_EXISTS ".
03 FILLER PIC X(30) VALUE "CURLE_TFTP_NOSUCHUSER ".
03 FILLER PIC X(30) VALUE "CURLE_CONV_FAILED ".
03 FILLER PIC X(30) VALUE "CURLE_CONV_REQD ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_CACERT_BADFILE ".
03 FILLER PIC X(30) VALUE "CURLE_REMOTE_FILE_NOT_FOUND ".
03 FILLER PIC X(30) VALUE "CURLE_SSH ".
03 FILLER PIC X(30) VALUE "CURLE_SSL_SHUTDOWN_FAILED ".
03 FILLER PIC X(30) VALUE "CURLE_AGAIN ".
01 FILLER REDEFINES LIBCURL_ERRORS.
02 CURLEMSG OCCURS 81 TIMES PIC X(30).
and an associated C file (though a lot of the C can be directly coded in COBOL as I was just learning the ins and outs of OpenCOBOL at the time of writing). occurl.c
/**********************************************************************/
/* wrap some common curl operations for use with OpenCOBOL 1.1 */
/* Author: Brian Tiffin */
/* Date: 21-July-2008 */
/* Version: 0.1 */
/* Purpose: Provide some net access to OpenCOBOL */
/* Tectonics: gcc -c occurl.c */
/* with libcurl dev installed */
/**********************************************************************/
#include <stdio.h>
#include <sys/stat.h>
#include <curl/curl.h>
/* Support structure for the file callbacks */
struct LocalFileStruc {
const char *filename;
FILE *stream;
};
/* Progress tracking */
double *Bar;
/* libcurl call back for file write */
static size_t wrap_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
struct LocalFileStruc *out=(struct LocalFileStruc *)stream;
if(out && !out->stream) {
/* open file for writing */
out->stream=fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, can't open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}
/* Progress */
int progress_callback(char *Bar, double t, double d, double ultotal, double ulnow) {
int oe;
double val;
if (t == 0) t = 1.0;
val = d / t * 100;
oe = (int)val;
if (oe & 1) {
putc('\\', stdout);
} else {
putc('/', stdout);
}
printf("%03.0f%%\b\b\b\b\b\b\b\b", val);
fflush(stdout);
return 0;
}
/* Routines to get and release CURL handles from OpenCOBOL */
/* Usage: */
/* DATA DIVISION. */
/* 01 handle usage is pointer. */
/* PROCEDURE DIVISION. */
/* CALL "occurl_init" RETURNING handle. */
CURL* occurl_init() {
return curl_easy_init();
}
/* Usage: */
/* CALL "occurl_cleanup" USING BY VALUE handle. */
void occurl_cleanup(CURL *curl) {
curl_easy_cleanup(curl);
}
/* Set verbosity */
/* Usage: vflag being 0 or 1 */
/* CALL "occurl_verbose" USING BY VALUE vflag. */
void occurl_verbose(CURL *curl, int vflag) {
/* Switch on or off full protocol/debug output */
if (curl) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, (long)vflag);
}
}
/* Set progress display on/off */
/* Usage: pflag being 0 or 1 */
/* CALL "occurl_verbose" USING BY VALUE pflag. */
void occurl_progress(CURL *curl, int pflag) {
/* Switch on or off progress display */
if (curl) {
if (pflag) {
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar);
} else {
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
}
}
}
/* Ease of use; check mod-times, if since then read url, write to file */
/* Retrieve URL and save to local file after checking timestamps */
/* Usage: */
/* DATA DIVISION. */
/* 01 handle USAGE IS POINTER. */
/* 01 url. */
/* 02 urlname PIC x(21) VALUE "http://opencobol.org/". */
/* 02 filler PIC x VALUE X"00". */
/* 01 filename */
/* 02 PIC x(). */
/* 02 filler pic x value low-value. */
/* 01 modtime USAGE IS BINARY-C-LONG */
/* PROCEDURE DIVISION. */
/* CALL "curl_retrieve_file" USING BY VALUE handle */
/* BY REFERENCE url */
/* BY REFERENCE filename */
/* BY REFERENCE modtime */
/* RETURNING result. */
/* Pass modtime of 0 to get local mtime field, */
/* modtime is modified with value from url if available */
int occurl_retrieve_file(CURL *curl, char *url, char *file, long *modtime) {
CURLcode res;
long urlstamp;
struct stat st;
struct LocalFileStruc localfile={
"occurl.default", /* default filename */
NULL /* stream */
};
/* point to the COBOL passed filename */
if (file) {
localfile.filename = file;
}
/* if modtime is zero, get local file modtime */
if (*modtime == 0) {
if (stat (file, &st) == 0) {
*modtime = st.st_mtime;
}
}
/* let libcurl do all the real work */
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
/* Only fetch new */
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, *modtime);
/* Define our callback to get called when there's data to be written */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrap_fwrite);
/* Set a pointer to our struct to pass to the callback */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &localfile);
/* After all the setopts, perform the operation */
res = curl_easy_perform(curl);
/* close off any file pointers */
if (localfile.stream) {
fclose(localfile.stream); /* close the local file */
}
/* return error results */
if (res != 0) {
return (int)res;
}
/* retrieve response code */
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &urlstamp);
if (res != 0) {
return (int)res;
} else {
if (urlstamp == 404) {
return CURLE_REMOTE_FILE_NOT_FOUND;
}
}
/* retrieve filetime for return value */
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &urlstamp);
if (res != 0) {
return (int)res;
} else {
*modtime = urlstamp;
return 0;
}
} else {
return CURLE_FAILED_INIT;
}
return 0;
}
/* Fetch a url to a local file */
int occurl_get_url(CURL *curl, char *theurl, char *thefile) {
CURLcode res;
long urlstamp;
struct LocalFileStruc localfile = {
"occurl.default", /* default filename */
NULL /* stream */
};
/* point to the COBOL field */
localfile.filename = thefile;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, theurl);
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
/* Define our callback to get called when there's data to be written */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrap_fwrite);
/* Set a pointer to our struct to pass to the callback */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &localfile);
res = curl_easy_perform(curl);
/* close the local file */
if (localfile.stream) {
fclose(localfile.stream);
}
/* return error results */
if (res != 0) {
return (int)res;
}
/* retrieve response code */
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &urlstamp);
if (res != 0) {
return (int)res;
} else {
if (urlstamp == 404) {
return CURLE_REMOTE_FILE_NOT_FOUND;
}
}
} else {
return CURLE_FAILED_INIT;
}
return 0;
}
/* The plan is to return a structure with all curl INFO fields filled */
int occurl_getinfo(CURL *curl, char *theurl, char *thedata) {
CURLcode res;
long urlstamp;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, theurl);
res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &urlstamp);
} else {
return -1;
}
return (int)res;
}
Please note, that things have changed in OpenCOBOL land of late, and we have moved to SourceForge. The 1.1 tarball is hosted at http://downloads.sourceforge.net/project/open-cobol/open-cobol/1.1/open-cobol-1.1.tar.gz now. You'd likely want to update occurlrefresh.cbl to use the new default filename. This code is old now, and will get an update for the OpenCOBOL FAQ file soon.
OpenCOBOL works on AS/400, with a binary posted to http://www.kiska.net/opencobol/1.1/ which is a server recently revived from a hurricane Sandy basement flood out.
Your particular problem would require some modifications of course, utilizing libCURL to pull data into WORKING-STORAGE instead of writing directly to a file.
OpenCOBOL samples also exist for CGI and AJAX, libSOUP serving and a few other web related examples. Google for the OpenCOBOL FAQ and look through section 5 on extensions. Calling libXML2 works the charm as well.
IBM is providing access to web-services with SQL user-defined functions in their SYSTOOLS-schema: https://www.ibm.com/developerworks/ibmi/library/i-incorporating-web-service/
We are using this technique to call a web-service from our cobol-application on IBM i 7.2.
If you are using Rational Development Studio for i, you should have the various project types where you can either give it a wsdl and have it generate a client Cobol program, or you can identify a copybook and have it generate a server Cobol program.
If you are doing old school, 1980's text editor development, then you kinda have to roll your own.
We looked at several options for doing this in RPG. While you can construct a SOAP packet manually through string concatenation and opening HTTP ports (yuck), we settled on using an IBM technology called Integrated Web Services for IBM i.
Roughly the process is that you point it at a WSDL and it will generate a web service client for you. This takes the form of a service program that you can then bind into your ILE program.
There is a programmer's guide on that link above if you would like more details.
© 2022 - 2024 — McMap. All rights reserved.