There are a variety of reasons why you may need to modify the REST service URL (aka Base Path) used in the Call REST statement of your Gen™ action block. For example: the original service URL changed, you are switching from HTTP to HTTPS, or you need to change from a Dev server to a QA server. In this article, we will discuss the 3 different ways to modify a REST service URL and the pros/cons of each.
Java Runtimes
The Gen Toolset offers “Configuration.[URL]” REST parameters in the Import REST API parameter matching screen.
How:
4. Match a new parameter “Configuration.[URL]” to an appropriate import view.
5. You can pass the value for REST service URL through the matched view either from other action block(s) or from the application.
6 . Generate the Gen model with the appropriate environment options (for java applications) and assemble the EAR file.
7. Deploy the EAR file in the appropriate application server.
★ Change is persisted in the model.
★ Requires regeneration of the model when the action block is modified.
The callrest.properties file is a server option file for Call REST statements. This file allows you to modify the REST service URL for a REST API call using the given SERVICE_NAME. The SERVICE_NAME is the name defined and associated with a Call REST statement in the Gen™ model. This enables you to use SERVICE_NAME as a key and modify the URL by providing a new URL string to the specific SERVICE_NAME.
How:
<SERVICE_NAME>=http ://< Server Name> :< port>/<Base Path>
For example:
3. Save the callrest.properties file.
4. Include the updated callrest.properties file in the EAR file.
5. Redeploy the EAR to the application server.
★ You don’t need to regenerate your model.
★ Allows you to modify multiple URLs simultaneously in the same application.
★ You need to provide the exact Service_Name as it appears in the Gen model.
★ You will need to redeploy the EAR file.
The Gen installation provides a user exit file named “WebServiceMethodCallExit” with a method that allows the Web Service URL to be modified.
How:
→ In case you want to compile using Java11, then file would be located in <Gen Installation directory>\classes\java11\com\ca\gen\exits\common
2. Write your own logic inside the method name “modifyURL”.
For example, here is a code snippet:
3. Save and compile the WebServiceMethodCallExit.java file.
4. Include the WebServiceMethodCallExit.class file in the Gen runtime jar that is packaged into EAR file.
5. Redeploy the application.
★ You don’t need to regenerate your model.
★ For all REST API calls to that matching URL, this update will apply to them all at once.
★ If you only want the new URL to apply to a single REST API call, try option 1 or 2 instead.
★ You will need to redeploy the EAR file.
▹ What happens if you input a URL in more than one way? Option 3 (User exit) overrides both the other options. In other cases, Gen will first look at the callrest.properties file (Option 2). If empty then Gen will look for the URL in the “Configuration.[URL]” from the Toolset parameters (Option 1)
▹ When modifying a URL you are only changing the address, not the content. If your modified URL has content that no longer adheres to the views you matched, then your application may fail.
There are a variety of reasons why you may need to modify the REST service URL in your Call REST statement. Pick the best approach for your needs. In most cases,the recommended option is Option 1: In the Toolset, edit the Call REST statement — Match import parameter to a view, because the change is persisted in the model.
Table 1: Summary of Options
For additional information, please see hub article: Gen 8.6 Consuming REST APIs (Call REST) feature