You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joonas Koivunen <jo...@gmail.com> on 2009/02/18 12:10:18 UTC

Using custom Charset's through CharsetProvider SPI in webapps not working

Hi everyone,

In my application I need to use a library that requires two custom
Charset implementations which are delivered in a jar, with proper SPI
meta information (META-INF/services/...). It works under Eclipse when
doing unit-tests.

This all is using Apache Tomcat 6.0.18, under Sun Java 1.6.0_07, Linux
2.6 (Kubuntu 8.04.2).

I've included the encoding-library jar in $WEBAPP/WEB-INF/lib, and
when I delpoy my webapp, an ExceptionInInitializerError is thrown as
one of the classes statically references the charset (private static
final Charset DEFAULT_CHARSET = Charset.forName("...");).

However when I test this with custom ServletContextListener [1] it is
able to find my custom Charset-implementations.

Looking at OpenJDK6 java.nio.charset.Charset implementation it's
"private static Charset lookupviaProviders(final String charsetName)"
does the lookup using
java.security.AccessController.doPriviledged(PriviledgedAction<T>).
It's priviledged action seems to always create a new anonymous class
instance that wraps ServiceLoader.load(CharsetProvider.class,
cl).iterator() and iterate it until it's exhausted or a charset is
found...

I guess the System's ClassLoader cannot see the webapp's libraries at
all? Or is this a fault in Tomcat's webapp -classloader, not exposing
SPI meta information?

This question has been brought up before; by Christoph Kutzinski in
2005 [2], but was left unanswered.

Is it impossible to have webapps that benefit from SPIs and custom
charset-implementations?

1 = http://www.rifers.org/paste/show/8801
2 = http://marc.info/?l=tomcat-user&m=111927941225330&w=2

-- 
-- Joonas Koivunen

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Using custom Charset's through CharsetProvider SPI in webapps not working

Posted by Mark Thomas <ma...@apache.org>.
Joonas Koivunen wrote:
> I guess the System's ClassLoader cannot see the webapp's libraries at
> all?
Correct.

> Or is this a fault in Tomcat's webapp -classloader, not exposing
> SPI meta information?
Unlikely.

> Is it impossible to have webapps that benefit from SPIs and custom
> charset-implementations?
It will depend on how the extension is loaded. In the case of Charset,
it looks like it isn't going to work.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org