我已在Keystore中添加了证书,我正在尝试使用Java代码连接到电子邮件交换服务器。当我连接它时抛出异常。
当我在eclipse中执行相同的Java代码时,同样的事情工作正常,但是当我执行相同的服务失败时失败。
这是我的代码:
public static void getEmailConnection(String folder){
try{
Store store = null;
Properties properties = System.getProperties();
Folder emailFolder = null;
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
String host = "HOST NAME";
String username = "username";// change accordingly
String password = "password";// change accordingly
String mailStoreType = "pop3";
String port = "1234";
//Set manual Properties
properties.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
properties.setProperty("mail.pop3.socketFactory.fallback", "false");
properties.setProperty("mail.pop3.socketFactory.port", port);
properties.setProperty("mail.store.protocol", mailStoreType);
properties.setProperty("mail.pop3.host", host);
properties.setProperty("mail.pop3.port", port);
Session emailSession = Session.getDefaultInstance(properties);
//create the POP3 store object and connect with the pop server
store = emailSession.getStore("pop3");
store.connect(host,1234,username, password);
emailFolder = store.getFolder(folder);
emailFolder.open(Folder.READ_ONLY);
}catch(Exception e){
throw new BsfConstraintViolationException("Unable to connect to Exchange Server",e);
}
}
请找到下面的堆栈跟踪。
引起:java.lang.RuntimeException:意外错误:java.security.InvalidAlgorithmParameterException:trustAnchors参数必须为非空 在sun.security.validator.PKIXValidator。(PKIXValidator.java:90) at sun.security.validator.Validator.getInstance(Validator.java:179) at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:314) at sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:173) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:186) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1320) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:154) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868) 在sun.security.ssl.Handshaker.process_record(Handshaker.java:804) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1032) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1328) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:882) at sun.security.ssl.AppInputStream.read(AppInputStream.java:102) ......还有24个
任何人都可以帮我解决这个问题。