SAP Process Integration, SAP NetWeaver Process Integration

REST Adapter Sender Channel – Customer Error Handling with Response Payload

There are many blogs out there which explain how to use custom error handling but they seem to concentrate on the receiver side. This blog is an example of how to send back the payload as defined in the response mapping along with a non-200 HTTP Status Code

NOTE: SAP Knowledge Base 2259871 implies there should be a “Use Message Payload” option on the sender adapter but in our environment PI 7.5 SP 11 we don’t have this so this blog explains how to still get the response payload sent to the consumer….

Scenario:REST to SOAP (Mock Service)

ESR Objects

Consumer (Sender)

SAP Process Integration, SAP NetWeaver Process Integration

Service Interface:

SAP Process Integration, SAP NetWeaver Process Integration

Request Message Type

NOTE:- As this is a RESTful GET call the element ‘dummy’ is not used

SAP Process Integration, SAP NetWeaver Process Integration

Response Message Type

SAP Process Integration, SAP NetWeaver Process Integration

Target (Receiver)

SAP Process Integration, SAP NetWeaver Process Integration

Service Interface

SAP Process Integration, SAP NetWeaver Process Integration

Request Message Type

SAP Process Integration, SAP NetWeaver Process Integration

Response Message Type

SAP Process Integration, SAP NetWeaver Process Integration

Operation Mapping

SAP Process Integration, SAP NetWeaver Process Integration

Request

SAP Process Integration, SAP NetWeaver Process Integration

Response

SAP Process Integration, SAP NetWeaver Process Integration

Fault

NOTE:- This has been done but we are not interested in fault handling in this blog!

SAP Process Integration, SAP NetWeaver Process Integration

Message Mapping

Request

NOTE:- We use a UDF to retrieve the REST ASMA ‘id’ and set the Id field to this value. The ASMA will be set in the REST sender adapter (under REST Resources tab)

SAP Process Integration, SAP NetWeaver Process Integration

UDF

SAP Process Integration, SAP NetWeaver Process Integration

Response

The response mapping will check the incoming ‘Success_Flag’ from the target (mock service) system and if it does not equal ‘Y’ then we create the Error structure

SAP Process Integration, SAP NetWeaver Process Integration

The ‘Error_Code’ and ‘Error_Desc’ fields are then set to some more helpful values. In a real world scenario we may have more complex logic based on what the target system returns.

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

Integration Builder

Adapters

REST Sender

The sender adapter is defined as synchronous (‘Best Effort’) and handles the request/response as JSON.

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

NOTE:- This is where we ASMA ‘id’ is set to the Id passed in the URL request and is then used in the request mapping in ESR.

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

NOTE:- The message type is based on the GET operation but in future we could set different message types based on the operation (POST, PUT etc)

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

NOTE:- They key definition for the sender is that we check for the value of ‘N’ in the field ‘Success_Flag’ and then use the placeholder {message_result} which is the payload of the response message AFTER the message mapping.

SAP Process Integration, SAP NetWeaver Process Integration

SOAP Receiver

The SOAP receiver is directed to a SOAPUI mock service running on my laptop.

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

ICO

The ICO uses the adapters and the ESR OM to bring it all together!

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

Running the Scenario

Mock Service

SOAPUI is configured with the mock service for the target (receiver) by importing the WSDL for the SI_Mock_Service from ESR.

SAP Process Integration, SAP NetWeaver Process Integration

NOTE: The port and path match the values used in the SOAP Receiver in PI

SAP Process Integration, SAP NetWeaver Process Integration

I have created two mock responses which will be called sequentially (one after the other)

SAP Process Integration, SAP NetWeaver Process Integration

The ‘Success’ mock response sets the ‘Success_Flag’ to ‘Y’ and sets the name field (hard coded for simplicity!) and Id field uses a script to pass back the Id from the request message.

SAP Process Integration, SAP NetWeaver Process Integration

The ‘failure’ mock response sets the ‘Success_Flag’ to ‘N’ and sets the name field (hard coded for simplicity!) and Id field uses a script to pass back the Id from the request message.

SAP Process Integration, SAP NetWeaver Process Integration

Calling the PI REST Service

The first call is to the PI endpoint with a customer Id of 876333 – the screenshot shows the mock service was called and we have returned the customer name. the second screenshot shows the HTP Status Code is 200 as expected!

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

The next call (customer Id ‘3333’)will trigger the ‘failure’ mock response as the mock service just responds with the next mock response in sequence (we have two defined; the Success and Failure). The second screenhot show the HTP Status Code is set to 404 as we defined this in the error handling in the REST sender adapter!

SAP Process Integration, SAP NetWeaver Process Integration

SAP Process Integration, SAP NetWeaver Process Integration

FEATURE ALERT FEATURE ALERT!

In testing I have noticed that there is some caching in PI when we call the endpoint using the same customer Id in rapid succession. I’m not 100% if this is related to the SOAPUI mock service or with PI itself.

Leave a Reply

Your email address will not be published. Required fields are marked *