on 06-16-2014 8:18 AM
Hi Experts ,
My scenario is Soap to File ( Sync) . Sender legacy system is expecting the response message with prefix tns in below format .
<tns:Data xmlns:tns="com.cad.xyz">
<HUMLast>00393155961240131287</HUMLast>
</tns:Data>
PI is able to send the response message in below format
<ns1:HumLastRequest xmlns:ns1="urn :cad.xyz">
<HUMLast>00393155965135748871</HUMLast>
</ns1:HumLastRequest>
How to remove Prefix ns1 and add prefix tns to match the requirement .
Expected result :
---------------------
<tns:HumLastRequest xmlns:tns="urn :cad.xyz">
<HUMLast>00393155965135748871</HUMLast>
</tns:HumLastRequest>
Please share any code if anyone has already gone through such requirements .
Note : I cannot use XMLAnonymizerBean at SOAP Sender channel as its a Synchronous scenario and response message need to have Prefix tns .
Aziz,
Try this code, working fine.
Paste the code in Attributes and Methods in Functions tab, Message Mapping Editor.
public void transform(TransformationInput in, TransformationOutput out)
throws StreamTransformationException {
try {
String sourcexml = "";
String targetxml ="";
String line ="";
InputStream ins = in.getInputPayload().getInputStream();
BufferedReader br = new BufferedReader( new InputStreamReader(ins));
while ((line = br.readLine()) != null)
sourcexml +=line+"\n";
br.close();
targetxml =sourcexml;
targetxml = targetxml.replaceAll("ns0", "pfx");
out.getOutputPayload().getOutputStream().write(targetxml.getBytes());
}
catch (Exception e)
{
throw new StreamTransformationException(e.getMessage());
}
}
Thanks,
Dhileep.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dhileep,
I tried the same way .
I have 2 mapping . Request message mapping and Response Message mapping .
I have placed the java code as per the above screen shot under
Responsemessagemapping--->Functions tab--->attributes and Methods .
But when i tried to test the message using Test Tab its not giving any results . I think i have done something wrong here ?
regards
Aziz khan
Thanks Dhileep kumar,
never expected changing ns1/ns0 from SAP PI messages to other like tns would be this easy.
I was able to do this with another Message Mapping after main mapping and adding the code you provided in the Functions Tab.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can try with a XSL transformation:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<xsl:template match="/">
<tns:HumLastRequest xmlns:tns="urn :cad.xyz">
<xsl:copy-of select="./child::*/child::*"/>
</tns:HumLastRequest>
</xsl:template>
</xsl:stylesheet>
I think it could be done more generally, but the last XSL example works too.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Inaki,
when i use the above xslt i get the below result
<?xml version="1.0" encoding="UTF-8"?>
<tns:HumResponse xmlns:tns="urn :cad.xyz">
<HUMLast xmlns:ns1="urn :cad.xyz">qwe</HUMLast>
</tns:HumResponse>
I am able to get the prefix tns at root node HumResponse but i am getting namespace xmls and ns1 at each node .
do i need to change something in the xslt code ?
regards,
Aziz khan .
User | Count |
---|---|
72 | |
26 | |
10 | |
9 | |
7 | |
6 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.