From 18b5cf88907ec024200abd5653d1fef3b5e95f23 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 2 Sep 2016 16:06:15 +0200 Subject: [PATCH] Added a check for missing bean --- .../messaging/stream/StreamStubMessages.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/StreamStubMessages.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/StreamStubMessages.java index f6553cce67..fccb14b3d4 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/StreamStubMessages.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/StreamStubMessages.java @@ -81,21 +81,25 @@ public class StreamStubMessages implements MessageVerifier> { } private String resolvedDestination(String destination) { - ChannelBindingServiceProperties channelBindingServiceProperties = this.context - .getBean(ChannelBindingServiceProperties.class); - for (Map.Entry entry : channelBindingServiceProperties - .getBindings().entrySet()) { - if (entry.getValue().getDestination().equals(destination)) { - if (log.isDebugEnabled()) { - log.debug("Found a channel named [{}] with destination [{}]", - entry.getKey(), destination); + try { + ChannelBindingServiceProperties channelBindingServiceProperties = this.context + .getBean(ChannelBindingServiceProperties.class); + for (Map.Entry entry : channelBindingServiceProperties + .getBindings().entrySet()) { + if (entry.getValue().getDestination().equals(destination)) { + if (log.isDebugEnabled()) { + log.debug("Found a channel named [{}] with destination [{}]", + entry.getKey(), destination); + } + return entry.getKey(); } - return entry.getKey(); } + } catch (Exception e) { + log.error("Exception took place while trying to resolve the destination. Will assume the name [" + destination + "]", e); } if (log.isDebugEnabled()) { log.debug( - "No destination named [{}] was found. Assuming that the destination equals the channel name", + "No destination named [" + destination + "] was found. Assuming that the destination equals the channel name", destination); } return destination;