on 01-13-2013 2:34 AM
Hi Experts,
I have a big problem with the mapping in PI. The transformation of data inside WSDL is very complex, I tried to use the graphical mapping but I can`t see the envelope Header and Body in Message Interface, so I needed to use Java Mapping because was necessary mapping header and body together in XML envelope.
See Below the example of the WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Web Services API : SfWsNotaFiscalVenda
-->
<definitions targetNamespace="http://soap.sforce.com/schemas/class/SfWsNotaFiscalVenda" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://soap.sforce.com/schemas/class/SfWsNotaFiscalVenda">
<types>
<xsd:schema elementFormDefault="qualified" targetNamespace="http://soap.sforce.com/schemas/class/SfWsNotaFiscalVenda">
<xsd:element name="DebuggingInfo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="debugLog" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="ID">
<xsd:restriction base="xsd:string">
<xsd:length value="18"/>
<xsd:pattern value="[a-zA-Z0-9]{18}"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="LogCategory">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Db"/>
<xsd:enumeration value="Workflow"/>
<xsd:enumeration value="Validation"/>
<xsd:enumeration value="Callout"/>
<xsd:enumeration value="Apex_code"/>
<xsd:enumeration value="Apex_profiling"/>
<xsd:enumeration value="Visualforce"/>
<xsd:enumeration value="System"/>
<xsd:enumeration value="All"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="LogCategoryLevel">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Internal"/>
<xsd:enumeration value="Finest"/>
<xsd:enumeration value="Finer"/>
<xsd:enumeration value="Fine"/>
<xsd:enumeration value="Debug"/>
<xsd:enumeration value="Info"/>
<xsd:enumeration value="Warn"/>
<xsd:enumeration value="Error"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="LogInfo">
<xsd:sequence>
<xsd:element name="category" type="tns:LogCategory"/>
<xsd:element name="level" type="tns:LogCategoryLevel"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="LogType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="None"/>
<xsd:enumeration value="Debugonly"/>
<xsd:enumeration value="Db"/>
<xsd:enumeration value="Profiling"/>
<xsd:enumeration value="Callout"/>
<xsd:enumeration value="Detail"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="DebuggingHeader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="categories" minOccurs="0" maxOccurs="unbounded" type="tns:LogInfo"/>
<xsd:element name="debugLevel" type="tns:LogType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="CallOptions">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="client" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="SessionHeader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="sessionId" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AllowFieldTruncationHeader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="allowFieldTruncation" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="Body">
<xsd:sequence>
<xsd:element name="AUBEL" minOccurs="0" type="xsd:string" nillable="true"/>
<xsd:element name="CANCEL" minOccurs="0" type="xsd:string" nillable="true"/>
<xsd:element name="MATNR" minOccurs="0" maxOccurs="unbounded" type="xsd:string" nillable="true"/>
<xsd:element name="NFENUM" minOccurs="0" type="xsd:string" nillable="true"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="NFE_CRM">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="data" type="tns:Body" nillable="true"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="NFE_CRMResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result" type="xsd:string" nillable="true"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<!-- Message for the header parts -->
<message name="Header">
<part name="AllowFieldTruncationHeader" element="tns:AllowFieldTruncationHeader"/>
<part name="CallOptions" element="tns:CallOptions"/>
<part name="DebuggingHeader" element="tns:DebuggingHeader"/>
<part name="DebuggingInfo" element="tns:DebuggingInfo"/>
<part name="SessionHeader" element="tns:SessionHeader"/> -> I need fill this tag in header envelope
</message>
<!-- Operation Messages -->
<message name="NFE_CRMRequest">
<part element="tns:NFE_CRM" name="parameters"/>
</message>
<message name="NFE_CRMResponse">
<part element="tns:NFE_CRMResponse" name="parameters"/>
</message>
<portType name="SfWsNotaFiscalVendaPortType">
<operation name="NFE_CRM">
<input message="tns:NFE_CRMRequest"/>
<output message="tns:NFE_CRMResponse"/>
</operation>
</portType>
<binding name="SfWsNotaFiscalVendaBinding" type="tns:SfWsNotaFiscalVendaPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="NFE_CRM">
<soap:operation soapAction=""/>
<input>
<soap:header use="literal" part="SessionHeader" message="tns:Header"/>
<soap:header use="literal" part="CallOptions" message="tns:Header"/>
<soap:header use="literal" part="DebuggingHeader" message="tns:Header"/>
<soap:header use="literal" part="AllowFieldTruncationHeader" message="tns:Header"/>
<soap:body use="literal" parts="parameters"/>
</input>
<output>
<soap:header use="literal" part="DebuggingInfo" message="tns:Header"/>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="SfWsNotaFiscalVendaService">
<documentation/>
<port binding="tns:SfWsNotaFiscalVendaBinding" name="SfWsNotaFiscalVenda">
<soap:address location="https://cs10-api.salesforce.com/services/Soap/class/SfWsNotaFiscalVenda"/>
</port>
</service>
</definitions>
In soapUI you can see:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sfw="http://soap.sforce.com/schemas/class/SfWsNotaFiscalVenda">
<soapenv:Header>
<sfw:SessionHeader>
<sfw:sessionId>1234567890</sfw:sessionId>
</sfw:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<sfw:NFE_CRM>
<sfw:data>
<sfw:AUBEL>0000100417</sfw:AUBEL>
<sfw:CANCEL></sfw:CANCEL>
<sfw:NFENUM>1234</sfw:NFENUM>
<!--Zero or more repetitions:-->
<sfw:MATNR>mat1</sfw:MATNR>
<sfw:MATNR>mat2</sfw:MATNR>
<sfw:MATNR>mat3</sfw:MATNR>
</sfw:data>
</sfw:NFE_CRM>
</soapenv:Body>
</soapenv:Envelope>
I wrote the java code below, but when I tested the interface mapping this error message "XML not well-formed" was generated.
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
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.AbstractTrace;
import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
public class SinTeste implements StreamTransformation {
private Map param = null;
private MappingTrace trace = null;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void setParameter(Map param) {
this.param = param;
if (param == null) {
this.param = new HashMap();
}
}
public void execute(InputStream input, OutputStream output)
throws StreamTransformationException {
AbstractTrace trace = null;
trace =
(AbstractTrace) param.get(
StreamTransformationConstants.MAPPING_TRACE);
String RESULT = new String();
String document_exit = "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"";
document_exit = document_exit + " xmlns:sfw=\"http://soap.sforce.com/schemas/class/SfWsNotaFiscalVenda\"" + ">";
document_exit = document_exit + "<soapenv:Header>";
document_exit = document_exit + "<sfw:SessionHeader><sfw:sessionId>1234567890<sfw:sessionId></sfw:SessionHeader></soapenv:Header>";
document_exit = document_exit + "<soapenv:Body>";
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(input);
trace.addInfo(doc.toString());
document_exit = document_exit + "<sfw:NFE_CRM>";
document_exit = document_exit + "<sfw:data>";
NodeList nodeLst = doc.getElementsByTagName("I_CAB");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
//document_exit = document_exit + "<v1:InstrumentIdentifier>"; alo
Element ValueElmnt = (Element) fstNode;
NodeList ValueElmntLst = ValueElmnt.getElementsByTagName("AUBEL");
Element ValueNmElmnt = (Element) ValueElmntLst.item(0);
NodeList ValueNm = ValueNmElmnt.getChildNodes();
RESULT = ValueNm.item(0).getNodeValue();
document_exit = document_exit + "<sfw:AUBEL>"
+ RESULT
+ "</sfw:AUBEL>";
Element TypeElmnt = (Element) fstNode;
NodeList TypeNmElmntLst = TypeElmnt.getElementsByTagName("NFENUM");
Element TypeNmElmnt = (Element) TypeNmElmntLst.item(0);
NodeList TypeNm = TypeNmElmnt.getChildNodes();
RESULT = TypeNm.item(0).getNodeValue();
document_exit = document_exit + "<sfw:NFENUM>"
+ RESULT
+ "</sfw:NFENUM>";
/* Element SourceElmnt = (Element) fstNode;
NodeList SourceNmElmntLst = SourceElmnt.getElementsByTagName("MATNR");
Element SourceNmElmnt = (Element) SourceNmElmntLst.item(0);
NodeList SourceNm = SourceNmElmnt.getChildNodes();
RESULT = SourceNm.item(0).getNodeValue();
document_exit = document_exit + "<v1:MATNR>"
+ RESULT
+ "</v1:MATNR>";
*/
// document_exit = document_exit + "</v1:InstrumentIdentifier>";
document_exit = document_exit + "<sfw:MATNR>AC 4102 </sfw:MATNR>";
}
}
document_exit = document_exit + "</sfw:data>";
document_exit = document_exit + "</sfw:NFE_CRM>";
document_exit = document_exit + "</soapenv:Body></soapenv:Envelope>";
output.write(document_exit.getBytes());
} catch (Exception e) {
trace.addDebugMessage(e.getMessage());
}
}
}
Hi Rafael,
Check the below blog:
Perform test with the Java Mapping in Operation Mapping Test Tab. Then save the xml generated after test completion and open in Browser (like IE/Firefox). It should get opened properly without any error, otherwise you need to find out which Tag / expressions of the xml is not generated properly after Java Mapping (also all the start tags has proper end tag). It may be for one of the special characters coming as Input.
Also please check whether the occurence for the source as well as for the target, whether all the nodes and fields have appropriate occurrence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nabendu Sen,
First thank you for reply my message.
I used java mapping because I needed mapping the header and body together in request message.
After developing java code I tested the java mapping in Test Tab the Interface Mapping, the error message "XML not well-formed" was exhibited, therefore, I could not generate the xml file to test the browser.
I'll wait your help ...
Hi Rafael,
Is you code generating multiple occurrence of the target structure? Then change the occurrence in your target message type. If you are performing standalone test with NWDS / Eclipse (like picking up a xml File from a Local folder and generating result xml file) and when opening with Browser, is it working fine?
Hi,
I try this code below:
public static void main(String[] args) {
try {
InputStream in = new FileInputStream(new File("C:\\temp\\in.txt"));
OutputStream out = new FileOutputStream(new File("C:\\temp\\out.xml"));
SinTeste myMapping = new SinTeste();
myMapping.execute(in, out);
} catch (Exception e){
e.printStackTrace();
}
}
I solved the problem in java code, I had forgotten to include the libraries below...
java.io.File
java.io.FileInputStream
java.io.FileOutputStream
but, now I have the messages error...
Exception occurred during launch
Reason:
Source locator does not exist: org.eclipse.jdt.debug.ui.javaSourceLocator
Exception occurred creating launch configuration labs
Reason:
No tab group defined for launch configuration type
org.eclipse.jdt.launching.localJavaApplication
Hi guys,
Beyond the error in code java commented by the Farhan I retired some other problems in the java code.
The generation of xml file made by the method below also helped a lot ...
public static void main(String[] args) {
try {
InputStream in = new FileInputStream(new File("C:\\temp\\in.txt"));
OutputStream out = new FileOutputStream(new File("C:\\temp\\out.xml"));
SinTeste myMapping = new SinTeste();
myMapping.execute(in, out);
} catch (Exception e){
e.printStackTrace();
}
}
Final Java Code:
package com.sap.pi.demo;
import java.io.InputStream;
import java.io.OutputStream;
//debug
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
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 SinTeste implements StreamTransformation {
public static void main(String[] args) {
// Debug
try {
InputStream in = new FileInputStream(new File("/Users/rafaelsa/Desktop/in.xml"));
OutputStream out = new FileOutputStream(new File("/Users/rafaelsa/Desktop/out.xml"));
SinTeste myMapping = new SinTeste();
myMapping.execute(in, out);
} catch (Exception e){
e.printStackTrace();
}
}
public void setParameter(Map param) {
}
public void execute(InputStream input, OutputStream output) throws StreamTransformationException {
String RESULT = new String();
String document_exit = "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"";
document_exit = document_exit + " xmlns:sfw=\"http://soap.sforce.com/schemas/class/SfWsNotaFiscalVenda\"" + ">";
document_exit = document_exit + "<soapenv:Header>";
document_exit = document_exit + "<sfw:SessionHeader><sfw:sessionId>00DJ0000000DqBT!AQYAQKr8L1YXDrHW1dxFE_SBlTKS1DmNa9ZcidU2M.DzxwZ4DqZLPuC3pUkd6gWtloCqQfvcEiov_YCePWDhGYpmg4SGXqwB</sfw:sessionId></sfw:SessionHeader></soapenv:Header>";
document_exit = document_exit + "<soapenv:Body>";
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(input);
document_exit = document_exit + "<sfw:NFE_CRM>";
document_exit = document_exit + "<sfw:data>";
NodeList nodeLst = doc.getElementsByTagName("I_CAB");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element ValueElmnt = (Element) fstNode;
NodeList ValueElmntLst = ValueElmnt.getElementsByTagName("AUBEL");
Element ValueNmElmnt = (Element) ValueElmntLst.item(0);
NodeList ValueNm = ValueNmElmnt.getChildNodes();
RESULT = ValueNm.item(0).getNodeValue();
document_exit = document_exit + "<sfw:AUBEL>"
+ RESULT
+ "</sfw:AUBEL>";
Element TypeElmnt = (Element) fstNode;
NodeList TypeNmElmntLst = TypeElmnt.getElementsByTagName("NFENUM");
Element TypeNmElmnt = (Element) TypeNmElmntLst.item(0);
NodeList TypeNm = TypeNmElmnt.getChildNodes();
RESULT = TypeNm.item(0).getNodeValue();
document_exit = document_exit + "<sfw:NFENUM>"
+ RESULT
+ "</sfw:NFENUM>";
/* Element SourceElmnt = (Element) fstNode;
NodeList SourceNmElmntLst = SourceElmnt.getElementsByTagName("MATNR");
Element SourceNmElmnt = (Element) SourceNmElmntLst.item(0);
NodeList SourceNm = SourceNmElmnt.getChildNodes();
RESULT = SourceNm.item(0).getNodeValue();
document_exit = document_exit + "<v1:MATNR>"
+ RESULT
+ "</v1:MATNR>";
document_exit = document_exit + "<sfw:MATNR>AC 4102 </sfw:MATNR>"*/;
}
}
document_exit = document_exit + "</sfw:data>";
document_exit = document_exit + "</sfw:NFE_CRM>";
document_exit = document_exit + "</soapenv:Body></soapenv:Envelope>";
output.write(document_exit.getBytes());
} catch (Exception e) {
}
}
}
Thank you a lot to all who helped me!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.