0 Replies Latest reply on Jun 6, 2011 4:37 AM by Pavlo Fenoga

    Can't use extra jar with groovy scripting

    Pavlo Fenoga Newbie

       

      Hello everyone,

       

       

      I am using Fuse ESB 3.5.0-fuse-00-00

       

       

      I need to create scripting endpoint with groovy script. Script should  use some java classes available in separate jar.

       

       

      This jar is put to SU and xbean.xml has classpath element with jar name and looks like this:

       

       

         <classpath>

       

       

            <location>.</location>

       

       

            <location>lib</location>

       

       

            <location>lib/extra.jar</location>

       

       

         </classpath>

       

       

      But there are problems to use any classes from extra.jar

       

       

      Groovy script can't be compiled when extra classes are use in import statements or as class names.

       

       

      But using reflection and SU class loaded I can load classes

       

       

       

      This statement doesn't work:

       

       

      def bean = new com.my.TestBean();

       

       

      Got errors:

       

       

      javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,

       

       

      Script1.groovy: 39: unable to resolve class com.my.TestBean

       

       

      @ line 39, column 35.Script1.groovy: 39: unable to resolve class com.my.TestBean

       

       

      @ line 39, column 42.Script1.groovy: 40: unable to resolve class com.scc.smx.utils.spring.TestBean

       

       

      @ line 40, column 1.

       

       

      3 errors

       

       

         at com.sun.script.groovy.GroovyScriptEngine.compile(GroovyScriptEngine.java:117)

       

       

         at com.sun.script.groovy.GroovyScriptEngine.compile(GroovyScriptEngine.java:122)

       

       

         at org.apache.servicemix.scripting.ScriptingEndpoint.process(ScriptingEndpoint.java:296)

       

       

         at org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:617)

       

       

         at org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:571)

       

       

         at org.apache.servicemix.common.AsyncBaseLifeCycle.onMessageExchange(AsyncBaseLifeCycle.java:525)

       

       

         at org.apache.servicemix.common.SyncLifeCycleWrapper.onMessageExchange(SyncLifeCycleWrapper.java:60)

       

       

         at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:632)

       

       

         at org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:185)

       

       

         at org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:168)

       

       

         at org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)

       

       

         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

       

       

         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

       

       

         at java.lang.Thread.run(Thread.java:619)

       

       

       

      The following works:

       

       

      ClassLoader loader = endpoint.getServiceUnit().getConfigurationClassLoader();

       

       

      String className = "com.my.TestBean";

       

       

      Class cl= Class.forName(className, true, loader);

       

       

      //def bean = cl.newInstance();

       

       

      bean.setFld1("22");

       

       

       

      Using reflection for all cases is not convenient.

       

       

      Is this configuration issue or some defect in scripting component?

      Thank you