cancel
Showing results for 
Search instead for 
Did you mean: 

How to create scenario with REST sender adapter in PI .

mrudularane
Explorer
0 Kudos

Hello Experts ,

We are having PI dual stack 7.31 . Third party has asked us to create web service or API which can be consumed by third party which is having REST technology . How can we create this scenario ? (Third Party(REST)->PI->SAP)

Kindly help .

Regards ,

Mrudula

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

Hi Mrudula,

First of all you need to have installed the SAP REST adapter, i think it is available from PI 7.4 SP 09 and PI 7.31 SP 14

Check this links:

Configuring the Sender REST Adapter - Advanced Adapter Engine - SAP Library

Regards.

mrudularane
Explorer
0 Kudos

Hello All ,

We were in continuous discussion with client regarding upgradation of 7.31 from SP04 to SP14 as we can get REST adapter directly . But they are not ready to do so and suggested us to make it possible with current version and support package .

     So we had decided to create normal SOAP to RFC scenario . While doing so we come to understand that we need to use either XSLT or JAVA mapping for the conversion of XML to JSON and vice versa .

  so we had referred below link to convert XML to JSON and we had converted successfully using XSLT code given .

http://www.bizcoder.com/index.php/2010/02/12/convert-xml-to-json-using-xslt/

But we are not getting any JAVA or XSLT code to convert JSON to XML .Kindly suggest .

Regards ,

Mrudula

arunneerolil
Contributor
0 Kudos

Mrudula,

I believe you have to use HTTP adapter instead of SOAP and pass JSON message as the sender is not on SOAP.

There are lot of reference libraries available for conversion.

http://tutorial4java.blogspot.de/2013/04/xml-to-json-conversion.html

This can be used only if the requirement is simple with a couple of interfaces.

If it is complex, better upgrade and go for the ODATA adapter.

regards, Arun

maheswarareddykonda
Active Contributor
0 Kudos

Mrudula,

instaed of going for conversion in mapping level , better to go for custome module which created by Eng Swee Yeoh and below is the link to get code

mrudularane
Explorer
0 Kudos

Hi Arun ,

Thanks .

The code you have given looks useful .But we are not able to understand like how we can use the same code in PI to convert incoming payload in JSON format from third party . Because in code it is picking .xml file from some location but in our case it will be payload from third party .

Regards ,

mrudula

arunneerolil
Contributor
0 Kudos

Mrudula,

You will have to use Java Mapping for this.

Create a method out of the conversion code in the Java Mapping class.

Call this code from the 'transform' method of mapping.

Make sure you import all the dependent jar files in to the ESR.

regards,

Arun

mrudularane
Explorer
0 Kudos

Hi Arun ,

Thanks .

Before modifying and using the code in java mapping , we were checking the same code given in the link  in nwds . But we are getting errors mentioned below sequentially .

1. JSONSerilizer can not be resolved

2. The method write(JSONArray) in the type XMLSerializer is not applicable for the arguments(JSON)

3. IO Exception can not be resolved by type .

Kindly assist as we are new in java . 

Regards ,

Mrudula

arunneerolil
Contributor
0 Kudos

Mrudula,

You will have to download all the dependent jar files to get it work.

Below is a much simpler way for XML to JSON conversion and it requires only java-json.jar

http://www.java2s.com/Code/JarDownload/java-json/java-json.jar.zip

regards,

Arun

mrudularane
Explorer
0 Kudos

Hi Arun ,

Thanks .

But i was asking you for JSON to XML and not XML to JSON . Because we have XSLT code for XML to JSON. But we are not getting anything for JSON to XML.

Kindly help .

Regards ,

Mrudula

arunneerolil
Contributor
0 Kudos

Mrudula,

Please refer below code for JSON to XML conversion.


regards,

Arun

mrudularane
Explorer
0 Kudos

Hi Arun ,

Thanks .

Now we have developed the code using your above code for JSON to XML conversion . But we are getting linkage error in operation mapping while testing .  Below is the code .

package test.app;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import org.json.JSONObject;

import org.json.XML;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class Jsontoxml extends AbstractTransformation {

      public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {

try {

String sourcexml = ""; String targetxml =""; String line ="";

       InputStream ins = in.getInputPayload().getInputStream();

BufferedReader br = new BufferedReader( new InputStreamReader(ins));

       while ((line = br.readLine()) != null)

sourcexml +=line+"\n";

br.close();

       

       JSONObject o = new JSONObject(sourcexml);

targetxml = XML.toString(o);

String start = "<?xml version=\"1.0\"encoding=\"UTF-8\"?> <ns0:msgtype_rest_service_contents_op xmlns:ns0=\"http://test.com/test\">";

String end  = "</ns0:msgtype_rest_service_contents_op>";

targetxml =  start+targetxml+end;

  out.getOutputPayload().getOutputStream().write(targetxml.getBytes());

       

}

catch (Exception e) {

throw new StreamTransformationException(e.getMessage());

}

        }

      }


Below is the error screendshot in operation mapping .



Kindly help .


Regards ,

Mrudula

arunneerolil
Contributor
0 Kudos

Mrudula,

I guess you missed to import the json jar to ESR.

Import 'java-json.jar' to ESR as an imported archive and it should solve this error.

regards,

Arun

mrudularane
Explorer
0 Kudos

Hi Arun ,

I have imported jar in nwds as well as ESR . Still the same error .

Please find below screens .

Regards ,

Mrudula

arunneerolil
Contributor
0 Kudos

Mrudula,

Import the java-json.jar as an independent archive to the same namespace and give it a try.

Thanks,

Arun

mrudularane
Explorer
0 Kudos

Hi Arun ,

Thanks a lot .Now we are able to see json to xml conversion in operation mapping .

Going ahead as you have suggested earlier , we need to use http  adapter . so i am having 2 queries

.

1. For SAP->PI->REST scenario , what  details we are going to fill in http receiver adapter .

2. For REST->PI->SAP scenario , if we use http sender adapter then what we are going to provide                                                        client as http adapter wont create wadl file .

Regards ,

Mrudula

arunneerolil
Contributor
0 Kudos

Mrudula,

Basically this will help you receive/send JSON message. This can be used only in limited scenarios and will not be a full

replacement for REST adapter.

1. For SAP->PI->REST scenario , what  details we are going to fill in http receiver adapter .

Test the REST service using a tool like soapUI.

Use the the details URL, Parameters, etc from the tool to fill your channel.

Depending upon the scenario you will end up in using dynamic configurations and header parameters as well.

2. For REST->PI->SAP scenario , if we use http sender adapter then what we are going to provide

                        

client as http adapter wont create wadl file .

This will be HTTP URL for the ICO/Configuration + additional parameters as per the requirement

Here also test this first with a test tool before using it in the consuming application.

regards,

Arun

maheswarareddykonda
Active Contributor
0 Kudos

Mrudula,

may i know wat is the reason you are going with http adaper instead of REST adapter to achieve this requirement.

the same thing, REST dapter also doing which is provided by SAP inbuild feature.

mrudularane
Explorer
0 Kudos

Hi Arun ,

Thanks .

See as of now client has not given us any REST service but we have found below service on google


http://maps.googleapis.com/maps/api/geocode/json?address={req_zipcode}


For example in req_zipcode field ,we need to pass any number like 101 and we get output in SOAP UI.


So above service we have tested in soap ui and gettinf proper output in soap ui


Now could you please tell me how to insert above url details in http receiver adapter and also how to pass the dynamic value that is req_zipcode in url ?


Regards ,

Mrudula


mrudularane
Explorer
0 Kudos

Hi Maheswarareddy Konda ,

The reason is , we are having PI 7.31 SP04  . But for Rest adapter we should have atleast SP14 and client is not ready to upgrade the support package for only 2 scenarios .

Hence we are trying with java mapping using http adapter . Could you suggest any other way like custom adapter module as you have suggested in your previous reply ?

regards ,

mrudula

maheswarareddykonda
Active Contributor
0 Kudos

Mrudula,

if you want to go with custom module below is the link..and if you had doubts you please check with Eng Swee Yeoh

in case you want thirdparty adapter then below are links.

Answers (2)

Answers (2)

maheswarareddykonda
Active Contributor
0 Kudos

Hi Mrudula,

just extend to Inaki and Harish...

you can upgrade 7.31 SP16 or 7.4 SP11 , which has very latest features(Poll method).

just follow Alex blog(mentioned above) and start development.

let us know if you stuck some where else.

Regards,

Maheswarareddy

Harish
Active Contributor
0 Kudos

Hi Mrudula,

You can use sender Rest adapter to expose as rest service. Please refer the below blog which have links for information about the rest adapter

regards,

Harish