Translator as Web Server to receive data from Lua ASTM TCP Server

This post was originally written for Iguana 5 so it uses version 5 screenshots, and may contain out of date references.

Description

This Web Server implementation is very basic.

Simple web service example can be found in this Wiki.

The uniqueness of this bare bones implementation is in fact that we will receive from ASTM TCP Server, located on another physical machine, one HTTP POST request at a time.

Each request will POST JSON object in this request body.

This JSON object contains set of ASTM message Frames, i.e. one complete ASTM message.

Received ASTM message, still in form of JSON object, is pushed into Iguana queue for any further processing by any channel.

Configuration

Channel Source Component is configured is configured as shown below.

Not to forget to adjust ‘path’ parameter in channel Source configuration.

Channel Destination Component is of type “To Channel”.

Iguana’s HTTP(S) Channel Settings used with this example shown on capture below.

Code

The only Translator script for this channel is in ‘main’ module.

There are no configurable parameters in this Translator script.

function main(Data)
   iguana.logInfo(Data)
   if (iguana.isTest()) then
      readPOST(Data)
   else
      local Success, Err = pcall(readPOST,Data)
      if not Success then 
         net.http.respond{body=json.serialize{data={Error=Err}}}
      end
   end
end

function readPOST(Data)
   local req = net.http.parseRequest{data=Data}
   if req.body then
      queue.push{data=req.body}
      net.http.respond{
         entity_type=
         'text/xml',
         'got it', 
         debug_result=true}
   end  

end

The complete ASTM_Webserver_From_HTTPS.zip available for download.

Processing results analysis

Example of received ASTM message can be seen in below capture from channel Logs.

Careful inspection of Hex dump will reveal that all <STX>, <ETB>, and <ETX> control characters had been preserved, and frame segments terminated by <CR>.

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.