Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Nifi - Java Reflection Processor

avatar

Is there a NiFi processor where I can pass a java class name, method name and arguments and get results? Similar to Hive reflect UDF.

I found ExecuteStreamCommand (which seems to do the same with OS commands) and ExecuteScript (but not sure if it's possible to call java methods using NiFi script language).

Thanks.

1 ACCEPTED SOLUTION

avatar
Master Guru

To @Artem Ervits comment, if the Java class is available in the class loader (either by being part of the NiFi Core or being specified as a JAR in the ExecuteScript's Module Directory property), then you can call it directly, you don't need reflection.

If I'm not answering your question, can you provide more details? I'm happy to help 🙂

View solution in original post

9 REPLIES 9

avatar
Master Mentor

ExecuteScript accepts Groovy, which is a jvm language.

avatar

Thanks @Artem Ervits, yes I remember your Groovy great post for hive. Would you have and groovy example for NiFi as well?

avatar
Master Mentor

I'm actually posting link to Matt's blog for an example http://funnifi.blogspot.com/2016/04/sql-in-nifi-with-executescript.html

avatar
Master Guru

To @Artem Ervits comment, if the Java class is available in the class loader (either by being part of the NiFi Core or being specified as a JAR in the ExecuteScript's Module Directory property), then you can call it directly, you don't need reflection.

If I'm not answering your question, can you provide more details? I'm happy to help 🙂

avatar

Thanks @mburgess.

Imagine, hypothetically, I want to call a static method passing a string as parameter, like reserve from Apache Commons StringUtils. Would something like this work?

org.apache.commons.lang3.StringUtils.reverse( ${my_nifi_attribute} )

avatar
Master Guru

Absolutely! with ExecuteScript (with, say, Groovy as the language), a script body could be something like:

import org.apache.commons.lang3.StringUtils
flowFile = session.get()
if(!flowFile) return
flowFile = session.putAttribute('my_nifi_attribute', StringUtils.reverse( flowFile.getAttribute('my_nifi_attribute') )
session.transfer(flowFile, REL_SUCCESS)

avatar

Awesome! Thank you.

This is much easier than writing a custom processor.

avatar
Master Mentor

avatar
New Contributor

Hi burgess I've tried to invoke stringutils.reverse() in the same u have suggested. what the processor will propagate on successexection ? Will it propagate reversed string on success?