3 Replies Latest reply on Dec 12, 2007 6:39 PM by Ronald van Kuijk

    Bug in Mail.java

    Laurent Michenaud Newbie

      I think something is missing in case of attribute 'to'

      Actual code :

      public List getRecipients() {
       List recipients = new ArrayList();
       if (actors != null) {
       String evaluatedActors = evaluate(actors);
       List tokenizedActors = tokenize(evaluatedActors);
       recipients.addAll(resolveAddresses(tokenizedActors));
       }
       if (to != null) {
       String resolvedTo = evaluate(to);
       recipients.addAll(tokenize(resolvedTo));
       }
       return recipients;
       }


      Proposal :


      public List getRecipients() {
       List recipients = new ArrayList();
       if (actors != null) {
       String evaluatedActors = evaluate(actors);
       List tokenizedActors = tokenize(evaluatedActors);
       recipients.addAll(resolveAddresses(tokenizedActors));
       }
       if (to != null) {
       String resolvedTo = evaluate(to);
       List tokenizedActors = tokenize(resolvedTo);
       recipients.addAll(resolveAddresses(tokenizedActors));
       }
       return recipients;
       }


        • 1. Re: Bug in Mail.java
          Laurent Michenaud Newbie

          Sorry, after a second though, i think the code is correct.
          'To' attribute should be used for hard email input.
          and 'actors' attribute should be used for email(s) to resolve.

          So, i think the error is in the documentation :

          <mail to='#{initiator}' subject='websale' text='your websale of #{quantity} #{item} was approved' />


          to='#{initiator}' will never work.

          • 2. Re: Bug in Mail.java
            Fady Matar Novice

            Very true.
            The attribute 'to' does not resolve EL expressions, use the attribute 'actor' instead.
            The documentation needs to be updated

            • 3. Re: Bug in Mail.java
              Ronald van Kuijk Master

              Not true (from what I see in the code)

              evaluate(to) is implemented as:

               String evaluate(String expression) {
               if (expression==null) {
               return null;
               }
               VariableResolver variableResolver = JbpmExpressionEvaluator.getUsedVariableResolver();
               if (variableResolver!=null) {
               variableResolver = new MailVariableResolver(templateVariables, variableResolver);
               }
               return (String) JbpmExpressionEvaluator.evaluate(expression, executionContext, variableResolver, null);
               }
              


              There are even a unittest
               public void testToVariableExpression() {
               ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
               "<process-definition>" +
               " <start-state>" +
               " <transition to='end'>" +
               " <mail name='send email' to='#{user.email}' subject='s' text='t' />" +
               " </transition>" +
               " </start-state>" +
               " <end-state name='end' />" +
               "</process-definition>"
               );
              
               User mrNobody = new User("hucklebuck@example.domain");
              
               ProcessInstance processInstance = new ProcessInstance(processDefinition);
               processInstance.getContextInstance().setVariable("user", mrNobody);
               processInstance.signal();
              
               assertEquals(1, server.getReceivedEmailSize());
               Iterator emailIter = server.getReceivedEmail();
               SmtpMessage email = (SmtpMessage) emailIter.next();
               assertEquals("hucklebuck@example.domain", email.getHeaderValue("To"));
               }
              
              


              So I'm inclined to close http://jira.jboss.com/jira/browse/JBPM-1073 as 'worksforme'