Quantcast
Channel: Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 741

Create two files with same time stamp using StreamTransformationConstants

$
0
0

Introduction

The requirement is to create two files with different file names from one source message but we have to keep the same time stamp for both files (ABC_20140409-1030-897.txt and XYZ_20140409-1030-897.xml). One approach for this is multi mapping with dynamic configuration using custom adapter module as mentioned in below blog.

A new approach: Multi-mapping Dynamic Configuration using a generic custom module

In this blog i want show how to do this using Dynamic Configuration UDF with TIME_SENT constant of StreamTransformationConstants without using adapter module.

 

Documentation of TIME_SENT:

Time stamp specifying when the message was sent by the sender. The format of the time stamp is as follows: YYYY-MM-DDTHH:MM:SSZ The letter 'T' separates the date from the time, which is generally specified in UTC. If it is a local time, the closing 'Z' is omitted.

More information you can find here.

 

Source Code

This UDF we can use it in both mappings and map it to variable under root node.

public String setFileName(Container container) throws StreamTransformationException {  Map<String, Object> mapParameters = container.getInputHeader().getAll();  // access dynamic configuration  DynamicConfiguration conf = (DynamicConfiguration) mapParameters  .get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);  // read TIME_SENT constant  String timeSent = (String) mapParameters.get(StreamTransformationConstants.TIME_SENT);  // change the format of TIME_SENT  SimpleDateFormat input = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");  SimpleDateFormat output = new SimpleDateFormat("yyyyMMdd-HHmmss-SSS");  Date date = null;  try {  date = input.parse(timeSent);  } catch (ParseException e) {  throw new StreamTransformationException("Parse Exception: " + e.getMessage());  }  timeSent = output.format(date);  DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File",  "FileName");  // read file name  String fileName = conf.get(KEY_FILENAME);  String name = fileName.substring(0, fileName.lastIndexOf("."));  String extension = fileName.substring(fileName.lastIndexOf("."), fileName.length());  fileName = name + "_" + timeSent + extension;  // set new file name  conf.put(KEY_FILENAME, fileName);  return fileName;  }


Configuration

Create one ICO with sender proxy interface and assign two receiver interfaces and two operation mapping under Receiver Interfaces tab like below.

InterfaceDetermination.PNG

Assign two receiver file communication channels under outbound processing.

 

Testing Results
The two files created under target directory with same time stamp.

FileNames.PNG

 

Conclusion

With this approach we can create files with same time stamp when we split the message into two or more messages.

I hope this helps.


Viewing all articles
Browse latest Browse all 741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>