This web log describes how to combine three differentaspects of PI (ASMA, AF Module and variable substitution) in one shot.
Requirement:
Set Receiver File Name as Payload Attribute Value:
Receiver file name should be "ORDERS<order_no>.xml"where <order_no> will be having the value of an attribute named"order_no" from Payload.
Brief Solution:
1. Using dynamic configuration, set the attribute value ofpayload dynamically to ASMA
2. Using AF module, write the value of ASMA in a variable
3. Using the variable substitution, set the receiver filename schema
Step 1: Dynamic Configuration
In message mapping, create a UDF that will store the valueof the attribute "order_no" dynamically in the adapter specific messageattributes named "FileName"
Java Code for UDF is below.
DynamicConfigurationconf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKeyFileName = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/File","FileName");
conf.put(FileName, a);
return "";
Step 2: AF Modules
Now as we have set the value of an attribute from payload inASMA so we will write its value in a variable "message.interface"
In the receiver CC, under Modules tab, we will call an AFmodule "AF_Modules/DynamicConfigurationBean" before the "Call SAP Adapter".
In the module configuration, we will set the followinginformation.
key.0 = write http://sap.com/xi/XI/System/File FileName
value.0 = message.interface
Step 3: VariableSubstitution
We have the value in "message.interface" so we will assignit to variable substitution.
The value of this variable substitution will be used in thereceiver file name schema.
Receiver File Name Schema = <Fixed text> + % +<variable name> + %.xml
For example: ORDERS%order_no%.xml
Since we are not going to use ASMA in our receiver File nameschema rather we are using the variable substitution so make sure that the ASMAis unchecked in your receiver CC.
Another Simple way
There is a simple way to achieve the above requirement "SetReceiver File Name as Payload Attribute Value" and the way is to write the UDFto store the value dynamically in ASMA.
UDF code will be as below.
String str = "ORDERS"+ a + ".xml"
DynamicConfigurationconf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKeyFileName = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/File","FileName");
conf.put(FileName, str);
return "";