How To Use Jms Adapter in Sap Cpi To Resend Message
How To Use Jms Adapter in Sap Cpi To Resend Message
How To Use Jms Adapter in Sap Cpi To Resend Message
Scenario
We send file XML from POSTMAN to 3rd system, but because of any reason, file XML can not go to SFTP.
And we get complain that can not see file in SFTP. In this case we have to push data again. To resolve
this issue, we use JMS adapter.
Kindly take short look diagram
In this case, message from sender will send to queue is call message queue. And from there, they will
send to SFTP. If any issue of FTP server, message will be hold and resend
For simple, this integration flow we will just include one sender (HTTPS) and one receiver (JMS)
Queue Name : Name of queue in CPI
When we use POSTMAN to run this integration flow We will receive message in Message Queues
Step 2 : Create integration flow consume message queue in step 1
In this step, we create new integration flow to consume message queue. We just add sender adapter is
JMS with name equal name of queue in step 1, and SFTP adapter for receiver. We simulate two case
Case 1 : Cannot connect to SFTP. We will see that message still in queue. Queue try resend message
every short time
Case 2 : Connect SFTP ok, so message send from POSTMAN to SFTP ok
Case 1 : Message send to queue, connect to SFTP error. Message will hold in queue
POSTMAN to queue
Create key pair and save private key (A) by yourself and send public key to partner. Partner will encrypt
data by public key and send to your system (CPI). CPI will use private key to decrypt data.
Save public key (B) of partner in your system and use it to encrypt data which sent to system partner (B)
In SAP CPI, we will use PGP keys, PGP ENCRYPTOR, PGP DECRYPTOR to do this. OK let’s begin.
I. Create private key and public key
To do this, we will use software KLEOPATRA. you can download it over internet.
OK, public key and private key will be used in encryption and decryption data.
II. PGP Encryption
Scenario – Data plain text will sent by HTTPS adapter. In IFLOW, data will be encrypt by use component
PGP ENCRYPTOR and send file XML to SFTP folder.
Scenario – Receive data which encrypted before to IFLOW, use component PGP DECRYPTOR to decrypt
data and send to backend
Step III-1. Import private key into PGP Keys.
In PGP Keys of CPI, just allow add only one public key, if we add one more another public key, It will be
overwrite. So, If we need add many public of many provider, how do we will do ?
The answer is very simple, we will add all public key into one file. And after that, add this file into CPI.
This is steps
With private key, we need make sure all key have to the same pass phrase. If not, we will receive error
when import into CPI.
[SAP CPI] – WORKING WITH JDBC ADAPTER RECEIVER ON SAP CPI AND SQL SERVER – INSERT STATEMENT
Hi guys, to be continue for series WORKING WITH JDBC ADAPTER RECEIVER ON SAP CPI AND SQL
SERVER, today I want to setup one scenario only about Insert statement, working with many rows many
table in SQL.
And we want insert many rows into this table, example 3 rows, we have to create XML for Insert
statement as below
With another system, JDBC can run one time and they can insert all rows into table of database. But
with CPI-JDBC supports only one record at a time, check this link . You can use General Splitter after
mapping and insert all the records into DB.
And after that, JDBC adapter will insert every message into database.
But, we also have another way, no need use Splitter Component. It is create structure XML with many
segment Statement. In above example we will create XML syntax as
With this syntax, data also insert into database as well.
Scenario 02 : Insert data(s) into multiple table. Example Master – Detail table.
In this scenario, we need focus to data which insert into database have to the same master and data. If
master cannot insert or detail cannot insert into database with any issue, all transaction will be
ROLLBACK. OK, let’s config it
Example we have two table in database which related together TBL_002 and TBL_002A. Key relationship
of two table is SAP_PO.
We need insert data from this XML structure into database through JDBC
Step 01 : Create XSD for source message
Step 02 : Create XSD for destination message (Insert aJDBC)
Step 03 : Create integration flow and mapping source message with destination message
Mapping for Header
After mapping is done, we test by run simulation
Add Filter component to get all Element Statement
Atomic : Considers each batch operation as a single unit. It updates the whole batch operation
successfully or reverts the entire operation to its initial state if anything in the batch operation fails.
Non-Atomic : This is based on the behavior of the database. It updates all the successfully executed
records and throws an exception if anything fails. It does not revert the failed records to its initial state.
Kindly reference this link for more detail about JDBC adapter
Test case
Request
Response
Case 02 : Happy case
Request
Response
Check data in SQL
Scenario
Integration Flow want get all files with extension XML from folder SFTP into flow. Do some logic and
then will sent payload into queue.
All information of SFTP, ex: address, folder, credential… will be set by parameter.
In this configuration, we will use externalize parameter to config dynamic value for SFTP.
This is parameter table for this configuration
#3. Configuration Content Modifier
In this content modifier, we will create header with name CAMELFILENAME to get extension of file
which get from SFTP folder.
Base on value of HEADER.CAMELFILENAME, we set condition in router to get just file with extension is
XML
After save, we need to input value for parameters which we define in integration flow.
Go to artifact, choose configure.
First, send file with extension NOT equal XML. (Ex: ZIP file). In this case flow will run router default
(Route 2), and we will receiver ABC as payload
Second, send file with extension EQUAL XML, in this case flow will run route 1, and we will receiver data
in JMS (data in JMS queue will be decrypt)
Check in queue
Scenario 01
We have one REST API which use access token to access. We want call this API, we will have do some action below:
Step 1: Call to URL TOKEN to get access token. In this article, for example TOKEN will get from service key.
Endpoint : https://<Host>/oauth/token
Step 2: Use access token in step 1 to call REST API. In this article endpoint : https://<host>/http/restapi
For simple in this article, I will use integration flow in CPI to create one REST API and call it from another integration.
Test this API from POSTMAN, we need to check this API run OK.
As we see, this API need authorize by OAUTH2 with grant type is Client Credentials. So, we need call to token provider to
get access token.
All information of token provider will be get from service key with type Process Integration Runtime.
Step 2 : Create integration flow call REST API in Step 01
In this step, we will create new integration flow will call REST API in step 01. We also focus that, REST API use access
token to call, so in integration flow we need call to token provider to get access token and after that will use this access
token to call REST API. All this things, we will action on integration flow.
Next, We will use component Request Reply to call direct REST API with Authentication Type is OAuth2 Client Credentials
and input name of Oauth2 client credentials above in here
Step 2.2: Second way – Use access token to call REST API
The first, we try call API which provided by Token Provider by POSTMAN to understand how to
Token URL
client_id : in this article, get it from service key. In fact, this value partner will provide
client_secret : in this article get it from service key. In fact this value partner will provide
Content-type : x-www-form-urlencoded
response_type : token
grant_type : client_credentials
OK, let configure this on SAP CPI integration flow
Add header
grant_type : client_credentials
response_type : token
Content-Type : application/x-www-form-urlencoded
client_id
client_serect
Next, because this REST API use content-type = x-www-form-urlendcoded. So we will create body for request with syntax :
Key1=Value1&Key2=Value2&Key3=Value3
Step 2.2.2: Add request reply call to REST API of token provider with http adapter to get access token
Step 2.2.3: Add Content modifier to get access token payload response
In this time, Run this integration from POSTMAN we will receive access token in payload response.
Key : Authorization
Value : Bearer <access_token>
For example
In this time, we call integration flow from POSTMAN we will receive data from REST API success.
OK, good ! To this time, we have already configured done scenario: How to call HTTP REST API with access token which
provide by Token provider with CLIENT_ID and CLIENT_SECRET. Next, we try to go deeper this scenario when REST API
use more CSRF-TOKEN
For example in this article, go to REST API which create in step 1. At HTTP adapter sender, check into check box CSRF
Protected
In this time, call this API we will receiver 403 HTTP status code Forbidden
And call from integration flow consume which created in step 2, we will receive 500 http status code
Check log in CPI, we also receiver status code 403
Step 2.2.1: Add more header with name x-csrf-token at component after get access token
Step 2.2.2: Add Request reply component and call to REST API with method GET and send 2 headers x-csrf-token
and Authorization into there
Step 2.2.3: Add Request reply component and call to REST API with method POSTand send 2 headers x-csrf-token
and Authorization into there
After this step, we have to add one more important config. If not config we still receiver 403 forbidden although send X-
CSRF-TOKEN into header.
In this step, we have to switch HTTP Session Reuse from default to On Exchange. Click anywhere outside flow, choose tab
Runtime Configuration, change value of HTTP Session Reuse
OK, Now we test API from POSTMAN and receive 200 HTTP status and payload
Summary
In this article I shared step by step one scenario call external REST API with authorization by use Oauth2. Access token will
be gotten from Token provider by Client ID, Client Secret, Token URL. If external REST API also use more one token called
X-CSRF-TOKEN to protect API, We also can get more CSRF token and call REST API with access token. Thanks for your
reading and hope this article useful. If have any advise, kindly leave your comment on this. Thanks.
In first TIP, I talk about how to run integration flow in simulation mode. Example I have integration flow collect data from XML
and insert database by JDBC adapter
I want to run simulator to check my integration right or wrong. This is step by step I do.
In mode read only, click on arrow from start to message mapping -> choose start point.
Click on icon Start Simulation -> enter body of request. IF your request include Header or Properties, also add in here
Click on arrow where you want to stop simulation -> Choose Stop endpoint.
After set start point and end point. Go to menu choose start simulation
Run simulation success we can click every envelop to view message data output.
Because of CPI mapping use format XML, XSD. Do we have to know how to parse XSD base on XML.
We have ZIP file which include many file in there and integration flow will split every file with file name, after that will send to
SFTP.
Create integration flow
NOTES
${header.CamelFileNameOnly.replaceAll(“[0-9A-Za-z]+\/”,””)}
Run Simulation. After success, we will see one list file which split from zip file
HTTP Inbuilt Retry Option
The retry option in HTTP receiver adapter (with adapter version number 1.15) provides you an option to select retrying of failed
HTTP requests. This features comes handy for the backend HTTP server facing some challenges to serve the requests, especially
intermittent issues at backed.
By default, this option is not selected. Once you select this option, you will need to provide HTTP error response codes for which
you want the HTTP receiver adapter to trigger the retry.
Also, you can choose the number of iterations and the time between the each iterations. Sample screenshot provided below.
Retry option with checkbox control
SCPI: Message Mapping simulation and Limitations
Simulate is functionality to test the message mapping while designing the Integration flow in CPI.
Step 1: Create an iFlow in a package as below.
Step 2: Configure the IDOC sender channel as below. Provide the endpoint name which is unique.
Step 3: Now add the message mapping in the iFlow and click on the pointed symbol as below.
Step 4: Now import the XSD from the local folder as input and output schemas as below.
Map source and target structures with conditions or one to one.
Step 5: To simulate or test, click on the Simulate option in the mapping as below and then a new window pops up. Now click on Browse button and select the input
file for testing.
Step 6: Now click on the test option and check the output structure is creating. Once the file uploaded, we can change the edit the field data and test multiple times
if necessary.
Verify the mapping conditions are working as defined as below.
Step 7: We can also perform the Display Queue option in mapping for analyzing node by node as below.
Limitations: