This article is an extension of the approach initially described in How to pick up files with filename dynamically specified in message content. In that article, the example use case was to pick up a specific file to be asynchronously transferred to another location.
This article is based on the solution provided for the thread. In order to synchronously retrieve a file based on the filename specified in the request message, the original approach requires further enhancements.
To achieve this requirement, the design uses a combination of the original approach together with a Sync-Async bridge (as described in the following document).
The main changes to the approach are as follows:-
- Add a field to store message ID in the target structure of the trigger file
- Store the PI message ID of the request into the field above during message mapping
- Trigger file created will have PI message ID in the content
- Create custom adapter module to be used in the sender channel of the second scenario
- The custom module will replace the position of DynamicConfigurationBean (used before NotifyResponseBean)
- Logic of the custom module will be to extract the PI message ID from the trigger file, and set the correlation ID in the PI response message
Design & Configuration
The main concepts behind this enhanced approach are similar to the original, so if you intend to implement this I would suggest that you familiarize yourself with the concepts by reading the original article. This article will focus on the enhancements required to achieve the retrieval using an S-A bridge.
iFlow Scenario 1 – Synchronous Request
Message mapping for the request
– Populate the message ID of the request into the target structure
– Change the filename’s extension to end with the trigger extension (i.e. “.trig”)
UDF to retrieve the request’s message ID
The filename’s extension is changed from “.txt” to “.trig”. This filename is then used in variable substitution as the target filename (refer receiver channel screenshot in previous article).
Sender channel configuration
The synchronous call will be triggered from a SOAP request message into PI. For the SOAP sender channel, check “Keep Attachments”, this ensures that the file that is picked up as an attachment in the response message will be available back to the calling SOAP program.
iFlow Scenario 2 – Synchronous Response
Custom adapter module
To close the S-A bridge, the asynchronous response needs to be correlated back to the original synchronous request. This is achieved by setting the request’s message ID as the correlation ID of the response message. To achieve this, the custom adapter module is developed with the logic below:
- Extract the message ID from the XML of the response message (which is also the trigger file)
- Set the message ID as the correlation ID
Sender channel configuration
The sender SFTP channel for the asynchronous response will poll the directory based on the trigger filename pattern. The actual file to be picked up (in this case a .txt file) is configured in the Additional file section.
Note: To avoid timeout on the synchronous part of the S-A bridge, the polling frequency should be set lower than the synchronous timeout setting.
The custom module is set as the first module (replacing DynamicConfigurationBean as shown in the reference S-A bridge article) of the sender channel. An XPath expression to the location of the message ID in the XML is configured as a parameter for the module.
FileABC123.txt is created and uploaded to the directory where it should be picked up from.
Using SOAPUI, a synchronous message is triggered specifying the filename to be picked up.
The first scenario creates a trigger file in the target directory with the same name as the requested file except with a different extension. This trigger file will contain the message ID of the synchronous request.
The sender SFTP channel of the second scenario picks up both the trigger file and the .txt file. The .txt file is included in the response message as an attachment.
After the files are picked up, the custom module is executed to set the correlation ID and route the message back synchronously to close the S-A bridge.
In the response section of SOAPUI, the file that was picked up can be viewed as an attachment of the SOAP response message.
If the file to be picked up is an XML file and it is required as the main response message, PayloadSwapBean can be included after the custom module to swap the attachment into the main payload.
The full source code for the adapter module can be found in the following GitHub repository.