Hello all,
when I try to use an own SSLSocketFactory with JavaMail (like described in SSLNOTES.txt), I'm getting a ClassNotFoundException when I try to connect.
I'm trying to run the code within a Web-App in a Tomcat Servlet-Container. I debugged it via remote-debugging in Eclipse:
First important thing:
java.security.Security.setProperty("ssl.SocketFactory.provider",
"de.lotk.yawebmail.business.YawebmailSSLSocketFactory");
Then I have a breakpoint here:
this.store.connect(this.loginData.getMailboxHost(),
this.loginData.getMailboxPort(), this.loginData.getMailboxUser(),
this.loginData.getMailboxPassword());
When the debugger reaches this breakpoint, I do this within the "Display"-View of Eclipse (it runs code within the current thread of the breakpoint-holded code):
java.security.Security.getProperty("ssl.SocketFactory.provider");
(java.lang.String) de.lotk.yawebmail.business.YawebmailSSLSocketFactory
Class.forName("de.lotk.yawebmail.business.YawebmailSSLSocketFactory").getName();
(java.lang.String) de.lotk.yawebmail.business.YawebmailSSLSocketFactory
So my Class is found, isn't it?
Now I go on with the Debugger. The "connect"-method throws an MessagingException:
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.SocketException: java.lang.ClassNotFoundException: de.lotk.yawebmail.business.YawebmailSSLSocketFactory
There seems to be a ClassLoader-problem... (again: The class is definitely present within my Webapp and can be found via Class.forName()).
Other people seem to have the same problem:
http://www.javaworld.com/javaforums/showflat.php?Cat=2&Board=javabeginner&Number=11720&page=15&view=collapsed&sb=5&o=&fpart=1
-> see post of "_GeorgeP_" (his solution is not an option for me)
In the sourcecode of the class "com.sun.mail.pop3.POP3Store" I can see that ClassLoader-Problems seem to be a familiar problem in JavaMail:
try {
ClassLoader cl = this.getClass().getClassLoader();
// now load the class
Class messageClass = null;
try {
// First try the "application's" class loader.
// This should eventually be replaced by
// Thread.currentThread().getContextClassLoader().
messageClass = cl.loadClass(s);
} catch (ClassNotFoundException ex1) {
// That didn't work, now try the "system" class loader.
// (Need both of these because JDK 1.1 class loaders
// may not delegate to their parent class loader.)
messageClass = Class.forName(s);
}
Could it be that such a (may I call it) "hack" would be appropriate within the "connect"-method, too??
Thanks a lot in advance for any hint...
Best regards
Stephan