Uploaded image for project: '[Read Only] - Hippo Site Toolkit 2'
  1. [Read Only] - Hippo Site Toolkit 2
  2. HSTTWO-3323

Make sure JCR eventListeners registered via HST Spring beans get their methods invoked with HST webapp classloader

    XMLWordPrintable

Details

    Description

      See [hippo-community] PooledSession not visible from class loader.

      Following code:

      public class DocListener extends GenericEventListener implements EventListenersContainerListener {

      private static final Logger log = LoggerFactory.getLogger(DocListener.class);
      private Credentials credentials;
      private Repository repository;

      @Override
      public void onEvent(EventIterator events)

      { Session session = repository.login(credentials); }

      @Override
      public void onEventListenersContainerStarted()

      { // do nothing }

      @Override
      public void onEventListenersContainerRefreshed() {

      }
      @Override
      public void onEventListenersContainerStopped() { // do nothing }

      public void setCredentials(Credentials credentials)

      { this.credentials = credentials; }

      public void setRepository(Repository repository)

      { this.repository = repository; }

      }

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
      <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
      <property name="targetObject" ref="jcrObservationEventListenerItems" />
      <property name="targetMethod" value="add" />
      <property name="arguments">
      <bean class="org.hippoecm.hst.core.jcr.EventListenerItemImpl">
      <property name="noLocal" value="false" />
      <property name="nodeAddedEnabled" value="false" />
      <property name="nodeRemovedEnabled" value="false" />
      <property name="propertyAddedEnabled" value="false" />
      <property name="propertyChangedEnabled" value="true" />
      <property name="propertyRemovedEnabled" value="false" />
      <property name="absolutePath" value="/content/documents" />
      <property name="deep" value="true" />
      <property name="eventListener">
      <bean class="org.onehippo.cms7.listener.DocListener">
      <property name="credentials" ref="javax.jcr.Credentials.default" />
      <property name="repository" ref="javax.jcr.Repository" />
      </bean>
      </property>
      </bean>
      </property>
      </bean>
      </beans>

      fails with the exception below:

      [INFO] [talledLocalContainer] 02.06.2015 11:02:03 ERROR ObservationManager [DocListener.onEvent:32]
      [INFO] [talledLocalContainer] javax.jcr.RepositoryException: javax.jcr.LoginException: Failed to borrow session from the pool. java.lang.IllegalArgumentException: interface org.hippoecm.hst.core.jcr.pool.PooledSession is not visible from class loader
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.LazyMultipleRepositoryImpl.login(LazyMultipleRepositoryImpl.java:207)
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.MultipleRepositoryImpl.login(MultipleRepositoryImpl.java:173)
      [INFO] [talledLocalContainer] at org.onehippo.cms7.listener.DocListener.onEvent(DocListener.java:29)
      [INFO] [talledLocalContainer] at org.apache.jackrabbit.core.observation.EventConsumer.consumeEvents(EventConsumer.java:249)
      [INFO] [talledLocalContainer] at org.apache.jackrabbit.core.observation.ObservationDispatcher.run(ObservationDispatcher.java:161)
      [INFO] [talledLocalContainer] at java.lang.Thread.run(Thread.java:745)
      [INFO] [talledLocalContainer] Caused by: javax.jcr.LoginException: Failed to borrow session from the pool. java.lang.IllegalArgumentException: interface org.hippoecm.hst.core.jcr.pool.PooledSession is not visible from class loader
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.BasicPoolingRepository.login(BasicPoolingRepository.java:350)
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.BasicPoolingRepository.login(BasicPoolingRepository.java:365)
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.LazyMultipleRepositoryImpl.login(LazyMultipleRepositoryImpl.java:189)
      [INFO] [talledLocalContainer] ... 5 more
      [INFO] [talledLocalContainer] Caused by: java.lang.IllegalArgumentException: interface org.hippoecm.hst.core.jcr.pool.PooledSession is not visible from class loader
      [INFO] [talledLocalContainer] at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:581)
      [INFO] [talledLocalContainer] at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:557)
      [INFO] [talledLocalContainer] at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:230)
      [INFO] [talledLocalContainer] at java.lang.reflect.WeakCache.get(WeakCache.java:127)
      [INFO] [talledLocalContainer] at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419)
      [INFO] [talledLocalContainer] at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:719)
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.util.ProxyFactory.createInterceptorProxy(ProxyFactory.java:52)
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.PooledSessionDecoratorProxyFactoryImpl.decorate(PooledSessionDecoratorProxyFactoryImpl.java:44)
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.BasicPoolingRepository$SessionFactory.makeObject(BasicPoolingRepository.java:1123)
      [INFO] [talledLocalContainer] at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1148)
      [INFO] [talledLocalContainer] at org.hippoecm.hst.core.jcr.pool.BasicPoolingRepository.login(BasicPoolingRepository.java:337)
      [INFO] [talledLocalContainer] ... 7 more

      Problem is related to ProxyFactory and current class loader from thread which is in case of JCR event listeners the CMS webapp classloader

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              aschrijvers Ard Schrijvers
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: