This content has been marked as final. Show 8 replies
Most likely Tomcat is not setting the thread's context class loader correctly,1 person found this helpful
causing the JAF implementation in JDK 6 to be unable to find the mailcap
configuration file in the mail.jar file. There are two workarounds:
1. Put the mail.jar file in Tomcat's lib directory instead of in the application.
2. Re: Error running SendMail when launch application from JNI
The first variant didn't work for me.
When I put such string you mentioned in second variant in my servlet listener which initializes the application it didn't work, but when I put it to my class which deals with emails it work.
But I found another interesting issue.
When I run my application everything works fine on first iteration. According to my code I get default instance of Session, get Store, get Folder and at last getMessages. After processing messages I close folder and store.
But if I don't restart my application and try to get messages again all of the SAME messages became plain (SharedByteArrayInputStream) again (as it was earlier).
If I restart my application first iteration works fine and others fails.
In both iterations used the same instance of class where I put Thread.currentThread().setContextClassLoader(BaseEmailService.class.getClassLoader());
What I must reinitialize to make it works on each iteration?
If you print out the class loader, is it the same value on both cases? If so, I have no idea what's wrong.
If not, check to make sure the workaround code is being executed in both cases.
Output of the classloader is overriden and doesn't answer on question if there are the same. But System.identityHashCode returns the same value in these two cases and when I try to save the instance of the first class loader and then compare to second using == it returns true. So I realized that classloaders are the same.
But problem is still exists ((
I don't understand why it would work once and not again.
First request to tomcat is being processed by thread which works correctly. If second request is being processed by the same thread it also works correctly. But if it is being handled by another thread the issue as I mentioned above appears.
If I put workaround line in the first line of MY! code wich thread executes everithing works fine. But If I put this line in the first line of method of the second class involved in processing (but knows nothing about emails) it doesn't work.
My class which deals with email is fifth in processing queue and of cource it doesn't work either (I mean works only on first iteration).
You're setting the context class loader for the thread, so you need to be sure to put it in
a place where it will be done for every thread.