on 11-24-2006 1:39 PM
Hi All,
I hve a scenario like this ERP->XI->Monitoring system
In the mapping, I need to assign the outbound payload (whole xml) to a field in the target
message field since the (Target) Monitoring system wants to receive the whole xml message in single field.
How can i achieve this?
Thanks
Deno
try this.. some of the imports are not required.. however I just copied from my code..
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import com.sap.aii.af.mp.module.Module;
import com.sap.aii.af.mp.module.ModuleContext;
import com.sap.aii.af.mp.module.ModuleData;
import com.sap.aii.af.mp.module.ModuleException;
import com.sap.aii.af.ra.ms.api.Message;
import com.sap.aii.af.service.trace.Trace;
import java.util.Hashtable;
//XML Parsing and Transformation classes
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import com.sap.aii.af.ra.ms.api.XMLPayload;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
import javax.xml.transform.*;
import javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
Object obj = null; //Handler to get principal data
Message msg = null;// Handler to get message object
String getXMLtoField = null;
try {
obj = inputModuleData.getPrincipalData();
msg = (Message)obj;
XMLPayload xmlpayload = msg.getDocument();
DocumentBuilderFactory factory;
factory =DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
// parse the XML Payload
Document document = builder.parse((InputStream)
xmlpayload.getInputStream());
OutputFormat format = new OutputFormat(document); // Serialize DOM
StringWriter stringOut = new StringWriter(); // Writer will be a String
XMLSerializer serial = new XMLSerializer(stringOut, format);
serial.asDOMSerializer(); // As a DOM Serializer
serial.serialize(document.getDocumentElement());
String FileContent = stringOut.toString();
}
return getXMLtoField;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
How many input fields you have?
It ist possible to make a small stupid customer function that will put all Values from all your input segments into one queue for the output field.
For each input field you need on input parameter:
- - -
result.addValue(a[0]);
result.addValue(b[0]);
result.addValue(c[0]);
.....
Daniel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot. I am decided to go for java user defined function. In the mapping editor, I tried to create the user defined function. But facing some errors when executed. What should I give the label name and argument according to Bhavesh's java code. Do I need to import any?
Here is the java code.
BufferedReader inp = new BufferedReader(new InputStreamReader(in));
StringBuffer buffer = new StringBuffer();
String line="";
while ((line = inp.readLine()) != null) {
buffer.append(line);
}
String source=buffer.toString();
Thanks
Deno
Thanks Prakash for the reply. I cannot use java mapping or xslt mapping in this scenario. Since the requirement is to map some source fields to target fields as well as take the payload of the inbound xml and map it a single field "Payload" in the target in the same message mapping. So I guess, the only option would to be to go for user-defined functions in Java. Since I am new to Java, I am unable to accomodate the logic to map the payload to a single field in target. If you have any idea, please let me know.
Thanks
Deno
Hi Deno,
You can do that with Java or XSLT mapping as well. If you need to go for UDF then you have to manually concatenate the values in the UDF.If it is few fields then fine but if there are many fields then it would be tedious. So the best way is to go for XSLT or Java mapping..
Here is the sample XSLT for ur requirement... you need to change it accordingly
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Root>
<Field1><xsl:value-of select="SField1"/></Field2>
<Field2><xsl:value-of select="SField2"/></Field2>
<SingleField>
<xsl:copy-of select="." />
</SingleField>
<Field3><xsl:value-of select="SField3"/></Field3>
</Root>
</xsl:template>
</xsl:stylesheet>
In the above code the whole source XML will be copied in the node SingleField. The Field1.. Field3 has respecive mapping.. You need to change the field name respectively. SField1.. SField3 you need to give the XPATH of the field in the source document.
Regards,
prakash
Hi,
If I use the below java program for java mapping the whole inbound xml payload to a single field in the target, what are the steps to be taken care of?
1) How should i save this java file?
2) Where should i import and along with this java file, do i need to import some other parser?
3) How should I use it in interface mapping? (Just import the jar file and use it or do some other as well)
Appreciate any help provided. If anyone has sample java mapping scenario blogs or links, please send across that as well.
Thanks
Deno
Hi Deno,
Following weblog might help you.
A three blog series on java mapping
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
Blog on Testing and Debugging Java Mapping
/people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
Thanks,
TUhin
Thanks a lot for the reply Tuhin. The blogs are really excelling for Java mapping but since I am really novice in Java, its very difficult for me to grasp it in a short span of time and at this very early stage. As I said, my requirement seems a quit simple and less coding needed for developing a mapping program in java. If anyone can show me step by step java mapping development for my requirement, it would be very helpful. Thanks
Deno
Hi,
You can use this XSLT code to copy to a single field.
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Root>
<Field>
<xsl:copy-of select="." />
</Field>
</Root>
</xsl:template>
</xsl:stylesheet>
Regards,
Prakash
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 Deno, you can do it very easy with Java Mapping.
Also with Message Mapping Tool you can do it, but if the payload has many fields it will take more time than pure Java Mapping
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.