本文主要是介绍Dynamic File name using ASMA (Adapter Specific Message Attributes) in PI/XI,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
转自:http://www.saptechnical.com/Tips/XI/ASMA/Index.htm
There has been an added feature from SP14 onwards to handle the Message Attributes dynamically using AdapterSpecificMessageAttibutes (e.g. Filename). This feature has been demonstrated with one of the example below using File adapter.
Business case:
There was a requirement in one of our interfaces to get the same file name that sender places in his FTP and get the same name as file name with the added time stamp separated by the “_ “(underscore) symbol on the target side.
Ex: Source side file name (DynamicPO.txt has to be converted to DynamicPO_<timestamp>.xml).
Technical challenge:
Time stamp can be added at the end of the file name by specifying the Add Timestamp parameter .But our requirement is to put underscore between filename and time stamp which is not possible in the former case. To achieve this we can make use of ASMA and modify the file name according to our requirement.
Procedure:
Design Part (IR):
Prerequisites:
All the required Interface objects have already been created,In the current case the message structures are:
Source Structure
| Target Structure |
<!-- [if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:137.25pt; height:150.75pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image001.png" o:title=""/> </v:shape><![endif]--> | <!-- [if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75" style='width:139.5pt;height:154.5pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image003.png" o:title=""/> </v:shape><![endif]--> |
Message mapping:
-
Create an UDF and include the piece of code that captures the Filename and Timestamp from source side via ASMA.
-
Modify them according to our requirement by adding the <Timestamp> at the end of <filename>.
-
Map the UDF to any of the top level node so that the modified filename will be available for the target communication channel.
UDF code:
<!-- [if gte vml 1]><v:shape id="_x0000_i1027" type="#_x0000_t75" style='width:378pt;height:266.25pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image005.png" o:title=""/> </v:shape><![endif]-->
Code:
try {
String filename = "";
String timestamp = "";
DynamicConfiguration conf1 = (DynamicConfiguration) container
.getTransformationParameters()
.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key1 = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","FileName");
DynamicConfigurationKey key2 = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","SourceFileTimestamp");
filename = conf1.get(key1);
timestamp = conf1.get(key2);
filename = filename.replaceAll( ".txt" ,"_" );
filename = filename+timestamp+".xml";
conf1.put(key1,filename);
return filename;
}
catch(Exception e)
{
String exception = e.toString();
return exception;
}
Configuration Part (ID):
à In the sender side communication channel, Mention *.txt as file name to pick all the txt files that will be placed in the source directory.
<!-- [if gte vml 1]><v:shape id="_x0000_i1028" type="#_x0000_t75" style='width:242.25pt;height:78pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image007.png" o:title=""/> </v:shape><![endif]-->
à Click on Advanced tab and check the Option “SetAdapterSpecificMessageAttributes ” in addition to that check the attribute that are required to be captured during run time. In our case File Name and Source File Time Stamp are required to be checked as shown in the below picture.
<!-- [if gte vml 1]><v:shape id="_x0000_i1029" type="#_x0000_t75" style='width:214.5pt;height:118.5pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image009.png" o:title=""/> </v:shape><![endif]-->
--> In the receiver communication channel Mention ‘ * ‘as File Name Scheme.
<!-- [if gte vml 1]><v:shape id="_x0000_i1030" type="#_x0000_t75" style='width:270.75pt;height:55.5pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image011.png" o:title=""/> </v:shape><![endif]-->
à Click on Advanced tab and check the Option “SetAdapterSpecificMessageAttributes ” in addition to that check the attribute “File Name ” which will carry the modified value in the UDF in mapping as shown below.
<!-- [if gte vml 1]><v:shape id="_x0000_i1031" type="#_x0000_t75" style='width:3in;height:118.5pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image013.png" o:title=""/> </v:shape><![endif]-->
à Create the Remaining IR objects as usual, save and activate them.
Execution:
Now it’s the time to test the interface .Place the “.txt ” file in the source directory and execute scenario. After successful execution you will see the “.xml ” file (as my scenario is FCC to xml ) created by the name that in way it has been modified in the UDF using Dynamic Configuration .
Sender system | Receiver System |
<!-- [if gte vml 1]><v:shape id="_x0000_i1032" type="#_x0000_t75" style='width:3in;height:51.75pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image015.png" o:title=""/> </v:shape><![endif]--> | <!-- [if gte vml 1]><v:shape id="_x0000_i1033" type="#_x0000_t75" style='width:255pt;height:59.25pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image017.png" o:title=""/> </v:shape><![endif]--> |
<!-- [if gte vml 1]><v:shape id="_x0000_i1034" type="#_x0000_t75" style='width:153pt;height:51pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image019.png" o:title=""/> </v:shape><![endif]--> | <!-- [if gte vml 1]><v:shape id="_x0000_i1035" type="#_x0000_t75" style='width:324pt;height:215.25pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image021.png" o:title=""/> </v:shape><![endif]--> |
Runtime Workbench:
The checking of options ASMA in communication channel allows sender file attributes to be available in RWB as shown in the figure to see them Go to sxmb_moni à click on the message à Inbound message à SOAP Header à Dynamic Configuration .
File name and timestamp in SXMB_MONI (Before Modification ) :
<!-- [if gte vml 1]><v:shape id="_x0000_i1036" type="#_x0000_t75" style='width:342pt;height:144.75pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image023.png" o:title=""/> </v:shape><![endif]-->
Go to sxmb_moni à click on the message à Call Adapter à SOAP Header à Dynamic Configuration .
File name in SXMB_MONI (After modification Modification using Dynamic Configuration):
<!-- [if gte vml 1]><v:shape id="_x0000_i1037" type="#_x0000_t75" style='width:425.25pt;height:204.75pt'> <v:imagedata src="file:///C:\DOCUME~1\SAPTEC~1\LOCALS~1\Temp\msohtml1\03\clip_image025.png" o:title=""/> </v:shape><![endif]-->
这篇关于Dynamic File name using ASMA (Adapter Specific Message Attributes) in PI/XI的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!