Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
CarlosRoggan
Product and Topic Expert
Product and Topic Expert

This  blog is about Integration Gateway in SAP Mobile Platform 3.0.

It is a follow up of the introduction blog Integration Gateway: Integration Gateway: Understanding REST data source [1]: QUERY (very simplified)

In this blog, we do the same, but with the only difference that we use JSON payload.

I’m not going to repeat anything only show the differences.

We can use the same REST service as in the previous blog, it does support JSON as well.

We have to add a parameter in order to request the payload format.

The relative URL which returns JSON-payload:

/street/streetsearch?lat=52.52&lng=13.41&format=json

The structure, that Integration Gateway expects if you want to convert a response body in JSON :


{


"results":


     [


          {


               "PropertyName1":"PropertyValue1",


               "PropertyName2":"PropertyValue2"


          }


     ]


}







In our concrete example project:


{


"results":


     [


          {


               "StreetID":"12344",


               "StreetName":"MainStreet"


          }


     ]


}







In our Groovy script, we have to encode the quotation marks:


message.setBody(


             "{\"results\":"+


                    "["+


                           "{\"StreetID\":\"1234567\","+


                           "\"StreetName\":\"MainStreet\"}"+


                    "]"+


             "}");







And set the proper header:


message.setHeader("Content-Type", new String("json"));





That’s it.

For your reference, here's the full (dummy) implementation:


def Message processResponseData(message) {


       String restResponse = message.getBody().toString();


  


       message.setBody(


             "{\"results\":"+


                    "["+


                           "{\"StreetID\":\"1234567\","+


                           "\"StreetName\":\"MainStreet\"}"+


                    "]"+


             "}");


  


       message.setHeader("Content-Type", new String("json"));


       return message;


}





As usual, don't forget to add the required import statements:


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

Note:

Just as reminder: this is a hardcoded payload, and we're using it only to understand the structure of the string that we have to provide in the custom code.

After deploy, you can reuse the same destination as created in our previous blog.

When invoking the OData service on SMP, you can request the payload in XML or in JSON.

For JSON, use:

https://localhost:8083/gateway/odata/SAP/REST_PROJECT_VERY_SIMPLE_2;v=1/StreetSet?$format=json

Enjoy!