This content has been marked as final. Show 8 replies
Most likely Tomcat is not setting the thread's context class loader correctly,
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
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?
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 ((
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).