Calling REST from Natural

Scenario: "I have a REST API and want to call this from a Natural application."

graphics/simple.png

This scenario uses the following tools of the Designer:

This document covers the following topics:

See also Common Integration Scenarios for other common user scenarios that can be handled by EntireX.


Introduction

To call the REST API from Natural, take an existing description of a REST API graphics/blue_1.gif and generate the integration logic graphics/blue_2.gif to call it from a Natural application graphics/blue_3.gif, as shown below.

graphics/solution.png

graphics/blue_1.gif Create the consumer REST API descriptor in Integration Server. See Service Development Help in the webMethods Integration Server documentation. Then generate Integration Server connections and listeners. See Using the IDL Extractor for Integration Server.
graphics/blue_2.gif Generate client interface objects and build Natural client application.
graphics/blue_3.gif Execute the call from the Natural client to the REST API.

This scenario makes the following important assumptions:

For Task 1:

  • You have an Integration Server with EntireX Adapter installed.

For Task 2:

  • You have a Natural RPC Server installed. Generating Natural code requires a running Natural RPC Server and either EntireX Broker or Integration Server.

    graphics/intro-assume2.png

    See your Natural documentation for setting up the Natural RPC Server.

For Task 3:

  • You have an Integration Server with EntireX Adapter installed.

  • You can call the REST API at runtime using different methods:

    • EntireX RPC
      For the EntireX RPC connection method you need EntireX Broker on one of the supported platforms: z/OS | UNIX | Windows | BS2000 | z/VSE.

      graphics/intro-assume3a.png

    • EntireX Direct RPC
      For the EntireX Direct RPC connection method there are no additional prerequisites. See also Direct RPC.

      graphics/intro-assume3b.png

Task 1: Create the Consumer REST API Descriptor, Connections and Listeners

This section covers the following topics:

Introduction

After you have created the consumer REST API descriptor, follow the instructions for extracting a webMethods Integration Server (IS) service under Using the IDL Extractor for Integration Server.

This process creates the following EntireX metafiles:

  • an IDL file, containing definitions of the interface between client and server; see Software AG IDL File in the IDL Editor documentation

  • a webMethods IS Connection

  • a webMethods IS Listener, depending on connection type. See Listeners in the EntireX Adapter documentation.

Connection types are described under Creating Listener Objects in Integration Server.

Creating a Consumer REST API Descriptor

Start of instruction setTo create a consumer REST API Descriptor

  1. Switch to the Service Development perspective. Create a package and folder in Designer where the API descriptor is placed into.

  2. Invoke the wizard to create a new REST API Descriptor in Eclipse. From the File menu, choose New > REST API Descriptor.

    Or:
    Choose New from the toolbar or context menu of a view showing resources.

    Or:
    Press Ctrl-N to start the selection of the New Wizards.

    graphics/many2cob-common_generate-server_restApi.png

  3. Follow the instructions on the screen. Provide the description of the REST API (Swagger file) and create the REST API descriptor for a Consumer.

For more information on REST API descriptors see Service Development Help in the webMethods Integration Server documentation.

Extracting the Interface of the webMethods IS Service

First create a project in Designer. This project is the container into which all extracted and generated EntireX artifacts are placed. Name this project Natural placeOrder client.

Start of instruction setTo start the IDL Extractor for Integration Server

  1. Switch to the EntireX perspective.

  2. Invoke the IDL Extractor for webMethods IS, which is a New Wizard in Eclipse. From the File menu, choose New. Select IDL Extractor for webMethods IS in the following page.

    Or:
    Choose New from the toolbar or context menu of a view showing resources.

    Or:
    Press Ctrl-N to start the selection of the New Wizards.

  3. If you are using the wizard for the first time without any predefined Integration Server connections, enter the TCP/IP address of the webMethods IS to extract from. Otherwise select the connection to the Integration Server.

  4. Press Next.

Start of instruction setTo extract the IDL from the selected package

  1. Under Source (Integration Server), select the package you want to extract from.

    graphics/common_generate-server_extract.png

  2. For Target (Eclipse Workspace), specify project Natural placeOrder client. Extraction results will be placed in this container. You can keep the IDL File Name as it has been derived from the package name by default. Since Natural is your desired endpoint, select Optimize extracted IDL for usage with: Natural.

  3. A listener is required for calling webMethods IS from an RPC client, so check Create Listener Objects in Integration Server.

  4. Press Next.

Creating Listener Objects in Integration Server

Start of instruction setTo create Listener Objects in Integration Server

  1. Select a Listener connection type used for inbound connection to the Integration Server.

    • An EntireX RPC Listener connection is the standard way and is always available.

    • If your interface contains only In parameters, an EntireX Reliable RPC Listener connection is available.

    • If it is enabled by the license for the webMethods Integration Server:

      • an EntireX Direct RPC Listener connection is available

      • if your interfaces contain only In parameters, an EntireX Direct Reliable RPC Listener connection is available

    graphics/common_generate-server_listener.png

  2. On this page, you set the properties for the listener objects to create; these objects will wait for the incoming Natural requests. Select the package and specify the folder name into which the listener is generated. If the folder does not exist, it will be created automatically.

  3. Keep the defaults given for RPC Listener Connection to EntireX. The Broker ID is a TCP/IP or SSL/TLS address and Server Address is an EntireX-specific namespace to locate a target server (here: OrderManagementListener).

  4. When creating a connection, a package dependency is added such that the selected package depends on webMethods EntireX (the package WmEntireX) with the version currently used.

  5. Press Finish. The listener and the connection appear in the package navigator. For the package navigator, switch to the service development perspective by choosing Window > Perspective > Open Perspective > Service Development.

Testing the Extraction Results (Optional)

You can test the results of the extraction and the server back end, using the EntireX IDL Tester.

Start of instruction setTo test the extraction results

  1. For EntireX RPC (see Task 3 in the Introduction) and an RPC Listner Connection, make sure EntireX Broker is running.

  2. Enable the EntireX Adapter Listener.

    graphics/common_generate-server_test.png

  3. Activate the EntireX perspective by choosing Window > Perspective > Open Perspective > EntireX, and from the context menu of the IDL file, choose IDL Tester.

  4. This step depends on the method used to call the server (see Task 3 in the Introduction).

    • For EntireX RPC, enter the same TCP/IP address for Broker that you supplied when you created the RPC Listener Connection to EntireX (localhost:1971).

    • For Direct RPC, that is, you generated a Direct RPC Listener Connection, enter the TCP/IP address from the Integration Server (localhost:1971).

  5. For Server, enter the values you specified for the server address (RPC/SRV1/CALLNAT).

    graphics/common_generate-server_test-2.png

Task 2: Generate Client Interface Objects and Build Client Application

Start of instruction setTo generate client interface objects and build a client application

  • For Natural code generation, make sure the EntireX Perspective is active: Choose Window > Perspective > Open Perspective > EntireX. From context menu of the IDL file, choose Natural > Generate RPC Client.

    graphics/generate-client.png

    In the Natural Wrapper you can specify the names of the generated Natural files to match your naming conventions (see picture above). Three Natural files are generated:

    • A client subprogram (extension .NSN). Also named CALLNAT. In EntireX terminology this acts as the client interface object.

    • A client PDA (extension .PDA). This contains the data description of the API.

    • A test program (extension .NSP). This calls the client interface object. Generation of test programs can be switched off.

    Natural developers often use use a single character on a fixed position in the 8-character Natural name to represent the object type of the Natural object (typically P=program; N=subprogram; A=PDA). The last character of the names from our example above uses this convention.

    The test program can also be used as an example of how to code an RPC client in Natural. It uses the Natural API RPC-CNTX. Parameters such as host, port, server address, user ID etc. can be set for RPC communication. Especially for a quick test, this is the simplest way to set the connection parameters. See your Natural documentation for more information on API RPC-CNTX. You can also set connection parameters using a service directory. See Service Directory Maintenance in the Natural SYSRPC Utility documentation for more information.

Task 3: Execute the Call from Natural to REST

The following alternatives are provided for testing:

Generated Test Program

Use the generated test program to execute the call.

Start of instruction setTo use the generated test program

  1. For EntireX RPC (see Task 3 in the Introduction) and an RPC Listner Connection, make sure EntireX Broker is running.

  2. Enable the EntireX Adapter Listener.

    graphics/common_generate-server_test.png

  3. This step depends on the method used to call the server (see Task 3 in the Introduction).

    • For EntireX RPC, enter the same TCP/IP address for Broker that you supplied when you created the RPC Listener Connection to EntireX (localhost:1971).

    • For Direct RPC, that is, you generated a Direct RPC Listener Connection, enter the TCP/IP address from the Integration Server (localhost:1971).

  4. Set the field Server name to match the middle part of the Server address specified under Creating Listener Objects in Integration Server. Example: If you specify SRV1 in the test program, RPC/SRV1/CALLNAT will be used.

    graphics/execute_generate.png

IDL Tester

Use the EntireX IDL Tester to execute the call.

Start of instruction setTo test the extraction results

  1. For EntireX RPC (see Task 3 in the Introduction) and an RPC Listner Connection, make sure EntireX Broker is running.

  2. Enable the EntireX Adapter Listener.

    graphics/common_generate-server_test.png

  3. Activate the EntireX perspective by choosing Window > Perspective > Open Perspective > EntireX, and from the context menu of the IDL file, choose IDL Tester.

  4. This step depends on the method used to call the server (see Task 3 in the Introduction).

    • For EntireX RPC, enter the same TCP/IP address for Broker that you supplied when you created the RPC Listener Connection to EntireX (localhost:1971).

    • For Direct RPC, that is, you generated a Direct RPC Listener Connection, enter the TCP/IP address from the Integration Server (localhost:1971).

  5. For Server, enter the values you specified for the server address (RPC/SRV1/CALLNAT).

    graphics/common_generate-server_test-2.png