on 12-22-2013 11:09 AM
Hi ,
I am facing issue with xsd structure which is not giving desired output while mapping is executed.
I am working on Proxy to SOAP scenario in which response is coming from third party system. I am getting some namespaces in payload in response which is getting mapped to target structure. I thought to use Xslt mapping or to use XMLAnonymizerBean module but it is not working.
I tried to test the payload having namespace in test tab in first attempt it didn't worked , I tried to remove first subnode and modified with ns2 to nso tested and it worked fine. how can I modify my xsd structure according to requirement.
Please find the below payloads..
Actual Payload Response:
<ns:createOrderResponse xmlns:ns="http://services.oms.ecom.ecc.com"><ns:return type="com.ecc.ecom.oms.beans.xsd.CreateOrderResponse">
<ns:omsGeneratedOrderId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<ns:responseCode>99</ns:responseCode>
<ns:responseDesc>INVALIDORDER</ns:responseDesc>
<ns:sellerSiteId>10196</ns:sellerSiteId>
<ns:serverProcElapsedTime>45</ns:serverProcElapsedTime>
<ns:siteGeneratedOrderId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<ns:subResponse>
<responseCodexmlns="http://beans.oms.ecom.ecc.com/xsd">1144</responseCode>
<responseDescription xmlns="http://beans.oms.ecom.ecc.com/xsd">Orderhttp://beans.oms.ecom.ecc.com/xsd%22%3EOrder Totalmismatch</responseDescription>
</ns:subResponse>
<ns:subResponse>
<responseCode xmlns="http://beans.oms.ecom.ecc.com/xsd">1147</responseCode>
<responseDescription xmlns="http://beans.oms.ecom.ecc.com/xsd">Order Grand Total and sum of OrderItem Grand Total mismatch</responseDescription>
</ns:subResponse>
<ns:transactionNumber>1069297098</ns:transactionNumber>
</ns:return></ns:createOrderResponse>
Output from Above payload:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:MT_Ordercreation_Resp xmlns:ns1="urn://abh.com:OTC:OrderCreationToOMS"><response><omsGeneratedOrderId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></omsGeneratedOrderId>
<responseCode>99</responseCode>
<responseDesc>INVALID ORDER</responseDesc>
<siteGeneratedOrderId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></siteGeneratedOrderId>
<subResponse></subResponse>
<subResponse></subResponse>
</response>
</ns1:MT_Ordercreation_Resp>
_________________________________________________________________________________________________
After Removing first Subresponse and puting ns0 in place ns2.
<?xml version="1.0" encoding="UTF-8"?>
<ns0:createOrderResponse xmlns:ns0="http://services.oms.ecom.ecchttp://services.oms.ecom.eccc.com/c.com">
<ns0:return type="com.ecc.ecom.oms.beans.xsd.CreateOrderResponse">
<ns0:omsGeneratedOrderId ns1:nil="true" xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance"/>
<ns0:responseCode>99</ns0:responseCode>
<ns0:responseDesc>INVALID ORDER</ns0:responseDesc>
<ns0:sellerSiteId>10196</ns0:sellerSiteId>
<ns0:serverProcElapsedTime>45</ns0:serverProcElapsedTime>
<ns0:siteGeneratedOrderId ns1:nil="true" xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance"/>
<ns0:subResponse>
<ns2-ns0:responseCode xmlns:ns2="http://beans.oms.ecom.ecc.com/xsd">1147</ns2-ns0:responseCode>
<ns2-ns0:responseDescription xmlns:ns2="http://beans.oms.ecom.echttp://beans.oms.ecom.ecc.com/xsd">Orderc.com/xsd">Order Grand Total and sum of OrderItem Grand Total mismatch</ns2-ns0:responseDescription>
</ns0:subResponse>
<ns0:transactionNumber>1069297098</ns0:transactionNumber>
</ns0:return>
</ns0:createOrderResponse>
Output---
<?xml version="1.0" encoding="UTF-8"?>
<ns1:MT_Ordercreation_Resp xmlns:ns1="urn://abh.com:OTC:OrderCreationToOMS">
<response>
<omsGeneratedOrderId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></omsGeneratedOrderId>
<responseCode>99</responseCode>
<responseDesc>INVALID ORDER</responseDesc>
<siteGeneratedOrderId xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></siteGeneratedOrderId>
<subResponse>
<responseCode>1147</responseCode>
<responseDesc>Order
Grand Total and sum of OrderItem Grand Total mismatch</responseDesc>
</subResponse>
</response>
</ns1:MT_Ordercreation_Resp>
Hi Abhay,
your map (graphical map) will not give desire output untill you have the same namespace prefix or no prefix in XML. so i would suggest to XSLT or Java map to remove the XML prefix from the input file.
Please refer the below links XML Anonymizer
SAP PI &#8211; Changing namespace prefix using XMLAnonymizerBean | EL Netweaver
regards,
Harish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Harish,
I just only need to replace http://beans.oms.ecom.ecc.com/xsd
to
<?xml version="1.0" encoding="UTF-8"?>
<ns0:createOrderResponse xmlns:ns0="http://services.oms.ecom.ecchttp://services.oms.ecom.eccc.com/c.com">
<ns0:return type="com.ecc.ecom.oms.beans.xsd.CreateOrderResponse">
<ns0:omsGeneratedOrderId ns1:nil="true" xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance"/>
<ns0:responseCode>99</ns0:responseCode>
<ns0:responseDesc>INVALID ORDER</ns0:responseDesc>
<ns0:sellerSiteId>10196</ns0:sellerSiteId>
<ns0:serverProcElapsedTime>45</ns0:serverProcElapsedTime>
<ns0:siteGeneratedOrderId ns1:nil="true" xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance"/>
<ns0:subResponse>
<ns2-ns0:responseCode xmlns:ns2="http://beans.oms.ecom.ecc.com/xsd">1147</ns2-ns0:responseCode>
<ns2-ns0:responseDescription xmlns:ns2="http://beans.oms.ecom.echttp://beans.oms.ecom.ecc.com/xsd">Orderc.com/xsd">Order Grand Total and sum of OrderItem Grand Total mismatch</ns2-ns0:responseDescription>
</ns0:subResponse>
<ns0:transactionNumber>1069297098</ns0:transactionNumber>
</ns0:return>
</ns0:createOrderResponse>
I guess in My case Remove namespace prefix or change XML encoding with the XMLAnonymizerBean will not work as I need to replace namespace http://beans.oms.ecom.ecc.com/xsd from http://services.oms.ecom.ecc . I tried with XSLT mapp but it didn't worked. Could you please suggest.
Regards
Hi Abhay,
you can add one more graphical mapping after your final mapping in operation map.
Please add the below code in Attributes and Methods section of graphical mapping
/*--------------------------------------------------------------------------------------------------*/
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("http://beans.oms.ecom.ecc.com/xsd", "http://services.oms.ecom.ecc");
out.getOutputPayload().getOutputStream().write(targetxml.getBytes());
} catch (Exception e) { throw new StreamTransformationException(e.getMessage()); }
}
public String concate(String str1, String str2, Container container) throws StreamTransformationException{
return (str1+str2);
}
/*--------------------------------------------------------------------------------------------------*/
Please let me know if it works.
regards,
Harish
Hi Harish,
I tried with above code it's working. however I tried with /XMLAnonymizerBean. with below parameters I am calling this bean after call adapter:
Module Name : AF_Modules/XMLAnonymizerBean
Module Key: 0 :
Module Key: 0
Parameter Name: anonymizer.acceptNamespaces
Parameter Value: http://beans.oms.ecom.ecc.com/xsd ‘’ (2 single quotes after space)
Module Key: 0
Parameter Name: anonymizer.quote
Parameter Value:'
below is the Input
<?xml version='1.0' encoding='utf-8'?>
http://services.oms.ecom.ecc.com/
<createOrderResponse><return type='com.ecc.ecom.oms.beans.xsd.CreateOrderResponse'><omsGeneratedOrderId nil='true'></omsGeneratedOrderId><responseCode>99</responseCode><responseDesc>INVALID ORDER</responseDesc><sellerSiteId>10196</sellerSiteId><serverProcElapsedTime>99</serverProcElapsedTime><siteGeneratedOrderId nil='true'></siteGeneratedOrderId><subResponse><responseCode xmlns='http://beans.oms.ecom.ecc.com/xsd'>1144</responseCode><responseDescription xmlns='http://beans.oms.ecom.ecc.com/xsd'>Order Total mismatch</responseDescription></subResponse><subResponse><responseCode xmlns='http://beans.oms.ecom.ecc.com/xsd'>1147</responseCode><responseDescription xmlns='http://beans.oms.ecom.ecc.com/xsd'>Order Grand Total and sum of OrderItem Grand Total mismatch</responseDescription></subResponse><transactionNumber>0186897010</transactionNumber></return></createOrderResponse>
_______________________________________
Output :It is removing first name http;//services.oms.ecom.ecc.com in place http://beans.oms.ecom.ecc.com/xsd
<?xml version='1.0' encoding='utf-8'?>
<createOrderResponse><return type='com.ecc.ecom.oms.beans.xsd.CreateOrderResponse'><omsGeneratedOrderId nil='true'></omsGeneratedOrderId><responseCode>99</responseCode><responseDesc>INVALID ORDER</responseDesc><sellerSiteId>10196</sellerSiteId><serverProcElapsedTime>99</serverProcElapsedTime><siteGeneratedOrderId nil='true'></siteGeneratedOrderId><subResponse><responseCode xmlns='http://beans.oms.ecom.ecc.com/xsd'>1144</responseCode><responseDescription xmlns='http://beans.oms.ecom.ecc.com/xsd'>Order Total mismatch</responseDescription></subResponse><subResponse><responseCode xmlns='http://beans.oms.ecom.ecc.com/xsd'>1147</responseCode><responseDescription xmlns='http://beans.oms.ecom.ecc.com/xsd'>Order Grand Total and sum of OrderItem Grand Total mismatch</responseDescription></subResponse><transactionNumber>0186897010</transactionNumber></return></createOrderResponse>
Regards,
Hi All,
I tried with Java mapping but still I am getting below error
does not implement the required interface com.sap.aii.mapping.api.StreamTransformation or does not enhance the class com.sap.aii.mapping.api.AbstractTransformation
Below is my java code is there anything I need to change in my code:
package repalcenamespace;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Namespace {
public static String repalceNamespace(String filePath){
StringBuffer sb = null;
try {
FileInputStream fstream = new FileInputStream(filePath);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
sb = new StringBuffer();
String temp = null;
while ((strLine = br.readLine()) != null) {
// System.out.println(strLine);
// Print the content on the console
if(strLine.indexOf("http://beans.oms.ecom.ecc.com/xsd") != -1){
// System.out.println(strLine);
temp = strLine.replace("http://beans.oms.ecom.ecc.com/xsd;","http://services.oms.ecom.ecc.com");
sb.append(temp);
// System.out.println(sb);
}
}
// System.out.println(sb);
//Close the input stream
in.close();
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
return sb.toString();
}
/**
* @param args
*/
/* public static void main(String args[]) {
//replaceSpecialChracters("C:\\DEVELOPMENT\\WORKSPACE\\YHIW\/src\\new.xml");
repalceNamespace("H:/Test//file.xml");
}*/
}
Regards,
Hi Abhay
The code you have provided will only work in your local machine. The correct java mapping code should have the below structure
package repalcenamespace;
import java.io.ByteArrayInputStream;
public class repalceNamespace extends AbstractTransformation {
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
try {
//your code;
} catch (Exception e) {
e.printStackTrace();
}
}
}
Please adjust your and test.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.