Domanda

I'm trying to set up Terracotta (Web Sessions + ehcache + hibernate) with Railo (Open Source ColdFusion Engine - www.getrailo.org). I'm able to start the Terracotta server, to connect the application server to the Terracotta server, and to run the application normally with all three elements (sessions, ehcache, and hibernate) fully functional.

The problem is if I shutdown the application server, and I restart it, it will connect properly to the Terracotta server, but it'll start to throw various classNotFoundExceptions, either on the session object, or on the ehcache objects.

I've attached various java stacktrace for your information. Any idea why this is happening only after the application server is restarted and how do I fix it?

Kind regards,

Philip

-

Java stack trace:

railo.runtime.type.scope.JSession

railo.runtime.type.StructImpl

È stato utile?

Soluzione

OK, I think I found a workaround to all those problems. Hopefully, it might help someone else.

First you need to upgrade your ehCache and add the terracotta jars to your classpath to be able to work with terracotta. This means you'll need to remove the ehcache.jar bundled with Railo, as this is an old version that doesn't work with terracotta. The jars are:

  • ehcache-core-##.##.##.jar (##.##.## is the version)
  • ehcache-terracotta-##.##.##.jar
  • slf4j-api-##.##.##.jar
  • slf4j-jdk14-##.##.##.jar
  • slf4j-log4j12-##.##.##.jar
  • terracotta-toolkit-1.3-runtime-##.##.##.jar
  • REMOVE the "ehcache.jar" from the Railo lib library, otherwise Terracotta will not load.

Next you need to add the <terracottaConfig url="localhost:9510" /> and <terracotta clustered="true" /> lines to your ehcache.xml, which needs to be in your class path. This is well documented on the Terracotta website.

ehCache takes the ContextClassLoader() to load all classes, it it fails, it fallbacks on ClassLoaderUtil. Railo contextClassLoader() is set by default to "org.apache.catalina.loader.WebappClassLoader" (Tomcat ClassLoader). This class loader wasn't able to find the railo objects properly, so you need to change it to "railo.loader.classloader.RailoClassLoader". Since this is a per thread (i.e. per request) context class loader, you need to call the following command at the start of your onRequestStart() method:

<cfset getPageContext().getThread().currentThread().setContextClassLoader( getPageContext().getClass().getClassLoader() ) />

This should fix ehcache and hibernate. Next sessions, using the tomcat valve with Terracotta seems to be a problem, because the valve seems to be called before Railo handles the request. Therefore the "org.apache.catalina.loader.WebappClassLoader" is used and a class not found exception is thrown. A workaround for this is to store the session itself in ehcache and Terracotta with distribute it across the cluster. The problem is that objects stored in Terracotta need to be serializable, and the J2EE session is based on "org.apache.catalina.connector.SessionFacade", which is not serializable. Therefore, to work around that limitation, I just converted the J2EE session to a simple struct, which is serializable, by using the structCopy(session) command, and put the resulting struct in ehcache.

That should be able to get you going with Terracotta and Railo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top