Chapter 3 - GETURI ILE Functions (F.GETURI)

Included with v10.10 and higher of GETURI is service program F.GETURI which contains ILE functions that will allow you to build and call GETURI.

Source member QCOPYSRC/P.GETURI contains the RPG prototype definitions for the functions available.

There is also a binding directory named GETURI that includes the F.GETURI service program. You can use this binding directory when using the functions included in the F.GETURI service program or add the F.GETURI service program to your own binding directory.

Available Functions

  1. #geturi_resetValues() - This is the first function to call to make sure all the functions are reset.
  2. #geturi_setValue() - This function is used to set the value of any of the parameters.
  3. #geturi_addHeader() - This function is used to add custom headers to the request.
  4. #geturi_call() - This function will execute the GETURI call.

The P.GETURI /copy Prototype Member

The prototype definitions and descriptions are as follows:

////////////////////////////////////////////////////////////////*
// #geturi_resetValues - Reset Values                           *
//                                                              *
// This function will reset the values and should be called     *
//  prior to calling any other functions when making a new call *
//  with GETURI.                                                *
//                                                              *
// Returns:                                                     *
//   -1 for error, 0 for no error.                              *
//                                                              *
////////////////////////////////////////////////////////////////*
dcl-pr #geturi_resetValues int(10) end-pr;

////////////////////////////////////////////////////////////////*
// #geturi_setValue - Set Value of Field                        *
//                                                              *
// This function set the value for a GETURI parameter.  The     *
//  paramter name is case insensitive.                          *
//                                                              *
// Input:                                                       *
//   in_parameter- The paramter to set (ie. gi_uri)             *
//   in_value (required) - The value for the parameter.         *
//                                                              *
// Output:                                                      *
//   out_errMsg - If an error is encountered this will          *
//    contain a description of the error.                       *
//                                                              *
// Returns:                                                     *
//   -1 for error, 0 for no error.                              *
//                                                              *
////////////////////////////////////////////////////////////////*
dcl-pr #geturi_setValue int(10);
  in_paramter char(256) Value;
  in_value char(65535) Value;
  out_errMsg char(256) Options(*NOPASS);
end-pr;

////////////////////////////////////////////////////////////////*
// #geturi_addHeader - Add Header                               *
//                                                              *
// This function will add a custom heder to the GETURI call.    *
//                                                              *
// Input:                                                       *
//   in_header (required) - The header lable                    *
//   in_headerValue (required) - The header value.              *
//                                                              *
// Output:                                                      *
//   out_errMsg - If an error is encountered this will          *
//    contain a description of the error.                       *
//                                                              *
// Returns:                                                     *
//   -1 for error, n for no error where n is the index of the   *
//    header just added.                                        *
//                                                              *
////////////////////////////////////////////////////////////////*
dcl-pr #geturi_addHeader int(10);
  in_header char(128) Value;
  in_headerValue char(2048) Value;
  out_errMsg char(256) Options(*NOPASS);
end-pr;

////////////////////////////////////////////////////////////////*
// #geturi_call - Call GETURI                                   *
//                                                              *
// This function is used to call the GETURI function.  Before   *
//  calling this the ##geturi_resetValues() function should be  *
//  called along with one or more ##geturi_setValue() functions *
//  to set up any values for the specific call.                 *
//                                                              *
// Output:                                                      *
//   out_repsonse - The response returned and *RETURN is used   *
//     for the output type.                                     *
//   out_head - The header data from the response.              *
//   out_msgCd - The message code returned from the call.       *
//   out_msg - The message returned from the call.              *
//   out_errMsg - If an error is encountered this will          *
//    contain a description of the error.                       *
//                                                              *
// Returns:                                                     *
//   -1 for error, 0 for no error.                              *
//                                                              *
////////////////////////////////////////////////////////////////*
dcl-pr #geturi_call int(10);
  out_response char(65535);
  out_head char(65535);
  out_msgCd char(1);
  out_msg char(65535);
  out_errMsg char(256) Options(*NOPASS);
end-pr; 

Sample RPGLE and COBOL Programs

The following is a sample RPGLE program using the ILE functions:

**FREE
ctl-opt DFTACTGRP(*NO) ACTGRP('GETURI') BNDDIR('GETURI');

// Imports
/COPY QCOPYSRC,P.GETURI

// Work Variables
dcl-s rc int(10);

dcl-s response varchar(65535);
dcl-s head varchar(65535);
dcl-s msgcd char(1);
dcl-s msg varchar(65535);
dcl-s errMsg char(256);

#geturi_resetValues();
#geturi_setValue('gi_uri':'www.google.com');
#geturi_setValue('gi_port':'443');
#geturi_setValue('gi_ssl':'*YES');
#geturi_setValue('gi_outtype':'*STMF');
#geturi_setValue('gi_stmf':'/tmp/geturitest.output.txt');
#geturi_setValue('gi_debug':'*YES');

rc = #geturi_call(response:head:msgcd:msg:errMsg);

EXSR $return;

//***************************************************************
//* Return
//***************************************************************
begsr $return;

  *INLR = *ON;
  return;

endsr; 

The following is an example ILE COBOL program (note, I am NOT a COBOL program by any stretch of the imagination :) ) I also would like to thank Jon Paris for working with me on brushing up on my COBOL programming!:

       Process Options NOMONOPRC NOSTDTRUNC
       Identification Division.
       Program-Id. GFTEST1.
       Data Division.
       Working-Storage Section.
       
       01 rc                   pic 9(9) Binary.
       01 errMsg               pic x(256).

       01  GetURISetValueData.
           05  in_parm         pic x(256).
           05  in_value        pic x(65535).

       01  GetURIAddHeader.
           05  in_header       pic x(128).
           05  in_headerValue  pic x(2048).

       01  GetURiCallData.
           05  out_response    pic x(65535).
           05  out_head        pic x(65535).
           05  out_msgCd       pic x.
           05  out_msg         pic x(65535).

       Procedure Division.
       Main.

           Call linkage procedure "#GETURI_RESETVALUES"
             Returning rc.

           move "gi_uri" to in_parm.
           move "www.google.com" to in_value.

           Call linkage procedure "#GETURI_SETVALUE"
             Using by value in_parm, by value in_value, errMsg
             Returning rc.

           move "gi_port" to in_parm.
           move "443" to in_value.

           Call linkage procedure "#GETURI_SETVALUE"
             Using by value in_parm, by value in_value, errMsg
             Returning rc.

           move "gi_ssl" to in_parm.
           move "*YES" to in_value.

           Call linkage procedure "#GETURI_SETVALUE"
             Using by value in_parm, by value in_value, errMsg
             Returning rc.

           move "gi_outtype" to in_parm.
           move "*STMF" to in_value.

           Call linkage procedure "#GETURI_SETVALUE"
             Using by value in_parm, by value in_value, errMsg
             Returning rc.

           move "gi_stmf" to in_parm.
           move "/tmp/COBOL_geturiout.txt" to in_value.

           Call linkage procedure "#GETURI_SETVALUE"
             Using by value in_parm, by value in_value, errMsg
             Returning rc.

           move "gi_debug" to in_parm.
           move "*YES" to in_value.

           Call linkage procedure "#GETURI_SETVALUE"
             Using by value in_parm, by value in_value, errMsg
             Returning rc.

           Call linkage procedure "#GETURI_CALL"
             Using out_response, out_head,
               out_msgCd, out_Msg, errMsg
             Returning rc.

           Stop Run.