Skip to content

Commit 867a8cf

Browse files
authored
GH-3155: Add support for Java DSL extensions (#3167)
* GH-3155: Add support for Java DSL extensions Fixes #3155 Provide an `IntegrationFlowExtension` for possible custom EI-operators in the target project use-cases. * * Move `IntegrationFlowExtension` tests ot its own test class * Make all the `IntegrationComponentSpec` ctors as `protected` for possible custom extensions * Make some `BaseIntegrationFlowDefinition` methods and properties as `protected` to get them access from the `IntegrationFlowExtension` implementations * Document the feature * * Fix language and typos in docs * * Add `protected` to one more `GatewayEndpointSpec` ctor * Add JavaDocs to `GatewayEndpointSpec` methods * * Add `protected` to one more `JmsPollableMessageChannelSpec` ctor
1 parent 00b771d commit 867a8cf

File tree

82 files changed

+607
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+607
-275
lines changed

spring-integration-core/src/main/java/org/springframework/integration/dsl/AbstractRouterSpec.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ public class AbstractRouterSpec<S extends AbstractRouterSpec<S, R>, R extends Ab
3434

3535
private boolean defaultToParentFlow;
3636

37-
AbstractRouterSpec(R router) {
37+
protected AbstractRouterSpec(R router) {
3838
super(router);
3939
}
4040

@@ -100,7 +100,7 @@ public S defaultOutputToParentFlow() {
100100
return _this();
101101
}
102102

103-
boolean isDefaultToParentFlow() {
103+
protected boolean isDefaultToParentFlow() {
104104
return this.defaultToParentFlow;
105105
}
106106

spring-integration-core/src/main/java/org/springframework/integration/dsl/AggregatorSpec.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ public class AggregatorSpec extends CorrelationHandlerSpec<AggregatorSpec, Aggre
3939

4040
private Function<MessageGroup, Map<String, Object>> headersFunction;
4141

42-
AggregatorSpec() {
42+
protected AggregatorSpec() {
4343
super(new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor()));
4444
}
4545

spring-integration-core/src/main/java/org/springframework/integration/dsl/BarrierSpec.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ public class BarrierSpec extends ConsumerEndpointSpec<BarrierSpec, BarrierMessag
5252

5353
private boolean async;
5454

55-
BarrierSpec(long timeout) {
55+
protected BarrierSpec(long timeout) {
5656
super(null);
5757
this.timeout = timeout;
5858
}

spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java

+33-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -121,10 +121,10 @@ public abstract class BaseIntegrationFlowDefinition<B extends BaseIntegrationFlo
121121

122122
private static final String MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL = "'messageProcessorSpec' must not be null";
123123

124-
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
125-
126124
private static final Set<MessageProducer> REFERENCED_REPLY_PRODUCERS = new HashSet<>();
127125

126+
protected static final SpelExpressionParser PARSER = new SpelExpressionParser(); //NOSONAR - final
127+
128128
protected final Map<Object, String> integrationComponents = new LinkedHashMap<>(); //NOSONAR - final
129129

130130
private MessageChannel currentMessageChannel;
@@ -380,7 +380,7 @@ public B wireTap(IntegrationFlow flow, Consumer<WireTapSpec> wireTapConfigurer)
380380
return wireTap(wireTapChannel, wireTapConfigurer);
381381
}
382382

383-
private MessageChannel obtainInputChannelFromFlow(IntegrationFlow flow) {
383+
protected MessageChannel obtainInputChannelFromFlow(IntegrationFlow flow) {
384384
Assert.notNull(flow, "'flow' must not be null");
385385
MessageChannel messageChannel = flow.getInputChannel();
386386
if (messageChannel == null) {
@@ -1222,6 +1222,18 @@ public B enrichHeaders(MapBuilder<?, String, Object> headers,
12221222
return enrichHeaders(headers.get(), endpointConfigurer);
12231223
}
12241224

1225+
/**
1226+
* Accept a {@link Map} of values to be used for the
1227+
* {@link Message} header enrichment.
1228+
* {@code values} can apply an {@link Expression}
1229+
* to be evaluated against a request {@link Message}.
1230+
* @param headers the Map of headers to enrich.
1231+
* @return the current {@link IntegrationFlowDefinition}.
1232+
*/
1233+
public B enrichHeaders(Map<String, Object> headers) {
1234+
return enrichHeaders(headers, null);
1235+
}
1236+
12251237
/**
12261238
* Accept a {@link Map} of values to be used for the
12271239
* {@link Message} header enrichment.
@@ -1908,7 +1920,7 @@ public B route(MessageProcessorSpec<?> messageProcessorSpec,
19081920
return route(new RouterSpec<>(new MethodInvokingRouter(processor)), routerConfigurer);
19091921
}
19101922

1911-
private <R extends AbstractMessageRouter, S extends AbstractRouterSpec<S, R>> B route(S routerSpec,
1923+
protected <R extends AbstractMessageRouter, S extends AbstractRouterSpec<? super S, R>> B route(S routerSpec,
19121924
Consumer<S> routerConfigurer) {
19131925

19141926
if (routerConfigurer != null) {
@@ -2825,6 +2837,17 @@ public <I, O> B fluxTransform(Function<? super Flux<Message<I>>, ? extends Publi
28252837
.addComponent(downstream);
28262838
}
28272839

2840+
/**
2841+
* Add a {@value IntegrationContextUtils#NULL_CHANNEL_BEAN_NAME} bean into this flow
2842+
* definition as a terminal operator.
2843+
* @return The {@link IntegrationFlow} instance based on this definition.
2844+
* @since 5.1
2845+
*/
2846+
public IntegrationFlow nullChannel() {
2847+
return channel(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)
2848+
.get();
2849+
}
2850+
28282851
/**
28292852
* Represent an Integration Flow as a Reactive Streams {@link Publisher} bean.
28302853
* @param <T> the expected {@code payload} type
@@ -2858,19 +2881,7 @@ protected <T> Publisher<Message<T>> toReactivePublisher() {
28582881
return new PublisherIntegrationFlow<>(components, publisher);
28592882
}
28602883

2861-
/**
2862-
* Add a {@value IntegrationContextUtils#NULL_CHANNEL_BEAN_NAME} bean into this flow
2863-
* definition as a terminal operator.
2864-
* @return The {@link IntegrationFlow} instance based on this definition.
2865-
* @since 5.1
2866-
*/
2867-
public IntegrationFlow nullChannel() {
2868-
return channel(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)
2869-
.get();
2870-
}
2871-
2872-
@SuppressWarnings(UNCHECKED)
2873-
private <S extends ConsumerEndpointSpec<S, ? extends MessageHandler>> B register(S endpointSpec,
2884+
protected <S extends ConsumerEndpointSpec<? super S, ? extends MessageHandler>> B register(S endpointSpec,
28742885
Consumer<S> endpointConfigurer) {
28752886

28762887
if (endpointConfigurer != null) {
@@ -2906,7 +2917,7 @@ public IntegrationFlow nullChannel() {
29062917
return addComponent(endpointSpec).currentComponent(factoryBeanTuple2.getT2());
29072918
}
29082919

2909-
private B registerOutputChannelIfCan(MessageChannel outputChannel) {
2920+
protected B registerOutputChannelIfCan(MessageChannel outputChannel) {
29102921
if (!(outputChannel instanceof FixedSubscriberChannelPrototype)) {
29112922
addComponent(outputChannel, null);
29122923
Object currComponent = getCurrentComponent();
@@ -2947,7 +2958,7 @@ else if (currComponent instanceof SourcePollingChannelAdapterSpec) {
29472958
return _this();
29482959
}
29492960

2950-
private boolean isOutputChannelRequired() {
2961+
protected boolean isOutputChannelRequired() {
29512962
Object currentElement = getCurrentComponent();
29522963
if (currentElement != null) {
29532964
if (AopUtils.isAopProxy(currentElement)) {
@@ -3006,27 +3017,15 @@ else if (currentChannel != null) {
30063017
return this.integrationFlow;
30073018
}
30083019

3009-
private void checkReuse(MessageProducer replyHandler) {
3020+
protected void checkReuse(MessageProducer replyHandler) {
30103021
Assert.isTrue(!REFERENCED_REPLY_PRODUCERS.contains(replyHandler),
30113022
"A reply MessageProducer may only be referenced once ("
30123023
+ replyHandler
30133024
+ ") - use @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) on @Bean definition.");
30143025
REFERENCED_REPLY_PRODUCERS.add(replyHandler);
30153026
}
30163027

3017-
/**
3018-
* Accept a {@link Map} of values to be used for the
3019-
* {@link Message} header enrichment.
3020-
* {@code values} can apply an {@link Expression}
3021-
* to be evaluated against a request {@link Message}.
3022-
* @param headers the Map of headers to enrich.
3023-
* @return the current {@link IntegrationFlowDefinition}.
3024-
*/
3025-
public B enrichHeaders(Map<String, Object> headers) {
3026-
return enrichHeaders(headers, null);
3027-
}
3028-
3029-
private static Object extractProxyTarget(Object target) {
3028+
protected static Object extractProxyTarget(Object target) {
30303029
if (!(target instanceof Advised)) {
30313030
return target;
30323031
}

spring-integration-core/src/main/java/org/springframework/integration/dsl/DelayerEndpointSpec.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,11 +42,11 @@
4242
*
4343
* @since 5.0
4444
*/
45-
public final class DelayerEndpointSpec extends ConsumerEndpointSpec<DelayerEndpointSpec, DelayHandler> {
45+
public class DelayerEndpointSpec extends ConsumerEndpointSpec<DelayerEndpointSpec, DelayHandler> {
4646

4747
private final List<Advice> delayedAdvice = new LinkedList<>();
4848

49-
DelayerEndpointSpec(DelayHandler delayHandler) {
49+
protected DelayerEndpointSpec(DelayHandler delayHandler) {
5050
super(delayHandler);
5151
Assert.notNull(delayHandler, "'delayHandler' must not be null.");
5252
this.handler.setDelayedAdviceChain(this.delayedAdvice);

spring-integration-core/src/main/java/org/springframework/integration/dsl/DirectChannelSpec.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,4 @@ protected DirectChannel doGet() {
3737
return super.doGet();
3838
}
3939

40-
DirectChannelSpec() {
41-
}
42-
4340
}

spring-integration-core/src/main/java/org/springframework/integration/dsl/EnricherSpec.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,11 +47,11 @@
4747
*/
4848
public class EnricherSpec extends ConsumerEndpointSpec<EnricherSpec, ContentEnricher> {
4949

50-
private final Map<String, Expression> propertyExpressions = new HashMap<>();
50+
protected final Map<String, Expression> propertyExpressions = new HashMap<>(); // NOSONAR - final
5151

52-
private final Map<String, HeaderValueMessageProcessor<?>> headerExpressions = new HashMap<>();
52+
protected final Map<String, HeaderValueMessageProcessor<?>> headerExpressions = new HashMap<>(); // NOSONAR - final
5353

54-
EnricherSpec() {
54+
protected EnricherSpec() {
5555
super(new ContentEnricher());
5656
}
5757

spring-integration-core/src/main/java/org/springframework/integration/dsl/ExecutorChannelSpec.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ public class ExecutorChannelSpec extends LoadBalancingChannelSpec<ExecutorChanne
2929

3030
private final Executor executor;
3131

32-
ExecutorChannelSpec(Executor executor) {
32+
protected ExecutorChannelSpec(Executor executor) {
3333
this.executor = executor;
3434
}
3535

spring-integration-core/src/main/java/org/springframework/integration/dsl/FilterEndpointSpec.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,9 +26,9 @@
2626
*
2727
* @since 5.0
2828
*/
29-
public final class FilterEndpointSpec extends ConsumerEndpointSpec<FilterEndpointSpec, MessageFilter> {
29+
public class FilterEndpointSpec extends ConsumerEndpointSpec<FilterEndpointSpec, MessageFilter> {
3030

31-
FilterEndpointSpec(MessageFilter messageFilter) {
31+
protected FilterEndpointSpec(MessageFilter messageFilter) {
3232
super(messageFilter);
3333
}
3434

spring-integration-core/src/main/java/org/springframework/integration/dsl/FluxMessageChannelSpec.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
2626
*/
2727
public class FluxMessageChannelSpec extends MessageChannelSpec<FluxMessageChannelSpec, FluxMessageChannel> {
2828

29-
FluxMessageChannelSpec() {
29+
protected FluxMessageChannelSpec() {
3030
this.channel = new FluxMessageChannel();
3131
}
3232

spring-integration-core/src/main/java/org/springframework/integration/dsl/GatewayEndpointSpec.java

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,43 +26,73 @@
2626
*
2727
* @since 5.0
2828
*/
29-
public final class GatewayEndpointSpec extends ConsumerEndpointSpec<GatewayEndpointSpec, GatewayMessageHandler> {
29+
public class GatewayEndpointSpec extends ConsumerEndpointSpec<GatewayEndpointSpec, GatewayMessageHandler> {
3030

31-
GatewayEndpointSpec(MessageChannel requestChannel) {
31+
protected GatewayEndpointSpec(MessageChannel requestChannel) {
3232
super(new GatewayMessageHandler());
3333
this.handler.setRequestChannel(requestChannel);
3434
}
3535

36-
GatewayEndpointSpec(String requestChannel) {
36+
protected GatewayEndpointSpec(String requestChannel) {
3737
super(new GatewayMessageHandler());
3838
this.handler.setRequestChannelName(requestChannel);
3939
}
4040

41+
/**
42+
* Set a reply channel.
43+
* @param replyChannel the reply channel
44+
* @return the spec
45+
*/
4146
public GatewayEndpointSpec replyChannel(MessageChannel replyChannel) {
4247
this.handler.setReplyChannel(replyChannel);
4348
return this;
4449
}
4550

51+
/**
52+
* Set a reply channel.
53+
* @param replyChannel the reply channel
54+
* @return the spec
55+
*/
4656
public GatewayEndpointSpec replyChannel(String replyChannel) {
4757
this.handler.setReplyChannelName(replyChannel);
4858
return this;
4959
}
5060

61+
/**
62+
* Set an error channel.
63+
* @param errorChannel the error channel
64+
* @return the spec
65+
*/
5166
public GatewayEndpointSpec errorChannel(MessageChannel errorChannel) {
5267
this.handler.setErrorChannel(errorChannel);
5368
return this;
5469
}
5570

71+
/**
72+
* Set an error channel.
73+
* @param errorChannel the error channel
74+
* @return the spec
75+
*/
5676
public GatewayEndpointSpec errorChannel(String errorChannel) {
5777
this.handler.setErrorChannelName(errorChannel);
5878
return this;
5979
}
6080

81+
/**
82+
* Set a request timeout.
83+
* @param requestTimeout the request timeout
84+
* @return the spec
85+
*/
6186
public GatewayEndpointSpec requestTimeout(Long requestTimeout) {
6287
this.handler.setRequestTimeout(requestTimeout);
6388
return this;
6489
}
6590

91+
/**
92+
* Set a reply timeout.
93+
* @param replyTimeout the reply timeout
94+
* @return the spec
95+
*/
6696
public GatewayEndpointSpec replyTimeout(Long replyTimeout) {
6797
this.handler.setReplyTimeout(replyTimeout);
6898
return this;

0 commit comments

Comments
 (0)