@Bean @ConditionalOnProperty(prefix = "syndesis.integration.runtime.capture", name = "enabled", matchIfMissing = true) public InterceptStrategy createOutMessageCaptureInterceptStrategy() { return new OutMessageCaptureInterceptStrategy(); } }
private void addToMap(Exchange exchange, String key, Message msg) { if( msg != null ) { Message copy = msg.copy(); Map<String, Message> outMessagesMap = getCapturedMessageMap(exchange); outMessagesMap.put(key, copy); } }
@Override public Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition, Processor target, Processor nextTarget) throws Exception { // First processor needs to handle the in message as the out message from the consumer since // we can't intercept consumers FromDefinition from = getFromDefinition(definition); boolean captureIn = from!=null; boolean captureOut = definition.hasCustomIdAssigned(); if (captureIn || captureOut) { return AsyncProcessorConverterHelper.convert(exchange -> { if( captureIn ) { addToMap(exchange, from.getId(), exchange.getIn()); } target.process(exchange); if( captureOut ) { Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn(); addToMap(exchange, definition.getId(), message); } }); } else { // skip over processors with a generated id return target; } }