Configuring a From Channel component using the HTTP Channel API

Configuring a From Channel component using the HTTP Channel API

This article was originally written for Iguana 5 so it contains version 5 screenshots, and may contain out of date references

Configuring From Channel components with this API can be tricky at first, but it is simple enough once you are used to it. The secret is that the settings for the From Channel are stored in the dequeue_list element of the destination component (rather than in the from_channel as you might expect).

We show you how to do three things:

  • Create a new channel with From Channel components
  • Update an existing channel with From Channel components
  • Remove a From Channel source channel

Create a new channel with From Channel components

Let’s create a new channel “My Second Channel” using a From Channel source and an To Translator destination, these are the steps:

  1. Get the default configuration settings for a From Channel to To Translator channel.
  2. Change the channel name to “My Second Channel”
  3. Change the source channel name to “My Channel”
  4. Optional: add a second source channel (you can add more the same way)
  5. Create the new channel

Let’s take a look at the settings of the new channel, using this code:

As you can see the from_channel settings are empty:

And the settings for the From Channel are contained in the dequeue_list element of the To Translator:

And here is the code for you to try:

function main(Data)
   -- create a new "From channel" to "To Translator" channel 

   -- get the default config for a "From channel" to "To Translator" channel
   local Config = net.http.post{url='localhost:6543/get_default_config',
      auth={password='password', username='admin'},
      parameters={compact='true', source='From Channel', destination='To Translator'},
      live=true
   }
   local XmlTreeCfg = xml.parse(Config)

   -- set the channel name
   XmlTreeCfg.channel.name = 'My Second Channel'

   -- Change the source channel (source_name attribute) to "My Channel"
   local List=XmlTreeCfg.channel.to_mapper.dequeue_list
   List:append(xml.ELEMENT,'dequeue')
   List.dequeue.source_name='My Channel'

   -- Optionally: add a 2nd (or 3rd etc) source channel
   List:child("dequeue", 2):append(xml.ATTRIBUTE,'source_name')
   List:child("dequeue", 2).source_name='My Other Channel'
   -- dequeue_guid must be created, but it is not necessary
   -- to set the value - it is set automatically
   List:child("dequeue", 2):append(xml.ATTRIBUTE,'dequeue_guid')

   -- create the new channel
   local MyChannelConfig = net.http.post{url='localhost:6543/add_channel',
      auth={password='password', username='admin'},
      parameters={compact='true', config=tostring(XmlTreeCfg)},
      live=false
   }

   -- run this after you have created the channel to
   -- display the settings for the new channel
   local Config = net.http.post{url='localhost:6543/get_channel_config',
      auth={password='password', username='admin'},
      parameters={compact='true', name='My Second Channel'},
      live=true
   }
   local XmlTreeCfg = xml.parse(Config) 
   trace(XmlTreeCfg) -- view the settings
end

Tip: We could could have used a more elegant looping construct to create our dequeue_list elements. See the iguanaServer.cloneXmlNode() function in the iguanaServer module for an example of how to do this.

Update an existing channel with From Channel components

To update an existing channel we simply make two change to the procedure:

  1. Change the first step to get the information from an existing channel:
  2. Change the fifth step to update the existing channel:

Remove a From Channel source channel

Removing a source channel from a From Channel component requires three steps:

  1. Get the information from an existing channel.
  2. Remove the appropriate dequeue element from the dequeue_list.
  3. Update the channel.

Let’s look at the settings of the updated channel, as you can see the second source channel (“My Other Channel”) has been removed:

And here is the code:

function main(Data)

   -- get the channel configuration information for an existing channel
   local Config = net.http.post{url='localhost:6543/get_channel_config',
      auth={password='password', username='admin'},
      parameters={compact='true', name='My Second Channel'},
      live=true
   }
   local XmlTreeCfg = xml.parse(Config)

   -- remove the second source channel
   local List=XmlTreeCfg.channel.to_mapper.dequeue_list
   List:remove(2)
   trace(XmlTreeCfg)

   -- update the channel
   local MyChannelConfig = net.http.post{url='localhost:6543/update_channel',
      auth={password='password', username='admin'},
      parameters={compact='true', config=tostring(XmlTreeCfg)},
      live=true
   }

   -- run this after you have updated the channel
   -- to display the changed channel settings
   local Config = net.http.post{url='localhost:6543/get_channel_config',
      auth={password='password', username='admin'},
      parameters={compact='true', name='My Second Channel'},
      live=true
   }
   local XmlTreeCfg = xml.parse(Config) 
   trace(XmlTreeCfg) -- view the settings

end

Leave A Comment?