cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Configuration: null pointer exception

robert_warde4
Active Participant
0 Kudos

I need to use dynamic configuration to read in the input directory and replace a string  and then put that back so that files are sent to the correct directory. However,I can’t read the dynamic configuration for the directory. Whenever I try to read the directory from the dynamic configuration its blank. I have confirmed this by running some tests. Using a constant value I can write back a new directory and the files appear in the right place. I just have a problem when I’m reading the directory name from the configuration.  The code I was using is below, all I am doing with this example is reading the directory name and writing it back. It doesn't work and returns a null pointer exception. Any ideas?


I’m going to carry on searching SDN and see if anything turns up but I was wondering if you have any ideas? FYI – I reconfigured all the comms channels to use dynamic directory configuration.

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

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

  1. conf.put(key, Name);

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

String  OrigDirPI = conf.get(keyDir); *** THIS IS THE BIT THAT FAILS*****

  1. conf.put(keyDir, DName);

return "";

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Please try this:

String Name1 ="XXX";

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

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

conf.put(key1, Name1);

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

String directoryIn = conf.get(key2);

String DName ="/usr/sap/interfaces/DPG/eChannel/OUT/RUK/10151" + "__" + directoryIn;

conf.put(key2, DName);

return "";

Note: I dont have a systemas of now, so kindly chk for syntax errors.

Thanks

Amit Srivastava

Message was edited by: Amit Srivastava

baskar_gopalakrishnan2
Active Contributor
0 Kudos

can you please tell me what way your code is different from Robert's code?  I see his code two versions and both gives the same result. Am I missing something here?

Former Member
0 Kudos

AFAIK there is no need to access the dynamic config (DynamicConfiguration) twice within the same code (u have to do it only once) and apparently this is what i have suggested/mentioned in my code..

Thanks

Amit Srivastava

Answers (3)

Answers (3)

Former Member
0 Kudos

First of all ensure you message has dynamic configuration value for directory. Ensure communication channel set up to get this parameter from file system and you could see all dynamic parameters in message header using sxmb_moni transaction.

robert_warde4
Active Participant
0 Kudos

This is the code I used to test the above comment.

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

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

conf.put(FileNameKey, FileName);

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

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

String directoryIn = conf2.get(DirectoryKey);

String DName ="/usr/sap/interfaces/DPG/eChannel/OUT/RUK/10151" + "__" + directoryIn;

conf.put(DirectoryKey, DName);

return "";

baskar_gopalakrishnan2
Active Contributor
0 Kudos

I think your code seems right. But I'm seeing in the below link the code has two instances of Dynamic configuration namely dynamicConfiguration and dynamicConfiguration1.  Each instance handles DIrectory and filename seperate.  You might want to try creating as this link

http://scn.sap.com/community/netweaver/blog/2012/04/07/sample-code-for-determining-the-direcoryascii...

See that helps.

robert_warde4
Active Participant
0 Kudos

Hi, I tried that and although the filename is returned I'm still getting nothing for the directory name.

Regards

Rob