SAP Process Integration

Consuming RESTful Service using JSON body parameters

Introduction

This is a scenario for connect a basic SAP-to-REST synchronous interface using JSON body parameters.

Motivation

I ran into this problem, I had to research about the specific configuration to use JSon as parameters in the body, not in the request header. Next, I’ll share the solution I’ve come up with…

System versions

SAP ECC 7.4 (SAP BASIS 740 SP 23)
SAP PI NETWEAVER 7.4 (SAP BASIS 740 SP 24)

Scenario

We would like to connect SAP ECC to a new RESTful web service, this uses JSON parameters as part of message body, not header. The first request we would connect to get a security identification token. This is the sample request format got from Soap UI:

POST https://xxxx.xxxx.com/api/xxxxService.svc/ExecuteCommand HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Content-Length: 91
Host: xxxx.xxxx.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
{
“__type”:”XXXX “,
“UserName”:”XXXX”,
“Password”:”XXXX”
}

We got this sample result for the request:
{
“Data”: {
“Data”: [ {
“Codigo”: “SecurityTokenId”,
“Descripcion”: “XXXX==”
}],
“Success”: true
}
}
}

Next picture shows the scenario in Soap UI:

We had to consider these annotations:

  1. Use of https requires of SSL certificate
  2. There are not parameters in the header of the request
  3. Media type is settled to application/json
  4. The JSON body parameter contents special characters (“__type”)

Step 1: System Landscape Directory

Transaction SXMB_IFR

1. Create a new product and version

In tab General set vendor and product name

In tab Software Components set a new Product Instance and a new Software Component Version

Step 2: Enterprise service builder

We created these objects:

1. Create software component version, got from SLD

2. Data types for request and response

* The name of field “__type” is not allowed, we had to use XML to JSON name mapping in Integration Builder Communication Channel.

Data Type for response

3. Message Types

Request

Response

4. Service interfaces

Request

Response

5. Message mappings

Request

Response

* Object ns0:mt_aut_response right-click marked “Return as XML”

6. Operation Mapping

Request Tab

Response Tab

Step 3: Trusted CA’s certificate installation

In SAP NetWeaver Administrator / Configuration / Certificates and Keys we installed the CA certificate.

Installed certificate.

Step 4: Integration Builder

We created these objects:

Already existed the Business Systems BS_BNV_D and ECC120UnitTest, they were created in the system landscape directory.

1. Communication channel

SAP XI adapter type (sender):

SAP REST adapter type (receiver):

*At first, we couldn´t see the adapter type REST when we were creating the communication channel, we had to upgrade the version of component XI CONTENT SAP_BASIS 7.40

After import finalized:

We used the key store of the installed certificate in trusted CA’s.

Rest URL Tab

REST Operation Tab

Data Format Tab

*Element Name corresponds with the message type created in ESR for the response.

*Here we defined the mapping name between XML and JSON.

HTTP Headers Tab

2. Receiver determination

3. Interface determination

4. Sender agreement

5. Receiver agreement

Step 5: Generating the proxy

In SAP ECC, SPROXY transaction we created the proxy.

How class looks.

Step 6: Testing the proxy in ECC120UnitTest client.

Define parameters for test, changing String X with the correct values.

Sucessfull answer from remote host

How it looks in SXI_Monitor transaction.

Message overview in SAP NetWeaver.

Rating: 0 / 5 (0 votes)

Leave a Reply

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