on 07-23-2011 8:24 AM
Hi
My PI server is able to make a soap call to the SFDC ( webservice ) ...however the response that is received within PI
has a SOAP envelope...and hence the response mapping is going in error....because the source data type in response mapping doesnot match with the soap response ( with envelope )
<?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com">
- <soapenv:Body>
- <upsertResponse>
- <result>
<created>false</created>
<id>a0UT0000004aeaMMAQ</id>
<success>true</success>
</result>
</upsertResponse>
</soapenv:Body>
</soapenv:Envelope>
how do i handle this
I have scenario to integrate Salesforce with ECC to integrate Customer Mater with Account in Salesforce. Salesforce create WSDL method is synchronous, so I need response in ECC, I am using proxy and calling it in ABAP report. I have created Message Type of Response structure of Salesforce in ESR. Used in target structure in response message mapping.
My message mapping is like this
This is working fine but final response is not what I want, actually I am calling proxy method in report and want response in exporting parameter of proxy method.
Response is coming as SOAP Envelope up to XML Validation Inbound Channel response in SXMB_MONI like above screen shoot.
Then after Response Message Mapping I am loosing response (I think its empty) But customer master is integrated successfully. So what mapping to do get the same as aspected (Want in exporting parameter of proxy call).
I need XSL or Java Mapping code that exact suite this scenario, i seen different XSL but its fulfilling my need.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think there is an option while configuration of SOAP adapter, where you can define, not to keep SOAP envelop. Please check the option Conversion Parameters\Do Not Use SOAP Envelope and set it as per your requirement. That might solve the problem. Here is the link which can be helpful
http://help.sap.com/saphelp_nw04/helpdata/en/29/5bd93f130f9215e10000000a155106/content.htm
Alternatively you need a java mapping or XSLT mapping to remove the envelop.
Here is the java mapping code to remove SOAP envelop
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
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 com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class RemoveSoapEnvelop implements StreamTransformation{
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
try
{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builderel=factory.newDocumentBuilder();
/*input document in form of XML*/
Document docIn=builderel.parse(in);
/*document after parsing*/
Document docOut=builderel.newDocument();
TransformerFactory tf=TransformerFactory.newInstance();
Transformer transform=tf.newTransformer();
Element root;
Node p;
NodeList l;
int mm,n1;
//if you need to include namespace use next two lines
//root=docOut.createElement("ns0:upsertResponse");
//root.setAttribute("xmlns:ns0","http://connectsystems.be/MAINFR/AccDocument");
root=docOut.createElement("upsertResponse");
p=docIn.getElementsByTagName("upsertResponse").item(0);
l=p.getChildNodes();
n1=l.getLength();
for(mm=0;mm<n1;++mm)
{
Node temp=docOut.importNode(l.item(mm),true);
root.appendChild(temp);
}
docOut.appendChild(root);
transform.transform(new DOMSource(docOut), new StreamResult(out));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setParameter(Map arg0) {
}
public static void main(String[] args) {
try{
RemoveSoapEnvelop genFormat=new RemoveSoapEnvelop();
FileInputStream in=new FileInputStream("C:\\Apps\\my folder\\sdn\\sd2.xml");
FileOutputStream out=new FileOutputStream("C:\\Apps\\my folder\\sdn\\removedEnvelop.xml");
genFormat.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
input xml file sd2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com">
<soapenv:Body>
<upsertResponse>
<result>
<created>false</created>
<id>a0UT0000004aeaMMAQ</id>
<success>true</success>
</result>
</upsertResponse>
</soapenv:Body>
</soapenv:Envelope>
Here is the output xml removedEnvelop.xml
<?xml version="1.0" encoding="UTF-8" ?>
<upsertResponse>
<result>
<created>false</created>
<id>a0UT0000004aeaMMAQ</id>
<success>true</success>
</result>
</upsertResponse>
Helpful articles on java mapping for PI 7.1
http://wiki.sdn.sap.com/wiki/display/XI/SampleJAVAMappingcodeusingPI7.1+API
You can also try following XSLT mapping to get the same output as java mapping
<xsl:stylesheet version="1.0"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="SOAP-ENV">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:for-each select="SOAP-ENV:Envelope/SOAP-ENV:Body">
<upsertResponse>
<result>
<xsl:variable name="var" select="normalize-space(.)"></xsl:variable>
<xsl:variable name="tokenizedSample" select="tokenize($var,' ')"/>
<created><xsl:value-of select="$tokenizedSample[1]"/></created>
<id><xsl:value-of select="$tokenizedSample[2]"/></id>
<success><xsl:value-of select="$tokenizedSample[3]"/></success>
</result>
</upsertResponse>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Other than these please refer to following links for further examples on the topic
Hope this helps your cause.
regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried to implement this java code and I'm getting this error in operation mapping = "Unable to display tree view; Error when parsing an XML document (Premature end of file.)"
Operation mapping log -
02:52:24 Start of test
Loaded class com.sap.xi.tf._MM_SFDC_To_ECC_CustomerMaster_Response_
Loaded class com.sap.xi.tf._MM_SFDC_To_ECC_CustomerMaster_Response_$MT$InnerLibsList
Loaded class com.sap.xi.tf._MM_SFDC_To_ECC_CustomerMaster_Response_$MT$InnerParamsList
Call method execute of the application Java mapping com.sap.xi.tf._MM_SFDC_To_ECC_CustomerMaster_Response_
Java mapping com/sap/xi/tf/_MM_SFDC_To_ECC_CustomerMaster_Response_ completed. (executeStep() of com.sap.xi.tf._MM_SFDC_To_ECC_CustomerMaster_Response_).
Loaded class com.sap.pi.com.RemoveSoapEnvelope
Call method execute of the application Java mapping com.sap.pi.com.RemoveSoapEnvelope
Java mapping com/sap/pi/com/RemoveSoapEnvelope completed. (executeStep() of com.sap.pi.com.RemoveSoapEnvelope).
Execution of mapping on server took 313 milli-seconds Executed successfully
02:52:24 End of test
Here is the payload for which I should remove the SOAP envelope -
<?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/PISapCustomerService">
- <soapenv:Body>
- <upsertSAPCustomersResponse>
- <result>
<sapAccountGroupCode>0001</sapAccountGroupCode>
<sapCustomerNumber>255010</sapCustomerNumber>
<sfdcCustomerId>001f000000BmzmFAAR</sfdcCustomerId>
- <transactionStatus>
- <errorDetail>
<errorCode>0</errorCode>
<message>SAP Customer with customer number = 255010 Updated Successfully</message>
</errorDetail>
<success>true</success>
</transactionStatus>
</result>
</upsertSAPCustomersResponse>
</soapenv:Body>
</soapenv:Envelope>
Please help me solve this.
I modified the java code. please let me know where the error could be
package com.sap.pi.com;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
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 com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
public class RemoveSoapEnvelope implements StreamTransformation {
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
try
{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builderel=factory.newDocumentBuilder();
/*input document in form of XML*/
Document docIn=builderel.parse(in);
/*document after parsing*/
Document docOut=builderel.newDocument();
TransformerFactory tf=TransformerFactory.newInstance();
Transformer transform=tf.newTransformer();
Element root;
Node p;
NodeList l;
int mm,n1;
//if you need to include namespace use next two lines
//root=docOut.createElement("ns0:upsertResponse");
//root.setAttribute("xmlns:ns0","http://connectsystems.be/MAINFR/AccDocument");
root=docOut.createElement("upsertSAPCustomersResponse");
p=docIn.getElementsByTagName("upsertSAPCustomersResponse").item(0);
l=p.getChildNodes();
n1=l.getLength();
for(mm=0;mm<n1;++mm)
{
Node temp=docOut.importNode(l.item(mm),true);
root.appendChild(temp);
}
docOut.appendChild(root);
transform.transform(new DOMSource(docOut), new StreamResult(out));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setParameter(Map arg0) {
}
public static void main(String[] args) throws Exception
{
try{
RemoveSoapEnvelope genFormat=new RemoveSoapEnvelope();
FileInputStream in=new FileInputStream("/D:/input.xml");
FileOutputStream out=new FileOutputStream("/D:/Output.xml");
genFormat.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Hi Satish,
We have implementing the same Integration scenario and getting the below Error. Please share how do you resolved the issue.
Unable to display tree view; Error when parsing an XML document (Premature end of file.) Runtime Exception when executing application mapping program com/sap/xi/tf/_MessageMapping_Response_; Details: com.sap.aii.utilxi.misc.api.BaseRuntimeException; Premature end of file.
See error logs for details.
Hi Yuga,
Sorry for delay in reply.
check the below java class.
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
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 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 ReturnOrderResponseMap extends AbstractTransformation {
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
try {
DocumentBuilderFactory tfactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder tbuilder = tfactory.newDocumentBuilder();
Document doc = tbuilder.parse(arg0.getInputPayload()
.getInputStream());
Document newdoc = tbuilder.newDocument();
Element root = (Element) newdoc.createElementNS(
"ns1:MT_XXXXX_Ack");
newdoc.appendChild(root);
Element record = (Element) newdoc.createElement("Record");
root.appendChild(record);
NodeList nlList = doc.getElementsByTagName("SFDCId");
if (nlList.getLength() != 0 && nlList != null) {
Node data = nlList.item(0);
String sourceval = data.getTextContent();
Element sfaid = (Element) newdoc.createElement("SFA_ID");
sfaid.setTextContent(sourceval);
record.appendChild(sfaid);
}
NodeList n2List = doc.getElementsByTagName("Status");
if (n2List.getLength() != 0 && n2List != null) {
Node data = n2List.item(0);
String sourceval = data.getTextContent();
Element sfastatus = (Element) newdoc.createElement("SFA_Status");
sfastatus.setTextContent(sourceval);
record.appendChild(sfastatus);
}
NodeList n3List = doc.getElementsByTagName("Description");
if (n3List.getLength() != 0 && n3List != null) {
Node data = n3List.item(0);
String sourceval = data.getTextContent();
Element sfades = (Element) newdoc.createElement("SFA_ErrorDescription");
sfades.setTextContent(sourceval);
record.appendChild(sfades);
}
Transformer transformer = TransformerFactory.newInstance()
.newTransformer();
Source source = new DOMSource(newdoc);
Result output = new StreamResult(arg1.getOutputPayload().getOutputStream());
transformer.transform(source, output);
} catch (Exception e) {
e.printStackTrace();
}
}
}
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.