wisdom-framework / wisdom

A modular and dynamic web framework
http://wisdom-framework.org
Apache License 2.0
88 stars 42 forks source link

ClassNotFoundException sl4j.loggerfactory is thrown when using net.shibboleth.utilities:java-support #526

Closed hboumedane closed 9 years ago

hboumedane commented 9 years ago

Hello,

I have an opensaml dependency in my wisdom project and when i try to use opensaml I got this exception :

java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_40]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_40]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_40]
        at org.opensaml.xml.security.credential.KeyStoreCredentialResolver.<init>(KeyStoreCredentialResolver.java:48) ~[xmltooling-1.3.2-1.jar:na]
        at org.opensaml.xml.security.credential.KeyStoreCredentialResolver.<init>(KeyStoreCredentialResolver.java:68) ~[xmltooling-1.3.2-1.jar:na]

opensaml it's not an OSGI bundle so I used it like this :

 <plugin>
                <groupId>org.wisdom-framework</groupId>
                <artifactId>wisdom-maven-plugin</artifactId>
                <version>0.9.1</version>
                <extensions>true</extensions>
                <configuration>
                    <!-- Defines the set of 'libraries' -->
                    <libraries>
                        <includes>
                            <include>:opensaml</include>
                        </includes>
                        <resolveTransitive>true</resolveTransitive>
                        <excludeFromApplication>false</excludeFromApplication>
                    </libraries>
                </configuration>
            </plugin>

I don't understand why i got this exception because the slf4j is already in the classpath ??

barjo commented 9 years ago

There is a bundle version of opensaml made by apache service mix:

<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.opensaml</artifactId>
    <version>3.1.0_1</version>
</dependency>

<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.opensaml</artifactId>
    <version>2.6.5_2</version>
</dependency>
hboumedane commented 9 years ago

thanks a lot, will try this and let you know if it work

hboumedane commented 9 years ago

thanks jonathan, you can close this issue, I will use the 3.1.0_1 of the bundle.

barjo commented 9 years ago

Ok :)

hboumedane commented 9 years ago

sorry to re-open this but still got the same exception but now when using another non OSGI lib

        <dependency>
            <groupId>net.shibboleth.utilities</groupId>
            <artifactId>java-support</artifactId>
            <version>7.1.1</version>
        </dependency>

i didn't found a bundle for this lib...

barjo commented 9 years ago

Since it's a classloader issue, you can try to switch the classloader.

ClassLoader loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
try {
  // execute the code that cause the issue
} finally {
  Thread.currentThread().setContextClassLoader(loader);
}
hboumedane commented 9 years ago

here what I did

final ClassLoader original = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(BasicParserPool.class.getClassLoader());
            // the code using the library.
            final SAML2ClientConfiguration cfg = new SAML2ClientConfiguration(keystore.getPath(),
                    "**********",
                    "**********",
                    metadata.getPath());
            SAML2Client saml2Client = new SAML2Client(cfg);

            final Clients clients = new Clients("http://localhost:9000/callback", saml2Client); // , casProxyReceptor);
            Config.setClients(clients);
        } finally {
            Thread.currentThread().setContextClassLoader(original);
        }

and still got the same exception, I'm out if idea. i don't understand why it's not founding the log4j because this lib is provided by bundle 0.

barjo commented 9 years ago

Can you provide the stack trace? and try:

Thread.currentThread().setContextClassLoader(SAML2Client.class.getClassLoader());
barjo commented 9 years ago

There is maybe a version conflict, the class org.slf4j.LoggerFactory required by java-support/SAML2Client is maybe not the same version as the one provided by the bundle 0?

hboumedane commented 9 years ago

here the stack trace for Thread.currentThread().setContextClassLoader(SAML2Client.class.getClassLoader());

[ERROR]  o.o.u.l.i.o.LoggerService {[iPOJO] pool-1-thread-1} - [ERROR]  : [sample.SecurityConfig-0] The callback method start has thrown an exception : org/slf4j/LoggerFactory 
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at net.shibboleth.utilities.java.support.xml.BasicParserPool.<init>(BasicParserPool.java:82) ~[java-support-7.1.1.jar:na]
    at org.pac4j.saml.util.Configuration.bootstrap(Configuration.java:53) ~[na:na]
    at org.pac4j.saml.util.Configuration.<clinit>(Configuration.java:49) ~[na:na]
    at org.pac4j.saml.client.SAML2Client.<clinit>(SAML2Client.java:105) ~[na:na]
    at sample.SecurityConfig.__M_registerClient(SecurityConfig.java:47) ~[na:na]
    at sample.SecurityConfig.registerClient(SecurityConfig.java) ~[na:na]
    at sample.SecurityConfig.__M_start(SecurityConfig.java:59) ~[na:na]
    at sample.SecurityConfig.start(SecurityConfig.java) ~[na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
    at org.apache.felix.ipojo.util.Callback.call(Callback.java:237) ~[org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.util.Callback.call(Callback.java:193) ~[org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86) ~[org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:162) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:560) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:440) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114) [org.apache.felix.ipojo-1.12.1.jar:na]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_40]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_40]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_40]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_40]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_40]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_40]
hboumedane commented 9 years ago

the SAML2Client require logback-classic version 1.0.7 but i did exculded from being loaded and still got the exception !!

barjo commented 9 years ago

You exclude it from the wisdom-maven-plugin configuration right?

hboumedane commented 9 years ago

no from the pom.xml like that :

        <dependency>
            <groupId>org.pac4j</groupId>
            <artifactId>pac4j-saml</artifactId>
            <version>1.8.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

this dependency is a bundle

barjo commented 9 years ago

In the wisdom-maven-plugin ? by any chance.

  <configuration>
    <libraries>
      <includes>
        <include>:java-support</include>
      </includes>
      <resolveTransitive>true</resolveTransitive>
      <excludeFromApplication>true</excludeFromApplication>
      <excludes>
        <exclude>:guava</exclude>
        <exclude>:logback-classic</exclude>
        <exclude>:logback-core</exclude>
        <exclude>:httpclient</exclude>
        <exclude>:httpcache</exclude>
        <exclude>:velocity</exclude>
        <exclude>:bcpkix-jdk15on</exclude>
        <exclude>:bcpkix-bcprov-jdk15on</exclude>
      </excludes>
    </libraries>
  </configuration>
hboumedane commented 9 years ago

will let you know tommorow and thanks for the help

hboumedane commented 9 years ago

after testing with switching the classloader and the option above i got the same exception :

        final ClassLoader original = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(SAML2Client.class.getClassLoader());
            // your code using the library.
            final SAML2ClientConfiguration cfg = new SAML2ClientConfiguration(keystore.getPath(),
                    "**********",
                    "**********",
                    metadata.getPath());
            SAML2Client saml2Client = new SAML2Client(cfg);

            final Clients clients = new Clients("http://localhost:9000/callback", saml2Client); // , casProxyReceptor);
            Config.setClients(clients);
        } finally {
            Thread.currentThread().setContextClassLoader(original);
        }

and

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at net.shibboleth.utilities.java.support.xml.BasicParserPool.<init>(BasicParserPool.java:82) ~[java-support-7.1.1.jar:na]
    at org.pac4j.saml.util.Configuration.bootstrap(Configuration.java:53) ~[na:na]
    at org.pac4j.saml.util.Configuration.<clinit>(Configuration.java:49) ~[na:na]
    at org.pac4j.saml.client.SAML2Client.<clinit>(SAML2Client.java:105) ~[na:na]
    at sample.SecurityConfig.__M_registerClient(SecurityConfig.java:47) ~[na:na]
    at sample.SecurityConfig.registerClient(SecurityConfig.java) ~[na:na]
    at sample.SecurityConfig.__M_start(SecurityConfig.java:59) ~[na:na]
    at sample.SecurityConfig.start(SecurityConfig.java) ~[na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
    at org.apache.felix.ipojo.util.Callback.call(Callback.java:237) ~[org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.util.Callback.call(Callback.java:193) ~[org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallback.call(LifecycleCallback.java:86) ~[org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:162) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:560) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:440) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:312) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.extender.internal.linker.ManagedType$InstanceSupport$1.call(ManagedType.java:306) [org.apache.felix.ipojo-1.12.1.jar:na]
    at org.apache.felix.ipojo.extender.internal.queue.JobInfoCallable.call(JobInfoCallable.java:114) [org.apache.felix.ipojo-1.12.1.jar:na]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_40]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_40]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_40]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]

and for the info if I set this in the wisdom-maven-plugin

<excludeFromApplication>true</excludeFromApplication>

my app dosen't wrok at all and if I set it to false at least i can access the monitor.

barjo commented 9 years ago

Have you try without switching the class loader in that case, and also adding an explicit dependency to slf4j. If nothing workout, I will try to reproduce a similar project and figure out something, maybe creating a bundle for java-support. But it won't be before this weekend.

barjo commented 9 years ago

I usually always have a dependency:

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
</dependency>
hboumedane commented 9 years ago

I tried with not switching the classloader and with and dependency

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
</dependency>

and still got the same exception

barjo commented 9 years ago

@hboumedane uhmm I haven't received anything.

hboumedane commented 9 years ago

@barjo : did you looked at the private mail :-)

barjo commented 9 years ago

It has been solved by embedded java-support into pac4j-saml.