cancel
Showing results for 
Search instead for 
Did you mean: 

java function with Dynamic config throws null pointer exception

gopalkrishna_baliga
Participant
0 Kudos

hi Experts,

I am using dynamic config using java function in my message mapping.

The source message has a field called "fname".

The value of "fname" is the input to my java UDF.

The java UDF code is:

public String getDynamicFile(String fname, Container container) throws StreamTransformationException{

String str = fname + ".xml";

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey FileName = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/File","FileName");

conf.put(FileName, str);

return str;

}

When I test this message mapping I get the following exception:

Runtime Exception:[java.lang.NullPointerException: while trying to invoke the method com.sap.aii.mapping.api.DynamicConfiguration.put(com.sap.aii.mapping.api.DynamicConfigurationKey, java.lang.String) of an object loaded from local variable '<4>'] in class com.sap.xi.tf._<message mapping>_ method getDynamicFile[test, com.sap.aii.mappingtool.tf7.rt.Context@2e52cb31]

What am I doing wrong in this UDF?

Thanks

Gopal

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Your UDF will run fine in an end to end execution,i.e, during runtime. However, if you want to test your message mapping test tab without the dynamic config UDF throwing an exception, encpasulate the code in a try catch block

public String getDynamicFile(String fname, Container container) throws StreamTransformationException{
String str = fname + ".xml";
try{
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);


DynamicConfigurationKey FileName = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/File","FileName");

conf.put(FileName, str);
}catch(Exception ex){}

return str;
}

The above code should run fine when you test in the message mapping test tab.

Regards

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>> When I test this message mapping I get the following exception:

Dynamic configuration code works during runtime.

Former Member
0 Kudos

Adding to the above, if you need to test your mapping in the test tab, you just have to add a try catch block in your udf code. In that case, the exception will be caught and the rest of your mapping can be checked.

Regards,

Ninu

Shabarish_Nair
Active Contributor
0 Kudos

/people/shabarish.vijayakumar/blog/2009/03/26/dynamic-configuration-vs-variable-substitution--the-ultimate-battle-for-the-file-name

are you testing it in message mapping? refer the blog.