This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes IMAP /TLS standalone programm works fine, in Tomcat fails. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "IMAP /TLS standalone programm works fine, in Tomcat fails." Watch "IMAP /TLS standalone programm works fine, in Tomcat fails." New topic
Author

IMAP /TLS standalone programm works fine, in Tomcat fails.

P Chaudhari
Greenhorn

Joined: Mar 22, 2004
Posts: 22
Hi All,

I have a IMAP4 server running with TLS authentication switched on and have self signed certificate. do not want toinstall certificates so I tried DummySSLSocketFactory and DummyTrustManager provided by SUN.

Standalone programm works correctly. Please see code below. But If I put the code into Tomcat throws exception. Any clue?

private void receiveEmails() throws NoSuchProviderException, MessagingException, IOException {
// String host, name, passwd;
String host = "HOST_NAME";
String name = "USER_ID";
String passwd = "PASSWORD";
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
java.security.Security.setProperty("ssl.SocketFactory.provider", "DummySSLSocketFactory");
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.imap.socketFactory.fallback", "false");
props.setProperty("mail.imap.starttls.enable", "true");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
Store store = session.getStore("imap");
try {
store.connect(host, name, passwd); // exception here
System.out.println("store connected");
} catch (Exception e) {
// System.out.println("Error :" + e.toString());
e.printStackTrace();
System.exit(1);
}
}
---------------------------------------------------------------------------------------------

Inside Tomcat :- Same code in tomcat throws exception. Also it does not give call to DummySSLSocketFactory.

Code and Exception.

public void doExecute(JobExecutionContext context) {
String host = "lxeext12.deutsche-boerse.de";
String name = "capacity";
String passwd = "capacity";
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Security.setProperty("ssl.SocketFactory.provider", com.deutscheboerse.comxerv.common.service.timer.DummySSLSocketFactory.class.getName());
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.imap.socketFactory.fallback", "false");
props.setProperty("mail.imap.starttls.enable", "true");

try {
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Store store = session.getStore("imap");
store.connect(host, name, passwd); // exception here
System.out.println("store connected");
}catch (Exception e) {
e.printStackTrace();
}
}



javax.mail.MessagingException: * BYE JavaMail Exception: java.net.SocketException: Socket closed;
nested exception is:
com.sun.mail.iap.ProtocolException: * BYE JavaMail Exception: java.net.SocketException: Socket closed
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:477)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)


--------------------------------------------------------------------------------

If I change the bold marked line below then.

public void doExecute(JobExecutionContext context) {
String host = "lxeext12.deutsche-boerse.de";
String name = "capacity";
String passwd = "capacity";
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.imap.socketFactory.class", com.deutscheboerse.comxerv.common.service.timer.DummySSLSocketFactory.class.getName());
props.setProperty("mail.imap.socketFactory.fallback", "false");
props.setProperty("mail.imap.starttls.enable", "true");

try {
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Store store = session.getStore("imap");
store.connect(host, name, passwd); // exception here
}catch (Exception e) {
e.printStackTrace();
}
}


- It calls the DummySSLSocketFactory but throws following exception.

Exception is:-
javax.mail.MessagingException: Unrecognized SSL message, plaintext connection?;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connecti
on?
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(S
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IMAP /TLS standalone programm works fine, in Tomcat fails.
 
Similar Threads
unknown host exception error
Problem using Java Mail API
proxy problem
javamail,No login methods supported exception
IMAP/TLS Problem in connecting using java mail api.