hazelcast / hazelcast-tomcat-sessionmanager

Tomcat Based Web Session Replication
Other
33 stars 37 forks source link

Unable to start Tomcat with Hazelcast Tomcat SessionManager when any application includes cache-api.jar #105

Open manish-in-java opened 3 years ago

manish-in-java commented 3 years ago

Describe the problem

  1. Followed instructions for using Tomcat Session Manager with Tomcat 9 and Hazelcast 4.1
  2. Was able to start Tomcat with a blank WAR
  3. Added WAR files to Tomcat containing cache-api.jar

Expected result

Tomcat should start successfully.

Actual result

Tomcat does not start. The following error stacktrace is seen:

17-Dec-2020 13:12:32.474 INFO [main] com.hazelcast.client.impl.spi.ClientInvocationService.null CLIENT_NAME [dev] [4.1] Running with 2 response threads, dynamic=true
17-Dec-2020 13:12:32.529 SEVERE [main] org.apache.catalina.core.StandardContext.startInternal The session manager failed to start
        org.apache.catalina.LifecycleException: Failed to start component [HazelcastSessionManager[StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]]
        Caused by: java.lang.NoClassDefFoundError: javax/cache/CacheException
                at com.hazelcast.client.impl.protocol.ClientExceptionFactory.<init>(ClientExceptionFactory.java:225)
                at com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl.initClientExceptionFactory(HazelcastClientInstanceImpl.java:797)
                at com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl.<init>(HazelcastClientInstanceImpl.java:258)
                at com.hazelcast.client.HazelcastClient.constructHazelcastClient(HazelcastClient.java:458)
                at com.hazelcast.client.HazelcastClient.newHazelcastClientInternal(HazelcastClient.java:416)
                at com.hazelcast.client.HazelcastClient.newHazelcastClient(HazelcastClient.java:136)
                at com.hazelcast.session.HazelcastInstanceFactory.getHazelcastInstance(HazelcastInstanceFactory.java:52)
                at com.hazelcast.session.HazelcastSessionManager.startInternal(HazelcastSessionManager.java:77)
        Caused by: java.lang.ClassNotFoundException: javax.cache.CacheException

Any help in how to overcome this error will be greatly appreciated.

Additional context

I do not have control over the WAR files and their content, so it will be useful to have a solution that involves changes only to Tomcat configuration.

manish-in-java commented 3 years ago

Ok, here is what I have found.

With both hazelcast-all-4.1.jar and cache-api-1.1.1.jar in $TOMCAT_HOME/lib, if I delete the file META-INF/services/javax.cache.spi.CachingProvider from hazelcast-all-4.1.jar, Tomcat starts fine.

This seems like a classloader problem.

Is it possible to use Tomcat Session Manager with a JAR that does not contain the file javax.cache.spi.CachingProvider?

robertoschwald commented 3 years ago

Same problem occurs here with Hazelcast 3.7.8 as (Hibernate) JCache provider and cache-api-1.1.1.jar, both within the application WEB-INF/lib dir. Tomcat 8.5.35 lib dir contains only the default Tomcat provided libraries plus mariadb-java-client-2.4.4.jar Java 8.

java.lang.ClassNotFoundException: javax.cache.CacheException
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1328)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1156)
    at com.hazelcast.cache.impl.CacheDataSerializerHook$25.createNew(CacheDataSerializerHook.java:250)
    at com.hazelcast.cache.impl.CacheDataSerializerHook$25.createNew(CacheDataSerializerHook.java:248)
    at com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory.create(ArrayDataSerializableFactory.java:42)
    at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.readInternal(DataSerializableSerializer.java:139)
    at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.read(DataSerializableSerializer.java:104)
    at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.read(DataSerializableSerializer.java:54)
    at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
    at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:172)
    at com.hazelcast.spi.impl.NodeEngineImpl.toObject(NodeEngineImpl.java:307)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:381)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:117)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:102)
Wrapped by: java.lang.NoClassDefFoundError: javax/cache/CacheException
    at com.hazelcast.cache.impl.CacheDataSerializerHook$25.createNew(CacheDataSerializerHook.java:250)
    at com.hazelcast.cache.impl.CacheDataSerializerHook$25.createNew(CacheDataSerializerHook.java:248)
    at com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory.create(ArrayDataSerializableFactory.java:42)
    at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.readInternal(DataSerializableSerializer.java:139)
    at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.read(DataSerializableSerializer.java:104)
    at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.read(DataSerializableSerializer.java:54)
    at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
    at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:172)
    at com.hazelcast.spi.impl.NodeEngineImpl.toObject(NodeEngineImpl.java:307)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:381)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:117)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:102)
    at ------ submitted from ------.(Unknown Source)
    at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolve(InvocationFuture.java:111)
    at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveAndThrow(InvocationFuture.java:74)
    at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:158)
    at com.hazelcast.spi.impl.AbstractInvocationFuture.join(AbstractInvocationFuture.java:134)
    at com.hazelcast.cache.impl.HazelcastServerCacheManager.getCacheConfig(HazelcastServerCacheManager.java:196)
    at com.hazelcast.cache.impl.HazelcastServerCacheManager.findCacheConfig(HazelcastServerCacheManager.java:146)
    at com.hazelcast.cache.impl.AbstractHazelcastCacheManager.getCacheUnchecked(AbstractHazelcastCacheManager.java:244)
    at com.hazelcast.cache.impl.AbstractHazelcastCacheManager.getCache(AbstractHazelcastCacheManager.java:218)
    at com.hazelcast.cache.impl.AbstractHazelcastCacheManager.getCache(AbstractHazelcastCacheManager.java:66)
    at org.hibernate.cache.jcache.internal.JCacheRegionFactory.getOrCreateCache(JCacheRegionFactory.java:97)
    at org.hibernate.cache.jcache.internal.JCacheRegionFactory.createDomainDataStorageAccess(JCacheRegionFactory.java:83)
    at org.hibernate.cache.jcache.internal.JCacheRegionFactory.buildDomainDataRegion(JCacheRegionFactory.java:72)
    at org.hibernate.cache.internal.EnabledCaching.prime(EnabledCaching.java:113)
    at org.hibernate.metamodel.internal.MetamodelImpl.primeSecondLevelCacheRegions(MetamodelImpl.java:331)
    at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:160)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:301)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:469)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
    at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:287)
bbarman4u commented 1 year ago

I have the same problem as well..

bbarman4u commented 1 year ago

Ok, here is what I have found.

With both hazelcast-all-4.1.jar and cache-api-1.1.1.jar in $TOMCAT_HOME/lib, if I delete the file META-INF/services/javax.cache.spi.CachingProvider from hazelcast-all-4.1.jar, Tomcat starts fine.

This seems like a classloader problem.

Is it possible to use Tomcat Session Manager with a JAR that does not contain the file javax.cache.spi.CachingProvider?

@manish-in-java how were you resolve this ?