1 Reply Latest reply on Aug 4, 2018 6:59 PM by Ralph Soika

    How to configure and inject a Mail Ressouce in Wildfly 13?

    Ralph Soika Apprentice


      I am just trying to deploy my web application on wildfly 13 which is running currently in Wildfy 10 and 11.

      My problem is the injection of a Mail Resource which currently breaks the deployment in Wildfly 13.


      I guess I have an issue with one of my deployment descriptors which may also be a little bit outdated over the past two years.


      So what I try is the following:


      Injecting the Mail Resource in a EJB:


      First of all I want to inject a Java EE Mail resouce in one of my EJBs:



      @Resource(name = "IMIXS_MAIL_SESSION")
      private String sMailSession = "org.imixs.workflow.mail";
      try {
      ic = new InitialContext();
      // add java: prafix if not defined in jndi ref
      if (!sMailSession.startsWith("java:")) {
      sJNDINName = "java:comp/env/" + sMailSession;
      } else {
      sJNDINName = sMailSession;
      logger.finest("...... Lookup MailSession '" + sJNDINName + "' ...");
      mailSession = (Session) ic.lookup(sJNDINName);
      logger.finest("...... Lookup MailSession '" + sJNDINName + "' successful");
      } catch (NamingException e) {
      logger.warning(" Lookup MailSession '" + sJNDINName + "' failed: " + e.getMessage());
      logger.warning(" Unable to send mails! Verify server resources -> mail session.");
      noMailSessionBound = true;


      Why do I use different code here? Because the component should also be deployabe in Glassfish4 (which is working fine) . The prafix :java is not working in glassfish....


      The Deployment Descriptors:


      Now I use the following descriptors:




      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Mail Ref -->



      First question: Is this descriptor still valid for Wildfly 13? In wildfly 10 it is.




      <!--Imixs JEE EJBs -->
      <!-- Mail Configuration -->
      <description>Mail Plugin Session name</description>
      <!-- Mail resource -->
      <!-- <res-ref-name>java:/mail/org.imixs.workflow.mail</res-ref-name> -->



      And finally my standalone.xml configuration in Wildfly 13:


              <subsystem xmlns="urn:jboss:domain:mail:3.0">
                  <mail-session name="default" jndi-name="java:jboss/mail/Default">
                      <smtp-server outbound-socket-binding-ref="mail-smtp"/>
                  <mail-session name="org.imixs.workflow.mail" jndi-name="java:/mail/org.imixs.workflow.mail" debug="false">
                  <smtp-server outbound-socket-binding-ref="mail-smtp"/>



      When I try to deploy it fails with:



      Caused by: java.lang.IllegalArgumentException: WFLYEE0047: Incompatible conflicting binding at java:comp/env/mail/org.imixs.workflow.mail source: lookup (java:jboss/resources/mail/org.imixs.workflow.mail) imixsofficeworkflow_1  | at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:263) imixsofficeworkflow_1  | at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:136) imixsofficeworkflow_1  | at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:143) imixsofficeworkflow_1  | ... 8 more


      This brings me to the conclusion that my configuration is wrong - maybe in different places.


      Can anyone help me how to inject a Mail Session correctly. Maybe there is a tutorial for wildfly 13?

      How is the correct setup for the deployment descriptors? In the moment I think that my ejb-jar.xml descriptor is not necessary at all? But what is with this jboss-web.xml file? Is this still valid? And how should it look like.


      Thanks for any help.



        • 1. Re: How to configure and inject a Mail Ressouce in Wildfly 13?
          Ralph Soika Apprentice

          Ok it seems that I missconfigured my envorinment with to much try-and-error.


          Mail Ressources works well in Wildfly 13.




          <?xml version="1.0" encoding="UTF-8"?>
           <!-- Mail Ref -->


          An additional mapping in ejb-jar.xml seems not to be necessary at all.