<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Can I call javascript from MyProcesssor code in Apache Nifi? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156941#M40983</link>
    <description>&lt;P&gt;I want to call javascript script from MyProcessor code  in Apache Nifi.&lt;/P&gt;&lt;P&gt;I am calling following binary parser  written in javascript in java which is npm module .Can package.son and npm modules part of NAR&lt;/P&gt;&lt;P&gt;Code: Calling following&lt;/P&gt;&lt;P&gt;Javascript.js&lt;/P&gt;&lt;P&gt;var Parser = require('binary-parser').Parser;&lt;/P&gt;&lt;P&gt;// Build an IP packet header Parser &lt;/P&gt;&lt;P&gt;var ipHeader = new Parser()&lt;/P&gt;&lt;P&gt;    .endianess('big')&lt;/P&gt;&lt;P&gt;    .bit4('version')&lt;/P&gt;&lt;P&gt;    .bit4('headerLength')&lt;/P&gt;&lt;P&gt;    .uint8('tos')&lt;/P&gt;&lt;P&gt;    .uint16('packetLength')&lt;/P&gt;&lt;P&gt;    .uint16('id')&lt;/P&gt;&lt;P&gt;    .bit3('offset')&lt;/P&gt;&lt;P&gt;    .bit13('fragOffset')&lt;/P&gt;&lt;P&gt;    .uint8('ttl')&lt;/P&gt;&lt;P&gt;    .uint8('protocol')&lt;/P&gt;&lt;P&gt;    .uint16('checksum')&lt;/P&gt;&lt;P&gt;    .array('src', {&lt;/P&gt;&lt;P&gt;        type: 'uint8',&lt;/P&gt;&lt;P&gt;        length: 4&lt;/P&gt;&lt;P&gt;    })&lt;/P&gt;&lt;P&gt;    .array('dst', {&lt;/P&gt;&lt;P&gt;        type: 'uint8',&lt;/P&gt;&lt;P&gt;        length: 4&lt;/P&gt;&lt;P&gt;    });&lt;/P&gt;&lt;P&gt;// Prepare buffer to parse. &lt;/P&gt;&lt;P&gt;var buf = new Buffer('450002c5939900002c06ef98adc24f6c850186d1', 'hex');&lt;/P&gt;&lt;P&gt;// Parse buffer and show result &lt;/P&gt;&lt;P&gt;console.log(ipHeader.parse(buf));&lt;/P&gt;&lt;P&gt;MyProcessor Code:&lt;/P&gt;&lt;P&gt;   ScriptEngineManager manager = new ScriptEngineManager();&lt;/P&gt;&lt;P&gt;        ScriptEngine engine = manager.getEngineByName("JavaScript");&lt;/P&gt;&lt;P&gt;        if (!(engine instanceof Invocable)) {&lt;/P&gt;&lt;P&gt;          System.out.println("Invoking methods is not supported.");&lt;/P&gt;&lt;P&gt;          return;&lt;/P&gt;&lt;P&gt;        }&lt;/P&gt;&lt;P&gt;        Invocable inv = (Invocable) engine;&lt;/P&gt;&lt;P&gt;        String scriptPath = "binaryParser.js";&lt;/P&gt;</description>
    <pubDate>Sat, 17 Sep 2016 09:57:19 GMT</pubDate>
    <dc:creator>philips1983grai</dc:creator>
    <dc:date>2016-09-17T09:57:19Z</dc:date>
    <item>
      <title>Can I call javascript from MyProcesssor code in Apache Nifi?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156941#M40983</link>
      <description>&lt;P&gt;I want to call javascript script from MyProcessor code  in Apache Nifi.&lt;/P&gt;&lt;P&gt;I am calling following binary parser  written in javascript in java which is npm module .Can package.son and npm modules part of NAR&lt;/P&gt;&lt;P&gt;Code: Calling following&lt;/P&gt;&lt;P&gt;Javascript.js&lt;/P&gt;&lt;P&gt;var Parser = require('binary-parser').Parser;&lt;/P&gt;&lt;P&gt;// Build an IP packet header Parser &lt;/P&gt;&lt;P&gt;var ipHeader = new Parser()&lt;/P&gt;&lt;P&gt;    .endianess('big')&lt;/P&gt;&lt;P&gt;    .bit4('version')&lt;/P&gt;&lt;P&gt;    .bit4('headerLength')&lt;/P&gt;&lt;P&gt;    .uint8('tos')&lt;/P&gt;&lt;P&gt;    .uint16('packetLength')&lt;/P&gt;&lt;P&gt;    .uint16('id')&lt;/P&gt;&lt;P&gt;    .bit3('offset')&lt;/P&gt;&lt;P&gt;    .bit13('fragOffset')&lt;/P&gt;&lt;P&gt;    .uint8('ttl')&lt;/P&gt;&lt;P&gt;    .uint8('protocol')&lt;/P&gt;&lt;P&gt;    .uint16('checksum')&lt;/P&gt;&lt;P&gt;    .array('src', {&lt;/P&gt;&lt;P&gt;        type: 'uint8',&lt;/P&gt;&lt;P&gt;        length: 4&lt;/P&gt;&lt;P&gt;    })&lt;/P&gt;&lt;P&gt;    .array('dst', {&lt;/P&gt;&lt;P&gt;        type: 'uint8',&lt;/P&gt;&lt;P&gt;        length: 4&lt;/P&gt;&lt;P&gt;    });&lt;/P&gt;&lt;P&gt;// Prepare buffer to parse. &lt;/P&gt;&lt;P&gt;var buf = new Buffer('450002c5939900002c06ef98adc24f6c850186d1', 'hex');&lt;/P&gt;&lt;P&gt;// Parse buffer and show result &lt;/P&gt;&lt;P&gt;console.log(ipHeader.parse(buf));&lt;/P&gt;&lt;P&gt;MyProcessor Code:&lt;/P&gt;&lt;P&gt;   ScriptEngineManager manager = new ScriptEngineManager();&lt;/P&gt;&lt;P&gt;        ScriptEngine engine = manager.getEngineByName("JavaScript");&lt;/P&gt;&lt;P&gt;        if (!(engine instanceof Invocable)) {&lt;/P&gt;&lt;P&gt;          System.out.println("Invoking methods is not supported.");&lt;/P&gt;&lt;P&gt;          return;&lt;/P&gt;&lt;P&gt;        }&lt;/P&gt;&lt;P&gt;        Invocable inv = (Invocable) engine;&lt;/P&gt;&lt;P&gt;        String scriptPath = "binaryParser.js";&lt;/P&gt;</description>
      <pubDate>Sat, 17 Sep 2016 09:57:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156941#M40983</guid>
      <dc:creator>philips1983grai</dc:creator>
      <dc:date>2016-09-17T09:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can I call javascript from MyProcesssor code in Apache Nifi?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156942#M40984</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/13158/philips1983grails.html" nodeid="13158"&gt;@Mohit Sharma&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;You should look at the &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.script.ExecuteScript/index.html"&gt;ExecuteScript&lt;/A&gt; and &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.script.InvokeScriptedProcessor/index.html"&gt;InvokeScriptedProcessor&lt;/A&gt; processors. Both of these processors can execute code written in Javascript directly from NiFi. &lt;A rel="user" href="https://community.cloudera.com/users/641/mburgess.html" nodeid="641"&gt;@Matt Burgess&lt;/A&gt; has written very &lt;A target="_blank" href="https://funnifi.blogspot.com/2016/02/executescript-using-modules.html"&gt;helpful blog posts&lt;/A&gt; on this functionality. &lt;/P&gt;</description>
      <pubDate>Sat, 17 Sep 2016 11:17:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156942#M40984</guid>
      <dc:creator>alopresto</dc:creator>
      <dc:date>2016-09-17T11:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can I call javascript from MyProcesssor code in Apache Nifi?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156943#M40985</link>
      <description>&lt;P&gt;Thanks Andy for your response .I did try above mentioned options but have doubt regarding npm modules and package.json are not working in InvokeScriptedProcessor &lt;/P&gt;&lt;P&gt;Can you provide some implementation examples using javascript part from above mentioned links&lt;/P&gt;</description>
      <pubDate>Sat, 17 Sep 2016 18:11:51 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156943#M40985</guid>
      <dc:creator>philips1983grai</dc:creator>
      <dc:date>2016-09-17T18:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can I call javascript from MyProcesssor code in Apache Nifi?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156944#M40986</link>
      <description>&lt;P&gt;Thank you for your quick reply!&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="https://javascript-obfuscator.org/"&gt;Javascript obfuscator&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 09:57:14 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156944#M40986</guid>
      <dc:creator>emilytaylor_170</dc:creator>
      <dc:date>2017-08-29T09:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Can I call javascript from MyProcesssor code in Apache Nifi?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156945#M40987</link>
      <description>&lt;P&gt;If you want to include NPM modules, check &lt;A target="_blank" href="https://www.n-k.de/riding-the-nashorn/#_npm"&gt;this link&lt;/A&gt; for more details on how to use them with Nashorn.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 13:03:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Can-I-call-javascript-from-MyProcesssor-code-in-Apache-Nifi/m-p/156945#M40987</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-08-30T13:03:36Z</dc:date>
    </item>
  </channel>
</rss>

