classnotfound when POP3s account connected to before IMAPs account

I have implemented the DummySSLSocketFactory stuff for handling unsinged certs on POP3s ser vers and it works fine, However is I connect to one of these servers before connecting to an IMAPs server I get the following error:

javax.mail.MessagingException: java.lang.ClassNotFoundException: com.cc.util.controller.email.DummySSLSocketFactory;

nested exception is:

java.net.SocketException: java.lang.ClassNotFoundException: com.cc.util.controller.email.DummySSLSocketFactory

at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)

at javax.mail.Service.connect(Service.java:275)

at javax.mail.Service.connect(Service.java:156)

at com.cc.util.controller.email.JavaMailEmailController.getJavaMailStoreIMAPS(JavaMailEmailController.java:203)

at com.cc.util.controller.email.JavaMailEmailController.getJavaMailStore(JavaMailEmailController.java:173)

at com.cc.util.controller.email.JavaMailEmailController.<init>(JavaMailEmailController.java:88)

at com.cc.util.controller.email.IMAPEmailController.<init>(IMAPEmailController.java:20)

at com.cc.util.controller.ControllerFactory.getEmailController(ControllerFactory.java:151)

at com.cc.util.controller.ControllerFactory.verifyLoginInformation(ControllerFactory.java:72)

at com.cc.util.discovery.DiscoveryService.discoverIMAPService(DiscoveryService.java:277)

at com.cc.util.discovery.DiscoveryService.checkEmailService(DiscoveryService.java:101)

at com.cc.applet.CCNonBlockingThread$1.run(CCNonBlockingThread.java:205)

at java.security.AccessController.$$YJP$$doPrivileged(Native Method)

at java.security.AccessController.doPrivileged(Unknown Source)

at com.cc.applet.CCNonBlockingThread.processEventData(CCNonBlockingThread.java:203)

at com.cc.applet.CCNonBlockingThread.run(CCNonBlockingThread.java:154)

Caused by: java.net.SocketException: java.lang.ClassNotFoundException: com.cc.util.controller.email.DummySSLSocketFactory

at javax.net.ssl.DefaultSSLSocketFactory.throwException(Unknown Source)

at javax.net.ssl.DefaultSSLSocketFactory.createSocket(Unknown Source)

at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:224)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)

at com.sun.mail.iap.Protocol.<init>(Protocol.java:84)

at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:87)

at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:446)

... 15 more

Caused by: java.lang.ClassNotFoundException: com.cc.util.controller.email.DummySSLSocketFactory

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.$$YJP$$doPrivileged(Native Method)

at java.security.AccessController.doPrivileged(Unknown Source)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at javax.net.ssl.SSLSocketFactory.getDefault(Unknown Source)

... 20 more

If the I reverse it, connect to IMAPs first and then to POP3s it works fine. I assume that this has to do with this code:

// the line below is for java 1.5

java.security.Security.setProperty("ssl.SocketFactory.provider","com.cc.util.controller.email.DummySSLSocketFactory");

// these are for java 1.4

props.setProperty("mail.pop3s.socketFactory.class","com.cc.util.controller.email.DummySSLSocketFactory");

props.setProperty("mail.pop3s.socketFactory.fallback","false");

which I do before connecting to the POP3s service. In this case the connection being made to POP3s comes from a different thread than the connection to the IMAPs. Everything is in a single jar and this is an applet. I'm confused as to why it can't find the class after it has already found it. I mean at the root the threads should all have the same class loader shouldn't they?

[4305 byte] By [zparticlea] at [2007-11-27 9:49:49]
# 1

If I remove the socket factory code everything works but then I can't to a server with a self signed certificate. So I tried this for imaps:

// the line below is for java 1.5

java.security.Security.setProperty("ssl.SocketFactory.provider","javax.net.ssl.SSLSocketFactory");

// these are for java 1.4

props.setProperty("mail.imaps.socketFactory.class","javax.net.ssl.SSLSocketFactory");

props.setProperty("mail.imaps.socketFactory.fallback", "false");

but that gives me this error:

javax.mail.MessagingException: java.lang.InstantiationException;

nested exception is:

java.net.SocketException: java.lang.InstantiationException

at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)

at javax.mail.Service.connect(Service.java:275)

at javax.mail.Service.connect(Service.java:156)

at com.cc.util.controller.email.JavaMailEmailController.getJavaMailStoreIMAPS(JavaMailEmailController.java:190)

at com.cc.util.controller.email.JavaMailEmailController.getJavaMailStore(JavaMailEmailController.java:153)

at com.cc.util.controller.email.JavaMailEmailController.<init>(JavaMailEmailController.java:86)

at com.cc.util.controller.email.IMAPEmailController.<init>(IMAPEmailController.java:20)

at com.cc.util.controller.ControllerFactory.getEmailController(ControllerFactory.java:151)

at com.cc.util.controller.ControllerFactory.verifyLoginInformation(ControllerFactory.java:72)

at com.cc.util.discovery.DiscoveryService.discoverIMAPService(DiscoveryService.java:284)

at com.cc.util.discovery.DiscoveryService.checkEmailService(DiscoveryService.java:101)

at com.cc.applet.CCNonBlockingThread$1.run(CCNonBlockingThread.java:205)

at java.security.AccessController.$$YJP$$doPrivileged(Native Method)

at java.security.AccessController.doPrivileged(Unknown Source)

at com.cc.applet.CCNonBlockingThread.processEventData(CCNonBlockingThread.java:203)

at com.cc.applet.CCNonBlockingThread.run(CCNonBlockingThread.java:154)

Caused by: java.net.SocketException: java.lang.InstantiationException

at javax.net.ssl.DefaultSSLSocketFactory.throwException(Unknown Source)

at javax.net.ssl.DefaultSSLSocketFactory.createSocket(Unknown Source)

at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:222)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:163)

at com.sun.mail.iap.Protocol.<init>(Protocol.java:84)

at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:87)

at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:446)

... 15 more

zparticlea at 2007-7-13 0:18:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
I have no idea why the order in which you connect to the servers would matter.What version of the JRE are you using in your applet container?If your applet container is using 1.4 and your classes are compiledfor 1.5, that might explain some of your problems.
bshannona at 2007-7-13 0:18:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
we compile with 1.4.2 and I'm running under 1.6
zparticlea at 2007-7-13 0:18:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...