Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-7621

Sending mail - org.apache.velocity.runtime.exception.ReferenceException:

    XMLWordPrintable

Details

    • Support Request
    • Resolution: Fixed
    • Medium
    • None
    • 3.2.3
    • Email notifications
    • None

    Description

      Hello,

      I'm developing a post function which allows a user to specify an email address to which a custom email is sent (custom meaning a custom email vm template).

      The email does get sent with the correct template, however the problem I'm having is that the velocity params are not populated in the template. In another words I get
      >
      Today is: ${today_date}
      >
      instead of :
      >
      Today is: 08/11/2005.
      >

      The stack trace shows the following errors where ${consolidatedVendorName} is one of the params in the template file.
      ..
      ..
      ..
      2005-08-11 13:23:25,157 WARN [velocity] org.apache.velocity.runtime.exception.ReferenceException: reference : template = templates/email/text/user-notification-function-mail.vm [line 3,column 27] : ${consolidatedVendorName} is not a valid reference.
      at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:277)
      at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
      at org.apache.velocity.Template.merge(Template.java:256)
      at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:450)
      at com.atlassian.velocity.DefaultVelocityManager.getEncodedBody(DefaultVelocityManager.java:76)
      at com.atlassian.velocity.DefaultVelocityManager.getEncodedBody(DefaultVelocityManager.java:60)
      at com.atlassian.jira.mail.UserMailQueueItem.send(UserMailQueueItem.java:50)
      ..
      ..
      ..
      Code is below
      Thanks,
      -Andreas

      >
      >
      public void execute(Map transientVars, Map args, PropertySet ps)
      throws WorkflowException
      {
      Issue issue = (Issue) transientVars.get("issue");
      com.opensymphony.user.User reporter = issue.getReporter();

      try

      { UserEvent ue = new UserEvent(createParamsMap(issue, transientVars), reporter); String template = "user-notification-function-mail.vm"; MailQueueItem item = new UserMailQueueItem(ue, computeSubject(issue,args), template); ManagerFactory.getMailQueue().addItem(item); }

      catch (Exception e)

      { log.error("Failed to send mail", e); }

      }

      private Map createParamsMap(Issue issue, Map transientVars)

      { // get the custom fields CustomFieldManager cfm = ManagerFactory.getCustomFieldManager(); skuField = cfm.getCustomFieldObjectByName(skuFieldName); skuDescriptionField = cfm.getCustomFieldObjectByName(skuDescriptionFieldName); consolidatedVendorNameField = cfm.getCustomFieldObjectByName(consolidatedVendorNameFieldName); merchantField = cfm.getCustomFieldObjectByName(merchantFieldName); // custom fields String skuValue = (issue.getCustomFieldValue(skuField)).toString(); String skuDescriptionValue = (issue.getCustomFieldValue(skuDescriptionField)).toString(); String consolidatedVendorNameValue = (issue.getCustomFieldValue(consolidatedVendorNameField)).toString(); String merchantValue = (issue.getCustomFieldValue(merchantField)).toString(); Map paramsMap = new HashMap(); // Sku, skuDescription, Merchant, consolidated vendor name // Blank Size Length, Blank Size Width paramsMap.put("sku", skuValue); paramsMap.put("skuDescription", skuDescriptionValue); paramsMap.put("merchant", merchantValue); paramsMap.put("consolidatedVendorName", consolidatedVendorNameValue); //paramsMap.put("blankSizeLength", ""); //paramsMap.put("blankSizeWidth", ""); return paramsMap; }

      private String computeSubject(Issue issue, Map args)

      { StringBuffer subject = new StringBuffer(); // Add the issue new status Status issueStatus = issue.getStatusObject(); subject.append(issueStatus.getName()); // Add the issue name subject.append(": ("); subject.append(issue.getKey()); subject.append(")"); // Add the issue description subject.append(" "); subject.append((String) issue.getSummary()); return subject.toString(); }

      private String getEmails(Issue issue, Map args)
      throws EntityNotFoundException
      {
      StringBuffer emails = new StringBuffer();

      // Add reporter
      com.opensymphony.user.User reporter = issue.getReporter();
      emails.append(reporter.getEmail());

      // Add assignee
      emails.append(',');
      com.opensymphony.user.User assignee = issue.getAssignee();
      emails.append(assignee.getEmail());

      // Add additional individual emails
      String individualEmails = (String) args.get("field.notifyEmail");
      StringTokenizer tokens = new StringTokenizer(individualEmails, ", ");
      while (tokens.hasMoreTokens())

      { String token = tokens.nextToken(); emails.append(','); User user = UserManager.getInstance().getUser(token); emails.append(user.getEmail()); }

      return emails.toString();
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            363272ee38da Andreas Vogel
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: