示例#1
0
  /**
   * Resolve the channel by name.
   *
   * @param channelName the name to resolve
   * @return the MessageChannel object
   */
  protected MessageChannel resolveChannelName(String channelName) {
    if (endpointConfiguration.getChannelResolver() == null) {
      endpointConfiguration.setChannelResolver(
          new BeanFactoryChannelResolver(endpointConfiguration.getBeanFactory()));
    }

    return endpointConfiguration.getChannelResolver().resolveDestination(channelName);
  }
示例#2
0
 /**
  * Gets the channel name depending on what is set in this message sender. Either channel name is
  * set directly or channel object is consulted for channel name.
  *
  * @return the channel name.
  */
 protected String getDestinationChannelName() {
   if (endpointConfiguration.getChannel() != null) {
     return endpointConfiguration.getChannel().toString();
   } else if (StringUtils.hasText(endpointConfiguration.getChannelName())) {
     return endpointConfiguration.getChannelName();
   } else {
     throw new CitrusRuntimeException(
         "Neither channel name nor channel object is set - "
             + "please specify destination channel");
   }
 }
示例#3
0
  @Override
  public Message receive(String selector, TestContext context, long timeout) {
    String destinationChannelName;
    MessageChannel destinationChannel = getDestinationChannel();

    if (StringUtils.hasText(selector)) {
      destinationChannelName = getDestinationChannelName() + "(" + selector + ")";
    } else {
      destinationChannelName = getDestinationChannelName();
    }

    if (log.isDebugEnabled()) {
      log.debug("Receiving message from: " + destinationChannelName);
    }

    Message message;
    if (StringUtils.hasText(selector)) {
      if (!(destinationChannel instanceof MessageSelectingQueueChannel)) {
        throw new CitrusRuntimeException(
            "Message channel type '"
                + endpointConfiguration.getChannel().getClass()
                + "' does not support selective receive operations.");
      }

      MessageSelector messageSelector =
          new DispatchingMessageSelector(selector, endpointConfiguration.getBeanFactory());
      MessageSelectingQueueChannel queueChannel =
          ((MessageSelectingQueueChannel) destinationChannel);

      if (timeout <= 0) {
        message =
            endpointConfiguration
                .getMessageConverter()
                .convertInbound(
                    queueChannel.receive(messageSelector), endpointConfiguration, context);
      } else {
        message =
            endpointConfiguration
                .getMessageConverter()
                .convertInbound(
                    queueChannel.receive(messageSelector, timeout), endpointConfiguration, context);
      }
    } else {
      if (!(destinationChannel instanceof PollableChannel)) {
        throw new CitrusRuntimeException(
            "Invalid destination channel type "
                + destinationChannel.getClass().getName()
                + " - must be of type PollableChannel");
      }

      endpointConfiguration.getMessagingTemplate().setReceiveTimeout(timeout);
      message =
          endpointConfiguration
              .getMessageConverter()
              .convertInbound(
                  endpointConfiguration
                      .getMessagingTemplate()
                      .receive((PollableChannel) destinationChannel),
                  endpointConfiguration,
                  context);
    }

    if (message == null) {
      throw new ActionTimeoutException(
          "Action timeout while receiving message from channel '" + destinationChannelName + "'");
    }

    log.debug("Received message from: " + destinationChannelName);
    return message;
  }