Tuesday, 3 May 2022

File Adapter in OIC

File and FTP adapters enable OIC to process files. These technology adapters are based on J2EE connector architecture (JCA).

Now the question is when to use File and when to use FTP adapter? 

The selection of File and FTP adapters depends on the capabilities of these adapters and the use cases. let's see the different use cases and understand their usage

Use Case 1: You have to connect with a local file system which no security policy.

Use Case 2: You have to poll the files from the FTP server 

Use Case 3: You have to connect the FTP server with a different authentication policy

Use Case 4: You have to Encrypt and Decrypt the file using PGP Key

For use cases 1 and 2 File Adapter is the best choice because it connects the file system without authentication and it also allows to poll of the data from the File server where an FTP adapter does not allow polling the data from FTP server

For use cases 3 and 4 FTP adapter is the best choice because it connects the file system with different authentication policies and it also allows to encrypt and decrypt the file where the File adapter does not allow these features till OIC version 22.2.1

File Adapter

A file adapter is basically used to connect the local file system with the help of the agent.

File Adapter can be used as a trigger as well as invoke

Only Read File i.e. polling operation is possible for trigger type connection

For invoke type connection, multiple operations are possible like below

  • Read File --> To read the file from the local file server
  • Write File --> To write a file to the local file server
  • List File --> To list the files 
  • Move File --> To move a file from location to other
  • Delete File --> Delete file
  • Download File --> Download from local file server to OIC server temporarily

To use the File adapter first create the connection

Sometimes you might work on the file content and sometimes you do not need the file content.

Depending on the use case you can select the structure of the content of the file by selecting yes. If you select no, it means you do not need the file content.

The structure of the file content can be described by choosing any one of the options below

  • Sample delimited document (e.g. CSV)
  • XML Schema (XSD document)
  • Sample XML document (With one or no namespace)
  • Sample JSON document

File Adapter as a Trigger

To use a file adapter for polling you have to create an app-driven integration. Post that drag and drop the file connection at the trigger point of the integration. By doing this, it will poll the files from the local file system one by one means per file one instance will be created at OIC.

You need to specify the parameters like input directory, file name pattern, and rejection directory, optionally you can select read files recursively.

You can also throttle the limit by entering Maximum file values and polling frequency and polling delays in seconds

After a successful read, you can also delete the file


   
The file poll will return the filename, directory, and element having binary content like below


The file Adapter will expose the below operations as Invoke
Read File: To Read a file from the specified directory. You can read the file by specifying the structure of the content or without specifying the structure of the content by selecting yes or no, where yes means read the file with content and you have to describe the structure of the content.
Here we will read the file with the content and will define the structure of the file with the sample JSON document





The file Read operation will require the file directory and file name as a request and return the file content as a response like below

Write File: Write file operation will write the file at the specified location and you can also specify the file name and optionally append the content to the file

While writing the file you may or may not specify the structure for the file content by selecting yes or no. Let's understand the scenario with the use case "You have to poll the file and then write to some other directory and no need to read the file content"

Whenever you will poll the file that time you will have the file name, directory, and base64 encoded data but you have to write the file without reading the content so the file write operation expects ICS file reference. In order to generate the file reference from encoded base 64 you have to use the function decodeBase64ToReference( ) and provide element0 as input

List File: The list file operation will list all the files from the given directory
You need to provide a directory and filename like below

You will receive position, item count, and a list of files where the File will contain directory, filename, lastModifiedTime, creationTime, and size of the file


Move File: This operation will be used to move the file from one directory to another directory
As you are moving the file from one location to another so you have to define the source directory and file name and target directory and target filename

Request and Response will be like below




Delete File: This operation will delete the file from the given location
Download File: This operation will download the file to OIC temp loaction









 




No comments:

Post a Comment