on 06-01-2014 1:33 AM
Hello,
I have a text file with XML payload in it. The text file has some header information and then the XML payload. How do I read only the XML payload for processing in PI?
the structure of the text file is something like this..
Header Information
Payload
Sample:
#Datetime: 20140318-09:28:50.129
#MessageID: sample123
#Sender: TEST
#SenderParty: TEST
#ReceiverService:
#ReceiverParty: Test
#Interface: Test123
#InterfaceNamespace: http://test.com
#
<?xml version="1.0" encoding="UTF-8"?>
<Sample ><Header>......
Please advise.
Thank you.
Larry.
hi Larry,
Simplest would be to use a java mapping and fetch the payload part.
Please let me know if you would require java mapping.
thanks and regards,
Praveen T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
package com.learning.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class FetchPayload extends AbstractTransformation {
String strData = null;
@Override
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
// TODO Auto-generated method stub
getTrace().addInfo("File Reading started ");
String strData = convertStreamToString(arg0.getInputPayload()
.getInputStream());
getTrace().addInfo("File Reading successfully completed ");
try {
getTrace().addInfo("Generating XML started");
strData.substring(strData.indexOf("<?xml"), strData.length());
arg1.getOutputPayload().getOutputStream().write(
strData.getBytes("UTF-8"));
getTrace().addInfo("Generating XML started");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String convertStreamToString(InputStream in) {
StringBuffer sb = new StringBuffer();
try {
InputStreamReader isr = new InputStreamReader(in);
Reader reader = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
sb.append((char) ch);
}
reader.close();
} catch (Exception exception) {
}
return sb.toString();
}
}
and u can get the xml as a resultant which u can use as input for next message mapping.
thanks and regards,
Praveen T
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.