In some integration scenarios, depending on certain forwarding conditions, messages may be forwarded to different recipients. We can use the Router tool to do such an operation in SAP CPI.
Advantages:
Messages can be sent to multiple adressess with a single connection address (SM59) from the S4 system.
Prerequisites:
- Intermediate ABAP Knowledge
- Basic SAP CPI Knowledge
- Intermediate HTTPS Methods Knowledge
In order to perform our operation, we first need to prepare an iFlow that is triggered by the HTTPS post method in SAP CPI and contains a router.
After logging into the SAP CPI system, we click on the content package button in the menu on the left.
To create a new package, click the Create button in the upper right.
After clicking the Create button, we name the package and click the Save button on the top left to create the package.
We click on the Artifacts section and add a new iFlow (integration flow) with the Add button.
After creating our iFlow, we first create the HTTPS connection that will be triggered by S4.
To create the HTTPS connection, we click on Sender and combine the connector arrow with the Start message by drag and drop.
We determine the adapter type on the screen that appears after the drag and drop operation.
We specify the address field from the Connection section. (Example: /solvia_routing)
We can specify the Authorization part here (User Role=Basic Authentication, client certificate)
In addition, to be protected from Cross-Site Request Forgery (CSRF) attacks, the CSRF protected button must be selected.
After creating our HTTPS connection, we add a new recipient using the participants button.
After adding our recipient, we need to add a new End Message.
After adding the End Message, we can now place our Router.
After adding the Router, we create our second connection by clicking on the Router and using the Connector arrow.
Then we combine End Messages and receivers with drag and drop. Since the receiver is the endpoint address to be reached here, SAP CPI will again ask us which adapter type to go with. In this example, we choose the HTTPS adapter because we are doing a HTTPS Post operation.
We make the same connection in both receiver. Here, the address part becomes the domain part of the address. The Query part specifies which extension we will post in the address.
As a final step, we need to determine the conditions of the router. For this, we click on the respective arrows coming out of the router and write which routing conditions we have.
In the Expression Type section, there are two options, XML and Non-XML. If the HTTPS body part we send is XML, we can use xpath functions here and get certain values. In this example, we will specify our conditions using the header part of the HTTPS post method, so we will select the Non-XML option and read from the header of the HTTPS message.
We can access the header information of the HTTPS message by typing this statement ”${header.on-premise} = ‘true’ ”.
Since we will send the request to the on-premise or cloud system according to the header information received in our scenario, we set a condition as follows.
1.Condition
2. Condition
And if these two conditions are not met, we create a new connection and select the Default option to determine where the router will head. Since the default route is not connected anywhere, the process will terminate if the header parameters are not sent.
The final state of the created iFlow:
We deploy our iFlow from the top right.
After the deployment process is completed, we can start the processes on the SAP side. After deployment, the SM59 connection is created using the endpoint created by SAP CPI.
After the SM59 connection is created, we can post to our iFlow with the code block below.