Monday, May 22, 2017

Using the ballerina file transport to access a local file

Ballerina provides support for multiple transports such as HTTP, JMS, Web Sockets, File, FTP and SFTP. A service file is bound to a single transport, however there are no restrictions on packaging services of different transports together, this allows programmers to craft interfaces and glue applications that span multiple varied transports.  Further, the mechanism in which content is accessed and manipulated is constant regardless of the protocol being used, meaning the manipulation logic written for one transport say HTTP can be used with another with little to no alterations. This uniformity provides for a smoother programming experience and is sure to increase your programming efficiency.

The example below uses the file transport to access a local file’s content, it then creates a simple xml payload using the content(if the given condition is met) before sending it out to a processing endpoint over HTTP.

Note: to use some of the transports mentioned above you will need to put in a few dependency jars into ballerina libs. Look to the respective transport’s documentation for further instructions.

Note: the example above s is meant to be a crude demonstration of the uniform, almost transport independent programming interface provided by ballerina.

Find out more about ballerina here:

Note: this example was written for ballerina 0.87 and may not work with other versions.

No comments:

Post a Comment