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 product id of 0WXIVEX-11

  • Method:

    • GET
  • Success Response:

    • Code: 200

    • Content:

      "SN: 123456"
  • Error Response:

    • Code: 404 NOT FOUND

    • Content:

      "PRODUCT_NOT_FOUND"

Process Connections Diagram

Connected Process Extension

To create a new extension:

  1. The standard folder for Process Connections is: src/META-INF/deployments/ProcessConnections. Create an empty directory in the TrainingPOSExtension project. Right Click New -> Folder and Enter Folder Name as ProcessConnections.

  2. Right Click on ProcessConnections folder New -> Other and Search for Connected Process. Select Connected Process under Enactor Development and Click Next

    Create New File Select Other

    Select Connected Process FromWizard

  3. In the Connected Process wizard, enter TrainingPosEstateManager as the Connected Process ID and Training connection strategy for Pos and Estate Manager as the Description. Then tick the Extending an existing Connected Process checkbox and click Next.

    Connected Process Wizard Enter ID

  4. In the Extending Connected Process field, enter StandardPosEstateManager. Then click Finish. Connected Process Extension Settings

This will open the newly created Connected Process diagram. Connected Process Initial View

Specifying an Endpoint

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

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

Double-click on the CallPostValidateProductExtension, and then click Create New Extension Process in the open wizard.

Select Extension View

Enter the Extension Name as Training Post Validate Product Extension and the Process ID as Pos/Product/GenerateProductSerialNumber, then click Browse to set the container.

Extension Point Wizard

Select the Process in the TrainingPOSExtension folder and click OK

Folder Selection Extension

Click Finish to complete

Extension Point Settings Finish

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.Location Id${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

TODO : Run the server and needs to take the SS

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

Select the Training Solution - Invoking A Restful Service Java launch