/** * 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); }
@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; }