Skip to Content
0
Jan 13, 2013 at 02:34 AM

Interface Sales Force - SessionId - JavaMapping - XML not well-formed

33 Views

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());

}

}

}