on 09-11-2012 11:44 AM
Hi All,
My system is XI3.0. so I worte below standard java code for call function module. I am getting error in addInfo method of AbstractTrace calss. Kindly help the same. Below code
I am getting error while test the data in Message mapping.
Error from udf
Exception:[java.lang.NullPointerException: while trying to invoke the method com.sap.aii.mapping.api.MappingTrace.addInfo(java.lang.String) of an object loaded from local variable 'importanttrace'] in class com.sap.xi.tf._MM_NCNCFile_To_CNCFile_ method Dynamic_Filename[[Ljava.lang.String;@fe5f620, com.sap.aii.mappingtool.tf7.rt.ResultListImpl@4281b707, com.sap.aii.mappingtool.tf7.rt.Context@52174ead]
com.sap.aii.utilxi.misc.api.BaseRuntimeException: Exception:[java.lang.NullPointerException: while trying to invoke the method com.sap.aii.mapping.api.MappingTrace.addInfo(java.lang.String) of an object loaded from local variable 'importanttrace'] in class com.sap.xi.tf._MM_NCNCFile_To_CNCFile_ method Dynamic_Filename[[Ljava.lang.String
Thanks and Regards,
Kumar
Hi Kumar,
Check if these statements are present in your mapping
public class DynamicFilenameGenerator implements StreamTransformation{
private Map map = null;
private AbstractTrace trace = null;
public void setParameter(Map arg0) {
map = arg0; // Store reference to the mapping parameters
if (map == null) {
this.map = new HashMap();
}
}
public void execute(InputStream arg0, OutputStream arg1)
throws StreamTransformationException {
trace = (AbstractTrace)map.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo("Processing message");
}
}
If these statements are already present, please could you post the complete java mapping code.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kumar,
As you are aware of the fact that java mapping code has undergone changes from 7.1 onwards. Thus this might be the reason for failure of the code. This class DynamicFileNameGenerator is called by some other class which contains the method "execute". Could you please upload the code which calls this class. DynamicFileNameGenerator does not contain "execute" method thus I feel there must be some other class calling this class. We need both the classes to understand possible cause of the error and eradication of the same.
Regards
Anupam
Hi Anupam,
Thanks for reply,
DynamicFileNameGenerator is not java mapping, It is standalone java class. just calling the DynamicFileNameGenerator.generate(strFilename,containerObj.getTransformationParameter()) metheod from UDF in message mapping.
Yes i am aware that mapping from PI7.1 onward mapping is changed from execute to transform method.
Thanks and Regards,
Kumar
Hi Kumar,
I have made some changes to the code. Uploading the code.
you will need eclipse/NWDS, java 1.5( or above) and com.sap.xpi.ib.mapping.lib file (as external jar file in project build path) to compile the code and finally upload the same in PI.
Hope the problem is resolved.
Regards
Hi Anupam,
I was try your code but still throws same error.
So i was create sample message mapping and java calss, which is attached in this replay, This also throws the same error
Hi Kumar,
Lets stop calling the function in java class all together. Bring in the code in UDF itself, thus I expect the code to look something like this
String UDF(Container)
{
String result = null;
AbstractTrace importanttrace = containerObj.getTrace();
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try {
importanttrace.addInfo("Started execution of generation method");
}catch(Exception e)
{
throw new StreamTransformationException("Error from udf "+e.getMessage(), e);
}
try {
//filling the string with our RFC-XML (with values)
String rfcInput =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<ns0:ZUCOM_DYNAMIC_FILENAME xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"><X_FILETYPE>"
+ strFilename
+ "</X_FILETYPE></ns0:ZUCOM_DYNAMIC_FILENAME>";
//RfcAccessor accessor = null;
//ByteArrayOutputStream out = null;
//1. Determine a channel (Business system, Communication channel)
importanttrace.addInfo("Retrive channel");
Channel channel =
LookupService.getChannel(BUSINESS_SYSTEM, CHANNEL_NAME);
//2. Get a RFC accessor for a channel.
importanttrace.addInfo("Retrive accessor");
accessor = LookupService.getRfcAccessor(channel);
//3. Create a xml input stream representing the function module request message.
importanttrace.addInfo("Retrive inputstream");
InputStream inputStream =
new ByteArrayInputStream(rfcInput.getBytes());
//4. Create xml payload
importanttrace.addInfo("Retrive payload");
XmlPayload payload = LookupService.getXmlPayload(inputStream);
//5. Execute lookup.
Payload rfcResult = accessor.call(payload);
InputStream in = rfcResult.getContent();
out = new ByteArrayOutputStream(1024);
importanttrace.addInfo("Read buffer");
byte[] buffer = new byte[1024];
for (int read = in.read(buffer);
read > 0;
read = in.read(buffer)) {
out.write(buffer, 0, read);
}
importanttrace.addInfo("Output result");
result = extractGenerationNumber(out.toString());
importanttrace.addInfo("GENERATION NUMBER = " + result);
} catch (LookupException e) {
importanttrace.addWarning("Error while lookup " + e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
importanttrace.addWarning("Error " + e.getMessage());
}finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
importanttrace.addWarning(
"Error while closing stream " + e.getMessage());
}
//7. close the accessor in order to free resources.
if (accessor != null) {
try {
accessor.close();
} catch (LookupException e) {
importanttrace.addWarning(
"Error while closing accessor " + e.getMessage());
}
}
}
}
//TODO:REMOVE IF REQD
return result;
}
This code might not compile unless you copy the same import statements as shown in this link .
I have made changes to include the trace object and used the variable strFilename instead of fileType. This code will take care of trace object I beleive. I do not have access to PI 7.3 to test the code, so you need to deploy and test results.
Hope this resolves the problem.
Regards
Anupam
User | Count |
---|---|
84 | |
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.