简体   繁体   English

从应用程序发送电子邮件时出现 javax.ejb.EJBException

[英]javax.ejb.EJBException when sending emails from the application

I am developing a JavaEE application with GlassFish 5.1, Java 1.8, JavaMail, JavaFaces 2.2, in the application I need to send emails as the method to do it is invoked, but when I run it from the server it shows me the following error:我正在使用 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

I was testing the code fragment in a separate project and it works perfectly, but at the moment of executing it from the server the error happens.我在一个单独的项目中测试代码片段并且它工作得很好,但是在从服务器执行它的那一刻发生了错误。 The code fragment is the following:代码片段如下:

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();
}

When I execute the code the error marks it in the following line transport.connect(mailSender, passwordSender);当我执行代码时,错误将其标记在以下行中transport.connect(mailSender, passwordSender); I have been trying with different versions of JavaMail (1.4.5 - 1.6.2), I was using JDK8u111 and updated it to JDK8u261 but nothing, I also tried to change the JAR of the glizzly-npn-bootstrap.jar from version 1.5 to 1.9 (As they say in the following error ) but it still gives me the same error.我一直在尝试使用不同版本的 JavaMail(1.4.5 - 1.6.2),我使用的是 JDK8u111 并将其更新为 JDK8u261 但没有,我还尝试从版本 1.5 更改glizzly-npn-bootstrap.jar的 JAR到 1.9(正如他们在以下错误中所说的那样),但它仍然给我同样的错误。 I don't understand what is wrong, nor how to solve it.我不明白哪里出了问题,也不明白如何解决。

I could not find a solution to the problem presented in the GlassFish 5.1 server, but when running the application from the Payara 5.2 server there was no error and everything worked perfectly, however I decided to leave the application with the JDK8u261 to avoid a possible problem of compatibility with the versions.我找不到解决 GlassFish 5.1 服务器中出现的问题的解决方案,但是当从 Payara 5.2 服务器运行应用程序时没有错误并且一切正常,但是我决定将应用程序保留在 JDK8u261 上以避免可能出现的问题与版本的兼容性。 The download link for the Payara I used is this .我使用的 Payara 的下载链接是这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM