Exemple #1
0
  @Override
  public boolean accept(String from, String recipient) {
    if (autoAccept) {
      return true;
    }

    StringResult result = new StringResult();
    marshaller.marshal(createAcceptRequest(from, recipient), result);
    Message response = getEndpointAdapter().handleMessage(new DefaultMessage(result.toString()));

    if (response == null || response.getPayload() == null) {
      throw new CitrusRuntimeException(
          "Did not receive accept response. Missing accept response because autoAccept is disabled.");
    }

    AcceptResponse acceptResponse = null;
    if (response.getPayload() instanceof AcceptResponse) {
      acceptResponse = (AcceptResponse) response.getPayload();
    } else if (response.getPayload() instanceof String) {
      acceptResponse = (AcceptResponse) marshaller.unmarshal(response.getPayload(Source.class));
    }

    if (acceptResponse == null) {
      throw new CitrusRuntimeException("Unable to read accept response from payload: " + response);
    }

    return acceptResponse.isAccept();
  }
Exemple #2
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()));
    }
  }
Exemple #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();
  }
Exemple #4
0
  @Override
  public void deliver(String from, String recipient, InputStream data) {
    try {
      MimeMailMessage mimeMailMessage = new MimeMailMessage(new MimeMessage(getSession(), data));
      Message request =
          messageConverter.convertInbound(mimeMailMessage, getEndpointConfiguration());
      Message response = invokeEndpointAdapter(request);

      if (response != null && response.getPayload() != null) {
        MailResponse mailResponse = null;
        if (response.getPayload() instanceof MailResponse) {
          mailResponse = (MailResponse) response.getPayload();
        } else if (response.getPayload() instanceof String) {
          mailResponse = (MailResponse) marshaller.unmarshal(response.getPayload(Source.class));
        }

        if (mailResponse != null && mailResponse.getCode() != MailResponse.OK_CODE) {
          throw new RejectException(mailResponse.getCode(), mailResponse.getMessage());
        }
      }
    } catch (MessagingException e) {
      throw new CitrusRuntimeException(e);
    }
  }