5 Replies Latest reply on Jul 15, 2016 4:56 AM by Миша Мишин

    Specifying an additional Charset provider (javamail)

    compileall Newbie

      Hello,

      I'm using Java Mail to read messages through IMAP.

      One of these messages has a problem in its content that's causing JavaMail to throw an UnsupportedEncodingException.

      The problem lies in the fact that one of the parts contained in the message declares this content type:

      Content-type: TEXT/HTML; charset=""

      and JavaMail fails with that empty charset.

       

      Reading on the JavaMail FAQs it seems that providing a custom charset provider could do the trick.

      That's a two step approach:

      1. declare a class that extends CharsetProvider;
      2. create the file META-INF/services/java.nio.charset.spi.CharsetProvider and write the name of that custom class in it (I entered it with the full package).

      In fact, I did what the FAQs prescribe and I finally managed to make it work on Tomcat within my Eclipse IDE, adding my custom jar to the classpath in Tomcat launch configuration.

      That has been the only way so that the JVM (?, or the java library?) could see the file in META-INF and load my custom class, there was no other place where I tried putting that jar that made it work.

       

      As my production server is JBoss, I tried to apply the same solution on it.

      But so far I failed; here's what I've attemped:

      • create a module, as in the current module system, and declare it as a dependency of my war;
      • create a global module, like it is suggested here: https://docs.jboss.org/author/display/AS7/Developer+Guide#DeveloperGuide-GlobalModules
      • put the jar with my custom class in jboss main directory, close to jboss-modules.jar - in this case the jar gets indexed, meaning a .index file is created;
      • change standalone.bat adding -cp ".;%JBOSS_HOME%\myjarfile.jar" around :RESTART, where the java executable is launched;
      • add the jar on the -mp parameter

      None of the above worked.

       

      For completeness, I found these two pages:

       

      As a final note, I'm on Windows Server 2003, running JBoss as standalone (no matter if it's started as a service or by direct invocation of standalone.bat).