on 08-02-2008 12:37 AM
Hi Guys,
Can somebody help me out to get the whole payload as a string into single field. For that i wrote the progrmme by fallowing the forums. i have no idea about the java mapping. so can somebody check it out please tell me the nessasary changes i have to made.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import com.sap.aii.mapping.api.StreamTransformation;
/**
@author Karthik
*
*/
public class xmlvalidation implements StreamTransformation {
public static void main(String args[]) throws Exception {
FileInputStream inFile =
new FileInputStream("C:/Documents and Settings/karthik/Desktop/SGD/T64.XML");
FileOutputStream outFile =
new FileOutputStream("C:/Documents and Settings/karthik/Desktop/SGD/T64-output.XML");
xmlvalidation xml = new xmlvalidation();
xml.execute(inFile, outFile);
System.out.println("Success");
}
/**
@param inFile
@param outFile
*/
public void setParameter(Map param) {
Map map = param;
}
public void execute(InputStream in, OutputStream out)
throws com.sap.aii.mapping.api.StreamTransformationException {
try {
//***********************Code To Generate The XML Parsing Objects****************************//
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transform = tf.newTransformer();
Document doc = db.parse(in);
Document docout = db.newDocument();
xmlvalidation vald = new xmlvalidation();
//***********************Code To Read The Input XML Document**********************************//
}// public void execute(InputStream in, OutputStream out) {
BufferedReader in = new BufferedReader(new InputStreamReader(inp));
StringBuffer buffer = new StringBuffer();
String line="";
while ((line = in.readLine()) != null) {
buffer.append(line);
}
String sourcexml=buffer.toString();[/code]
//***********************Code To Return the generated XML Objects****************************//
domS = new DOMSource(doc);
transform.transform((domS), new StreamResult(out));
//***********************End of Code To Generate The XML OutPut Document***********************//
} catch (Exception e) {
System.out.print("Problem parsing the file: " + e.getMessage());
e.printStackTrace();
}
}
}
Thanks.
Kartik.
Hi Karthik...
Have a look at my Wiki...
[Java Mapping- Convert the Input xml to String |https://wiki.sdn.sap.com/wiki/display/XI/JavaMapping-ConverttheInputxmlto+String]
Thanks
SaNv...
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.
I don't understand your question, is this your scenario?
You have a sample input message like:
<a>
<b>1</b>
</a>
And you want to transform it to:
<output>
<field>
<a>
<b>1</b>
</a>
</field>
</output>
or even applying a base64 encoding to input message like:
<output>
<field>
ZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmlt=
</field>
</output>
is this your scenario?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.util.Map;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
public class MsgWrapper implements StreamTransformation {
private Map map;
public void setParameter (Map param){
map = param;
}
public void execute (InputStream in, OutputStream out){
byte[] buffer = new byte[4096];
OutputStream auxStream = new ByteArrayOutputStream();
while (true) {
int read = in.read(buffer);
if (read == -1) {
break;
}
auxStream.write(buffer, 0, read);
}
auxStream.close();
in.close();
String raw_xml = auxStream.toString();
}
After this, the string raw_xml will contain your input message.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
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.