Fundamentals / Delegate the start of an application or service |
Each request of the form /wa/r, /ja/r and /ws/r coming from the user agent are delegated to the Genero REST service via its entry point.
When a /wa/r, /ja/r or /ws/r request is delegated to the REST service, the dispatcher appends the string /Delegate to the service URL in order to distinguish a dispatcher delegation from any other standard REST request. In other words, if an application has delegation, the REST service is called with a /Delegate appended in the URL.
IMPORT com DEFINE req com.HTTPServiceRequest ... LET req = com.WebServiceEngine.GetHttpServiceRequest(-1) LET url = req.getUrl() IF url.getIndexOf("/ws/r/RestGroup/RestService/Delegate",1)>1 THEN CALL HandleDelegation(req) ELSE CALL HandleStandardService(req) END IF ...
If parameters are defined in the DELEGATE configuration, they will be transmitted to the Genero REST service at each /wa/r, /ja/r and /ws/r request as HTTP headers.
There is one HTTP header per parameter set in the configuration, and it is of the form X-FourJs-Environment-Parameter-XXX where XXX is the parameter name and the parameter value is the HTTP header value.
IMPORT com DEFINE req com.HTTPServiceRequest ... LET param1 = req.getRequestHeader("X-FourJs-Environment-Parameter-AnyParameter") DISPLAY param1 # Displays MyFirstParameter LET param2 = req.getRequestHeader("X-FourJs-Environment-Parameter-Other") DISPLAY param2 # Displays MySecondParameter ...
<EXECUTION> <PATH>$(res.path)</PATH> <MODULE>myApp.42r</MODULE> <DELEGATE service="MyGroup/MyDelegateService"> <AnyParameter>MyFirstParameter</AnyParameter> <Other>MySecondParameter</Other> </DELEGATE> </EXECUTION>
When a /wa/r, /ja/r or /ws/r request is delegated to a REST service, the original URL is transmitted to the service in the queryString of the request. The readFormEncodedRequest() retrieves that queryString, but you can also use getURL() and retrieve the original URL after the ? character. You can then check the URL the user agent wants to access. This URL can contain a query string if the user added parameters in the browser.
REST sample:
IMPORT com ... DEFINE req com.HTTPServiceRequest DEFINE original STRING DEFINE query STRING DEFINE url STRING ... LET original = req.readFormEncodedRequest(false) CALL SplitUrl(original) RETURNING url, query DISPLAY url # http://host:port/wa/r/MyGrp/MyApp DISPLAY query # P=1&P=2 ...