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

      Hi,

      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:

       

      jboss-web.xml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-web>
      <!-- Mail Ref -->
      <resource-ref>
      <res-ref-name>mail/org.imixs.workflow.mail</res-ref-name>
      <res-type>javax.mail.Session</res-type>
      <jndi-name>java:/mail/org.imixs.workflow.mail</jndi-name> 
      <lookup-name>java:/mail/org.imixs.workflow.mail</lookup-name>
      </resource-ref>
      
      <context-root>${imixs-office.contextroot}</context-root>
      <security-domain>${imixs-office.realm}</security-domain>
      </jboss-web>
      

       

       

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

       

      ejb-jar.xml:

       

      <enterprise-beans>
      <!--Imixs JEE EJBs -->
      <session>
      <ejb-name>WorkflowService</ejb-name>
      <ejb-class>org.imixs.workflow.engine.WorkflowService</ejb-class>
      <session-type>Stateless</session-type>
      
      
      <!-- Mail Configuration -->
      <env-entry>
      <description>Mail Plugin Session name</description>
      <env-entry-name>IMIXS_MAIL_SESSION</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>java:/mail/org.imixs.workflow.mail</env-entry-value>
      </env-entry>
      <!-- Mail resource -->
      <resource-ref>
      <!-- <res-ref-name>java:/mail/org.imixs.workflow.mail</res-ref-name> -->
      <res-ref-name>mail/org.imixs.workflow.mail</res-ref-name>
      <res-type>javax.mail.Session</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>
      
      
      </session>
      </enterprise-beans>
      

       

       

      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>
                  <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"/>
                  </mail-session>
              </subsystem>
      

       

       

      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.

       

      ===
      Ralph

        • 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.

           

          jboss-web.xml

           

          <?xml version="1.0" encoding="UTF-8"?>
          <jboss-web>
           <!-- Mail Ref -->
           <resource-ref>
            <res-ref-name>mail/org.imixs.workflow.mail</res-ref-name>
            <res-type>javax.mail.Session</res-type>
            <jndi-name>java:/mail/org.imixs.workflow.mail</jndi-name>
          </resource-ref>
          ...
          

           

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