Tuesday, 23 July 2019

HTTP Sender CSRF token Handling in SAP CPI

We would like to add some more authentication on the passing the message from the Sender system to CPI, so HTTP adapter is capable of handling the CSRF token at the sender side.

As this feature is not enabled for the HTTP receiver, so we can go ahead with the ODATA adapter to use this feature.

In this post, will read about fetching the CSRF token and post the data to CPI from sender system.

For the demonstration, we use POSTMAN tool as a sender system.

Step 1: Get the CSRF token by calling the CPI system

                                                       (Click to Zoom if not visible)


Step 2: POST the actual data with the CSRF token as mentioned in the below screenshot:



CPI Flow design for simple testingSimple connectivity cal made to CPI and posted the data successfully.


Happy Learning!!!





Tuesday, 9 July 2019

java.io.IOException: Remotely closed - SAP CPI

When you are facing this issue on the development phase, then it could be the minor mistake in URL as mentioned below.

If you encounter this same issue at the live scenario, then it could be the connection to the respective system is broken..Eg: No able to connect to the target system.

https://test/sap/opu/odata//SAP/test_SRV/MarketingPermissions

FYI.. Some occasions minor mistakes can happen. 



Friday, 14 June 2019

Routing Condition formation in SAP CPI

Based on certain routing conditions the messages are directed to different receivers. Store the condition in any header or property values and call them in router dynamically. Different acceptable formats are below:

In Router configuration, mention the Expression Type: Non-XML


Usage of Operators in Non-XML Conditions


OperatorExample
=${header.SenderId} = '1'
!=${header.SenderId} != '1'
>${header.SenderId} > '1'
>=${header.SenderId} >= '1'
<${header.SenderId} < '1'
<=${header.SenderId} <= '1'
and${header.SenderId}= '1' and ${header.ReceiverId} = '2'
or${header.SenderId}= '1' or ${header.ReceiverId}= '2'
contains${header.SenderId} contains '1'
not contains${header.SenderId} not contains '1'
in${header.SenderId} in '1,2'
not in${header.SenderId} not in '1,2'
regex${header.SenderId} regex '1.*'
not regex${header.SenderId} not regex '1.*'



Friday, 7 June 2019

Accessing value mapping in groovy script

For some scenarios, we would need to access the deployed Value mapping table in the iflow, there is a possible way to access the values using the below script:


Groovy Script:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.sap.it.api.ITApiFactory;
import com.sap.it.api.mapping.ValueMappingApi;

def Message processData(Message message)
{
def a = ITApiFactory.getApi(ValueMappingApi.class, null);

//format sourceAgency, sourceIdentifier, sourceValue, targetAgency, targetIdentifier

def mappedValue = a.getMappedValue("C4C", "Country", "yMKT", "Country", "Austria");

def messageLog = messageLogFactory.getMessageLog(message);

messageLog.setStringProperty("Mapped Value", mappedValue);

return message;
}


Hope this Helps!!!



Wednesday, 5 June 2019

Converting the File from field fixed length file to XML Success-factor Simplified


There is no standard way of converting the flat file into XML format using the fixed field length in CPI, as we have in PI using FCC parameters. To solve this problem, you can implement the below code.


GroovyScript:

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

    def Message processData(Message message) {

//Body

    def body = message.getBody(java.lang.String) as String;
    def lines = body.split("\n");

//root node
    def body1 ="<Files>";

//looping to read the lines and form a XML
    for(i=0;i<lines.length;i++)

     {

         body1 += "<EmpDetails>";
         body1 += "<Name>"+lines[i].substring(0,4)+"</Name>";
         body1 += "<Age>"+lines[i].substring(4,6)+"</Age>";
         body1 += "<DOB>"+lines[i].substring(6,26)+"</DOB>";
         body1 += "<JobTitle>"+lines[i].substring(14,26)+"</JobTitle>";
         body1 += "<Country>"+lines[i].substring(26,31)+"</Country>";
         body1 += "</EmpDetails>";
    }

//closing root note
    body1 +="</Files>";

//storing the converted XML to body
    message.setBody(body1);

    return message;

   }


Input File(Flat):

Rama2123051990SrConsultantIndia
Ravi3322021994 ConsultantIndia
Siva3322021994SrConsultantIndia

Output File(XML):

<Files>
<EmpDetails>
<Name>Rama</Name>
<Age>21</Age>
<DOB>23051990SrConsultant</DOB>
<JobTitle>SrConsultant</JobTitle>
<Country>India</Country>
</EmpDetails>
<EmpDetails>
<Name>Ravi</Name>
<Age>33</Age>
<DOB>22021994 Consultant</DOB>
<JobTitle> Consultant</JobTitle>
<Country>India</Country>
</EmpDetails>
<EmpDetails>
<Name>Siva</Name>
<Age>33</Age>
<DOB>22021994SrConsultant</DOB>
<JobTitle>SrConsultant</JobTitle>
<Country>India</Country>
</EmpDetails>
</Files>

Hope this helps!!!





Thursday, 16 May 2019

Setting HTTP header for API Key in SAP CPI


Add the Header in the HTTP POST request for appending the API Key and Content Type

Groovy Script:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def Message processData(Message message) {

message.setHeader("Content-Type", "text/xml" + "; charset=utf-8" );
message.setHeader("Authorization", "api_key 2R3jWC1s3GKF1qzV2FdWOm" );

return message;

}



Tuesday, 14 May 2019

SAP CPI releases 2019



The remaining takt increments of 2018 are scheduled (if all quality checks are passed timely) to reach your customer systems at the following dates:

            
Increment
Delivery Date
1901
17-Mar-19
1902
14-Apr-19
1903
12-May-19
1904
09-Jun-19
1905
07-Jul-19
1906
04-Aug-19
1907
01-Sep-19
1908
29-Sep-19
1909
27-Oct-19
1910
24-Nov-19
1911
22-Dec-2019 (tbc)
1912
20-Jan-20
1913
16-Feb-20