cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to pass Dynamic Attribute from Rest Adapter to File Adapter to use like file name?

pavel-kvasnicka
Discoverer
0 Kudos
1,320

Hi skilled developers,

I am making Rest2File scenario and I use Dynamic Attribute of URL and I would like to pass this attribute to file adapter and use it like file name on output.

I went through all possible posts, but nothing help me.

Thank you very much for help

PK

View Entire Topic
alex_bundschuh
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Pavel,

the settings in the REST sender adapter writes the id into the message header id2 with namespace http://sap.com/xi/XI/System/REST, in the file variable substitution you can either read from pre-defined message headers or the message payload as described here https://help.sap.com/docs/SAP_NETWEAVER_750/5cf7d2de571a45cc81f91261668b7361/446a316af5a23672e100000...

With the prefix message: you can only refer to the message header that are listed in the docu, to read from payload you need to use the prefix payload:

Not sure if Priyanka's approach works, you may try it out. From what I see you have two options:

1. Option: map the value of the id2 message header to the payload, and use variable substitution from the payload

2. Option: map the value of the id2 message header concatenated with the file suffix to the message header FileName with namespace http://sap.com/xi/XI/System/File and in the receiver channel use the adapter-specific message header setting instead of the variable substitution, i.e., select the Use Adapter-Specific Message Attributes flag and select the File Name flag, in this case regardless of what you have specified in the file name schema it will be overwritten with the specified file name, if you have chosen Add timestamp then it will add a timestamp to your file, if the value of id2 is unique anyway you can choose create

see https://help.sap.com/docs/SAP_NETWEAVER_750/5cf7d2de571a45cc81f91261668b7361/446830e67f2a6d12e100000...

For both options you need an UDF to read the id2 header in a message mapping, for the second option you also need an UDF to write message headers

here are functions that you can use, for the getASMA function you need to pass the REST namespace to the first argument, and the constant id2 to the second attribute, the returned value needs to be then passed to the first argument writeASMA if you go for the second option, namespace would be then the file NS and attribute would be FileName, hope this helps

Alex

@LibraryMethod(title="getASMA", description="get adapter specific message attribute", category="UDFPool", type=ExecutionType.SINGLE_VALUE)

public String getASMA (

@Argument(title="") String namespace,

@Argument(title="") String attribute,

Container container) throws StreamTransformationException{

Map<String, Object> all = container.getInputHeader().getAll();

DynamicConfiguration dynConf = (DynamicConfiguration)all.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create( namespace, attribute);

String value = dynConf.get(key);

return value;

}

@LibraryMethod(title="writeASMA", description="write adapter specific message attribute", category="UDFPool", type=ExecutionType.SINGLE_VALUE)

public String writeASMA (

@Argument(title="") String value,

@Argument(title="") String namespace,

@Argument(title="") String attribute,

Container container) throws StreamTransformationException{

Map<String, Object> all = container.getInputHeader().getAll();

DynamicConfiguration dynConf = (DynamicConfiguration)all.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create( namespace, attribute);

dynConf.put(key,value);

return value;

}

pavel-kvasnicka
Discoverer
0 Kudos

Hi Alexander,

thank you very much for your answer and your approach to help beginners like me.

Pavel