1. Alex Peters
  2. PowerServer
  3. Wednesday, 23 February 2022 14:44 PM UTC

Hello!
I have a probably small problem smile.

I would like to get the url of the WebAPI of my PowerServer application. Reason is that I would like to access the PowerServer Management APIs of my application in my application.

Unfortunately I can't find a suitable method in the documentation and the examples always use a fixed url. The application itself knows the WebAPI url, so I assume that I can query it somehow and I just haven't found the appropriate method yet.

I mean the URL, which the customer will get later via command line


dotnet CustomizeDeploy.dll -url=https://172.16.100.71:5009  <-- Url of the WebAPI

so I can use it to build for example the URL "[https://172.16.100.71:5009]/api/Session/LoadAll"" in my application without having to enter it there again.

 

Thank you in advance

Alex

Samples from APIs that i want to access from the Application itself.

https://docs.appeon.com/ps2021/Get_Kill_user_sessions.html
https://docs.appeon.com/ps2021/View_the_API_documentation.html

Alex Peters Accepted Answer Pending Moderation
  1. Thursday, 24 February 2022 07:22 AM UTC
  2. PowerServer
  3. # 1

Thank you for your answer Armeen, 


the advantages of a hostname over an IP address are undisputed and my example call (copy&paste from Change_the_Web_API_URL_for_an_application.html) was just to clarify what URL I would like. I hadn't assumed it was a problem or non-existent feature until just now either. Since the client is already connected to the WebAPI, I assumed that there must be a way to retrieve that address or URL to avoid doing it via an INI file like Chris did. Entering the same information in two places is something I usually try to prevent. But if there is no other way, that is of course the way for now and the other a wish for a future version.

@Chris Thanks for your snippets and for pointing out your STD Foundation. I will have a look at that. ??

 

 

Comment
  1. Armeen Mazda @Appeon
  2. Thursday, 24 February 2022 15:19 PM UTC
Thanks for clarifying. Our product management team is aware of this feature enhancement request, but in meantime please consider workaround Chris provided.
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Thursday, 5 May 2022 14:56 PM UTC
This feature enhancement is scheduled to be included in PowerBuilder 2022, which we hope to release 1st week of September.
  1. Helpful 1
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 23 February 2022 16:51 PM UTC
  2. PowerServer
  3. # 2

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

Comment
  1. mike S
  2. Wednesday, 23 February 2022 17:22 PM UTC
This is a clever workaround for this omission of functionality in ps2021.

  1. Helpful
  1. Chris Pollach @Appeon
  2. Thursday, 24 February 2022 16:14 PM UTC
Thanks Mike. ;-)
  1. Helpful
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 23 February 2022 16:09 PM UTC
  2. PowerServer
  3. # 3

The URL of the Web API server is dependent on how your network admin configures the infrastructure.  PowerServer itself doesn't dictate what the URL should be.  And generally, you would want to use domain name rather than IP address so more flexibility to point to different IP address in future without having to change configs in your app. We have some basic documentation how to deploy the Web APIs, but setting up such infrastructure reliably and securely really requires somebody with strong past experience doing this stuff.  https://docs.appeon.com/ps2021/Hosting_Web_APIs_in_IIS.html

 

Comment
  1. mike S
  2. Wednesday, 23 February 2022 18:46 PM UTC
Armeen,

During beta i said i needed functionality provided in prior verisons of PS that was in appeon_workarounds.pbl. such as getting session counts, sessionid, url, client ip address, etc. I gave use cases on how this stuff is used.



It seems no one reviewed the work_arounds.pbl to ensure that you provided similar PS functionality in 21 as 20 had.





  1. Helpful
  1. Armeen Mazda @Appeon
  2. Wednesday, 23 February 2022 18:51 PM UTC
We certainly reviewed every feature of prior versions when revamping the product, we just couldn't get everything into the 2021 version. There are much more important features than what you mentioned missing from 2021, and we are first addressing those as higher priority for 2022 version tentatively to be released in July 2022.
  1. Helpful
  1. mike S
  2. Wednesday, 23 February 2022 19:18 PM UTC
sounds good. I hope function to get the URL of the connected powerserver at runtime is added, can't use PS in production without it.

Most of that stuff was added - i believe all of it was, and geturl was just missed. its all on the application object, or in the REST apis.



its too bad that a 2021 version of appeon_workarounds.pbl wasn't provided. it would either call the new application object functions, or the rest apis.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.