@@ -17,14 +17,74 @@ using Spark.Core.Manager.ICatalogManager from propath.
1717
1818block-level on error undo , throw .
1919
20- class Spark.Core.Service.Catalog implements Spark.Core.Service.ICatalog :
20+ class Spark.Core.Service.Catalog inherits Spark.Diagnostic.Util.OSPath implements Spark.Core.Service.ICatalog use-widget-pool :
21+
22+ /* Tracks the last time the CB props file was loaded from the file system. */
23+ define protected variable dCBPropsLastLoaded as datetime no-undo initial ? .
24+
25+ /* Find a better default port in use with this instance. */
26+ define protected variable iPort as integer no-undo .
2127
2228 method public void initialize ( ):
29+ this-object :Discovery (). /* Perform local discovery of server info. */
2330 end method . /* initialize */
2431
2532 method public void dispose ( ):
2633 end method . /* dispose */
2734
35+ method protected void Discovery ( ):
36+ define variable cLine as character no-undo .
37+ define variable cAppName as character no-undo .
38+ define variable cAppNames as character no-undo .
39+ define variable cWebApp as character no-undo .
40+ define variable cTransport as character no-undo .
41+ define variable lcConfigTemp as longchar no-undo .
42+ define variable iLines as integer no-undo .
43+ define variable iLine as integer no-undo .
44+ define variable iX as integer no-undo .
45+ define variable iHttpPort as integer no-undo .
46+ define variable iHttpsPort as integer no-undo .
47+ define variable lFound as logical no-undo .
48+ define variable dLastDate as datetime no-undo .
49+ define variable oWebAppList as JsonArray no-undo .
50+
51+ /* Examine the catalina.properties for info about the available ports. */
52+ file-info :file-name = substitute (" &1/conf/catalina.properties" , this-object :CatalinaBase ).
53+ if file-info :full-pathname ne ? then do :
54+ /* Get the current date/time that the file was last modified. */
55+ assign dLastDate = datetime (file-info :file-mod-date , file-info :file-mod-time * 1000 ).
56+
57+ if dLastDate ne dCBPropsLastLoaded then do :
58+ /* Mark down the current modified date/time for this file. */
59+ assign dCBPropsLastLoaded = dLastDate .
60+
61+ /* Read the file into a longchar value (avoids keeping the file open). */
62+ copy-lob from file file-info :full-pathname to lcConfigTemp no-error .
63+
64+ assign iLines = num-entries (lcConfigTemp , " ~n " ).
65+ if iLines ge 1 then cfgblk :
66+ do iLine = 1 to iLines :
67+ assign cLine = trim (entry (iLine , lcConfigTemp , " ~n " )).
68+
69+ case true :
70+ when cLine begins " psc.as.http.port=" then
71+ assign iHttpPort = integer (trim (entry (2 , cLine , " =" ))).
72+ when cLine begins " psc.as.https.port=" then
73+ assign iHttpsPort = integer (trim (entry (2 , cLine , " =" ))).
74+ end case .
75+ end . /* do iLines */
76+
77+ /* Look to the same server at either the HTTP or HTTPS port for OEManager. */
78+ if iHttpPort gt 0 then
79+ this-object :iPort = iHttpPort .
80+ else if iHttpsPort gt 0 then
81+ this-object :iPort = iHttpsPort .
82+
83+ assign lcConfigTemp = ? . /* Reset the variable. */
84+ end . /* file updated */
85+ end . /* catalina.properties */
86+ end method . /* Discovery */
87+
2888 method protected JsonObject getDataObjectServiceCatalogs ( ):
2989 define variable oServices as DataObjectService no-undo extent .
3090 define variable oOperation as MappedOperation no-undo .
@@ -46,9 +106,10 @@ class Spark.Core.Service.Catalog implements Spark.Core.Service.ICatalog:
46106 assign oOperation = oServices [iX ]:GetOperation (" /" , MethodEnum :Get ).
47107 if valid-object (oOperation ) and oOperation :TargetName matches " *.json" then do :
48108 assign
49- cFilename = replace (oOperation :TargetName , " $CATALINA_BASE" , os-getenv ( " CATALINA_BASE " ) )
109+ cFilename = replace (oOperation :TargetName , " $CATALINA_BASE" , this-object : CatalinaBase )
50110 cFilename = replace (cFilename , " $oepas-webapp" , trim (web-context :get-cgi-value (" env" , " CONTEXT_PATH" ), " /" ))
51111 .
112+
52113 file-info :file-name = cFilename .
53114 if file-info :full-pathname ne ? then do :
54115 define variable oParser as ObjectModelParser no-undo .
@@ -64,6 +125,7 @@ class Spark.Core.Service.Catalog implements Spark.Core.Service.ICatalog:
64125 end . /* Operation Not Available */
65126 end . /* No Catalog */
66127 else if oServices [iX ]:Catalog :Has (" services" ) then
128+ /* Each service should only have one defined catalog for that service. */
67129 oSvcArray :Add (oServices [iX ]:Catalog :GetJsonArray (" services" ):GetJsonObject (1 )).
68130 end . /* do ix */
69131
@@ -82,6 +144,7 @@ class Spark.Core.Service.Catalog implements Spark.Core.Service.ICatalog:
82144 end method . /* getDataObjectServiceCatalogs */
83145
84146 method public void getOpenApiCatalog ( output catalog as JsonObject ):
147+ /* Specialized method to return an Open API v3.0 formatted description of resource endpoints. */
85148 define variable oServiceWriter as OpenAPI30ServiceWriter no-undo .
86149 assign oServiceWriter = new OpenAPI30ServiceWriter ().
87150 if valid-object (oServiceWriter ) then do :
@@ -90,6 +153,16 @@ class Spark.Core.Service.Catalog implements Spark.Core.Service.ICatalog:
90153 oServiceWriter :close ().
91154
92155 assign catalog = cast (oServiceWriter :Value , JsonObject ).
156+ if valid-object (catalog ) then do :
157+ define variable oVars as JsonObject no-undo .
158+
159+ assign oVars = catalog :GetJsonArray (" servers" ):GetJsonObject (1 ):GetJsonObject (" variables" ).
160+ oVars :GetJsonObject (" port" ):Set (" default" , string (iPort )). /* Use the discovered port for the instance. */
161+ oVars :GetJsonObject (" basePath" ):Set (" default" , " /api" ). /* Use the default typically set for a Spark-based application. */
162+
163+ assign oVars = catalog :GetJsonArray (" servers" ):GetJsonObject (2 ):GetJsonObject (" variables" ).
164+ oVars :GetJsonObject (" basePath" ):Set (" default" , " /api" ). /* Use the default typically set for a Spark-based application. */
165+ end .
93166 delete object oServiceWriter no-error .
94167 end .
95168
0 commit comments