/** * Add a single header specification. If the header exists, it will <b>not</b> be * overwritten unless {@link #defaultOverwrite(boolean)} is true. * @param name the header name. * @param value the header value (not an {@link Expression}). * @param <V> the value type. * @return the header enricher spec. */ public <V> HeaderEnricherSpec header(String name, V value) { return header(name, value, null); }
/** * Add header specifications from the {@link MapBuilder}; the {@link Map} values must * be String representations of SpEL expressions that will be evaluated at run time * when the message headers are enriched. Headers derived from the map will <b>not</b> * overwrite existing headers, unless {@link #defaultOverwrite(boolean)} is true. * @param headers the header map builder. * @return the header enricher spec. */ public HeaderEnricherSpec headerExpressions(MapBuilder<?, String, String> headers) { return headerExpressions(headers, null); }
/** * Add a single header specification where the value is obtained by invoking the * {@link Function} callback. If the header exists, it will <b>not</b> be overwritten * unless {@link #defaultOverwrite(boolean)} is true. * @param name the header name. * @param function the function. * @param <P> the payload type. * @return the header enricher spec. * @see FunctionExpression */ public <P> HeaderEnricherSpec headerFunction(String name, Function<Message<P>, Object> function) { return headerFunction(name, function, null); }
/** * Accept a {@link Map} of values to be used for the * {@link Message} header enrichment. * {@code values} can apply an {@link org.springframework.expression.Expression} * to be evaluated against a request {@link Message}. * @param headers the Map of headers to enrich. * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options. * @return the current {@link IntegrationFlowDefinition}. * @see GenericEndpointSpec */ public B enrichHeaders(final Map<String, Object> headers, Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) { HeaderEnricherSpec headerEnricherSpec = new HeaderEnricherSpec(); headerEnricherSpec.headers(headers); Tuple2<ConsumerEndpointFactoryBean, MessageTransformingHandler> tuple2 = headerEnricherSpec.get(); return addComponents(headerEnricherSpec.getComponentsToRegister()) .handle(tuple2.getT2(), endpointConfigurer); }
@Bean @SuppressWarnings("rawtypes") public IntegrationFlow splitResequenceFlow(MessageChannel executorChannel) { return f -> f.enrichHeaders(s -> s.header("FOO", "BAR")) .split("testSplitterData", "buildList", c -> c.applySequence(false)) .channel(executorChannel) .split(Message.class, Message::getPayload, c -> c.applySequence(false)) .channel(MessageChannels.executor(taskExecutor())) .split(s -> s .applySequence(false) .delimiters(",")) .channel(MessageChannels.executor(taskExecutor())) .<String, Integer>transform(Integer::parseInt) .enrichHeaders(h -> h.headerFunction(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, Message::getPayload)) .resequence(r -> r.releasePartialSequences(true).correlationExpression("'foo'")) .headerFilter("foo", false); }
@Bean public IntegrationFlow xpathHeaderEnricherFlow() { return IntegrationFlows.from("xpathHeaderEnricherInput") .enrichHeaders( s -> s.header("one", new XPathExpressionEvaluatingHeaderValueMessageProcessor("/root/elementOne")) .header("two", new XPathExpressionEvaluatingHeaderValueMessageProcessor("/root/elementTwo")) .headerChannelsToString("12345") .messageProcessor(m -> s.header("foo", "bar")), c -> c.autoStartup(false).id("xpathHeaderEnricher") ) .get(); }
/** * Add a single header specification where the value is obtained by calling the * {@link HeaderValueMessageProcessor}. * @param headerName the header name. * @param headerValueMessageProcessor the message processor. * @param <V> the value type. * @return the header enricher spec. */ public <V> HeaderEnricherSpec header(String headerName, HeaderValueMessageProcessor<V> headerValueMessageProcessor) { Assert.hasText(headerName, "'headerName' must not be empty"); this.headerToAdd.put(headerName, headerValueMessageProcessor); return _this(); }
/** * Add a single header specification where the value is a String representation of a * SpEL {@link Expression}. If the header exists, it will <b>not</b> be overwritten * unless {@link #defaultOverwrite(boolean)} is true. * @param name the header name. * @param expression the expression. * @return the header enricher spec. */ public HeaderEnricherSpec headerExpression(String name, String expression) { return headerExpression(name, expression, null); }
/** * Add header specifications from the {@link MapBuilder}; if a map value is an * {@link Expression}, it will be evaluated at run time when the message headers are * enriched. Otherwise the value is simply added to the headers. Headers derived from * the map will <b>not</b> overwrite existing headers, unless * {@link #defaultOverwrite(boolean)} is true. * @param headers the header map builder. * @return the header enricher spec. */ public HeaderEnricherSpec headers(MapBuilder<?, String, Object> headers) { return headers(headers, null); }
/** * Configure an {@link ExpressionEvaluatingMessageProcessor} that evaluates to a * {@link Map} of additional headers. They will be added to the inbound message * headers before evaluating the individual configured header specifications. * @param expression the expression. * @return the header enricher spec. * @see #messageProcessor(MessageProcessor) */ public HeaderEnricherSpec messageProcessor(String expression) { return messageProcessor(new ExpressionEvaluatingMessageProcessor<>(expression)); }
/** * Populate a {@link MessageTransformingHandler} for * a {@link org.springframework.integration.transformer.HeaderEnricher} * as the result of provided {@link Consumer}. * In addition accept options for the integration endpoint using {@link GenericEndpointSpec}. * Typically used with a Java 8 Lambda expression: * <pre class="code"> * {@code * .enrichHeaders( *s -> s.header("one", new XPathExpressionEvaluatingHeaderValueMessageProcessor("/root/elementOne")) * .header("two", new XPathExpressionEvaluatingHeaderValueMessageProcessor("/root/elementTwo")) * .headerChannelsToString(), * c -> c.autoStartup(false).id("xpathHeaderEnricher")) * } * </pre> * @param headerEnricherConfigurer the {@link Consumer} to use. * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options. * @return the current {@link IntegrationFlowDefinition}. * @see HeaderEnricherSpec * @see GenericEndpointSpec */ public B enrichHeaders(Consumer<HeaderEnricherSpec> headerEnricherConfigurer, Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) { Assert.notNull(headerEnricherConfigurer, "'headerEnricherConfigurer' must not be null"); HeaderEnricherSpec headerEnricherSpec = new HeaderEnricherSpec(); headerEnricherConfigurer.accept(headerEnricherSpec); return transform(headerEnricherSpec.get(), endpointConfigurer); }
/** * Add header specifications to automatically convert header channels (reply, error * channels) to Strings and store them in a header channel registry. Allows * persistence and serialization of messages without losing these important framework * headers. * @return the header enricher spec. * @see org.springframework.integration.support.channel.HeaderChannelRegistry */ public HeaderEnricherSpec headerChannelsToString() { return headerChannelsToString(null); }
/** * Populate a {@link MessageTransformingHandler} for * a {@link org.springframework.integration.transformer.HeaderEnricher} * as the result of provided {@link Consumer}. * Typically used with a Java 8 Lambda expression: * <pre class="code"> * {@code * .enrichHeaders(h -> h.header(FileHeaders.FILENAME, "foo.sitest") * .header("directory", new File(tmpDir, "fileWritingFlow"))) * } * </pre> * @param headerEnricherConfigurer the {@link Consumer} to use. * @return the current {@link IntegrationFlowDefinition}. * @see HeaderEnricherSpec */ public B enrichHeaders(Consumer<HeaderEnricherSpec> headerEnricherConfigurer) { Assert.notNull(headerEnricherConfigurer, "'headerEnricherConfigurer' must not be null"); return register(new HeaderEnricherSpec(), headerEnricherConfigurer); }
@Bean public IntegrationFlow splitResequenceFlow() { return f -> f.enrichHeaders(s -> s.header("FOO", "BAR")) .split("testSplitterData", "buildList", c -> c.applySequence(false)) .channel(c -> c.executor(taskExecutor())) .split(Message.class, m -> m.getPayload(), c -> c.applySequence(false)) .channel(MessageChannels.executor(taskExecutor())) .split(s -> s .applySequence(false) .delimiters(",")) .channel(c -> c.executor(taskExecutor())) .<String, Integer>transform(Integer::parseInt) .enrichHeaders(h -> h.headerFunction(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, Message::getPayload)) .resequence(r -> r.releasePartialSequences(true).correlationExpression("'foo'")) .headerFilter("foo", false); }
/** * Accept a {@link Map} of values to be used for the * {@link Message} header enrichment. * {@code values} can apply an {@link org.springframework.expression.Expression} * to be evaluated against a request {@link Message}. * @param headers the Map of headers to enrich. * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options. * @return the current {@link IntegrationFlowDefinition}. * @see GenericEndpointSpec */ public B enrichHeaders(final Map<String, Object> headers, Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) { HeaderEnricherSpec headerEnricherSpec = new HeaderEnricherSpec(); headerEnricherSpec.headers(headers); Tuple2<ConsumerEndpointFactoryBean, MessageTransformingHandler> tuple2 = headerEnricherSpec.get(); return addComponents(headerEnricherSpec.getComponentsToRegister()) .handle(tuple2.getT2(), endpointConfigurer); }
/** * Determine the default action to take when setting individual header specifications * without an explicit 'overwrite' argument. * @param defaultOverwrite the defaultOverwrite. * @return the header enricher spec. * @see HeaderEnricher#setDefaultOverwrite(boolean) */ public HeaderEnricherSpec defaultOverwrite(boolean defaultOverwrite) { this.headerEnricher.setDefaultOverwrite(defaultOverwrite); return _this(); }
/** * Add header specifications to automatically convert header channels (reply, error * channels) to Strings and store them in a header channel registry. Allows * persistence and serialization of messages without losing these important framework * headers. * @param timeToLiveExpression the minimum time that the mapping will remain in the registry. * @return the header enricher spec. * @see org.springframework.integration.support.channel.HeaderChannelRegistry */ public HeaderEnricherSpec headerChannelsToString(String timeToLiveExpression) { return headerExpression("replyChannel", "@" + IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME + ".channelToChannelName(headers.replyChannel" + (StringUtils.hasText(timeToLiveExpression) ? ", " + timeToLiveExpression : "") + ")", true) .headerExpression("errorChannel", "@" + IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME + ".channelToChannelName(headers.errorChannel" + (StringUtils.hasText(timeToLiveExpression) ? ", " + timeToLiveExpression : "") + ")", true); }
/** * Add header specifications from the {@link Map}; if a map value is an * {@link Expression}, it will be evaluated at run time when the message headers are * enriched. Otherwise the value is simply added to the headers. Headers derived from * the map will <em>not</em> overwrite existing headers, unless * {@link #defaultOverwrite(boolean)} is true. * @param headers The header builder. * @return the header enricher spec. */ public HeaderEnricherSpec headers(Map<String, Object> headers) { return headers(headers, null); }
/** * Configure an * {@link org.springframework.integration.handler.MethodInvokingMessageProcessor} that * invokes the method on the bean - the method must return a {@link Map} of headers. * They will be added to the inbound message headers before evaluating the individual * configured header specifications. * @param beanName The bean name. * @param methodName The method name. * @return the header enricher spec. * @see #messageProcessor(MessageProcessor) */ public HeaderEnricherSpec messageProcessor(String beanName, String methodName) { return messageProcessor(new BeanNameMessageProcessor<>(beanName, methodName)); }