cancel
Showing results for 
Search instead for 
Did you mean: 

Removing CDATA around XML Adds Unwanted Escaping

Former Member
0 Kudos

I've tried to follow examples in other posts but they have issues. This seems like something that should have a straight forward solution. I use a web service that returns a <DATA> node that contains CDATA that interns contains the XML payload I need. I've managed to write the java mapping to strip out the <DATA> and the CDATA and it looks fine when I test it in the OM test tab. But when I run this through PI the XML inside the CDATA is all escaped and everything I do to use it throws errors. I seriously need to get this working and could use any help. Here is a sample of the XML...

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MT_ExportPayload xmlns:ns0="http://isbdcapp86/Enablon7.8Train/rpc_literal.wsdl">

<Data><![CDATA[<?xml version="1.0" encoding="UTF-16" standalone="yes" ?>

<Document>

  <Record>

    <EmployeeID>ID000006150265</EmployeeID>

    <ApplicationUser>&lt;None&gt;</ApplicationUser>

    <LastName>Shi</LastName>

    <FirstName>Nansun</FirstName>

  </Record>

</Document>]]>

</Data>

</ns0:MT_ExportPayload>

OM Test Tab using my java map (code below) gives me this...

<Data>

<Document>

  <Record>

    <EmployeeID>ID000006150265</EmployeeID>

    <ApplicationUser>&lt;None&gt;</ApplicationUser>

    <LastName>Shi</LastName>

    <FirstName>Nansun</FirstName>

  </Record>

</Document>

</Data>

But when I look at logs (soap message logs), I see this note the XML preamble in the <DATA> and even my needed xml is escaped...

<enab:ExportDataResponse xmlns:enab="enablon"> <Data>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot; standalone=&quot;yes&quot; ?&gt;

&lt;Document&gt;

  &lt;Record&gt;

    &lt;EmployeeID&gt;ID000006150265&lt;/EmployeeID&gt;

    &lt;ApplicationUser&gt;&amp;lt;None&amp;gt;&lt;/ApplicationUser&gt;

    &lt;LastName&gt;Shi&lt;/LastName&gt;

    &lt;FirstName&gt;Nansun&lt;/FirstName&gt;

&lt;/Record&gt;

&lt;/Document&gt;</Data>

</enab:ExportDataResponse>

The Java map based on what I have found in other, somewhat old posts...

import org.w3c.*;

import org.w3c.dom.Document;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

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

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

public class GetEnablonPayload2 extends AbstractTransformation { 

  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException { 

  try { 

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

             OutputStream out = transformationOutput.getOutputPayload().getOutputStream(); 

             // Copy Input content to Output content 

             byte[] b = new byte[in.available()]; 

             in.read(b);

             DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();

            

             DocumentBuilder builderel=factory.newDocumentBuilder();                       

             Document docIn=builderel.parse(new ByteArrayInputStream(b));

            

             Document docOut = null; 

             docOut=builderel.newDocument();

            

             Node node; 

             NodeList nListRec = docIn.getElementsByTagName("Data"); 

             node = nListRec.item(0);

            

             Node clon = docOut.importNode(node,true); 

             docOut.appendChild(clon);

                        

             String sResult = null; 

             sResult = convertDocument_String(docOut);

             sResult = sResult.replace("<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\" ?>","");

             sResult = sResult.replace("]]>","");  

            

             out.write(sResult.getBytes());

         } catch (Exception exception) { 

             getTrace().addDebugMessage(exception.getMessage()); 

             throw new StreamTransformationException(exception.toString()); 

         } 

     } 

  public static String convertDocument_String(Document Doc){ 

   String sResult =""; 

   StringWriter writer = new StringWriter(); 

   try { 

       DOMSource domSource = new DOMSource(Doc); 

       StreamResult result = new StreamResult(writer); 

       TransformerFactory tf = TransformerFactory.newInstance();

       Transformer transformer = tf.newTransformer(); 

       transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

       transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

       transformer.transform(domSource, result); 

   } catch (Exception ex) { 

       ex.printStackTrace(); 

   } 

   sResult = writer.toString(); 

   return sResult; 

}

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

Hi Carlton,

The error you are getting is because of after the xml you have soap envelope tags and the namespace of envelope tags are different from your namespace that is why the XML after XSLT is not matching expected input XML of message mapping and target side the field occurrence is 1..1 that means it is mandatory element not optional that is why you are getting above error.


<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="enablon">

   <xsl:output encoding="utf-8"/>

   <xsl:template match="@*|node()">

      <xsl:copy>

         <xsl:apply-templates select="@*|node()"/>

      </xsl:copy>

   </xsl:template>

   <xsl:template match="SOAP-ENV:*">

      <xsl:apply-templates select="@* | node()"/>

   </xsl:template>

   <xsl:template match="ns0:*">

      <xsl:element name="ns0:{local-name()}" namespace="http://isbdcapp86/Enablon7.8Train/rpc_literal.wsdl">

         <xsl:apply-templates select="@*|node()"/>

      </xsl:element>

   </xsl:template>

   <xsl:template match="*">

      <xsl:copy>

         <xsl:apply-templates select="*"/>

         <xsl:value-of select="substring-after(text(),&apos;?&gt;&apos;)" disable-output-escaping="yes"/>

      </xsl:copy>

   </xsl:template>

</xsl:stylesheet>

This XSLT will do below:

Regards,

Praveen.

Answers (6)

Answers (6)

Former Member
0 Kudos

Praveen & Eng, I finally have the end-to-end example working. And a lot of thanks goes to you guys. I learned so much! I do have one more question though, why is it necessary to remove the name space on the Message Types? Is this because the messages used by the web services are not using the same namespace? Because I tried to line them up. My next example will be 3rd party to SAP module.

engswee
Active Contributor
0 Kudos

Praveen did all the heavy lifting, and I just cheered both of you on from the sidelines

Regarding the namespace issue, if an XML payload is generated from a third party, normally it's best to get an XSD from them and import it as an External Definition in PI - this would minimize any namespace related conflicts. In your case, you had to define a DT/MT in PI that "represents" the extracted XML payload. DT/MT created in PI by default includes PI's namespace and therefore might cause mismatch with the actual XML payload.

The best way to check for mismatches is to put the XML payload in the Test tab of a Message Mapping object and check whether the icons are Red or Green as mentioned in one of my earlier replies.

Anyway, glad everything is sorted for you. Do stick around and not just for your own issues, you can learn a lot by also being exposed to other's issues and resolutions.

Former Member
0 Kudos

Praveen,

Thanks, I suspected there was something going on with the namespaces. I only use xsl occasionally and I'm just not that good at it yet. Unfortunatly something I've done has now broken the inbound side of this example so once I can get it working I'll try your xml. I had created one to strip out all the name spaces but still had this problem. And, it is still confuseing to me that it works in the test tab of the OM. I would think it would complain there too if the namespace did not match the target xml schema. I'll update when I can try this. Thank you!!!

RaghuVamseedhar
Active Contributor
0 Kudos

Carlton,

Please use below Java Mapping before Graphical Mapping in OM.

package com.map; 

import java.io.*; 

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

public class Test_JavaMapping extends AbstractTransformation { 

    @Override 

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException { 

        try { 

            InputStream inputstream = transformationInput.getInputPayload().getInputStream(); 

            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream(); 

            byte[] b = new byte[inputstream.available()]; 

            inputstream.read(b); 

     String input = new String(b);

     input = input.replaceAll("<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\" ?>","").replaceAll("]]>","")

      .replaceAll("&gt;",">").replaceAll("&lt;","<").replaceAll("&amp;","&"); //Remove or replace characters as required.

            outputstream.write(input.getBytes()); 

        } catch (Exception exception) { 

            getTrace().addDebugMessage(exception.getMessage()); 

            throw new StreamTransformationException(exception.toString()); 

        } 

    } 

}

anupam_ghosh2
Active Contributor
0 Kudos

Hi Carlton,

                  Joined this discussion late. I believe the java mapping code you wrote needs modification. I can suggest changes required in the code. Please can you provide  the exact target XML you expect out of this source XML.


<?xml version="1.0" encoding="UTF-8"?>

<ns0:MT_ExportPayload xmlns:ns0="http://isbdcapp86/Enablon7.8Train/rpc_literal.wsdl">

<Data><![CDATA[<?xml version="1.0" encoding="UTF-16" standalone="yes" ?>

<Document>

  <Record>

    <EmployeeID>ID000006150265</EmployeeID>

    <ApplicationUser>&lt;None&gt;</ApplicationUser>

    <LastName>Shi</LastName>

    <FirstName>Nansun</FirstName>

  </Record>

</Document>]]>

</Data>

</ns0:MT_ExportPayload>

Regards

Anupam

Former Member
0 Kudos

First, if I do not need a java map, I'd rather avoid it. it looks like an XSLT will strip out this cdata and deliver the contents as XML. What I need out of that is a very simple single element with a string. I have full control over this end so the element names can be anything so for example <UserName>John Doe</UserName> or <Document><UserName>John Doe</UserName></Document> either of these I can work with.

former_member182412
Active Contributor
0 Kudos

Hi Carlton,

Use below XSLT mapping.


<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>

   <!--Identity template simply copies content forward -->

   <xsl:template match="@*|node()">

      <xsl:copy>

         <xsl:apply-templates select="@*|node()"/>

      </xsl:copy>

   </xsl:template>

   <xsl:template match="*">

      <xsl:copy>

         <xsl:apply-templates select="*"/>

         <xsl:value-of select="substring-after(text(),&apos;?&gt;&apos;)" disable-output-escaping="yes"/>

      </xsl:copy>

   </xsl:template>

</xsl:stylesheet>

Operation mapping test output.

Regards,

Praveen.

Former Member
0 Kudos

This works "IF" what I see in PI looks like what I see in SOAP UI. But this is the problem, SOAP UI contains the CDATA element but what is being seen by PI based on SOAP message logging has the CDATA removed and all the text that was inside of it is now escaped as below. Notice the service response is UTF-16, I have no control over this. Could this be the cause of PI escaping the CDATA?

But, if I stop this escaping your transform should be what I need. Thanks!!!!!!!

<enab:ExportDataResponse xmlns:enab="enablon"> <Data>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot; standalone=&quot;yes&quot; ?&gt;

&lt;Document&gt;

  &lt;Record&gt;

former_member182412
Active Contributor
0 Kudos

Hi Carlton,

It will work for even escaping and with UTF-16 also.

Regards,

Praveen.

Former Member
0 Kudos

Okay, what may be confusing me is that the SOAP message trace still shows the escaped characters. And, fails on the mapping that should execute next. I find it very difficult to see exactly what is happening with only the SOAP message trace and the log file so if anyone knows of other tools please share. So the SOAP message trace shows the escaped characters for the CDATA, but the CDATA is gone, and the log shows a fail (copy below) on the mapping (also below) that should be next which is a simple copy of the user's last name to a single string inside a very simple XML structure.

>Information XISOAP: XI message received for processing

>Information SOAP: Continuing to response message 7203c178-dc04-11e5-ad63-0000006fa7ca

>Information SOAP: Processing completed

>Error SOAP: Call failed: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error encountered while executing mapping: com.sap.aii.af.service.mapping.MappingException: Mapping failed in runtimeRuntime Exception when executing application mapping program com/sap/xi/tf/_MAP_EnablonExport2UserName_; Details: com.sap.aii.mappingtool.tf7.IllegalInstanceException; Cannot create target element /ns0:MT_UserNameOut/UserName. Values missing in queue context. Target XSD requires a value for this element, but the target-field mapping does not create one. Check whether the XML instance is valid for the source XSD, and whether the target-field mapping fulfils the requirement of the target XSD

>Error Returning to application. Exception: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error encountered while executing mapping: com.sap.aii.af.service.mapping.MappingException: Mapping failed in runtimeRuntime Exception when executing application mapping program com/sap/xi/tf/_MAP_EnablonExport2UserName_; Details: com.sap.aii.mappingtool.tf7.IllegalInstanceException; Cannot create target element /ns0:MT_UserNameOut/UserName. Values missing in queue context. Target XSD requires a value for this element, but the target-field mapping does not create one. Check whether the XML instance is valid for the source XSD, and whether the target-field mapping fulfils the requirement of the target XSD

former_member182412
Active Contributor
0 Kudos

Hi Carlton,

This error because of namespace mismatch between your message type and the response message coming from web service.

Use below XSLT mapping.


<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:enab="enablon" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:output omit-xml-declaration="yes"/>

   <xsl:template match="/">

      <xsl:value-of select="/enab:ExportDataResponse/Data" disable-output-escaping="yes"/>

   </xsl:template>

</xsl:stylesheet>

It will generate the output like below after XSLT mapping.

Create the message type like below but dont give any xml namespace like below.

Message mapping output after xslt mapping.

Regards,

Praveen.

Former Member
0 Kudos

This is the transform (XSL) seems to work like I want but I can't get this message mapping to do this final part before the entire integration works. I removed the name space off the message type and I edited the structure as you said. I've tried putting the XSL followed by the message map on the response side of the OM, it didn’t work. Then I tried putting just the XSL on the response from the web service and the message map on the other OM that consumes this response (export data). In both cases, the message map will not even successfully test.  WS1-SI-OM1 – PI – OM2 –SI-WS2 is the scenario. Below is the error and my message map. I feel like I'm almost there and this is the simplest of message maps but I have no clue what this error message is saying but it has to be something simple. Thanks for any help you can provide.


former_member182412
Active Contributor
0 Kudos

Hi Carlton,

I think i fix the namespace problem but i forgot about UTF-16 that is why it is failing. use below XSLT mapping to change the namespace from xmlns:enab="enablon" to 'http://isbdcapp86/Enablon7.8Train/rpc_literal.wsdl' and remove UTF-16 from source XML.

Based on your initial post i assume your source namespace is xmlns:enab="enablon" if this is not the source namespace you can adjust the XSLT mapping according to your source xml.

Adjust the below line with your source xml namespace which namespace of element ExportDataResponse.

<xsl:stylesheet version="1.0" xmlns:ns0="enablon" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:ns0="enablon" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>

   <xsl:template match="@*|node()">

      <xsl:copy>

         <xsl:apply-templates select="@*|node()"/>

      </xsl:copy>

   </xsl:template>

   <xsl:template match="ns0:*">

      <xsl:element name="ns0:{local-name()}" namespace="http://isbdcapp86/Enablon7.8Train/rpc_literal.wsdl">

         <xsl:apply-templates select="@*|node()"/>

      </xsl:element>

   </xsl:template>

   <xsl:template match="*">

      <xsl:copy>

         <xsl:apply-templates select="*"/>

         <xsl:value-of select="substring-after(text(),&apos;?&gt;&apos;)" disable-output-escaping="yes"/>

      </xsl:copy>

   </xsl:template>

</xsl:stylesheet>

Regards,

Praveen.

Former Member
0 Kudos

I have no control over the UTF-16 from the web service I am using. I can try to deal with this in the transform too. I'll follow up when I have time to try this.

Former Member
0 Kudos

I still can't get it to work. The mappings work if run them through the test on the OM. It would be really nice if I could see the message body just before or just after a mapping is applied so I could see what it's working with. It just feels crazy trying to debug this without seeing what is actually being used, ie payload. I even turned on the emit xml declaration thinking it failed because it didn't know the payload was xml but this didn't work either.

former_member182412
Active Contributor
0 Kudos

Hi Carlton,

I guess you enable the Do Not Use SOAP Envelope option in SOAP receiver channel so SOAP adapter is not removing the soap envelope tags, you need to handle this soap envelope in the mapping, i think after my XSLT mapping the xml contain soap envelope tags that is why it is not matching to your message mapping request payload structure and it is failing.

Can you paste the response payload xml here, you can get the response payload in Message Monitor. You must select the message which is having sender component as your web service business system. You will see two messages in message monitor one is request (SENDER->RECEIVER) and another one is response (RECEIVER->SENDER)

Take the payload and run the operation mapping only with XSLT mapping as shown by Eng and if the output contains soap envelope tags then add the soap envelope tags in your message mapping input structure, create exactly matched to your input payload of the mapping then it should work.

Regards,

Praveen.

Former Member
0 Kudos

The payload here is the web service request. The Canceled row has no payload. But when I check the Log Viewer/Expert View, the response to this request is logged and all the CDATA is escaped. The message log errors on the transform after I extract the xml in the CDATA but I have no way to see exactly what is extracted. Finally, the mapping I need after is so very simple I can only assume there is a namespace, encoding or schema issue but since I'm blind to the inputs and outputs other than the SOAP response I received I'm walking in the dark. Oh, and yes I have "use No SOAP Envelope" checked where I receive the SOAP response.

This is the only message in Message Monitor that shows a payload but it's only the SOAP Request I send out to the web service

But, in the Log Viewer/Expert View you can see I did get a response that I expect

And, in the red box, this Message Map is AFTER I extract the xml from the CDATA but I expect something went wrong but I have no way to see this. When I run the received SOAP through the OM's test, it looks right.

I find it hard to believe this message map would fail IF it gets the correct message, but again, I can't see this message. It's hard to imagine what looks like it should be so simple is taking so much time to solve. I just need to have visibility on what the message looks like after I extract the CDATA xml.

engswee
Active Contributor
0 Kudos

Hi Carlton

Ignore the MessageLoggerBean as you can retrieve the response XML from the Log Viewer, plus the bean does not let you view output between different mapping steps.

Copy the payload from the Log Viewer and use OM to test just the first step which is the XSL mapping. Then view the output, you should see the extracted inner XML. Paste a screenshot of it (in SRC view format) so that we can see what you are getting.

Regards

Eng Swee

Former Member
0 Kudos

It works when I do this. The error in the log gives me no clue why this fails on this mapping when I run it starting from Soap UI. It just looks like it should work to me.

former_member182412
Active Contributor
0 Kudos

Hi Carlton,

Can you paste the response XML here not the screen shot, copy and paste the xml here.

Regards,

Praveen.

Former Member
0 Kudos

I'm sure this is something simple but I have done a few tutorials that I had no problem with. Here is the response from the web service I call as seen in the expert view of the log view. Also, I am traveling until Friday so may not get to test anything else until then but I can't tell you enough how much I appreciate all your help but thank you many times....

<?xml version="1.0" encoding="UTF-8" ?>

<SOAP-ENV:Envelope xmlns:Encoding="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" >

<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<enab:ExportDataResponse xmlns:enab="enablon"> <Data>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot; standalone=&quot;yes&quot; ?&gt;

&lt;Document&gt;

  &lt;Record&gt;

    &lt;EmployeeID&gt;ID000006150265&lt;/EmployeeID&gt;

    &lt;ApplicationUser&gt;&amp;lt;None&amp;gt;&lt;/ApplicationUser&gt;

    &lt;LastName&gt;Shi&lt;/LastName&gt;

    &lt;FirstName&gt;Nansun&lt;/FirstName&gt;

    &lt;MiddleInitial/&gt;

    &lt;Active&gt;Yes&lt;/Active&gt;

    &lt;FunctionalGroups/&gt;

    &lt;Picture/&gt;

    &lt;Gender&gt;Male&lt;/Gender&gt;

    &lt;Nationality&gt;AM &amp;gt; USA&lt;/Nationality&gt;

    &lt;MaritalStatus&gt;Single&lt;/MaritalStatus&gt;

    &lt;BirthDate&gt;02/19/1974&lt;/BirthDate&gt;

    &lt;JobStatus&gt;EMP&lt;/JobStatus&gt;

    &lt;ActualContract&gt;EMP&lt;/ActualContract&gt;

    &lt;JobStatusStartDate&gt;05/04/1948&lt;/JobStatusStartDate&gt;

    &lt;JobStatusEndDate/&gt;

    &lt;JobTitle&gt;TECH&lt;/JobTitle&gt;

    &lt;JobTitleStartDate/&gt;

    &lt;JobTitleEndDate/&gt;

    &lt;DepartmentsTask/&gt;

    &lt;JobTaskStartDate/&gt;

    &lt;JobTaskEndDate/&gt;

    &lt;CSRVolunteeringType/&gt;

    &lt;EntityInitialWorking/&gt;

    &lt;EntityCurrentWorking/&gt;

    &lt;WorkingPerimeter&gt;US.3&lt;/WorkingPerimeter&gt;

    &lt;Entities&gt;GP&lt;/Entities&gt;

    &lt;WorkCountry&gt;USA&lt;/WorkCountry&gt;

    &lt;WeeklyHoursOfWork/&gt;

    &lt;CurriculumVitae/&gt;

    &lt;LastDiploma/&gt;

    &lt;Diplomes/&gt;

    &lt;NativeLanguage/&gt;

    &lt;TechnicalTrainingRelatedPositionUV/&gt;

    &lt;GeneralhoursoftechnicaltrainingUV/&gt;

    &lt;ExecutiveManager/&gt;

    &lt;Supervisor&gt;ID000006150277&lt;/Supervisor&gt;

    &lt;ResponsibleTitle/&gt;

    &lt;Address&gt;02 Rue de Prague&lt;/Address&gt;

    &lt;Geography&gt;EU &amp;gt; FRA &amp;gt; FR.10 &amp;gt; 75000&lt;/Geography&gt;

    &lt;Country&gt;FRA&lt;/Country&gt;

    &lt;ZipCode&gt;75013&lt;/ZipCode&gt;

    &lt;PhoneNo&gt;01 77 67 04 03&lt;/PhoneNo&gt;

    &lt;FaxNo&gt;01 71 15 50 17&lt;/FaxNo&gt;

    &lt;MobileNo&gt;06 39 66 34 50&lt;/MobileNo&gt;

    &lt;Email&gt;nshi@enablon.net&lt;/Email&gt;

    &lt;Id&gt;20&lt;/Id&gt;

    &lt;AccountStatus/&gt;

    &lt;AdmissionDate&gt;04/05/1948&lt;/AdmissionDate&gt;

    &lt;LastMod&gt;06/10/2015 08:26:23&lt;/LastMod&gt;

    &lt;RMFirstAxis&gt;GP&lt;/RMFirstAxis&gt;

    &lt;RMRisks/&gt;

  &lt;/Record&gt;

&lt;/Document&gt;</Data> </enab:ExportDataResponse>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

Former Member
0 Kudos

So I added the SOAP structure to the message and then went field by field to see what was breaking the transform. The problem seems to be that after the transform that removes the escapes, there are SOAP namespaces on the Envelope and Body notes. If I removed these, it at least passes in message map test. But, now I have to find a way to strip these out of the data or include them in the DT's schema.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:Encoding="http://schemas.xmlsoap.org/soap/encoding/">

<SOAP-ENV:Body>

<ns0:ExportDataResponse xmlns:ns0="http://isbdcapp86/Enablon7.8Train/rpc_literal.wsdl">

<Data xmlns:enab="enablon">

<Document>

former_member182412
Active Contributor
0 Kudos

Hi Carlton,

To keep it simple if you only need FirstName from the response you can use below XSLT only in the operation mapping no need to include message mapping because i am taking only FirstName field from the response.


<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enab="enablon">

   <xsl:template match="/">

      <ns0:MT_UserNameOut xmlns:ns0="http://isbdcapp86/Enablon7.8Train/rpc_literal.wsdl">

         <UserName>

            <xsl:value-of select="substring-before(substring-after(/SOAP-ENV:Envelope/SOAP-ENV:Body/enab:ExportDataResponse/Data, &apos;&lt;FirstName&gt;&apos;), &apos;&lt;/FirstName&gt;&apos;)"/>

         </UserName>

      </ns0:MT_UserNameOut>

   </xsl:template>

</xsl:stylesheet>

Regards,

Praveen.

Former Member
0 Kudos

I can try this but I will have to make changes to this over time and we have several that are based on this same scenario to do; so, I really need to understand why this isn't working not just find a mystical way to get this example to work. I split the transform that removes the escapes on the CDATA and the message map that pulls out just the LastName into different OM's. And when I run the SOAP message I see through the "Test" tabs on each OM, taking the output from the first as the input for the second it works. But the test worked when I had them on the same OM. There is nothing else in the path but to output that final xml but if fails no matter if either way (the two maps together in one OM or broken apart on the receiver side of the two OMs). It is crazy to me that there is no better way to see what the problem is. Do I need to break this entire example down, delete it and start again because it is corrupted? Is it a configuration issue on the SI, OM, Channel. You guys seem to think this is simple so I can only assume there is something not being considered. But, why on earth would it work in the TEST tabs and not work when you run it live???

Transmitting the message using connection SOAP_http://sap.com/xi/XI/System failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error encountered while executing mapping: com.sap.aii.af.service.mapping.MappingException: Mapping failed in runtimeRuntime Exception when executing application mapping program com/sap/xi/tf/_MAP_EnablonExport2UserName_; Details: com.sap.aii.mappingtool.tf7.IllegalInstanceException; Cannot create target element /ns0:MT_UserNameOut/UserName. Values missing in queue context. Target XSD requires a value for this element, but the target-field mapping does not create one. Check whether the XML instance is valid for the source XSD, and whether the target-field mapping fulfils the requirement of the target XSD

Former Member
0 Kudos

i guess you should use value as "no" for the below line or //comment the line.

   

transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

Former Member
0 Kudos

I have already tried that, it makes no difference because the XML preamble isn't coming from that. And, this wouldn't solve the problem of all my XML being escaped. So there are 2 issues though they may be related (1) the unwanted XML preamble and (2) all the pay load xml is escaped. If the payload were not escaped, the additional XML preamble would break the XML's "well" formed restriction. SOAP only works now because this extra preamble, and my payload, are all escaped.

engswee
Active Contributor
0 Kudos

It looks like the actual SOAP response do not store the wrapped XML in a CDATA section (which was what you expected). If you try it in SOAP UI, does it use CDATA for the <Data> field?

Former Member
0 Kudos

Yes, in SOAP UI, the CDATA field is there. It looks like PI is striping off the CDATA and escaping all the contents of the CDATA. This is a problem, if true. Some of my text nodes inside the CDATA's xml contain special characters but are not part of the actual xml. If I have to parse the escaped text back to XML, this makes it more complicated. It would be better if PI could send me the CDATA content without escaping it.

engswee
Active Contributor
0 Kudos

Hi Carlton

It's not entirely clear whether you are getting all these escape characters as a raw response back from the SOAP service or after some logic/mapping has been performed in PI.

We need to establish when this happens and if it is due to your Java mapping above.

Can you add the module MessageLoggerBean on your SOAP receiver channel? Add it as the module AFTER the CallAdapter step so that it logs a payload of the raw response from the SOAP service. Refer to the following blog for usage details of the module.

One you have this, can you provide a screenshot of the raw response that was logged by the module?

If the raw response from the SOAP service is as per your first sample XML above (which has CData) then I can provide you a much simpler Java mapping to extract the XML content wrapped in the <Data> node. The Java mapping above that you got from other posts is actually quite horrible - it can be so much more simpler.

Regards

Eng Swee

Former Member
0 Kudos

You can see what actually appears from the web service and before I can do anything has all the CDATA escaped. But the transform Praveen gave me seems to have dealt with this. I am failing on the transform after this....this of course assumes I DO successfully extract the CDATA xml and present it to the next transform but I am blind to exactly what happens. All I know is I receive this below from the web service and I fail on the transform AFTER I use Praveen's transform to extract the inner xml. If I could see the message after I have extracted that inner xml it would be a huge help. Thanks for taking the time to look at this for me.

engswee
Active Contributor
0 Kudos

Hi Carlton

From the Log Viewer, it looks like when the web service is accessed from PI, the response is not CData-wrapped which differs from it's behavior when accessed by SOAP UI.

Anyway, that is besides the point, since Praveen has been assisting you based on that non-CData structure.

I think you are not far from resolving this and I encourage you to persevere as Praveen is providing you very good assistance. I won't provide you with anything specific at the moment since Praveen is already guiding you, but I will give you some general pointers. If you approach this issue one-step at a time, you will eventually get there.

At the moment, it looks like you are stuck with the message mapping after extracting the inner XML using XSL. The error is most likely because the input data does not match the source structure expected by the Message Mapping.

The few tips I'd suggest are:-

i) Use MessageLoggerBean as mentioned above in the receiver channel to log a version of the response payload

ii) Use this response payload and run through the OM one-step at a time. This way, it'd allow you to see the output of each step, i.e. output after XSL, output after MM. The output of each mapping step of the OM will be the input to the next step. You can select which step(s) of the OM is/are executed as shown below.

iii) Check that the output of the XSL step matches the input structure of the MM step

If there is a mismatch, you'd see that the icons are red as shown below.

Regards

Eng Swee

Former Member
0 Kudos

Eng,

This is super helpful. I have a bean for logging the SOAP messages but not the messages between all the mappings. I'll have to read the link in detail later; another project has taken my time for now and is why I wanted to get this integration working asap. And, yes Praveen has been great and so have you! I will mark his answers as helpful/solved once I know what is actually the solution. I do have a question for you, how did you get to be very good with PI? I'd like to grow my skills with it too but there are parts of PI that seem very deep and complicated or maybe it just looks like it now. Anyway, any advice for improving my knowledge would be nice to know. I don't see my employer paying for classes but if they are not too expensive I might do it. Thanks again for all your help.

Former Member
0 Kudos

When I go to add the MessageLoggerBean it isn't showing in the list of available modules. Can I just type it in?