Hi Alex;
In my STD Framework I use this command to read the PS URL & Port from an INI file ...
Code:
is_powerserver_url = ProFileString (ls_app_ini_name , ls_section_name, &
"PS_URL", '<Not found In INI>' )
INI:
PS_URL=http://localhost:5008
Once the framework has the PS's URL, it then calls PS's built-in web services to perform a System-To-System check on the PS health & version and will inform the PB App user of any mismatch / issue while logging all of these at the PS App's start up ...
ls_url = is_powerserver_url // Format URL
ls_url += "/api/License/LoadInstanceInfo"
lo_http = CREATE ns_http_client_master // Instantiate HTTPclient
lo_http.of_register ( THIS ) // Register Parent
lo_http.SetRequestHeaders ( "content-type:application/json; charset=UTF-8~r~nCache-Control:no-cache" ) // Set Headers
IF go_ac.of_is_debug_mode( ) = TRUE THEN // Debug ON?
ls_msg = "** PowerServer Information RestFul Web Service call STARTED **" // YES=>Format MSG
THIS.of_write_log ( ls_msg ) // Log MSG
ls_msg = "URL: " + ls_url // URL Info
THIS.of_write_log ( Space ( 4 ) + ls_msg ) // Log MSG
END IF
lo_http.sendrequest ( "Get", ls_url) // Send Request
IF lo_http.GetResponseStatuscode ( ) = 200 THEN // Response OK?
lo_http.getresponsebody (ls_json) // YES=>Get Response
lo_ds = CREATE ns_ds_master // Instaniate DataStore
lo_ds.of_register ( THIS ) // Register Parent
lo_ds.dataobject = "dw_ps_instance" // Set DWO to use
ls_json = "[" + ls_json // Add JSON array marker
ls_json += "]" // Add JSON array marker
il_rc = lo_ds.ImportJson( ls_json ) // Import JSON data
IF lo_ds.RowCount ( ) > 0 THEN // Any data?
is_powerserver_version = lo_ds.GetItemString ( 1, "powerserverversion" ) // YES=>Get version
IF go_ac.of_is_debug_mode( ) = TRUE THEN // Debug ON?
ls_msg = "JSON: " + ls_json // YES=>Format MSG
THIS.of_write_log ( Space ( 4 ) + ls_msg ) // Log MSG
END IF
ELSE
ls_msg = "JSON Import failure - RC: " + String ( il_rc) // NO=>Format MSG
THIS.of_write_log ( Space ( 4 ) + ls_msg ) // Log MSG
THIS.of_write_log ( Space ( 4 ) + ls_json ) // Log JSON
END IF
lo_ds.Reset( )
lo_ds.dataobject = ""
Destroy lo_ds
IF is_powerserver_version <> is_ps_expected_version THEN // Version OK?
lo_sr.si_data [ 1 ] = is_powerserver_version // NO=>Load PS found
lo_sr.si_data [ 2 ] = is_ps_expected_version // Load PS expected
THIS.of_get_message (111, ls_title, ls_msg, lo_sr) // Get 'Display Name' MSG
THIS.of_write_log ( Space ( 4 ) + ls_msg ) // Write 2 LOG!
ii_rc = THIS.of_messagebox ( ls_title, ls_msg, Question!, YesNo!, 2 ) // MSG 2 User!
IF ii_rc = 2 THEN // Abort?
THIS.of_get_message (37, ls_title, ls_msg, lo_sr) // YES=>Get Msg
THIS.of_write_log ( Space ( 4 ) + ls_msg ) // Write 2 LOG!
HALT CLOSE // Stop the App.!
else
THIS.of_get_message (40, ls_title, ls_msg, lo_sr) // No=> Get Msg
THIS.of_write_log ( Space ( 4 ) + ls_msg ) // Write 2 LOG!
END IF
END IF
ELSE
ls_msg = "SendRequest Failed - RC: ( " + &
String (lo_http.GetResponseStatuscode ( )) + " ) ... URL: " + &
ls_url // NO->Format MSG
THIS.of_write_log ( Space ( 4 ) + ls_msg ) // Log it!
END IF
IF go_ac.of_is_debug_mode( ) = TRUE THEN // Debug ON?
ls_msg = "** PowerServer Information RestFul Web Service call ENDED **" // YES=>Format MSG
THIS.of_write_log ( ls_msg ) // Log MSG
END IF
Destroy lo_http // Unload HTTPClient
SetPointer ( lo_ptr ) // Restore mouse pointer
Return ii_rc // Return 2 Caller!
Then in other environments, I just change the value of PS_URL in the INI file. Then the framework uses that so that the framework forces all PS App's to begin all PS Sessions so that the App has control of all session information and can also log this PS information for trouble shooting & tracing of work. For example (see BEGINSESSION command below):
IF go_ac.of_get_client_type( ) = "PS" THEN // PowerServer App?
Application lo_app // YES=>App pointer
String ls_session_id
lo_app = GetApplication ( ) // Load Ptr
ls_session_id = lo_app.getsessionid ( ) // Get PS Session
IF ls_session_id = "" THEN // Active Session?
ii_rc = lo_app.beginsession ( ) // NO=>Start PS Session!
ls_msg = "PowerServer Session Started - RC: " // Set MSG
ii_rc = go_ac.of_write_log ( ls_msg + String (ii_rc ) ) // Log PS Session start!
ls_msg = "PowerServer Session No: " // Set MSG
ls_session_id = lo_app.getsessionid ( ) // Get new PS Session #
ii_rc = go_ac.of_write_log ( ls_msg + ls_session_id ) // Log PS Session info!
go_ac.of_set_ps_session ( ls_session_id ) // Save current Session ID
END IF
END IF
FYI: you can check out all this logic or just review the App Log's PS related information in the STD Framework OrderEntry Demo App for PB2021 build 1506. The latest version is available for download from here: https://sourceforge.net/projects/stdfndclass/files/Applications/PowerBuilder/OrderEntry/Beta. Note that this "beta" of the OrderEntry Demo App is using the beta of the STD Framework. I will be releasing this beta soon as a GA. This will be release 2022R1 of the 1st version of the framework for 2022. ;-)
HTH
Regards ... Chris