Class ClassloaderSwitcherInterceptor

  • All Implemented Interfaces:
    org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

    public class ClassloaderSwitcherInterceptor
    extends Object
    implements org.aopalliance.intercept.MethodInterceptor

    This interceptor changes the thread context classloader to the class' current classloader.

    We need this because of the ConversionServiceConverterManager which was introduced in spring-security-2.0.0.

    This manager uses ClassUtils.getDefaultClassLoader() which creates new class instance using thread context classloader which differs from the current classloader of the caller class:

    • thread context classloader is the org.apache.activemq.activemq-osgi
    • current classloader is the spring's WebappClassLoader
    When ConversionServiceConverterManager tries to cast clazz.newInstance() to the GenericConversionService it throws ClassCastException if the context classloader hadn't changed.

    That's why we need to proxy all classes which might use the ConversionServiceConverterManager.

    Andrei Abramov
    • Constructor Detail

      • ClassloaderSwitcherInterceptor

        public ClassloaderSwitcherInterceptor()
    • Method Detail

      • invoke

        public Object invoke​(org.aopalliance.intercept.MethodInvocation invocation)
                      throws Throwable
        Specified by:
        invoke in interface org.aopalliance.intercept.MethodInterceptor