-
1. Re: mail-session: If EMail server is restarted, will JBoss AS 7 reconnect to it?
sfcoy Aug 4, 2013 3:01 AM (in response to ybxiang.china)I think you will find that Java Mail opens connections as required and closes them when done.
-
2. Re: mail-session: If EMail server is restarted, will JBoss AS 7 reconnect to it?
ybxiang.china Aug 4, 2013 9:08 AM (in response to sfcoy)Thanks for your reply. But my case is:
(1) I configured mail session in jboss as 7.2.0:
<subsystem xmlns="urn:jboss:domain:mail:1.1"> <mail-session jndi-name="java:/Mail" debug="false" from="javaarm@gmail.com"> <smtp-server ssl="true" outbound-socket-binding-ref="mail-smtp-gmail"> <login name="javaarm@gmail.com" password="blabla"/> </smtp-server> </mail-session> </subsystem> <outbound-socket-binding name="mail-smtp-gmail"> <remote-destination host="smtp.gmail.com" port="465"/> </outbound-socket-binding> (2) The service
@Local(IEmailService.class)
@Singleton
@Startup
public class EmailService implements IEmailService{
public static final Logger log = Logger.getLogger(EmailService.class.getName());
@PersistenceContext
private EntityManager em;
@Resource(name = "java:/Mail")
private Session mailSession;
...
}
(3) If I start my jboss while xxxmail server is NOT availabe because of poor network connectivity or email server restarting or other issue, I will get bellow exception:
20:57:02,573 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.mail-session.java:/Mail: org.jboss.msc.service.StartException in service jboss.mail-session.java:/Mail: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_15]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_15]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_15]
Caused by: java.lang.RuntimeException: JBAS015451: Unknown host for outbound socket binding configuration 'mail-smtp-gmail'.
at org.jboss.as.mail.extension.MailSessionService.getServerSocketAddress(MailSessionService.java:163)
at org.jboss.as.mail.extension.MailSessionService.setServerProps(MailSessionService.java:131)
at org.jboss.as.mail.extension.MailSessionService.getProperties(MailSessionService.java:90)
at org.jboss.as.mail.extension.MailSessionService.start(MailSessionService.java:64)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
... 3 more
Caused by: java.net.UnknownHostException: smtp.gmail.com
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) [rt.jar:1.7.0_15]
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:866) [rt.jar:1.7.0_15]
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1258) [rt.jar:1.7.0_15]
at java.net.InetAddress.getAllByName0(InetAddress.java:1211) [rt.jar:1.7.0_15]
at java.net.InetAddress.getAllByName(InetAddress.java:1127) [rt.jar:1.7.0_15]
at java.net.InetAddress.getAllByName(InetAddress.java:1063) [rt.jar:1.7.0_15]
at java.net.InetAddress.getByName(InetAddress.java:1013) [rt.jar:1.7.0_15]
at org.jboss.as.network.OutboundSocketBinding.getDestinationAddress(OutboundSocketBinding.java:146)
at org.jboss.as.mail.extension.MailSessionService.getServerSocketAddress(MailSessionService.java:161)
... 8 more
20:57:02,870 INFO
(4) my EmailService will never be instantiated:
20:59:29,837 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.mail-session.java:/Mail: org.jboss.msc.service.StartException in service jboss.mail-session.java:/Mail: Failed to start service
service jboss.deployment.subunit."ybxiang-forum.ear"."ybxiang-forum-ejb.jar".component.EmailService.START: org.jboss.msc.service.StartException in service jboss.deployment.subunit."ybxiang-forum.ear"."ybxiang-forum-ejb.jar".component.EmailService.START: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
(5) If the mail server is availabe again (the EmailService is still null, unless I restart JBoss AS) and I call the EmailService , I will get bellow exception :
21:02:29,834 ERROR [org.jboss.as.ejb3] (http-/127.0.0.1:443-1) javax.ejb.EJBTransactionRolledbackException: JBAS011048: Failed to construct component instance
21:02:29,834 ERROR [org.jboss.as.ejb3.invocation] (http-/127.0.0.1:443-1) JBAS014134: EJB Invocation failed on component EmailService for method public abstract boolean com.ybxiang.forum.ejb.session.core.IEmailService.sendMail(com.ybxiang.forum.ejb.entity.Email): javax.ejb.EJBTransactionRolledbackException: JBAS011048: Failed to construct component instance
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:138) [jboss-as-ejb3-7.2.0.Final.jar:7.2.0.Final]
The EmailService will always be null, unless I restart JBoss AS!
If I use JCA to create the JavaMail session when I need it, this issue will be resolved.
Do you have better solution for this case?
-
3. Re: mail-session: If EMail server is restarted, will JBoss AS 7 reconnect to it?
ybxiang.china Aug 4, 2013 9:14 AM (in response to ybxiang.china)Do you agree that we should NOT suppose the email server and the network are always reliable?
-
4. Re: mail-session: If EMail server is restarted, will JBoss AS 7 reconnect to it?
sfcoy Aug 4, 2013 9:01 PM (in response to ybxiang.china)This is a DNS failure, not a connection failure per sé.
Is your DNS hosted on the same machine as the mail server? You really should have more than one DNS.
-
5. Re: mail-session: If EMail server is restarted, will JBoss AS 7 reconnect to it?
sfcoy Aug 4, 2013 9:08 PM (in response to ybxiang.china)1 of 1 people found this helpfulYou should always assume that network connectivity can be transient. However there is an assumption that DNS is always available, otherwise nothing at all will work.
Therefore you must ensure that the DNS in your production environment is backed by at least two and preferably three different host servers.
-
6. Re: mail-session: If EMail server is restarted, will JBoss AS 7 reconnect to it?
ybxiang.china Aug 5, 2013 12:40 AM (in response to sfcoy)Actually, I unplugged the network cable on purpose just for test.
Maybe I think too much on all kinds of failures.