Example #1
0
  /**
   * Invokes the endpoint adapter with constructed mail message and headers.
   *
   * @param request
   */
  protected Message invokeEndpointAdapter(Message request) {
    MailMessage mailMessage = (MailMessage) request.getPayload();

    if (splitMultipart) {
      return split(mailMessage.getBody(), request.copyHeaders());
    } else {
      StringResult result = new StringResult();
      marshaller.marshal(mailMessage, result);
      return getEndpointAdapter()
          .handleMessage(new DefaultMessage(result.toString(), request.copyHeaders()));
    }
  }
Example #2
0
 /**
  * Creates a new mail message model object from message headers.
  *
  * @param messageHeaders
  * @return
  */
 protected MailMessage createMailMessage(Map<String, Object> messageHeaders) {
   MailMessage message = new MailMessage();
   message.setFrom(messageHeaders.get(CitrusMailMessageHeaders.MAIL_FROM).toString());
   message.setTo(messageHeaders.get(CitrusMailMessageHeaders.MAIL_TO).toString());
   message.setCc(messageHeaders.get(CitrusMailMessageHeaders.MAIL_CC).toString());
   message.setBcc(messageHeaders.get(CitrusMailMessageHeaders.MAIL_BCC).toString());
   message.setSubject(messageHeaders.get(CitrusMailMessageHeaders.MAIL_SUBJECT).toString());
   return message;
 }
Example #3
0
  /**
   * Split mail message into several messages. Each body and each attachment results in separate
   * message invoked on endpoint adapter. Mail message response if any should be sent only once
   * within test case. However latest mail response sent by test case is returned, others are
   * ignored.
   *
   * @param bodyPart
   * @param messageHeaders
   */
  private Message split(BodyPart bodyPart, Map<String, Object> messageHeaders) {
    MailMessage mailMessage = createMailMessage(messageHeaders);
    mailMessage.setBody(new BodyPart(bodyPart.getContent(), bodyPart.getContentType()));

    StringResult result = new StringResult();
    Stack<Message> responseStack = new Stack<Message>();
    if (bodyPart instanceof AttachmentPart) {
      marshaller.marshal(mailMessage, result);
      fillStack(
          getEndpointAdapter()
              .handleMessage(
                  new DefaultMessage(result.toString(), messageHeaders)
                      .setHeader(
                          CitrusMailMessageHeaders.MAIL_CONTENT_TYPE, bodyPart.getContentType())
                      .setHeader(
                          CitrusMailMessageHeaders.MAIL_FILENAME,
                          ((AttachmentPart) bodyPart).getFileName())),
          responseStack);
    } else {
      marshaller.marshal(mailMessage, result);
      fillStack(
          getEndpointAdapter()
              .handleMessage(
                  new DefaultMessage(result.toString(), messageHeaders)
                      .setHeader(
                          CitrusMailMessageHeaders.MAIL_CONTENT_TYPE, bodyPart.getContentType())),
          responseStack);
    }

    if (bodyPart.hasAttachments()) {
      for (AttachmentPart attachmentPart : bodyPart.getAttachments().getAttachments()) {
        fillStack(split(attachmentPart, messageHeaders), responseStack);
      }
    }

    return responseStack.isEmpty() ? null : responseStack.pop();
  }