Class JavascriptSender

All Implemented Interfaces:
ICacheEnabled<String,String>, AdapterAware, IConfigurable, IConfigurationAware, INamedObject, IScopeProvider, ISender, ISenderWithParameters, IWithParameters, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

@Category("Advanced") public class JavascriptSender extends SenderSeries
Sender used to run JavaScript code using `JavascriptEngine` implementations.

This sender can execute a function of a given Javascript file, the result of the function will be the output of the sender. The parameters of the Javascript function to run are given as parameters by the adapter configuration The sender doesn't accept nor uses the given input, instead for each argument for the jsFunctionName method, you will need to create a parameter on the sender.

The result of the Javascript function should be of type String, or directly convertible to String from a primitive type or an array of primitive types / strings, as the output of the sender will be of type String.

Failure to ensure the output is a string may mean the result will look like [Object object].

Since:
7.4
  • Constructor Details

    • JavascriptSender

      public JavascriptSender()
  • Method Details

    • configure

      public void configure() throws ConfigurationException
      Description copied from interface: ISender
      configure() is called once at startup of the framework in the configure method of the owner of this sender. Purpose of this method is to check whether the static configuration of the sender is correct. As much as possible class-instantiating should take place in the configure() or open() method, to improve performance.
      Specified by:
      configure in interface IConfigurable
      Specified by:
      configure in interface ISender
      Overrides:
      configure in class SenderSeries
      Throws:
      ConfigurationException
    • isSenderConfigured

      protected boolean isSenderConfigured()
      Overrides:
      isSenderConfigured in class SenderSeries
    • sendMessage

      @Nonnull public SenderResult sendMessage(@Nonnull Message message, @Nonnull PipeLineSession session) throws SenderException
      Description copied from interface: ISender
      Send a message to some destination (as configured in the Sender object). This method may only be called after the configure() method is called.

      The following table shows the difference between synchronous and a-synchronous senders:

       synchronousa-synchronous
      ISender.isSynchronous() returnstruefalse
      return value of sendMessage() isthe reply-messagethe messageId of the message sent
      the correlationID specified with sendMessage()may be ignoredis sent with the message
      a {link TimeOutException}may be thrown if a timeout occurs waiting for a replyshould not be expected

      Multiple objects may try to call this method at the same time, from different threads. Implementations of this method should therefore be thread-safe, or synchronized.

      Specified by:
      sendMessage in interface ISender
      Overrides:
      sendMessage in class SenderWrapperBase
      Throws:
      SenderException
    • addSender

      @Optional public void addSender(ISender sender)
      Description copied from class: SenderSeries
      one or more specifications of senders that will be executed one after another. Each sender will get the result of the preceding one as input.
      Overrides:
      addSender in class SenderSeries
    • setJsFileName

      @Mandatory public void setJsFileName(String jsFileName)
      the name of the javascript file containing the functions to run
    • setJsFunctionName

      public void setJsFunctionName(String jsFunctionName)
      the name of the javascript function that will be called (first)
      Default value
      main
    • setEngineName

      public void setEngineName(JavascriptSender.JavaScriptEngines engineName)
      the name of the JavaScript engine to use.
      Default value
      J2V8
    • getJsFileName

      public String getJsFileName()
    • getJsFunctionName

      public String getJsFunctionName()
    • getEngine