on 05-20-2013 6:04 PM
Hi,
How to resolve this error ????
I am executing below code in Eclipse.
package com.sap.integration.sfsf;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.AbstractTrace;
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 PassThrough implements StreamTransformation
{
//private Map param = null;
private AbstractTrace trace = null;
public void setParameter(Map param)
{
this.trace = (AbstractTrace) param.get(StreamTransformationConstants.MAPPING_TRACE);
}
public void execute(InputStream arg0, OutputStream arg1) throws StreamTransformationException
{
//AbstractTrace trace = (AbstractTrace)params.get(StreamTransformationConstants.MAPPING_TRACE);
//trace = (AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo("Processing message Starts. Execute Method.");
System.out.println("Processing message Starts. Execute Method.");
}
public static void main(String[] args)
{
try
{
InputStream in = new FileInputStream(new File("K:/QueryOperation.xml"));
OutputStream out = new FileOutputStream(new File("K:/Output.xml"));
PassThrough myMapping = new PassThrough();
myMapping.execute(in, out);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Hi Prabhat,
Hope the below code will solve your problem. I have done some modifications to your code!
Reward points if it solves your problem.
public class PassThrough implements StreamTransformation
{
private Map param = null;
private AbstractTrace trace = null;
public void setParameter(Map objparam)
{
this.param = objparam;
if(objparam == null)
{
this.param = new HashMap();
//this.trace = (AbstractTrace) param.get(StreamTransformationConstants.MAPPING_TRACE);
}
public void execute(InputStream arg0, OutputStream arg1) throws StreamTransformationException
{
trace = (AbstractTrace)objMap.get(StreamTransformationConstants.MAPPING_TRACE );
trace.addWarning("Processing message Starts. Execute Method.");
BufferedReader br = new BufferedReader(new InputStreamReader(arg0));
BufferedWriter bw = new BufferedWriter (new OutputStreamWriter(arg1));
try
{
// use br to read the file content
{
catch()
{
}
finally
{
try
{
// close all steam and buffers
}
catch()
}
}
public static void main(String[] args) throws FileNotFoundException, StreamTransformationException
{
FileInputStream in = new FileInputStream("K:\\QueryOperation.xml");
FileOutputStream out = new FileOutputStream("K:\\Output.xml");
PassThrough myMapping = new PassThrough();
myMapping.execute(in, out);
System.out.println("Executed Successfully");
}
}
Regards,
Stephen Rouvier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Still not working.
Error : -
java.lang.NullPointerException at com.sap.integration.sfsf.PassThrough.execute(
PassThrough.java:44)
at com.sap.integration.sfsf.PassThrough.main(
PassThrough.java:76)
I have executed following code line by line ..
package com.sap.integration.sfsf;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.AbstractTrace;
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 PassThrough implements StreamTransformation
{
private Map param = null;
private AbstractTrace trace = null;
public void setParameter(Map objparam)
{
this.param = objparam;
if(objparam == null)
{
this.param = new HashMap();
}
}
public void execute(InputStream arg0, OutputStream arg1) throws StreamTransformationException
{
trace = (AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE );
trace.addWarning("Processing message Starts. Execute Method.");
System.out.println("Processing message Starts. Execute Method.");
try
{
System.out.println("Processing message Starts. Execute Method.");
BufferedReader reader = new BufferedReader(new InputStreamReader(arg0));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
arg1.write(line.getBytes());
arg1.write("\n".getBytes());
}
}
catch (Exception ex)
{
trace.addWarning("Could not process source message");
System.out.println("Could not process source message");
throw new RuntimeException(ex.getMessage());
}
System.out.println("Processing completed successfully");
}
public static void main(String[] args)
{
try
{
InputStream in = new FileInputStream(new File("K:/QueryOperation.xml"));
OutputStream out = new FileOutputStream(new File("K:/Output.xml"));
PassThrough myMapping = new PassThrough();
myMapping.execute(in, out);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Regards
PS.
Hello,
You need to read the input stream and write to output stream inside the execute method (not from the main) if you are testing inside XI. The main method is only used if you are testing your java mapping externally.
public static void main(String[] args)
{
try
{
InputStream in = new FileInputStream(new File("K:/QueryOperation.xml"));
OutputStream out = new FileOutputStream(new File("K:/Output.xml"));
PassThrough myMapping = new PassThrough();
myMapping.execute(in, out);
}
catch (Exception e)
{
e.printStackTrace();
}
}
Hope this helps,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hope you have added PI mapping jar files.
Regards,
Loordh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Parabhat,
Refer below link
http://scn.sap.com/thread/1392993
http://scn.sap.com/thread/2037583
Regards
Bhargava krishna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.