Tuesday, August 31, 2010

Using slf4j in hosted mode :

Hi,

I've had difficulties to use slf4j in Hosted mode. This post (http://
groups.google.com/group/google-web-toolkit/browse_thread/thread/
ca28213d01632087/74f8cf4628f84eda?lnk=gst&q=slf4j#74f8cf4628f84eda
)
helped me, but I stlil have a problem with this :

The solution described works, and solved the problem, but it
reappeared after I added some slf4j logging to a ContextListener,
which is declared in the web.xml..

Here is what I found :


Jetty uses several configuration ojbects to configure the
WebAppContext. Among these, 2 are important regarding this issue :

The WebXmlConfiguration, which loads the Listener classes, and
instantiates Listeners,
The JettyWebXmlConfiguration, which loads the jetty-web.xml

As you can see here :http://jetty.codehaus.org/jetty/jetty-6/apidocs/
org/mortbay/jetty/webapp/Configuration.html
, the Configuration
interface has several methods. 2 of them are interesting here : void
configureClassLoader() and configureWebApp()

The startup code for the WebAppContext (at least in version 6.1.11,
which is embedded in gwt-dev-2.0.3) calls configureClassKLoader() for
each configuration, and later, calls configureWebApp()

But here : http://jetty.codehaus.org/jetty/jetty-6/apidocs/org/mortbay/jetty/webapp/JettyWebXmlConfiguration.html,
you can see that configureClassLoader() is not used in
JettyWebXmlConfiguration : the ClassLoader modification (using
serverClasses and SystemClasses as specified in the jety-web.xml
file) is performed in configureWebApp().

The loading order of configurations seems to be set directly in the
code in WebAppContext (a private static field called
_dftConfigurationClasses) : the WebXmlConfiguration is loaded BEFORE
jettyWebXmlConfiguration.

So, event if we promote slf4j to system classes, as our listener is
loaded by the WebXmlConfiguration before slf4j is promoted to system
classes by JettyWebXmlConfiguration, it fails with a
ClassNotFoundExcepton

As we have 2 web.xml (one in src/main/webapp and another one in src/
test/weapp for DevMode) we managed to find a workaround by creating 2
differents Listeners, with loggin methods, calling either a slf4j
logger, or System.out.println....But this is quite ugly.

I searched the Jetty issue management for comments about this, but I
found nothing. I don't know if there is a way to tune the way Jetty
loads its configurations, or if a new version solves this problem : I
don't really have much time to do that right now...

If someone knows a way to use slf4j in WebAppListeners, without having
to add slf4j jars somewhere (we want to use our Maven dependency
management), I'll be very hapy to learn about it!

Etienne Lacazedieu

PS : excuse my english! :)

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment