/** * 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(); }
private void fillStack(Message message, Stack<Message> responseStack) { if (message != null) { responseStack.push(message); } }