0

我正在使用 GlassFish 5.1、Java 1.8、JavaMail、JavaFaces 2.2 开发一个 JavaEE 应用程序,在应用程序中我需要发送电子邮件作为调用它的方法,但是当我从服务器运行它时它向我显示以下错误:

Warning: javax.ejb.EJBException
    at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:728)
    at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:678)
    at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:483)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4576)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2084)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2054)
    at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:188)
    at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:55)
    at com.sun.proxy.$Proxy268.preInscripcion(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:113)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:143)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:490)
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:161)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1520)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1396)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:901)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:183)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:665)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:467)
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2193)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:467)
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:510)
Caused by: java.lang.NoClassDefFoundError: sun/security/ssl/HandshakeStateManager
    at sun.security.ssl.Handshaker.init(Handshaker.java:282)
    at sun.security.ssl.Handshaker.<init>(Handshaker.java:242)
    at sun.security.ssl.ClientHandshaker.<init>(ClientHandshaker.java:160)
    at sun.security.ssl.SSLSocketImpl.initHandshaker(SSLSocketImpl.java:1329)
    at sun.security.ssl.SSLSocketImpl.doneConnect(SSLSocketImpl.java:690)
    at sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:569)
    at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:110)
    at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:528)
    at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2126)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:728)
    at javax.mail.Service.connect(Service.java:342)
    at javax.mail.Service.connect(Service.java:222)
    at javax.mail.Service.connect(Service.java:243)
    at com.prueba.dao.UsuarioDAO.enviarEmail(UsuarioDAO.java:80)
    at com.prueba.model.Estudiante.agregarUsuario(Estudiante.java:19)
    at com.prueba.sessionbeans.EstudianteBean.preInscripcion(EstudianteBean.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1057)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1129)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4796)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:632)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:584)
    at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:81)
    at org.jboss.weld.module.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:859)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:799)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:584)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:139)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:116)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:859)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:799)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:345)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4768)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4756)
    at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:181)
    ... 19 more

我在一个单独的项目中测试代码片段,它运行良好,但是在从服务器执行它的那一刻发生错误。代码片段如下:

try{
    Properties props=new Properties();
    props.setProperty("mail.smtp.host", "smtp.gmail.com");
    props.setProperty("mail.smtp.starttls.enable", "true");
    props.setProperty("mail.smtp.port", "587");
    props.setProperty("mail.smtp.aunth", "true");
    Session session=Session.getDefaultInstance(props);
    MimeMessage message=new MimeMessage(session);
    message.setFrom(new InternetAddress(mailSender));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(mailReceptor));
    message.setSubject(asunto);
    message.setText(mensaje);
    Transport transport=session.getTransport("smtp");
    transport.connect(mailSender, passwordSender);
    transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
    transport.close();
    return true;
}
catch(AddressException e){
    e.printStackTrace();
}
catch(MessagingException e){
    e.printStackTrace();
}

当我执行代码时,错误将其标记在以下行transport.connect(mailSender, passwordSender); 中从 1.5 版到 1.9 版的 JAR glizzly-npn-bootstrap.jar(正如他们在以下错误中所说),但它仍然给我同样的错误。我不明白出了什么问题,也不知道如何解决。

4

1 回答 1

0

我找不到 GlassFish 5.1 服务器中出现的问题的解决方案,但是从 Payara 5.2 服务器运行应用程序时没有错误并且一切正常,但是我决定使用 JDK8u261 保留应用程序以避免可能的问题与版本的兼容性。我使用的 Payara 的下载链接是这个

于 2020-10-09T04:01:04.537 回答