You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nifi.apache.org by Mike Thomsen <mi...@gmail.com> on 2018/11/02 12:38:50 UTC

Mixing ScriptEngine w/ controller services

I have a working relationship between a controller service and a processor,
but the processor uses a user-supplied Groovy script to massage some data.
The ScriptEngine is used to make a CompiledScript. I then have a pattern
that looks like this:

    @Override
    public void onTrigger(ProcessContext context, ProcessSession session)
throws ProcessException {
        FlowFile input = session.get();
        if (input == null) {
            return;
        }

        try (InputStream is = session.read(input)) {
            RecordReader reader = readerFactory.createRecordReader(input,
is, getLogger());

            Bindings bindings = engine.createBindings();
            bindings.put("READER", reader);
            bindings.put("SOME_SERVICE", someService);

            script.eval(bindings);

            is.close();

            session.transfer(input, REL_SUCCESS);
        } catch (Exception ex) {
            getLogger().error("Could not build segments.", ex);
            session.transfer(input, REL_FAILURE);
        }
    }

When I run the processor, I get a ScriptException whose ultimate cause is:

Caused by: java.lang.ClassNotFoundException: com.test.DAO
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)

Is there any way I can configure the classloader for the processor to be
able to work with the one used for the controller service so the script has
the ability to access the entire classpath from the controller service nar?

Thanks,

Mike