Skip to Content
0

SAP REST adapter-XML structure issue-PO

Jun 02, 2017 at 06:23 AM

93

avatar image

hI All

It is IPAD to CRM flow using SAP rest adapter in PO.
We send jason to PO with no mapping in PO and then fwd it to CRM system(synchronous):: Additonal header <TokenDetailsMT> is created in PO which is not recognizable by CRM proxy and throws an error response back. Can anyone suggest, little urgent.Thanks
.
The request structure expected by CRM;
<?xml version="1.0" encoding="UTF-8"?>
<ns0:TokenMT xmlns:ns0="http://XX/ipadmobileintegration/webservice_bapi">
<Token>XXX</Token>
<language>FR</language>
<timeStamp/>
<userID>fr-</userID>
<PartnerID>22222</PartnerID>
</ns0:TokenDetailsMT>

BUt we are sending below from PO
<?xml version="1.0" encoding="UTF-8"?>
<ns0:TokenMT xmlns:ns0="http://XX/ipadmobileintegration/webservice_bapi">
<TokenDetailsMT>
<Token>XXX</Token>
<language>FR</language>
<timeStamp/>
<userID>fr-</userID>
<PartnerID>22222</PartnerID>
</TokenDetailsMT>
</ns0:TokenDetailsMT>

if we remove the wrapper class this is removed "

<ns0:TokenMT xmlns:ns0="http://XX/ipadmobileintegration/webservice_bapi">

"
channel1.png (17.7 kB)
channel2.png (12.7 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Anupam Ghosh Jun 02, 2017 at 10:01 AM
0

Hi Partibha,

Please post the actual json message sent from IPAD to PI server.

Regards

Anupam

Share
10 |10000 characters needed characters left characters exceeded
pratibha singh Jun 02, 2017 at 11:08 AM
0

HI Anupam

Here it is

{"TokenDetailsMT":{

"PartnerID":"2222",

"Token":"843497124923423BB632F069F56",

"language":"EN",

"timeStamp":"20170518074730",

"userID":"admin"

}}

Share
10 |10000 characters needed characters left characters exceeded
Anupam Ghosh Jun 05, 2017 at 05:43 AM
0

Hi Pratibha,

You need to include following java mapping in the ESR with Dummy sender and receiver interfaces . This will remove extra root node arriving in JSON payload

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import abc.com.OTC.I2553.GenerateHierarchy;

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 RemoveFirstChild extends AbstractTransformation{

@Override

public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
// TODO Auto-generated method stub
execute(arg0.getInputPayload().getInputStream(),arg1.getOutputPayload().getOutputStream());
}
private void execute(InputStream in, OutputStream out) throws StreamTransformationException {
// TODO Auto-generated method stub
try
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

Document doc = docBuilder.parse(in);

Document docOut = docBuilder.newDocument();
Node SourceRootNode=doc.getDocumentElement();


Element root=(Element) docOut.importNode(SourceRootNode,true);
docOut.appendChild(root);
//get all record nodes
root=docOut.getDocumentElement();
System.out.println(root.getNodeName());
NodeList children=root.getChildNodes();
Element firstChildOfRootNode=null;
for(int i=0;i<children.getLength();++i)
{

if(children.item(i).getNodeType()==Element.ELEMENT_NODE)
{
firstChildOfRootNode=(Element)children.item(i);
break;
}
}
System.out.println(firstChildOfRootNode.getNodeName());
NodeList listOfChildren=firstChildOfRootNode.getChildNodes();
for(int i=0;i<listOfChildren.getLength();++i)
{
if(listOfChildren.item(i).getNodeType()==Element.ELEMENT_NODE)
{
Node child=listOfChildren.item(i);
System.out.println(child.getNodeName());
child=firstChildOfRootNode.removeChild(child);
root.appendChild(child);
}
}
root.removeChild(firstChildOfRootNode);
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(docOut);
StreamResult result = new StreamResult(out);

// Output to console for testing

transformer.transform(source, result);



}
catch(Exception e)
{
e.printStackTrace();


}
}
public static void main(String[] args) throws FileNotFoundException, StreamTransformationException {
// TODO Auto-generated method stub
String zipFile="C:\\donloads\\2553_correct4.xml";
zipFile="C:\\apps\\inscn.xml";
String Output="C:/apps/out.xml";
InputStream in=new FileInputStream(zipFile);
OutputStream out=new FileOutputStream(Output);
RemoveFirstChild r=new RemoveFirstChild();
r.execute(in,out);
}

}

input to the mapping

<ns0:TokenMT xmlns:ns0="http://XX/ipadmobileintegration/webservice_bapi">
<TokenDetailsMT>
<Token>XXX</Token>
<language>FR</language>
<timeStamp/>
<userID>fr-</userID>
<PartnerID>22222</PartnerID>
</TokenDetailsMT>
</ns0:TokenMT>

output

<ns0:TokenMT xmlns:ns0="http://XX/ipadmobileintegration/webservice_bapi">
<Token>XXX</Token>
<language>FR</language>
<timeStamp/>
<userID>fr-</userID>
<PartnerID>22222</PartnerID>
</ns0:TokenMT>

In case any of these elements are coming as array objects then please follow this blog

Regards

Anupam

Share
10 |10000 characters needed characters left characters exceeded
pratibha singh Jun 05, 2017 at 06:36 AM
0

HI Anupam

Thanks so much...and I wil implement this and update.

Share
10 |10000 characters needed characters left characters exceeded