cancel
Showing results for 
Search instead for 
Did you mean: 

NullPointerException: while trying to invoke the method com.sap.aii.mapping.api.MappingTrace.addInfo

0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

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             

  


0 Kudos

Hi,

Thanks for replay,

I have attached the java code. Same code is runinning in live XI3.0 system.

But it throws exception in PI7.3 system.

Thanks and regards,

Kumar

anupam_ghosh2
Active Contributor
0 Kudos

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 

0 Kudos

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

anupam_ghosh2
Active Contributor
0 Kudos

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

Anupam 

0 Kudos

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

Exception:[com.sap.aii.mapping.api.StreamTransformationException: Inside UDF: while trying to invoke the method com.sap.aii.mapping.api.AbstractTrace.addInfo(java.lang.String) of an object returned from com.sap.xirig.lookup.DynamicSampleFile.getTrace()] in class com.sap.xi.tf._MM_ZUMT_UKGAS_MRS_To_MRSFiles_ method getGenerationNumber[M01, com.sap.aii.mappingtool.tf7.rt.Context@19b9f6bd]
com.sap.aii.utilxi.misc.api.BaseRuntimeException: Exception:[com.sap.aii.mapping.api.StreamTransformationException: Inside UDF: while trying to invoke the method com.sap.aii.mapping.api.AbstractTrace.addInfo(java.lang.String) of an object returned from com.sap.xirig.lookup.DynamicSampleFile.getTrace()] in class com.sap.xi.tf._MM_ZUMT_UKGAS_MRS_To_MRSFiles_ method getGenerationNumber[M01, com.sap.aii.mappingtool.tf7.rt.Context@19b9f6bd]
at com.sap.aii.mappingtool.tf7.rt.MethodImplementedIteratorHelper.executeMethod(MethodImplementedIteratorHelper.java:188)
Thanks and Regards,
Kumar

anupam_ghosh2
Active Contributor
0 Kudos

Hi Kumar,

                  Need the complete UDF code calling this java class to comment further on the issue.

Regards

Anupam

0 Kudos

Hi Anupam,

It is just one line UDF

return new DynamicSampleFile().generate();

Thanks and Regards,

Kumar

anupam_ghosh2
Active Contributor
0 Kudos

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

0 Kudos

Hi Anupam,

Very thanks for your reply.

Finally we replace the java code and add RFCLookup in mapping.

Thanks and Regards,

Kumar

Answers (0)