Hi Jochen When using Tomcat server and putting the Groovy object into HttpSession I do not have control over to choose the child classloader for deserialization hence I thought if I could load into the parent then the default web app class loader will be able to find the class and deserialize them.
On Wed, Nov 16, 2016 at 10:43 AM, Jochen Theodorou <[email protected]> wrote: > > > On 16.11.2016 16:27, Venkat Sadasivam wrote: > >> Hello: >> >> We are using Groovy in the web application and some classes loaded via >> Groovy script get serialized and added into HttpSession object. In >> clustered environment when other Tomcat server try to deserialize we get >> ClassNotFoundException. >> >> I tried something like below code in a simple Java. >> >> ScriptEngineManager factory = new ScriptEngineManager(Serializat >> ion.class.getClassLoader()); >> >> ScriptEngine engine = factory.getEngineByName("Groovy"); >> >> String groovyScript = IOUtils.toString(Serialization >> .class.getResourceAsStream("/blah.groovy"), Charset.defaultCharset()); >> >> Class<?> myClass = (Class<?>) engine.eval(groovyScript); // this line >> loads org.venkat.Blah class >> >> GroovyObject myObj = (GroovyObject) myClass.newInstance(); >> >> Serialization.class.getClassLoader().loadClass("org.venkat.Blah"); // >> this like shows class not found exception >> > > Is there any way to load Groovy script classes into parent classloader? >> > > you do not need a parent, you need the right child. Children of > ClassLaoders are always supposed to ask their parents first, before serving > a loadClass call themselves. > > So I assume that: > myClass.getClassLoader().laodClass("org.venkat.Blah") > would work. > > Is that right? > > > bye Jochen >
