Skip to main content

Invoking a Restful Service

Overview

This document will explain how to use the Enactor framework to call your own Restful Services.

What You Will Learn

  • Specifying the location of the Endpoint for the service in the Connection Diagram
  • Process Connection Extensions
  • Calling the service via an Application Process

Mock Rest API

For this document, we will use a customer lookup service. If this is not already running, you can launch it by running the Start Mock Service shortcut on the desktop.

This has the following API:

  • URL:

    • http://localhost:3000/<productId>

    • The mock implementation only supports a customer number of 123

  • Method:

    • GET
  • Success Response:

    • Code: 200

    • Content:

      "SN: 123456"
  • Error Response:

    • Code: 404 NOT FOUND

    • Content:

      "PRODUCT_NOT_FOUND"

Process Connections Diagram

Specifying an Endpoint

The connection diagram is employed to define the location of any service that an Enactor application will call.

Bring up the Resource Library View and search for and open the Connection Diagram TrainingPosEstateManager

Search For Training Pos Estate Manager

From the Palette, Add a new Application (Connected Process)

Connected Process Palette New Connected Process

Select to view the properties of the Connected Process and edit the following

Set the Process ID to RestMock

Edit the Outputs and add a new Output named GenerateSerial

Connected Process Rest Mock

From the Palette, add a new Web Service Group

Web Service Group Palette

Select to view the properties of the Web Service Group and edit the following

Set the Name to RestMockService Set the Service ID to RestMockService

Web Servic Group Properties

Select the Unnamed Service from within the Web Services section

Set the Endpoint Reference Type to Rest Endpoint

info

A new new set of properties should appear

Re Select the Unnamed Service from within the Web Services section

Set the following properties

  • Dynamic Endpoint : Select true from the drop down menu
  • HTTP Method : Select GET from the drop down menu
  • URL : http://localhost:3000/#{productId}
  • Connection Provider ID : MockRest

Web Service Properties

Link the GenerateSerial Output from the Connected Process to MockRest Service

Link Connected Process To Web Service

Connected Process Extension

Open the Packages.xml located with the Training - Common Data Project (same project as the Process Connection Diagram)

Select Pacakges

Selected the Connected Processes Tab

Expand the Connected Process Extensions

For the Extending Connected Process, enter StandardPosEstateManager

Select Pacakges

Application Flow

Identifying key location in the application flow

Using Enactor Pos Overview of Key Application Processes as a reference, we need to identify an ideal extension point to use during the selling of a product.

Bring up the Resource Library View and search for the Process ValidateProductSale

Select and open ValidateProductSale_1.0.xml

SearchForValidateProductSale

Using the Outline View expand the Actions Group and search for CallPostValidateProductExtension

SearchForCallPostValidateProductExtension

The PostValidateProductExtension extension is well-suited for its purpose due to its positioning at the end of validating a product. This strategic location ensures that the sell flow can be aborted if the service fails before creating a basket item.

Creating an Extension Point Process

GenerateProductSerialNumber

Create the following directory paths relative to the Process directory, Training/Pos/Product/

Create Directory Paths

Create a new Application Process with an ID of GenerateProductSerialNumber

Register the new Application Process GenerateProductSerialNumber for the Extension Point ID PostValidateProductExtension

Register Extension

Add a new Starting State

Add a new State Event StateEntered

Bring up the Resource Library View and search for the Action InvokeRestServiceAction, Ensuring the Process ID InvokeRestServiceAction is Selected, Place the new action alongside the State

Reading the Extension point decleration for CallPostValidateProductExtension, we can see there is an input named Product. We need to declar this as an input to our own extension to make it available.

Select to view the properties of the Process and create the following Input Data

NameType
enactor.mfc.Productcom.enactor.mfc.product.IProduct
info

State data will be automatically populated when declaring new input variables

Select to view the properties of the Process and create the following State Data

NameType
enactor.pos.SerialNumberjava.lang.String

Create Input Data

Select to view the properties of the InvokeRestServiceAction and add the foillowing Input

NameType
productIdjava.lang.String

Select to view the properties of the InvokeRestServiceAction and add the foillowing Perameters

NameValueType
enactor.coreUI.ConnectedProcessClientId${Service.DeviceID}java.lang.String
enactor.coreUI.ConnectedProcessHostId${Service.DeviceType}java.lang.String
enactor.coreUI.ConnectedProcessClientId${Service.LocationID}java.lang.String
enactor.coreUI.ConnectedProcessIdRestMockjava.lang.String
enactor.coreUI.ConnectionPointIdGenerateSerialjava.lang.String

Invoke Rest Service Perameter

Select to edit the mappings for InvokeRestServiceAction

Link the Product Process State Data Object to the Action Input Data productId

Select the newly creasted link and enter the following expression product.productId

Mark all the remaining Inputs as unsued

Link the Object Output to the process State Data SerialNumber

Mark all the remaining Outputs as unsued

Add an End Process Actions with an outcome of Fail

Link the Fail Outcome of InvokeRestServiceAction to the End Process Action for Fail

Bring up the Resource Library View and search for the Action UILogMessageAction

Place the UILogMessageAction alongside InvokeRestServiceAction

Link the Success Outcome of InvokeRestServiceAction to UILogMessageAction

Select to view the properties of the UILogMessageAction and add the foillowing Perameters

NameValueType
enactor.coreUI.logging.LogLevelLOG_DEBUGjava.lang.String

Select to edit the mappings for UILogMessageAction and link the Process State Data SerialNumber to the Input LogMessage

Mark all the remaining Inputs as unsued

Add an End Process Actions with an outcome of Success

Link the Success Outcome of UILogMessageAction to the End Process Action for Success

Answers

After completing the tutorial, this is how the application process should look like

Complete

The completed solution can be found InvokingARestfulService Project located at /WorkspaceSetup/Solutions/InvokingARestfulService

To run the solution, import the project as a maven project to your workspace

Select the Training Solution - Invoking A Restful Service Java launch