on 03-22-2016 11:25 PM
Hi Experts,
My scenario is to take CSV file and convert it to XML file. for that i wrote a java mapping code. but when i import and test in XI Integration Repository an error is trowing out as below
02:41:17 Start of test
02:41:18 End of test
a part of java code - - -
I tested in sandbox XI 3.0 system.
please give me some suggestions.
Hi Yaswant,
In XI 3.0 and PI 7.0 the code should be like this:
public class myClassName implements StreamTransformation {
private Map param = null; |
private MappingTrace trace = null;
public void setParameter(Map param) { | ||
this.param = param; | ||
if (param == null) this.param = new HashMap(); | ||
}
public void execute(InputStream in, OutputStream out) {
try {
//yourcode
} catch (Exception e)
{
//dealWithyourExceptions
}
} |
}
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Iñaki Vila,
I am finding difficulty in using StreamTransformation.
can you please guide me out how to convert the abstracttransform code in to StreamTransformation
this is my code
package com.test.CSVtoXML;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
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 CSVtoXML extends AbstractTransformation
{
String initialtag = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:CSVtoXML xmlns:ns0=\"https://sample.nestle.com\">";
String endtag = "</ns0:CSVtoXML>";
String outputxml ="";
String line ;
String[] splitLine;
public void transform(TransformationInput tip, TransformationOutput top)throws StreamTransformationException
{
InputStream in = tip.getInputPayload().getInputStream();
OutputStream out = top.getOutputPayload().getOutputStream();
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(in));
out.write(initialtag.getBytes());
while((line = br.readLine()) != null)
{
splitLine = line.split("\\,");
outputxml = createXML(splitLine);
getTrace().addInfo("XML Created Successfully");
}
// String finaloutput = initialtag + outputxml + endtag;
out.write(outputxml.getBytes());
out.write(endtag.getBytes());
getTrace().addInfo("Payload written Successfully");
}
catch(Exception e)
{
getTrace().addInfo("Error while reading input payload");
}
}
private static String createXML(String[] splitLine)
{
..........
....
...
}
}
Regards,
Yaswanth
Hi Yaswanth,
Use below Java Mapping.
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
public class CSVtoXML implements StreamTransformation {
private Map param = null;
String initialtag = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:CSVtoXML xmlns:ns0=\"https://sample.nestle.com\">";
String endtag = "</ns0:CSVtoXML>";
String outputxml = "";
String line;
String[] splitLine;
@Override
public void setParameter(Map map) {
param = map;
if (param == null) {
param = new HashMap();
}
}
@Override
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
AbstractTrace trace = (AbstractTrace) param.get(StreamTransformationConstants.MAPPING_TRACE);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(in));
out.write(initialtag.getBytes());
while ((line = br.readLine()) != null) {
splitLine = line.split("\\,");
outputxml = createXML(splitLine);
trace.addInfo("XML Created Successfully");
}
// String finaloutput = initialtag + outputxml + endtag;
out.write(outputxml.getBytes());
out.write(endtag.getBytes());
trace.addInfo("Payload written Successfully");
} catch (Exception e) {
trace.addInfo("Error while reading input payload");
}
}
private static String createXML(String[] splitLine) {
return "";
}
}
Regards,
Praveen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
in XI 3.0 AbstractTransformation is not supported you need to use streamtransformation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Yaswanth,
Did you export the file as JAR and impor the same in ESR?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
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.