On 04/25/2011 10:44 AM, Edvin Syse wrote: >> Hmm. >> >> When you call request.getSession(), have you already set the >> Thread.setContextClassLoader? >> >> It might be cleaner for us to add a "use-context-class-loader" as a >> <session-config> configuration. >> >> -- Scotthttp://maillist.caucho.com/mailman/listinfo/resin-interest > Basically, I construct a classloader that extends URLClassLoader that > points to the user's compiled classes. This classloader does > myClassLoader.loadClass("name-of-the-controller-for-this-page").newInstance(), > casts it to a "PageController" and runs it's execute() method > (PageController interface).
The typical pattern for a custom classloader would also use: Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(myClassLoader); pageController.execute(); } finally { thread.setContextClassLoader(oldLoader); } That way, any dependent classes would get picked up properly even if using reflection. > This makes sure that all operations in the > PageController has access to the other controller-classes as well. The > controller will see a variable called "session", that is basically a > HashMap set as an attribute in the real HttpSession object. This HashMap > will often contain variables that can only be serialized/deserialized > using the same classloader that instantiated the PageController. > > Maybe a better route is to configure my own serializer/deserializer? If > I use a custom ObjectInputStream that overrides the loadClass() method > and delegates to my special classloader, I should be home free. Is it > possible to configure custom serializers in Resin? (I'm Running Resin > Pro 4.0.17 2CPU). Well, for 4.0.18, one of the bugs/features we need to put in is a way to customize the persistence (primarily for jdbc-style sessions, but I believe some others want to customize the capability.) So I can keep this use-case in mind when I put together that API. But it might be cleaner to use the ContextClassLoader pattern with a session-config so you don't actually need to write a custom serializer. -- Scott > -- Edvin > > > > _______________________________________________ > resin-interest mailing list > resin-interest@caucho.com > http://maillist.caucho.com/mailman/listinfo/resin-interest > _______________________________________________ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest