How to load a custom CharsetProvider when using Wildfly ?

225 views
Skip to first unread message

Olivier Masseau

unread,
Jun 27, 2023, 8:32:13 AM6/27/23
to WildFly
Hello,

My webapp (running on Wildfly 23) needs to support the utf-7 charset.
So I added jcharset.jar (https://www.freeutils.net/source/jcharset/) in my war libs folder next to all the other dependencies my app needs.

Problem:
The charset provider declared in jcharset.jar/META-INF/services/java.nio.charset.spi.CharsetProvider seems to be ignored by the classloader and I don't understand why.

Is there anything more I need to do to have it processed ?

JCharset doc says :
The Java Charset package is written in pure Java, runs on JDK 1.5 or later, and requires no special installation - just add the jar file to your classpath.

This works well for a standalone app but I cannot make it work for a webapp running on Wildfly.

Thanks for any help.




Scott Marlow

unread,
Jun 27, 2023, 8:50:20 AM6/27/23
to Olivier Masseau, WildFly

Hello,

Please see "services" under documentation link https://docs.wildfly.org/28/Developer_Guide.html#dependencies-manifest-entries which describes adding a jboss-deployment-structure.xml file to your deployment. 

Scott

--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/c9152bd5-eb07-49c4-b2bb-1229debd1f12n%40googlegroups.com.

Olivier Masseau

unread,
Jun 27, 2023, 10:41:31 AM6/27/23
to WildFly
Hello,

Thanks but the jcharset dependency is not a module but a simple jar embedded in our war libs folder.
As I understand manifest entries are only valid for module dependencies right ?

Olivier Masseau

unread,
Jun 27, 2023, 10:58:13 AM6/27/23
to WildFly
By the way I already tried to create a module containing the jar and declare a dependency on it in jboss-deployment-structure.xml :
<module name="com.mymodule" services="import"/>
But the charset provider implementation declared in jcharset META-INF/services is still ignored.

Emmanuel Hugonnet

unread,
Jun 27, 2023, 12:17:17 PM6/27/23
to Olivier Masseau, WildFly
I think that the issue is that this service needs to be discovered and loaded by the jvm.
So I think it should be defined as a global module:

Try to modify /bin/standalone.conf, /search for JBOSS_MODULES_SYSTEM_PKGS and modify it accordingly.

if [ "x$JBOSS_MODULES_SYSTEM_PKGS" = "x" ]; then

JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,net.freeutils.charset"

fi

and create a net.freeutils.charset module

Le 27/06/2023 à 16:58, Olivier Masseau a écrit :
> By the way I already tried to create a module containing the jar and declare a dependency on it in jboss-deployment-structure.xml :
> <module name="com.mymodule" services="import"/>
> But the charset provider implementation declared in jcharset META-INF/services is still ignored.
> Le mardi 27 juin 2023 à 16:41:31 UTC+2, Olivier Masseau a écrit :
>
> Hello,
>
> Thanks but the jcharset dependency is not a module but a simple jar embedded in our war libs folder.
> As I understand manifest entries are only valid for module dependencies right ?
>
> Le mardi 27 juin 2023 à 14:50:20 UTC+2, Scott Marlow a écrit :
>
> Hello,
>
> Please see "services" under documentation link https://docs.wildfly.org/28/Developer_Guide.html#dependencies-manifest-entries
> which describes adding a jboss-deployment-structure.xml file to your deployment.
>
> Scott
>
> On 6/27/23 8:32 AM, Olivier Masseau wrote:
>> Hello,
>>
>> My webapp (running on Wildfly 23) needs to support the utf-7 charset.
>> So I added jcharset.jar (https://www.freeutils.net/source/jcharset/) in my war libs folder next to all the other dependencies my
>> app needs.
>>
>> Problem:
>> The charset provider declared in *jcharset.jar/META-INF/services/java.nio.charset.spi.CharsetProvider* seems to be ignored by the
>> classloader and I don't understand why.
>>
>> Is there anything more I need to do to have it processed ?
>>
>> JCharset doc says :
>> /The Java Charset package is written in pure Java, runs on JDK 1.5 or later, and requires no special installation - just add the
>> jar file to your classpath./
>>
>> This works well for a standalone app but I cannot make it work for a webapp running on Wildfly.
>>
>> Thanks for any help.
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "WildFly" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/wildfly/c9152bd5-eb07-49c4-b2bb-1229debd1f12n%40googlegroups.com
>> <https://groups.google.com/d/msgid/wildfly/c9152bd5-eb07-49c4-b2bb-1229debd1f12n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google Groups "WildFly" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wildfly/c18cbdc2-ce08-487d-8de4-55c9ffd13a2an%40googlegroups.com
> <https://groups.google.com/d/msgid/wildfly/c18cbdc2-ce08-487d-8de4-55c9ffd13a2an%40googlegroups.com?utm_medium=email&utm_source=footer>.

Richard Opalka

unread,
Jun 27, 2023, 12:29:08 PM6/27/23
to Olivier Masseau, WildFly
Hello Olivier,

   The information you provided is not sufficient.
How are you looking up UTF-7 charset provider in your code?
Could you share a snippet of code that works for you on a regular java classpath but doesn't in the WildFly web app?

Richard

Olivier Masseau

unread,
Jun 28, 2023, 4:39:43 AM6/28/23
to WildFly
Hello,

Just a simple line like this :

"test".getBytes("UTF-7") ;

is enough to test if it is working or not ;)

Standalone app -> No error.
Webapp on Wildfly -> java.io.UnsupportedEncodingException

Olivier Masseau

unread,
Jun 28, 2023, 4:46:51 AM6/28/23
to WildFly
Thanks a lot,

Indeed it seems Charset providers can only be discovered by the jvm system class loader and not the current thread's context class loader.
Apperently it is a known bug specific to CharsetProvider that has never been fixed :

Having discovered this I've found a solution by copying the jar on the server file system  and adding this to JAVA_OPTS in standalone.conf :

-Xbootclasspath/a:<Path_to_charset_provider_jar>
Reply all
Reply to author
Forward
0 new messages