Mixing ScriptEngine w/ controller services

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Mixing ScriptEngine w/ controller services

Mike Thomsen
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:

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

        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);



            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?