Can't use slf4j on hosted mode

95 views
Skip to first unread message

Célio

unread,
Apr 13, 2009, 10:34:40 AM4/13/09
to Google Web Toolkit
I have just migrated our gwt app from 1.5 to 1.6. Everything is fine
except that slf4j classes can't be loaded on hosted mode. We actually
use slf4j in our web app to log our own stuff. The problem is that
the hosted mode class loader don't allow server classes to be loaded
from the outside world. It checks the class name against a list of
server classes that jetty hard-codes somewhere, and that list contains
the org.slf4f package.

WebAppClassLoaderExtension.findClass(String name) {
@Override
protected Class<?> findClass(String name) throws
ClassNotFoundException {
...
// Don't allow server classes to be loaded from the outside.
if (isServerPath(name)) {
throw e;
}
...
}
}

isServerPath is defined by the subclass:

public class WebAppClassLoader
{
public boolean isServerPath(String name)
{
...
String[] server_classes = _context.getServerClasses();
// if the name is in the list, return true (basically).
}

Where _context is a:

public class WebAppContext extends Context
{
...
private String[] _serverClasses = {"-
org.mortbay.jetty.plus.jaas.", "org.mortbay.jetty.", "org.slf4j."};
// TODO
hide all mortbay classes
...
public String[] getServerClasses()
{
return _serverClasses;
}
}


Does anybody know how to workaround this issue?

Cheers,

Célio

Célio

unread,
Apr 13, 2009, 2:58:44 PM4/13/09
to Google Web Toolkit
Solved.

If you need to use slf4j in your server classes, you must "promote"
slf4j classes to system classes. You do that by configuring the
WebAppContext just like this:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="systemClasses">
<Array type="java.lang.String">

<!-- we copied these paths from jetty WebAppContext source code ...
-->
<Item>java.</Item>
<Item>javax.servlet.</Item>
<Item>javax.xml.</Item>
<Item>org.mortbay.</Item>
<Item>org.xml.</Item>
<Item>org.w3c.</Item>
<Item>org.apache.commons.logging.</Item>
<Item>org.apache.log4j.</Item>

<!-- and ... added slf4j -->
<Item>org.slf4j.</Item>

<!-- we must promote slf4j to system classes, otherwise gwt
hosted mode will not allow loading them due to a policy
that don't allow server classes to be loaded from the
outside world (see gwt JettyLauncher source code). -->

</Array>
</Set>
</Configure>

You should put this file at /war/WEB-INF/jetty-web.xml. For more
information, see http://docs.codehaus.org/display/JETTY/jetty-web.xml

Cheers,

Célio
Reply all
Reply to author
Forward
0 new messages