javax.ejb.EJBException when sending emails from the application

244 views Asked by At

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:

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); 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. I don't understand what is wrong, nor how to solve it.

1

There are 1 answers

0
Santiago Noguera Pardo On

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. The download link for the Payara I used is this.