Modify/Override 'Call REST' URL in Gen Java Applications
search cancel

Modify/Override 'Call REST' URL in Gen Java Applications

book

Article ID: 246085

calendar_today

Updated On:

Products

Gen - Host Encyclopedia Gen - Run Time Distributed Gen - Workstation Toolset Gen

Issue/Introduction

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.

Environment

Java Runtimes

Resolution

Option 1: In the Toolset, edit the Call REST statement — Match import parameter to a view

This is the recommended option as the change is persisted in the model.

The Gen Toolset offers “Configuration.[URL]” REST parameters in the Import REST API parameter matching screen.

How:

  1. In the Toolset, open the action block which has the Call REST statement you need to modify.
  2. Double click the service name to open the REST Method parameter screen.
  3.  

  4. 3. Under the matched Input parameters, click “Edit”.

  5. 4. Match a new parameter “Configuration.[URL]” to an appropriate import view.

  1. 5. You can pass the value for REST service URL through the matched view either from other action block(s) or from the application.

  2. 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.

    Pros:

    ★ Change is persisted in the model.

    Cons:

    ★ Requires regeneration of the model when the action block is modified.

  3.  
  4. Option 2: Modify the callrest.properties file

    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:

    1. Look for the callrest.properties file in the Gen installation directory.
    2. Add an entry for the new REST service URL (Base Path) in the following format:
    <SERVICE_NAME>=http ://< Server Name> :< port>/<Base Path>

    For example:


  5. 3. Save the callrest.properties file.

    4. Include the updated callrest.properties file in the EAR file.

    • Or reassemble the EAR file with the “Include Optional runtime property files” option checked to pick up the updated properties file.

    5. Redeploy the EAR to the application server.

    Pros:

    ★ You don’t need to regenerate your model.

    ★ Allows you to modify multiple URLs simultaneously in the same application.

    Cons:

    ★ You need to provide the exact Service_Name as it appears in the Gen model.

    ★ You will need to redeploy the EAR file.

  6. Option3: Modify the user exit: WebServiceMethodCallExit

    The Gen installation provides a user exit file named “WebServiceMethodCallExit” with a method that allows the Web Service URL to be modified.

    How:

    1. Look for the WebServiceMethodCallExit.java file in
      <Gen Installation directory>\classes\com\ca\gen\exits\common

    → 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.

  • Or reassemble your EAR file to pick up the updated user exit.

5. Redeploy the application.

Pros:

★ 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.

Cons:

 

★ 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.

Special Notes:

▹ What happens if you input a URL in more than one wayOption 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 contentIf your modified URL has content that no longer adheres to the views you matched, then your application may fail.

Conclusion:

 

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

 

Additional Information

Additional helpful documentation:

 

For additional information, please see hub article: Gen 8.6 Consuming REST APIs (Call REST) feature