diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundChannelAdapterSpec.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundChannelAdapterSpec.java index 094c2f010f..1209d3b618 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundChannelAdapterSpec.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundChannelAdapterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,13 +43,13 @@ public abstract class AmqpInboundChannelAdapterSpec protected final MessageListenerContainerSpec listenerContainerSpec; // NOSONAR final protected AmqpInboundChannelAdapterSpec(MessageListenerContainerSpec listenerContainerSpec) { - super(new AmqpInboundChannelAdapter(listenerContainerSpec.get())); + super(new AmqpInboundChannelAdapter(listenerContainerSpec.getObject())); this.listenerContainerSpec = listenerContainerSpec; } @Override public Map getComponentsToRegister() { - return Collections.singletonMap(this.listenerContainerSpec.get(), this.listenerContainerSpec.getId()); + return Collections.singletonMap(this.listenerContainerSpec.getObject(), this.listenerContainerSpec.getId()); } } diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundGatewaySpec.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundGatewaySpec.java index 52e611a9da..ec66787129 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundGatewaySpec.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundGatewaySpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public abstract class AmqpInboundGatewaySpec protected final AbstractMessageListenerContainerSpec listenerContainerSpec; // NOSONAR final protected AmqpInboundGatewaySpec(AbstractMessageListenerContainerSpec listenerContainerSpec) { - super(new AmqpInboundGateway(listenerContainerSpec.get())); + super(new AmqpInboundGateway(listenerContainerSpec.getObject())); this.listenerContainerSpec = listenerContainerSpec; } @@ -53,16 +53,16 @@ public abstract class AmqpInboundGatewaySpec * @param listenerContainerSpec the {@link AbstractMessageListenerContainerSpec} to use. * @param amqpTemplate the {@link AmqpTemplate} to use. */ - AmqpInboundGatewaySpec( - AbstractMessageListenerContainerSpec listenerContainerSpec, + AmqpInboundGatewaySpec(AbstractMessageListenerContainerSpec listenerContainerSpec, AmqpTemplate amqpTemplate) { - super(new AmqpInboundGateway(listenerContainerSpec.get(), amqpTemplate)); + + super(new AmqpInboundGateway(listenerContainerSpec.getObject(), amqpTemplate)); this.listenerContainerSpec = listenerContainerSpec; } @Override public Map getComponentsToRegister() { - return Collections.singletonMap(this.listenerContainerSpec.get(), this.listenerContainerSpec.getId()); + return Collections.singletonMap(this.listenerContainerSpec.getObject(), this.listenerContainerSpec.getId()); } } diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/RabbitStreamMessageHandlerSpec.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/RabbitStreamMessageHandlerSpec.java index fde1aef521..9f703c07d8 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/RabbitStreamMessageHandlerSpec.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/RabbitStreamMessageHandlerSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,7 +122,7 @@ public class RabbitStreamMessageHandlerSpec * Set to true to wait for a confirmation. * @param sync true to wait. * @return this spec. - * @see #setConfirmTimeout(long) + * @see #confirmTimeout(long) */ public RabbitStreamMessageHandlerSpec sync(boolean sync) { this.target.setSync(sync); diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/dsl/AmqpTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/dsl/AmqpTests.java index 1a4ca0cf81..3b457d338d 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/dsl/AmqpTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/dsl/AmqpTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,7 @@ import org.springframework.context.Lifecycle; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.amqp.channel.AbstractAmqpChannel; +import org.springframework.integration.amqp.channel.PollableAmqpChannel; import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter.BatchMode; import org.springframework.integration.amqp.inbound.AmqpInboundGateway; import org.springframework.integration.amqp.support.AmqpHeaderMapper; @@ -472,15 +473,16 @@ public class AmqpTests { } @Bean - public AbstractAmqpChannel unitChannel(ConnectionFactory rabbitConnectionFactory) { + public AmqpPollableMessageChannelSpec unitChannel( + ConnectionFactory rabbitConnectionFactory) { + return Amqp.pollableChannel(rabbitConnectionFactory) .queueName("si.dsl.test") .channelTransacted(true) .extractPayload(true) .inboundHeaderMapper(mapperIn()) .outboundHeaderMapper(mapperOut()) - .defaultDeliveryMode(MessageDeliveryMode.NON_PERSISTENT) - .get(); + .defaultDeliveryMode(MessageDeliveryMode.NON_PERSISTENT); } @Bean diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/RabbitStreamMessageHandlerTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/RabbitStreamMessageHandlerTests.java index 0088383b00..3580fbae9a 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/RabbitStreamMessageHandlerTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/RabbitStreamMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 the original author or authors. + * Copyright 2021-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Gary Russell * @author Chris Bono + * @author Artem Bilan + * * @since 6.0 */ public class RabbitStreamMessageHandlerTests implements RabbitTestContainer { @@ -56,7 +58,7 @@ public class RabbitStreamMessageHandlerTests implements RabbitTestContainer { RabbitStreamMessageHandler handler = RabbitStream.outboundStreamAdapter(streamTemplate) .sync(true) - .get(); + .getObject(); handler.handleMessage(MessageBuilder.withPayload("foo") .setHeader("bar", "baz") diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java index f004c2a0a8..e0f624a6c1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 the original author or authors. + * Copyright 2019-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.integration.dsl; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.concurrent.Executor; import java.util.function.Consumer; @@ -233,7 +232,7 @@ public abstract class BaseIntegrationFlowDefinition messageChannelSpec) { Assert.notNull(messageChannelSpec, "'messageChannelSpec' must not be null"); - return channel(messageChannelSpec.get()); + return channel(messageChannelSpec.getObject()); } /** @@ -367,7 +366,7 @@ public abstract class BaseIntegrationFlowDefinition * This method can be used after any {@link #channel} for explicit {@link MessageChannel}, - * but with the caution do not impact existing {@link org.springframework.messaging.support.ChannelInterceptor}s. + * but with the caution do not impact existing {@link ChannelInterceptor}s. * @param wireTapChannel the {@link MessageChannel} bean name to wire-tap. * @return the current {@link BaseIntegrationFlowDefinition}. */ @@ -377,8 +376,7 @@ public abstract class BaseIntegrationFlowDefinition * {@code @@ -388,7 +386,7 @@ public abstract class BaseIntegrationFlowDefinition * This method can be used after any {@link #channel} for explicit {@link MessageChannel}, - * but with the caution do not impact existing {@link org.springframework.messaging.support.ChannelInterceptor}s. + * but with the caution do not impact existing {@link ChannelInterceptor}s. * @param wireTapChannel the {@link MessageChannel} to wire-tap. * @return the current {@link BaseIntegrationFlowDefinition}. */ @@ -398,8 +396,7 @@ public abstract class BaseIntegrationFlowDefinition * {@code @@ -409,7 +406,7 @@ public abstract class BaseIntegrationFlowDefinition * This method can be used after any {@link #channel} for explicit {@link MessageChannel}, - * but with the caution do not impact existing {@link org.springframework.messaging.support.ChannelInterceptor}s. + * but with the caution do not impact existing {@link ChannelInterceptor}s. * @param flow the {@link IntegrationFlow} for wire-tap subflow as an alternative to the {@code wireTapChannel}. * @param wireTapConfigurer the {@link Consumer} to accept options for the {@link WireTap}. * @return the current {@link BaseIntegrationFlowDefinition}. @@ -438,8 +435,7 @@ public abstract class BaseIntegrationFlowDefinition * {@code @@ -449,7 +445,7 @@ public abstract class BaseIntegrationFlowDefinition * This method can be used after any {@link #channel} for explicit {@link MessageChannel}, - * but with the caution do not impact existing {@link org.springframework.messaging.support.ChannelInterceptor}s. + * but with the caution do not impact existing {@link ChannelInterceptor}s. * @param wireTapChannel the {@link MessageChannel} bean name to wire-tap. * @param wireTapConfigurer the {@link Consumer} to accept options for the {@link WireTap}. * @return the current {@link BaseIntegrationFlowDefinition}. @@ -462,8 +458,7 @@ public abstract class BaseIntegrationFlowDefinition * {@code @@ -473,7 +468,7 @@ public abstract class BaseIntegrationFlowDefinition * This method can be used after any {@link #channel} for explicit {@link MessageChannel}, - * but with the caution do not impact existing {@link org.springframework.messaging.support.ChannelInterceptor}s. + * but with the caution do not impact existing {@link ChannelInterceptor}s. * @param wireTapChannel the {@link MessageChannel} to wire-tap. * @param wireTapConfigurer the {@link Consumer} to accept options for the {@link WireTap}. * @return the current {@link BaseIntegrationFlowDefinition}. @@ -489,8 +484,7 @@ public abstract class BaseIntegrationFlowDefinition It is useful when an implicit {@link MessageChannel} is used between endpoints: *
 	 * {@code
@@ -500,14 +494,16 @@ public abstract class BaseIntegrationFlowDefinition
 	 * This method can be used after any {@link #channel} for explicit {@link MessageChannel},
-	 * but with the caution do not impact existing {@link org.springframework.messaging.support.ChannelInterceptor}s.
+	 * but with the caution do not impact existing {@link ChannelInterceptor}s.
 	 * @param wireTapSpec the {@link WireTapSpec} to use.
-	 * 

When this EIP-method is used in the end of flow, it appends {@code nullChannel} to terminate flow properly, - * Otherwise {@code Dispatcher has no subscribers} exception is thrown for implicit {@link DirectChannel}. + *

When this EIP-method is used in the end of flow, + * it appends a {@code nullChannel} to terminate flow properly, + * Otherwise a {@code Dispatcher has no subscribers} exception + * is thrown for implicit {@link DirectChannel}. * @return the current {@link BaseIntegrationFlowDefinition}. */ public B wireTap(WireTapSpec wireTapSpec) { - WireTap interceptor = wireTapSpec.get(); + WireTap interceptor = wireTapSpec.getObject(); InterceptableChannel currentChannel = currentInterceptableChannel(); addComponent(wireTapSpec); currentChannel.addInterceptor(interceptor); @@ -613,7 +609,7 @@ public abstract class BaseIntegrationFlowDefinition * {@code * .transform(Scripts.script("classpath:myScript.py").variable("foo", bar())) @@ -629,7 +625,7 @@ public abstract class BaseIntegrationFlowDefinition * {@code @@ -646,7 +642,7 @@ public abstract class BaseIntegrationFlowDefinition> endpointConfigurer) { Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); - MessageProcessor processor = messageProcessorSpec.get(); + MessageProcessor processor = messageProcessorSpec.getObject(); return addComponent(processor) .transform(null, new MethodInvokingTransformer(processor), endpointConfigurer); } @@ -832,7 +828,7 @@ public abstract class BaseIntegrationFlowDefinition messageProcessorSpec, Consumer endpointConfigurer) { Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); - MessageProcessor processor = messageProcessorSpec.get(); + MessageProcessor processor = messageProcessorSpec.getObject(); return addComponent(processor) .filter(null, new MethodInvokingSelector(processor), endpointConfigurer); } @@ -1089,7 +1085,7 @@ public abstract class BaseIntegrationFlowDefinition> endpointConfigurer) { Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); - MessageProcessor processor = messageProcessorSpec.get(); + MessageProcessor processor = messageProcessorSpec.getObject(); return addComponent(processor) .handle(new ServiceActivatingHandler(processor), endpointConfigurer); } @@ -1118,7 +1114,7 @@ public abstract class BaseIntegrationFlowDefinition tuple2 = headerEnricherSpec.get(); + Tuple2 tuple2 = headerEnricherSpec.getObject(); return addComponents(headerEnricherSpec.getComponentsToRegister()) .handle(tuple2.getT2(), endpointConfigurer); } @@ -1478,7 +1474,7 @@ public abstract class BaseIntegrationFlowDefinition> endpointConfigurer) { Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); - MessageProcessor processor = messageProcessorSpec.get(); + MessageProcessor processor = messageProcessorSpec.getObject(); return addComponent(processor) .split(new MethodInvokingSplitter(processor), endpointConfigurer); } @@ -1569,7 +1565,7 @@ public abstract class BaseIntegrationFlowDefinition B split(MessageHandlerSpec splitterMessageHandlerSpec, Consumer> endpointConfigurer) { Assert.notNull(splitterMessageHandlerSpec, "'splitterMessageHandlerSpec' must not be null"); - return split(splitterMessageHandlerSpec.get(), endpointConfigurer); + return split(splitterMessageHandlerSpec.getObject(), endpointConfigurer); } /** @@ -1960,7 +1956,7 @@ public abstract class BaseIntegrationFlowDefinition> routerConfigurer) { Assert.notNull(messageProcessorSpec, MESSAGE_PROCESSOR_SPEC_MUST_NOT_BE_NULL); - MessageProcessor processor = messageProcessorSpec.get(); + MessageProcessor processor = messageProcessorSpec.getObject(); addComponent(processor); return route(new RouterSpec<>(new MethodInvokingRouter(processor)), routerConfigurer); @@ -2713,7 +2709,7 @@ public abstract class BaseIntegrationFlowDefinition factoryBeanTuple2 = endpointSpec.get(); + Tuple2 factoryBeanTuple2 = endpointSpec.getObject(); addComponents(endpointSpec.getComponentsToRegister()); - if (inputChannel instanceof MessageChannelReference) { - factoryBeanTuple2.getT1().setInputChannelName(((MessageChannelReference) inputChannel).getName()); + if (inputChannel instanceof MessageChannelReference messageChannelReference) { + factoryBeanTuple2.getT1().setInputChannelName(messageChannelReference.getName()); } else { - if (inputChannel instanceof FixedSubscriberChannelPrototype) { - String beanName = ((FixedSubscriberChannelPrototype) inputChannel).getName(); + if (inputChannel instanceof FixedSubscriberChannelPrototype fixedSubscriberChannel) { + String beanName = fixedSubscriberChannel.getName(); inputChannel = new FixedSubscriberChannel(factoryBeanTuple2.getT2()); if (beanName != null) { ((FixedSubscriberChannel) inputChannel).setBeanName(beanName); @@ -3002,8 +2998,8 @@ public abstract class BaseIntegrationFlowDefinition lastComponent = - components.keySet() - .stream() - .reduce((first, second) -> second); - if (lastComponent.get() instanceof WireTapSpec) { - bridge(); - } + components.keySet() + .stream() + .reduce((first, second) -> second) + .filter(WireTapSpec.class::isInstance) + .ifPresent((wireTap) -> bridge()); } this.integrationFlow = new StandardIntegrationFlow(components); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java index b1253dd8d8..ca86c24a06 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/EndpointSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,7 +86,7 @@ public abstract class EndpointSpec, F extends Be if (components != null) { this.componentsToRegister.putAll(components); } - return poller(pollerMetadataSpec.get()); + return poller(pollerMetadataSpec.getObject()); } /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java index 9ca2ade6ad..5337dca13f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,21 @@ package org.springframework.integration.dsl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.context.Lifecycle; import org.springframework.context.SmartLifecycle; import org.springframework.expression.spel.standard.SpelExpressionParser; /** - * The common Builder abstraction. The {@link #get()} method returns the final component. + * The common Builder abstraction. + * If used as a bean definition, must be treated as an {@link FactoryBean}, + * therefore its {@link #getObject()} method must not be called in the target configuration. * * @param the target {@link IntegrationComponentSpec} implementation type. * @param the target type. @@ -35,11 +41,12 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; */ @IntegrationDsl public abstract class IntegrationComponentSpec, T> - extends AbstractFactoryBean - implements SmartLifecycle { + implements FactoryBean, InitializingBean, DisposableBean, SmartLifecycle { protected static final SpelExpressionParser PARSER = new SpelExpressionParser(); + protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR - final + protected volatile T target; // NOSONAR private String id; @@ -61,8 +68,25 @@ public abstract class IntegrationComponentSpec getObjectType() { + return getObject().getClass(); + } + + /** + * !!! This method must not be called from the target configuration !!! + * @return the object backed by this factory bean. + */ + @Override + public T getObject() { if (this.target == null) { this.target = doGet(); } @@ -70,69 +94,57 @@ public abstract class IntegrationComponentSpec getObjectType() { - return get().getClass(); - } - - @Override - protected T createInstance() { - T instance = get(); - if (instance instanceof InitializingBean) { - try { - ((InitializingBean) instance).afterPropertiesSet(); - } - catch (Exception e) { - throw new IllegalStateException("Cannot initialize bean: " + instance, e); + public void afterPropertiesSet() { + try { + if (this.target instanceof InitializingBean initializingBean) { + initializingBean.afterPropertiesSet(); } } - return instance; + catch (Exception ex) { + throw new BeanInitializationException("Cannot initialize bean: " + this.target, ex); + } } @Override - protected void destroyInstance(T instance) { - if (instance instanceof DisposableBean) { + public void destroy() { + if (this.target instanceof DisposableBean disposableBean) { try { - ((DisposableBean) instance).destroy(); + disposableBean.destroy(); } catch (Exception e) { - throw new IllegalStateException("Cannot destroy bean: " + instance, e); + throw new IllegalStateException("Cannot destroy bean: " + this.target, e); } } } @Override public void start() { - T instance = get(); - if (instance instanceof Lifecycle) { - ((Lifecycle) instance).start(); + if (this.target instanceof Lifecycle lifecycle) { + lifecycle.start(); } } @Override public void stop() { - T instance = get(); - if (instance instanceof Lifecycle) { - ((Lifecycle) instance).stop(); + if (this.target instanceof Lifecycle lifecycle) { + lifecycle.stop(); } } @Override public boolean isRunning() { - T instance = get(); - return !(instance instanceof Lifecycle) || ((Lifecycle) instance).isRunning(); + return !(this.target instanceof Lifecycle lifecycle) || lifecycle.isRunning(); } @Override public boolean isAutoStartup() { - T instance = get(); - return instance instanceof SmartLifecycle && ((SmartLifecycle) instance).isAutoStartup(); + return this.target instanceof SmartLifecycle lifecycle && lifecycle.isAutoStartup(); } @Override public void stop(Runnable callback) { - T instance = get(); - if (instance instanceof SmartLifecycle) { - ((SmartLifecycle) instance).stop(callback); + if (this.target instanceof SmartLifecycle lifecycle) { + lifecycle.stop(callback); } else { callback.run(); @@ -141,9 +153,8 @@ public abstract class IntegrationComponentSpec messageChannelSpec) { Assert.notNull(messageChannelSpec, "'messageChannelSpec' must not be null"); - return from(messageChannelSpec.get()); + return from(messageChannelSpec.getObject()); } /** @@ -217,7 +217,7 @@ public interface IntegrationFlow { Consumer endpointConfigurer) { Assert.notNull(messageSourceSpec, "'messageSourceSpec' must not be null"); - return from(messageSourceSpec.get(), endpointConfigurer, registerComponents(messageSourceSpec)); + return from(messageSourceSpec.getObject(), endpointConfigurer, registerComponents(messageSourceSpec)); } /** @@ -321,7 +321,7 @@ public interface IntegrationFlow { * @see MessageProducerSpec */ static IntegrationFlowBuilder from(MessageProducerSpec messageProducerSpec) { - return from(messageProducerSpec.get(), registerComponents(messageProducerSpec)); + return from(messageProducerSpec.getObject(), registerComponents(messageProducerSpec)); } /** @@ -362,7 +362,7 @@ public interface IntegrationFlow { * @since 6.0 */ static IntegrationFlowBuilder from(MessagingGatewaySpec inboundGatewaySpec) { - return from(inboundGatewaySpec.get(), registerComponents(inboundGatewaySpec)); + return from(inboundGatewaySpec.getObject(), registerComponents(inboundGatewaySpec)); } /** @@ -445,14 +445,14 @@ public interface IntegrationFlow { "' must be declared as a bean in the application context"); Object lastIntegrationComponentFromOther = integrationComponents.keySet().stream().reduce((prev, next) -> next).orElse(null); - if (lastIntegrationComponentFromOther instanceof MessageChannel) { - return from((MessageChannel) lastIntegrationComponentFromOther); + if (lastIntegrationComponentFromOther instanceof MessageChannel messageChannel) { + return from(messageChannel); } - else if (lastIntegrationComponentFromOther instanceof ConsumerEndpointFactoryBean) { - MessageHandler handler = ((ConsumerEndpointFactoryBean) lastIntegrationComponentFromOther).getHandler(); + else if (lastIntegrationComponentFromOther instanceof ConsumerEndpointFactoryBean factoryBean) { + MessageHandler handler = factoryBean.getHandler(); handler = extractProxyTarget(handler); - if (handler instanceof AbstractMessageProducingHandler) { - return buildFlowFromOutputChannel((AbstractMessageProducingHandler) handler); + if (handler instanceof AbstractMessageProducingHandler producingHandler) { + return buildFlowFromOutputChannel(producingHandler); } lastIntegrationComponentFromOther = handler; // for the exception message below } @@ -489,9 +489,9 @@ public interface IntegrationFlow { } private static IntegrationFlowBuilder registerComponents(Object spec) { - if (spec instanceof ComponentsRegistration) { + if (spec instanceof ComponentsRegistration componentsRegistration) { return new IntegrationFlowBuilder() - .addComponents(((ComponentsRegistration) spec).getComponentsToRegister()); + .addComponents(componentsRegistration.getComponentsToRegister()); } return null; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/MessageChannelSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/MessageChannelSpec.java index 1f07ef2eef..8be41af56c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/MessageChannelSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/MessageChannelSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,7 +100,7 @@ public abstract class MessageChannelSpec, C e * @see WireTap */ public S wireTap(WireTapSpec wireTapSpec) { - WireTap interceptor = wireTapSpec.get(); + WireTap interceptor = wireTapSpec.getObject(); this.componentsToRegister.put(interceptor, null); return interceptor(interceptor); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/DslIntegrationConfigurationInitializer.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/DslIntegrationConfigurationInitializer.java index 7fc0e45b77..eba70d2c93 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/DslIntegrationConfigurationInitializer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/DslIntegrationConfigurationInitializer.java @@ -31,11 +31,12 @@ import org.springframework.util.Assert; * Registers {@link IntegrationFlowBeanPostProcessor} and checks if all * {@link org.springframework.integration.dsl.IntegrationComponentSpec} are extracted to * the target object using - * {@link org.springframework.integration.dsl.IntegrationComponentSpec#get()}. + * {@link org.springframework.integration.dsl.IntegrationComponentSpec#getObject()}. * * @author Artem Bilan * @author Gary Russell * @author Chris Bono + * * @since 5.0 * * @see org.springframework.integration.config.IntegrationConfigurationBeanFactoryPostProcessor diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java index 9b7322e375..f180061be4 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,14 +113,14 @@ public class IntegrationFlowBeanPostProcessor @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof StandardIntegrationFlow) { - return processStandardIntegrationFlow((StandardIntegrationFlow) bean, beanName); + if (bean instanceof StandardIntegrationFlow standardIntegrationFlow) { + return processStandardIntegrationFlow(standardIntegrationFlow, beanName); } - else if (bean instanceof IntegrationFlow) { - return processIntegrationFlowImpl((IntegrationFlow) bean, beanName); + else if (bean instanceof IntegrationFlow integrationFlow) { + return processIntegrationFlowImpl(integrationFlow, beanName); } - if (bean instanceof IntegrationComponentSpec) { - processIntegrationComponentSpec(beanName, (IntegrationComponentSpec) bean); + if (bean instanceof IntegrationComponentSpec integrationComponentSpec) { + processIntegrationComponentSpec(beanName, integrationComponentSpec); } return bean; } @@ -156,8 +156,8 @@ public class IntegrationFlowBeanPostProcessor for (Map.Entry entry : integrationComponents.entrySet()) { Object component = entry.getKey(); if (component instanceof ConsumerEndpointSpec endpointSpec) { - MessageHandler messageHandler = endpointSpec.get().getT2(); - ConsumerEndpointFactoryBean endpoint = endpointSpec.get().getT1(); + MessageHandler messageHandler = endpointSpec.getObject().getT2(); + ConsumerEndpointFactoryBean endpoint = endpointSpec.getObject().getT1(); String id = endpointSpec.getId(); if (id == null) { @@ -177,8 +177,8 @@ public class IntegrationFlowBeanPostProcessor registerComponent(endpoint, id, flowBeanName); targetIntegrationComponents.put(endpoint, id); } - else if (component instanceof MessageChannelReference) { - String channelBeanName = ((MessageChannelReference) component).getName(); + else if (component instanceof MessageChannelReference messageChannelReference) { + String channelBeanName = messageChannelReference.getName(); if (!this.beanFactory.containsBean(channelBeanName)) { DirectChannel directChannel = new DirectChannel(); registerComponent(directChannel, channelBeanName, flowBeanName); @@ -196,7 +196,7 @@ public class IntegrationFlowBeanPostProcessor generateBeanName(o.getKey(), flowNamePrefix, o.getValue(), useFlowIdAsPrefix))); } - SourcePollingChannelAdapterFactoryBean pollingChannelAdapterFactoryBean = spec.get().getT1(); + SourcePollingChannelAdapterFactoryBean pollingChannelAdapterFactoryBean = spec.getObject().getT1(); String id = spec.getId(); if (id == null) { id = generateBeanName(pollingChannelAdapterFactoryBean, flowNamePrefix, entry.getValue(), @@ -209,12 +209,13 @@ public class IntegrationFlowBeanPostProcessor registerComponent(pollingChannelAdapterFactoryBean, id, flowBeanName); targetIntegrationComponents.put(pollingChannelAdapterFactoryBean, id); - MessageSource messageSource = spec.get().getT2(); + MessageSource messageSource = spec.getObject().getT2(); if (noBeanPresentForComponent(messageSource, flowBeanName)) { String messageSourceId = id + ".source"; - if (messageSource instanceof NamedComponent - && ((NamedComponent) messageSource).getComponentName() != null) { - messageSourceId = ((NamedComponent) messageSource).getComponentName(); + if (messageSource instanceof NamedComponent namedComponent + && namedComponent.getComponentName() != null) { + + messageSourceId = namedComponent.getComponentName(); } registerComponent(messageSource, messageSourceId, flowBeanName); } @@ -342,7 +343,7 @@ public class IntegrationFlowBeanPostProcessor } private void processIntegrationComponentSpec(String beanName, IntegrationComponentSpec bean) { - Object target = bean.get(); + Object target = bean.getObject(); invokeBeanInitializationHooks(beanName, target); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/reactive/FluxMessageChannelTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/reactive/FluxMessageChannelTests.java index 6c4de15cab..bed97230ba 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/reactive/FluxMessageChannelTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/reactive/FluxMessageChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -119,7 +119,7 @@ public class FluxMessageChannelTests { @Test void testFluxMessageChannelCleanUp() throws InterruptedException { - FluxMessageChannel flux = MessageChannels.flux().get(); + FluxMessageChannel flux = MessageChannels.flux().getObject(); CountDownLatch finishLatch = new CountDownLatch(1); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/PollersTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/PollersTests.java index e2fc767ddd..089c93d70d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/PollersTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/PollersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 the original author or authors. + * Copyright 2019-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,19 +35,19 @@ public class PollersTests { @Test public void testDurations() { - PeriodicTrigger trigger = (PeriodicTrigger) Pollers.fixedDelay(Duration.ofMinutes(1L)).get().getTrigger(); + PeriodicTrigger trigger = (PeriodicTrigger) Pollers.fixedDelay(Duration.ofMinutes(1L)).getObject().getTrigger(); assertThat(trigger.getPeriodDuration()).isEqualTo(Duration.ofSeconds(60)); assertThat(trigger.isFixedRate()).isFalse(); trigger = (PeriodicTrigger) Pollers.fixedDelay(Duration.ofMinutes(1L), Duration.ofSeconds(10L)) - .get().getTrigger(); + .getObject().getTrigger(); assertThat(trigger.getPeriodDuration()).isEqualTo(Duration.ofSeconds(60)); assertThat(trigger.getInitialDelayDuration()).isEqualTo(Duration.ofSeconds(10)); assertThat(trigger.isFixedRate()).isFalse(); - trigger = (PeriodicTrigger) Pollers.fixedRate(Duration.ofMinutes(1L)).get().getTrigger(); + trigger = (PeriodicTrigger) Pollers.fixedRate(Duration.ofMinutes(1L)).getObject().getTrigger(); assertThat(trigger.getPeriodDuration()).isEqualTo(Duration.ofSeconds(60)); assertThat(trigger.isFixedRate()).isTrue(); trigger = (PeriodicTrigger) Pollers.fixedRate(Duration.ofMinutes(1L), Duration.ofSeconds(10L)) - .get().getTrigger(); + .getObject().getTrigger(); assertThat(trigger.getPeriodDuration()).isEqualTo(Duration.ofSeconds(60)); assertThat(trigger.getInitialDelayDuration()).isEqualTo(Duration.ofSeconds(10)); assertThat(trigger.isFixedRate()).isTrue(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java index 7496181d00..d3413cacf1 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/composition/IntegrationFlowCompositionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 the original author or authors. + * Copyright 2021-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; +import org.springframework.integration.dsl.PollerSpec; import org.springframework.integration.dsl.Pollers; import org.springframework.integration.dsl.context.IntegrationFlowContext; import org.springframework.integration.scheduling.PollerMetadata; @@ -142,8 +143,8 @@ public class IntegrationFlowCompositionTests { public static class ContextConfiguration { @Bean(PollerMetadata.DEFAULT_POLLER) - PollerMetadata defaultPoller() { - return Pollers.fixedDelay(100).get(); + PollerSpec defaultPoller() { + return Pollers.fixedDelay(100); } @Bean diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java index 47521b3c5d..c8c79f2df5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,13 +54,16 @@ import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.FixedSubscriberChannel; import org.springframework.integration.channel.NullChannel; +import org.springframework.integration.channel.PublishSubscribeChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.GenericTransformer; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.MessageChannels; +import org.springframework.integration.dsl.PollerSpec; import org.springframework.integration.dsl.Pollers; +import org.springframework.integration.dsl.QueueChannelSpec; import org.springframework.integration.dsl.Transformers; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.endpoint.EventDrivenConsumer; @@ -575,8 +578,8 @@ public class IntegrationFlowTests { } @Bean(name = PollerMetadata.DEFAULT_POLLER) - public PollerMetadata poller() { - return Pollers.fixedRate(100).get(); + public PollerSpec poller() { + return Pollers.fixedRate(100); } @Bean(name = IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME) @@ -588,8 +591,8 @@ public class IntegrationFlowTests { @Bean - public MessageChannel suppliedChannel() { - return MessageChannels.queue(10).get(); + public QueueChannelSpec suppliedChannel() { + return MessageChannels.queue(10); } } @@ -608,8 +611,8 @@ public class IntegrationFlowTests { } @Bean - public MessageChannel suppliedChannel2() { - return MessageChannels.queue(10).get(); + public QueueChannelSpec suppliedChannel2() { + return MessageChannels.queue(10); } } @@ -627,12 +630,12 @@ public class IntegrationFlowTests { @Bean public MessageChannel inputChannel() { - return MessageChannels.direct().get(); + return new DirectChannel(); } @Bean public MessageChannel foo() { - return MessageChannels.publishSubscribe().get(); + return new PublishSubscribeChannel(); } } @@ -682,7 +685,7 @@ public class IntegrationFlowTests { @Bean public MessageChannel publishSubscribeChannel() { - return MessageChannels.publishSubscribe().get(); + return new PublishSubscribeChannel(); } @Bean @@ -784,8 +787,8 @@ public class IntegrationFlowTests { private MethodInterceptor delayedAdvice; @Bean - public QueueChannel successChannel() { - return MessageChannels.queue().get(); + public QueueChannelSpec successChannel() { + return MessageChannels.queue(); } @Bean diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/gateway/GatewayDslTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/gateway/GatewayDslTests.java index 63ce7c46fe..08921d744c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/gateway/GatewayDslTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/gateway/GatewayDslTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 the original author or authors. + * Copyright 2019-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,6 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.core.MessagingTemplate; import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.MessageChannels; import org.springframework.integration.gateway.GatewayProxyFactoryBean; import org.springframework.integration.gateway.MessagingGatewaySupport; import org.springframework.integration.gateway.MethodArgsHolder; @@ -189,7 +188,7 @@ public class GatewayDslTests { @Bean public MessageChannel gatewayError() { - return MessageChannels.queue().get(); + return new QueueChannel(); } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java index 3695909145..4bdaeb1401 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java @@ -30,12 +30,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.MessageRejectedException; import org.springframework.integration.annotation.Transformer; +import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.FixedSubscriberChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.codec.Codec; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.MessageChannels; import org.springframework.integration.dsl.Transformers; import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice; import org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice; @@ -423,7 +423,7 @@ public class TransformerTests { @Bean public MessageChannel enricherReplyChannel() { - return MessageChannels.direct().get(); + return new DirectChannel(); } @Bean diff --git a/spring-integration-core/src/test/java/org/springframework/integration/json/ContentTypeConversionTests.java b/spring-integration-core/src/test/java/org/springframework/integration/json/ContentTypeConversionTests.java index 56ed5d07ee..9f9afd651d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/json/ContentTypeConversionTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/json/ContentTypeConversionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,7 @@ import java.util.Collections; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -32,6 +31,7 @@ import org.springframework.integration.annotation.GatewayHeader; import org.springframework.integration.annotation.MessagingGateway; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.dsl.DirectChannelSpec; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.MessageChannels; import org.springframework.messaging.Message; @@ -39,7 +39,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.messaging.support.ChannelInterceptor; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @since 5.0 */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig public class ContentTypeConversionTests { @Autowired @@ -91,7 +91,7 @@ public class ContentTypeConversionTests { } @Bean - public MessageChannel serviceChannel(final AtomicReference sendData) { + public DirectChannelSpec serviceChannel(AtomicReference sendData) { return MessageChannels.direct() .interceptor(new ChannelInterceptor() { @@ -101,8 +101,7 @@ public class ContentTypeConversionTests { return message; } - }) - .get(); + }); } @Bean diff --git a/spring-integration-core/src/test/kotlin/org/springframework/integration/dsl/KotlinDslTests.kt b/spring-integration-core/src/test/kotlin/org/springframework/integration/dsl/KotlinDslTests.kt index 23bb5c5cb1..bf0f87f589 100644 --- a/spring-integration-core/src/test/kotlin/org/springframework/integration/dsl/KotlinDslTests.kt +++ b/spring-integration-core/src/test/kotlin/org/springframework/integration/dsl/KotlinDslTests.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -231,7 +231,7 @@ class KotlinDslTests { @Bean(PollerMetadata.DEFAULT_POLLER) fun defaultPoller() = - Pollers.fixedDelay(100).maxMessagesPerPoll(1).get() + Pollers.fixedDelay(100).maxMessagesPerPoll(1) @Bean fun convertFlow() = diff --git a/spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy b/spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy index a7b38e396f..27ed13d271 100644 --- a/spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy +++ b/spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy @@ -216,7 +216,7 @@ class GroovyDslTests { @Bean(PollerMetadata.DEFAULT_POLLER) poller() { - Pollers.fixedDelay(1000).get() + Pollers.fixedDelay(1000) } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpInboundChannelAdapterSpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpInboundChannelAdapterSpec.java index 4c3549a639..3db20370d0 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpInboundChannelAdapterSpec.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpInboundChannelAdapterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ public class TcpInboundChannelAdapterSpec */ protected TcpInboundChannelAdapterSpec(AbstractConnectionFactorySpec connectionFactorySpec) { super(new TcpReceivingChannelAdapter()); - this.connectionFactory = connectionFactorySpec.get(); + this.connectionFactory = connectionFactorySpec.getObject(); this.target.setConnectionFactory(this.connectionFactory); } @@ -94,7 +94,7 @@ public class TcpInboundChannelAdapterSpec public Map getComponentsToRegister() { return this.connectionFactory != null ? Collections.singletonMap(this.connectionFactory, this.connectionFactory.getComponentName()) - : null; + : Collections.emptyMap(); } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpInboundGatewaySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpInboundGatewaySpec.java index d24018b193..0cd601dfc0 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpInboundGatewaySpec.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpInboundGatewaySpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ public class TcpInboundGatewaySpec extends MessagingGatewaySpec connectionFactorySpec) { super(new TcpInboundGateway()); - this.connectionFactory = connectionFactorySpec.get(); + this.connectionFactory = connectionFactorySpec.getObject(); this.target.setConnectionFactory(this.connectionFactory); } @@ -93,7 +93,7 @@ public class TcpInboundGatewaySpec extends MessagingGatewaySpec getComponentsToRegister() { return this.connectionFactory != null ? Collections.singletonMap(this.connectionFactory, this.connectionFactory.getComponentName()) - : null; + : Collections.emptyMap(); } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundChannelAdapterSpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundChannelAdapterSpec.java index 211aa47ce0..e1d510e576 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundChannelAdapterSpec.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundChannelAdapterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ public class TcpOutboundChannelAdapterSpec */ protected TcpOutboundChannelAdapterSpec(AbstractConnectionFactorySpec connectionFactorySpec) { this.target = new TcpSendingMessageHandler(); - this.connectionFactory = connectionFactorySpec.get(); + this.connectionFactory = connectionFactorySpec.getObject(); this.target.setConnectionFactory(this.connectionFactory); } @@ -94,7 +94,7 @@ public class TcpOutboundChannelAdapterSpec public Map getComponentsToRegister() { return this.connectionFactory != null ? Collections.singletonMap(this.connectionFactory, this.connectionFactory.getComponentName()) - : null; + : Collections.emptyMap(); } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundGatewaySpec.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundGatewaySpec.java index 9e2ba4acbd..5737bacb50 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundGatewaySpec.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/TcpOutboundGatewaySpec.java @@ -58,7 +58,7 @@ public class TcpOutboundGatewaySpec extends MessageHandlerSpec connectionFactorySpec) { this.target = new TcpOutboundGateway(); - this.connectionFactory = connectionFactorySpec.get(); + this.connectionFactory = connectionFactorySpec.getObject(); this.target.setConnectionFactory(this.connectionFactory); } @@ -120,8 +120,21 @@ public class TcpOutboundGatewaySpec extends MessageHandlerSpec getComponentsToRegister() { return this.connectionFactory != null ? Collections.singletonMap(this.connectionFactory, this.connectionFactory.getComponentName()) - : null; + : Collections.emptyMap(); } } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFacforyTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFactoryTests.java similarity index 92% rename from spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFacforyTests.java rename to spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFactoryTests.java index d30783520b..bd03f34dd7 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFacforyTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFactoryTests.java @@ -45,16 +45,18 @@ import static org.mockito.Mockito.mock; /** * @author Gary Russell * @author Tim Ysewyn + * @author Artem Bilan + * * @since 5.0 * */ -public class ConnectionFacforyTests { +public class ConnectionFactoryTests { @Test public void test() throws Exception { ApplicationEventPublisher publisher = e -> { }; - AbstractServerConnectionFactory server = Tcp.netServer(0).backlog(2).soTimeout(5000).get(); + AbstractServerConnectionFactory server = Tcp.netServer(0).backlog(2).soTimeout(5000).getObject(); final AtomicReference> received = new AtomicReference<>(); final CountDownLatch latch = new CountDownLatch(1); server.registerListener(m -> { @@ -66,7 +68,7 @@ public class ConnectionFacforyTests { server.afterPropertiesSet(); server.start(); TestingUtilities.waitListening(server, null); - AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get(); + AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).getObject(); client.setApplicationEventPublisher(publisher); client.afterPropertiesSet(); client.start(); @@ -78,20 +80,20 @@ public class ConnectionFacforyTests { } @Test - public void shouldReturnNioFlavor() throws Exception { - AbstractServerConnectionFactory server = Tcp.nioServer(0).get(); + public void shouldReturnNioFlavor() { + AbstractServerConnectionFactory server = Tcp.nioServer(0).getObject(); assertThat(server instanceof TcpNioServerConnectionFactory).isTrue(); - AbstractClientConnectionFactory client = Tcp.nioClient("localhost", server.getPort()).get(); + AbstractClientConnectionFactory client = Tcp.nioClient("localhost", server.getPort()).getObject(); assertThat(client instanceof TcpNioClientConnectionFactory).isTrue(); } @Test - public void shouldReturnNetFlavor() throws Exception { - AbstractServerConnectionFactory server = Tcp.netServer(0).get(); + public void shouldReturnNetFlavor() { + AbstractServerConnectionFactory server = Tcp.netServer(0).getObject(); assertThat(server instanceof TcpNetServerConnectionFactory).isTrue(); - AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get(); + AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).getObject(); assertThat(client instanceof TcpNetClientConnectionFactory).isTrue(); } @@ -104,7 +106,7 @@ public class ConnectionFacforyTests { .socketSupport(sockSupp) .connectionSupport(conSupp) .socketFactorySupport(factSupp) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(server, "tcpSocketSupport")).isSameAs(sockSupp); assertThat(TestUtils.getPropertyValue(server, "tcpNetConnectionSupport")).isSameAs(conSupp); assertThat(TestUtils.getPropertyValue(server, "tcpSocketFactorySupport")).isSameAs(factSupp); @@ -118,7 +120,7 @@ public class ConnectionFacforyTests { .socketSupport(sockSupp) .directBuffers(true) .connectionSupport(conSupp) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(server, "tcpSocketSupport")).isSameAs(sockSupp); assertThat(TestUtils.getPropertyValue(server, "usingDirectBuffers", Boolean.class)).isTrue(); assertThat(TestUtils.getPropertyValue(server, "tcpNioConnectionSupport")).isSameAs(conSupp); @@ -133,7 +135,7 @@ public class ConnectionFacforyTests { .socketSupport(sockSupp) .connectionSupport(conSupp) .socketFactorySupport(factSupp) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(client, "tcpSocketSupport")).isSameAs(sockSupp); assertThat(TestUtils.getPropertyValue(client, "tcpNetConnectionSupport")).isSameAs(conSupp); assertThat(TestUtils.getPropertyValue(client, "tcpSocketFactorySupport")).isSameAs(factSupp); @@ -147,7 +149,7 @@ public class ConnectionFacforyTests { .socketSupport(sockSupp) .directBuffers(true) .connectionSupport(conSupp) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(client, "tcpSocketSupport")).isSameAs(sockSupp); assertThat(TestUtils.getPropertyValue(client, "usingDirectBuffers", Boolean.class)).isTrue(); assertThat(TestUtils.getPropertyValue(client, "tcpNioConnectionSupport")).isSameAs(conSupp); diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/IpIntegrationTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/IpIntegrationTests.java index 6622bfe0b5..9e5501d08c 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/IpIntegrationTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/IpIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,6 +48,8 @@ import org.springframework.integration.ip.tcp.TcpSendingMessageHandler; import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory; import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory; import org.springframework.integration.ip.tcp.connection.TcpConnectionServerListeningEvent; +import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory; +import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory; import org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer; import org.springframework.integration.ip.tcp.serializer.TcpCodecs; import org.springframework.integration.ip.udp.MulticastSendingMessageHandler; @@ -126,21 +128,21 @@ public class IpIntegrationTests { void testTcpAdapters() { ApplicationEventPublisher publisher = e -> { }; - AbstractServerConnectionFactory server = Tcp.netServer(0).backlog(2).soTimeout(5000).id("server").get(); + AbstractServerConnectionFactory server = Tcp.netServer(0).backlog(2).soTimeout(5000).id("server").getObject(); assertThat(server.getComponentName()).isEqualTo("server"); server.setApplicationEventPublisher(publisher); server.afterPropertiesSet(); - TcpReceivingChannelAdapter inbound = Tcp.inboundAdapter(server).get(); + TcpReceivingChannelAdapter inbound = Tcp.inboundAdapter(server).getObject(); QueueChannel received = new QueueChannel(); inbound.setOutputChannel(received); inbound.afterPropertiesSet(); inbound.start(); TestingUtilities.waitListening(server, null); - AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).id("client").get(); + AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).id("client").getObject(); assertThat(client.getComponentName()).isEqualTo("client"); client.setApplicationEventPublisher(publisher); client.afterPropertiesSet(); - TcpSendingMessageHandler handler = Tcp.outboundAdapter(client).get(); + TcpSendingMessageHandler handler = Tcp.outboundAdapter(client).getObject(); handler.start(); handler.handleMessage(new GenericMessage<>("foo")); Message receivedMessage = received.receive(10000); @@ -193,7 +195,8 @@ public class IpIntegrationTests { UdpMulticastOutboundChannelAdapterSpec udpMulticastOutboundChannelAdapterSpec2 = udpMulticastOutboundChannelAdapterSpec1.timeToLive(10); - assertThat(udpMulticastOutboundChannelAdapterSpec2.get()).isInstanceOf(MulticastSendingMessageHandler.class); + assertThat(udpMulticastOutboundChannelAdapterSpec2.getObject()) + .isInstanceOf(MulticastSendingMessageHandler.class); } @Test @@ -249,17 +252,16 @@ public class IpIntegrationTests { private volatile String connectionId; @Bean - public AbstractServerConnectionFactory server1() { + public TcpNetServerConnectionFactorySpec server1() { return Tcp.netServer(0) .serializer(TcpCodecs.lengthHeader1()) - .deserializer(TcpCodecs.crlf()) - .get(); + .deserializer(TcpCodecs.crlf()); } @Bean - public IntegrationFlow inTcpGateway() { + public IntegrationFlow inTcpGateway(TcpNetServerConnectionFactory server1) { return IntegrationFlow.from( - Tcp.inboundGateway(server1()) + Tcp.inboundGateway(server1) .replyTimeout(1) .errorOnTimeout(true) .errorChannel("inTcpGatewayErrorFlow.input")) @@ -276,8 +278,8 @@ public class IpIntegrationTests { } @Bean - public IntegrationFlow unsolicitedServerSide() { - return f -> f.handle(Tcp.outboundAdapter(server1())); + public IntegrationFlow unsolicitedServerSide(TcpNetServerConnectionFactory server1) { + return f -> f.handle(Tcp.outboundAdapter(server1)); } @Bean @@ -321,19 +323,17 @@ public class IpIntegrationTests { } @Bean - public AbstractClientConnectionFactory client1() { - return Tcp.netClient("localhost", server1().getPort()) + public TcpNetClientConnectionFactorySpec client1(TcpNetServerConnectionFactory server1) { + return Tcp.netClient("localhost", server1.getPort()) .serializer(TcpCodecs.crlf()) - .deserializer(TcpCodecs.lengthHeader1()) - .get(); + .deserializer(TcpCodecs.lengthHeader1()); } @Bean - public TcpOutboundGateway tcpOut() { - return Tcp.outboundGateway(client1()) + public TcpOutboundGatewaySpec tcpOut(TcpNetClientConnectionFactory client1) { + return Tcp.outboundGateway(client1) .remoteTimeout(m -> 5000) - .unsolictedMessageChannelName("unsolicited") - .get(); + .unsolicitedMessageChannelName("unsolicited"); } @Bean @@ -342,19 +342,17 @@ public class IpIntegrationTests { } @Bean - public AbstractClientConnectionFactory client2() { - return Tcp.netClient("localhost", server1().getPort()) + public TcpNetClientConnectionFactorySpec client2(TcpNetServerConnectionFactory server1) { + return Tcp.netClient("localhost", server1.getPort()) .serializer(TcpCodecs.crlf()) - .deserializer(TcpCodecs.lengthHeader1()) - .get(); + .deserializer(TcpCodecs.lengthHeader1()); } @Bean - public TcpOutboundGateway tcpOutAsync() { - return Tcp.outboundGateway(client2()) + public TcpOutboundGatewaySpec tcpOutAsync(TcpNetClientConnectionFactory client2) { + return Tcp.outboundGateway(client2) .async(true) - .remoteTimeout(m -> 5000) - .get(); + .remoteTimeout(m -> 5000); } @Bean @@ -371,9 +369,9 @@ public class IpIntegrationTests { } @Bean - public IntegrationFlow clientTcpFlow() { + public IntegrationFlow clientTcpFlow(TcpOutboundGateway tcpOut) { return f -> f - .handle(tcpOut(), e -> e.advice(testAdvice())) + .handle(tcpOut, e -> e.advice(testAdvice())) .transform(Transformers.objectToString()); } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java index 4f6b330ab7..e3cba216ff 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/Jms.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -208,7 +208,7 @@ public final class Jms { public static JmsMessageDrivenChannelAdapterSpec messageDrivenChannelAdapter( JmsListenerContainerSpec jmsListenerContainerSpec) { - return new JmsMessageDrivenChannelAdapterSpec<>(jmsListenerContainerSpec.get()); + return new JmsMessageDrivenChannelAdapterSpec<>(jmsListenerContainerSpec.getObject()); } /** @@ -216,7 +216,9 @@ public final class Jms { * @param listenerContainer the {@link AbstractMessageListenerContainer} to build on * @return the {@link JmsMessageDrivenChannelAdapterSpec} instance */ - public static JmsMessageDrivenChannelAdapterSpec messageDrivenChannelAdapter(AbstractMessageListenerContainer listenerContainer) { + public static JmsMessageDrivenChannelAdapterSpec messageDrivenChannelAdapter( + AbstractMessageListenerContainer listenerContainer) { + return new JmsMessageDrivenChannelAdapterSpec<>(listenerContainer); } @@ -227,14 +229,10 @@ public final class Jms { */ public static JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec messageDrivenChannelAdapter(ConnectionFactory connectionFactory) { - try { - return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<>( - new JmsDefaultListenerContainerSpec() - .connectionFactory(connectionFactory)); - } - catch (Exception e) { - throw new IllegalStateException(e); - } + + return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<>( + new JmsDefaultListenerContainerSpec() + .connectionFactory(connectionFactory)); } /** @@ -249,15 +247,11 @@ public final class Jms { public static JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec messageDrivenChannelAdapter(ConnectionFactory connectionFactory, Class containerClass) { - try { - JmsListenerContainerSpec spec = - new JmsListenerContainerSpec<>(containerClass) - .connectionFactory(connectionFactory); - return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec(spec); - } - catch (Exception e) { - throw new IllegalStateException(e); - } + + JmsListenerContainerSpec spec = + new JmsListenerContainerSpec<>(containerClass) + .connectionFactory(connectionFactory); + return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec(spec); } /** @@ -268,14 +262,10 @@ public final class Jms { */ public static JmsDefaultListenerContainerSpec container(ConnectionFactory connectionFactory, Destination destination) { - try { - return new JmsDefaultListenerContainerSpec() - .connectionFactory(connectionFactory) - .destination(destination); - } - catch (Exception e) { - throw new IllegalStateException(e); - } + + return new JmsDefaultListenerContainerSpec() + .connectionFactory(connectionFactory) + .destination(destination); } /** @@ -286,14 +276,10 @@ public final class Jms { */ public static JmsDefaultListenerContainerSpec container(ConnectionFactory connectionFactory, String destinationName) { - try { - return new JmsDefaultListenerContainerSpec() - .connectionFactory(connectionFactory) - .destination(destinationName); - } - catch (Exception e) { - throw new IllegalStateException(e); - } + + return new JmsDefaultListenerContainerSpec() + .connectionFactory(connectionFactory) + .destination(destinationName); } private Jms() { diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsInboundChannelAdapterSpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsInboundChannelAdapterSpec.java index 156375bf07..7f21ed3602 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsInboundChannelAdapterSpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsInboundChannelAdapterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,8 @@ public class JmsInboundChannelAdapterSpec getComponentsToRegister() { - return Collections.singletonMap(this.jmsTemplateSpec.get(), this.jmsTemplateSpec.getId()); + return Collections.singletonMap(this.jmsTemplateSpec.getObject(), this.jmsTemplateSpec.getId()); } } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsInboundGatewaySpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsInboundGatewaySpec.java index f9539f4bbc..d84d45a703 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsInboundGatewaySpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsInboundGatewaySpec.java @@ -246,9 +246,9 @@ public class JmsInboundGatewaySpec> private final S spec; protected JmsInboundGatewayListenerContainerSpec(S spec) { - super(spec.get()); + super(spec.getObject()); this.spec = spec; - this.spec.get().setAutoStartup(false); + this.spec.getObject().setAutoStartup(false); } /** diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsMessageDrivenChannelAdapterSpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsMessageDrivenChannelAdapterSpec.java index a89169fd30..ee2884ed8e 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsMessageDrivenChannelAdapterSpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsMessageDrivenChannelAdapterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -80,9 +80,9 @@ public class JmsMessageDrivenChannelAdapterSpec configureListenerContainer( Consumer configurer) { + Assert.notNull(configurer, "'configurer' must not be null"); configurer.accept(this.spec); return _this(); @@ -148,7 +149,7 @@ public class JmsMessageDrivenChannelAdapterSpec getComponentsToRegister() { - return Collections.singletonMap(this.spec.get(), this.spec.getId()); + return Collections.singletonMap(this.spec.getObject(), this.spec.getId()); } } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsOutboundChannelAdapterSpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsOutboundChannelAdapterSpec.java index 02cf087bfe..4dade6b2f6 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsOutboundChannelAdapterSpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsOutboundChannelAdapterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,8 @@ public class JmsOutboundChannelAdapterSpec the expected payload type. * @return the current {@link JmsOutboundChannelAdapterSpec}. - * @see JmsSendingMessageHandler#setDestinationExpression(Expression) + * @see JmsSendingMessageHandler#setDestinationExpression * @see FunctionExpression */ public

S destination(Function, ?> destinationFunction) { @@ -194,7 +195,7 @@ public class JmsOutboundChannelAdapterSpec getComponentsToRegister() { - return Collections.singletonMap(this.jmsTemplateSpec.get(), this.jmsTemplateSpec.getId()); + return Collections.singletonMap(this.jmsTemplateSpec.getObject(), this.jmsTemplateSpec.getId()); } } diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsOutboundGatewaySpec.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsOutboundGatewaySpec.java index 5b3cb674c5..90172547e2 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsOutboundGatewaySpec.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/dsl/JmsOutboundGatewaySpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -296,7 +296,7 @@ public class JmsOutboundGatewaySpec extends MessageHandlerSpectransform(String::toUpperCase) - .channel(this.jmsOutboundInboundReplyChannel()) + .channel(jmsOutboundInboundReplyChannel) .get(); } @Bean - public BroadcastCapableChannel jmsPublishSubscribeChannel() { + public JmsPublishSubscribeMessageChannelSpec jmsPublishSubscribeChannel() { return Jms.publishSubscribeChannel(amqFactory) - .destination("pubsub") - .get(); + .destination("pubsub"); } @Bean - public IntegrationFlow pubSubFlow() { + public IntegrationFlow pubSubFlow(SubscribableJmsChannel jmsPublishSubscribeChannel) { return f -> f - .publishSubscribeChannel(jmsPublishSubscribeChannel(), + .publishSubscribeChannel(jmsPublishSubscribeChannel, pubsub -> pubsub .subscribe(subFlow -> subFlow .channel(c -> c.queue("jmsPubSubBridgeChannel"))) @@ -408,8 +409,7 @@ public class JmsTests extends ActiveMQMultiContextTests { .from(Jms.messageDrivenChannelAdapter( Jms.container(amqFactory, "containerSpecDestination") .pubSubDomain(false) - .taskExecutor(Executors.newCachedThreadPool()) - .get())) + .taskExecutor(Executors.newCachedThreadPool()))) .transform(String::trim) .channel(jmsOutboundInboundReplyChannel()) .get(); diff --git a/spring-integration-jms/src/test/kotlin/org/springframework/integration/jms/dsl/JmsDslKotlinTests.kt b/spring-integration-jms/src/test/kotlin/org/springframework/integration/jms/dsl/JmsDslKotlinTests.kt index e1d38f6558..af723f62dd 100644 --- a/spring-integration-jms/src/test/kotlin/org/springframework/integration/jms/dsl/JmsDslKotlinTests.kt +++ b/spring-integration-jms/src/test/kotlin/org/springframework/integration/jms/dsl/JmsDslKotlinTests.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Qualifier import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.integration.IntegrationMessageHeaderAccessor +import org.springframework.integration.channel.QueueChannel import org.springframework.integration.config.EnableIntegration import org.springframework.integration.dsl.MessageChannels import org.springframework.integration.dsl.integrationFlow @@ -112,10 +113,10 @@ class JmsDslKotlinTests : ActiveMQMultiContextTests() { } @Bean - fun jmsOutboundInboundReplyChannel() = MessageChannels.queue().get() + fun jmsOutboundInboundReplyChannel() = MessageChannels.queue() @Bean - fun jmsMessageDrivenFlowWithContainer() = + fun jmsMessageDrivenFlowWithContainer(jmsOutboundInboundReplyChannel: QueueChannel) = integrationFlow( Jms.messageDrivenChannelAdapter( Jms.container(amqFactory, "containerSpecDestination") @@ -125,7 +126,7 @@ class JmsDslKotlinTests : ActiveMQMultiContextTests() { .headerMapper(jmsHeaderMapper()) ) { transform { it: String -> it.trim { it <= ' ' } } - channel(jmsOutboundInboundReplyChannel()) + channel(jmsOutboundInboundReplyChannel) } } diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaInboundGatewaySpec.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaInboundGatewaySpec.java index 96407478f8..f06a9d2ec4 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaInboundGatewaySpec.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaInboundGatewaySpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -102,6 +102,7 @@ public class KafkaInboundGatewaySpec, ConsumerSeekAware.ConsumerSeekCallback> onPartitionsAssignedCallback) { + this.target.setOnPartitionsAssignedSeekCallback(onPartitionsAssignedCallback); return _this(); } @@ -128,7 +129,7 @@ public class KafkaInboundGatewaySpec containerSpec, KafkaTemplateSpec templateSpec) { - super(containerSpec.get(), templateSpec.getTemplate()); + super(containerSpec.getObject(), templateSpec.getTemplate()); this.containerSpec = containerSpec; this.templateSpec = templateSpec; } @@ -164,8 +165,8 @@ public class KafkaInboundGatewaySpec getComponentsToRegister() { return new ObjectStringMapBuilder() - .put(this.containerSpec.get(), this.containerSpec.getId()) - .put(this.templateSpec.get(), this.templateSpec.getId()) + .put(this.containerSpec.getObject(), this.containerSpec.getId()) + .put(this.templateSpec.getObject(), this.templateSpec.getId()) .get(); } diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaMessageDrivenChannelAdapterSpec.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaMessageDrivenChannelAdapterSpec.java index cb1c7e066a..8d3062966d 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaMessageDrivenChannelAdapterSpec.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaMessageDrivenChannelAdapterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,6 +57,7 @@ public class KafkaMessageDrivenChannelAdapterSpec messageListenerContainer, KafkaMessageDrivenChannelAdapter.ListenerMode listenerMode) { + super(new KafkaMessageDrivenChannelAdapter<>(messageListenerContainer, listenerMode)); this.container = messageListenerContainer; } @@ -174,6 +175,7 @@ public class KafkaMessageDrivenChannelAdapterSpec, ConsumerSeekAware.ConsumerSeekCallback> onPartitionsAssignedCallback) { + this.target.setOnPartitionsAssignedSeekCallback(onPartitionsAssignedCallback); return _this(); } @@ -196,7 +198,7 @@ public class KafkaMessageDrivenChannelAdapterSpec spec, KafkaMessageDrivenChannelAdapter.ListenerMode listenerMode) { - super(spec.get(), listenerMode); + super(spec.getObject(), listenerMode); this.spec = spec; } @@ -208,6 +210,7 @@ public class KafkaMessageDrivenChannelAdapterSpec configureListenerContainer( Consumer> configurer) { + Assert.notNull(configurer, "The 'configurer' cannot be null"); configurer.accept(this.spec); return _this(); @@ -215,7 +218,7 @@ public class KafkaMessageDrivenChannelAdapterSpec getComponentsToRegister() { - return Collections.singletonMap(this.spec.get(), this.spec.getId()); + return Collections.singletonMap(this.spec.getObject(), this.spec.getId()); } } diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaOutboundGatewaySpec.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaOutboundGatewaySpec.java index 91dad5cf77..99beb2326f 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaOutboundGatewaySpec.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaOutboundGatewaySpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,7 +110,7 @@ public class KafkaOutboundGatewaySpec getComponentsToRegister() { - return Collections.singletonMap(this.kafkaTemplateSpec.get(), this.kafkaTemplateSpec.getId()); + return Collections.singletonMap(this.kafkaTemplateSpec.getTemplate(), this.kafkaTemplateSpec.getId()); } } diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaProducerMessageHandlerSpec.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaProducerMessageHandlerSpec.java index 9127d51895..68c0c5040e 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaProducerMessageHandlerSpec.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaProducerMessageHandlerSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -429,10 +429,9 @@ public class KafkaProducerMessageHandlerSpec getComponentsToRegister() { - return Collections.singletonMap(this.kafkaTemplateSpec.get(), this.kafkaTemplateSpec.getId()); + return Collections.singletonMap(this.kafkaTemplateSpec.getTemplate(), this.kafkaTemplateSpec.getId()); } } } - diff --git a/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/dsl/KafkaDslTests.java b/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/dsl/KafkaDslTests.java index 13eac986e8..bf2037ee1d 100644 --- a/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/dsl/KafkaDslTests.java +++ b/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/dsl/KafkaDslTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,12 +38,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.IntegrationMessageHeaderAccessor; import org.springframework.integration.MessageRejectedException; -import org.springframework.integration.channel.BroadcastCapableChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.Pollers; import org.springframework.integration.kafka.channel.PollableKafkaChannel; +import org.springframework.integration.kafka.channel.PublishSubscribeKafkaChannel; import org.springframework.integration.kafka.inbound.KafkaErrorSendingMessageRecoverer; import org.springframework.integration.kafka.inbound.KafkaInboundGateway; import org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter; @@ -427,10 +427,11 @@ public class KafkaDslTests { @Bean public IntegrationFlow channels(KafkaTemplate template, ConcurrentKafkaListenerContainerFactory containerFactory, - KafkaMessageSource channelSource) { + KafkaMessageSource channelSource, + PublishSubscribeKafkaChannel publishSubscribeKafkaChannel) { return IntegrationFlow.from(topic6Channel(template, containerFactory)) - .publishSubscribeChannel(pubSub(template, containerFactory), channel -> channel + .publishSubscribeChannel(publishSubscribeKafkaChannel, channel -> channel .subscribe(f -> f.channel( Kafka.pollableChannel(template, channelSource).id("topic8Channel"))) .subscribe(f -> f.channel( @@ -439,11 +440,10 @@ public class KafkaDslTests { } @Bean - public BroadcastCapableChannel pubSub(KafkaTemplate template, + public KafkaPublishSubscribeChannelSpec pubSub(KafkaTemplate template, ConcurrentKafkaListenerContainerFactory containerFactory) { - return Kafka.publishSubscribeChannel(template, containerFactory, TEST_TOPIC7) - .get(); + return Kafka.publishSubscribeChannel(template, containerFactory, TEST_TOPIC7); } @Bean diff --git a/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/inbound/MessageDrivenAdapterTests.java b/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/inbound/MessageDrivenAdapterTests.java index 66b1de007f..8bf0b64966 100644 --- a/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/inbound/MessageDrivenAdapterTests.java +++ b/spring-integration-kafka/src/test/java/org/springframework/integration/kafka/inbound/MessageDrivenAdapterTests.java @@ -539,7 +539,7 @@ class MessageDrivenAdapterTests { .messageDrivenChannelAdapter(container, ListenerMode.record) .recordMessageConverter(new StringJsonMessageConverter()) .payloadType(Foo.class) - .get(); + .getObject(); QueueChannel out = new QueueChannel(); adapter.setOutputChannel(out); adapter.afterPropertiesSet(); diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/dsl/MongoDbTests.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/dsl/MongoDbTests.java index 4b419fdd42..d4237c3999 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/dsl/MongoDbTests.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/dsl/MongoDbTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,9 +40,11 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext; import org.springframework.data.mongodb.core.query.BasicQuery; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; +import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.MessageChannels; +import org.springframework.integration.dsl.QueueChannelSpec; import org.springframework.integration.handler.ReplyRequiredException; import org.springframework.integration.mongodb.MongoDbContainerTest; import org.springframework.integration.mongodb.outbound.MessageCollectionCallback; @@ -333,16 +335,16 @@ class MongoDbTests implements MongoDbContainerTest { } @Bean - public IntegrationFlow gatewayCollectionCallbackFlow() { + public IntegrationFlow gatewayCollectionCallbackFlow(QueueChannel getResultChannel) { return f -> f .handle(collectionCallbackOutboundGateway( (collection, requestMessage) -> collection.countDocuments())) - .channel(getResultChannel()); + .channel(getResultChannel); } @Bean - public MessageChannel getResultChannel() { - return MessageChannels.queue().get(); + public QueueChannelSpec getResultChannel() { + return MessageChannels.queue(); } @Bean diff --git a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/dsl/ScriptMessageSourceSpec.java b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/dsl/ScriptMessageSourceSpec.java index dae6a1faaf..2d9fada5d5 100644 --- a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/dsl/ScriptMessageSourceSpec.java +++ b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/dsl/ScriptMessageSourceSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,7 +67,7 @@ public class ScriptMessageSourceSpec extends MessageSourceSpec doGet() { - return new MessageProcessorMessageSource(this.delegate.get()); + return new MessageProcessorMessageSource(this.delegate.getObject()); } @Override public Map getComponentsToRegister() { - return Collections.singletonMap(this.delegate.get(), this.delegate.getId()); + return Collections.singletonMap(this.delegate.getObject(), this.delegate.getId()); } } diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/dsl/WsDslTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/dsl/WsDslTests.java index 6e2994d77f..9c2c8ce246 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/dsl/WsDslTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/dsl/WsDslTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 the original author or authors. + * Copyright 2020-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,12 +59,12 @@ public class WsDslTests { Unmarshaller unmarshaller = mock(Unmarshaller.class); MarshallingWebServiceInboundGateway gateway = Ws.marshallingInboundGateway(marshaller) .unmarshaller(unmarshaller) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(gateway, "marshaller")).isSameAs(marshaller); assertThat(TestUtils.getPropertyValue(gateway, "unmarshaller")).isSameAs(unmarshaller); marshaller = mock(Both.class); - gateway = Ws.marshallingInboundGateway(marshaller).get(); + gateway = Ws.marshallingInboundGateway(marshaller).getObject(); assertThat(TestUtils.getPropertyValue(gateway, "marshaller")).isSameAs(marshaller); assertThat(TestUtils.getPropertyValue(gateway, "unmarshaller")).isSameAs(marshaller); } @@ -73,7 +73,7 @@ public class WsDslTests { void simpleInbound() { SimpleWebServiceInboundGateway gateway = Ws.simpleInboundGateway() .extractPayload(false) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(gateway, "extractPayload", Boolean.class)).isFalse(); } @@ -104,7 +104,7 @@ public class WsDslTests { .messageSenders(messageSender) .requestCallback(requestCallback) .uriVariableExpressions(uriVariableExpressions) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(gateway, "webServiceTemplate.marshaller")).isSameAs(marshaller); assertThat(TestUtils.getPropertyValue(gateway, "webServiceTemplate.unmarshaller")).isSameAs(unmarshaller); assertThat(TestUtils.getPropertyValue(gateway, "webServiceTemplate.messageFactory")).isSameAs(messageFactory); @@ -147,7 +147,7 @@ public class WsDslTests { .requestCallback(requestCallback) .uriVariableExpressions(uriVariableExpressions) .extractPayload(false) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(gateway, "webServiceTemplate.messageFactory")).isSameAs(messageFactory); assertThat(TestUtils.getPropertyValue(gateway, "webServiceTemplate.faultMessageResolver")) .isSameAs(faultMessageResolver); @@ -178,7 +178,7 @@ public class WsDslTests { .ignoreEmptyResponses(true) .requestCallback(requestCallback) .uriVariableExpressions(uriVariableExpressions) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(gateway, "uri")).isSameAs(uri); assertThat(TestUtils.getPropertyValue(gateway, "headerMapper")).isSameAs(headerMapper); assertThat(TestUtils.getPropertyValue(gateway, "requestCallback")).isSameAs(requestCallback); @@ -209,7 +209,7 @@ public class WsDslTests { .requestCallback(requestCallback) .uriVariableExpressions(uriVariableExpressions) .extractPayload(false) - .get(); + .getObject(); assertThat(TestUtils.getPropertyValue(gateway, "headerMapper")).isSameAs(headerMapper); assertThat(TestUtils.getPropertyValue(gateway, "requestCallback")).isSameAs(requestCallback); assertThat(TestUtils.getPropertyValue(gateway, "uriVariableExpressions")).isEqualTo(uriVariableExpressions); @@ -225,4 +225,3 @@ public class WsDslTests { } } - diff --git a/src/reference/asciidoc/dsl.adoc b/src/reference/asciidoc/dsl.adoc index 9b18c0a54e..89c65f0f70 100644 --- a/src/reference/asciidoc/dsl.adoc +++ b/src/reference/asciidoc/dsl.adoc @@ -39,8 +39,8 @@ public class MyConfiguration { } @Bean - public IntegrationFlow myFlow() { - return IntegrationFlow.fromSupplier(integerSource()::getAndIncrement, + public IntegrationFlow myFlow(AtomicInteger integerSource) { + return IntegrationFlow.fromSupplier(integerSource::getAndIncrement, c -> c.poller(Pollers.fixedRate(100))) .channel("inputChannel") .filter((Integer p) -> p > 0) @@ -63,6 +63,10 @@ You need not replace all of your existing XML configuration to use Java configur The `org.springframework.integration.dsl` package contains the `IntegrationFlowBuilder` API mentioned earlier and a number of `IntegrationComponentSpec` implementations, which are also builders and provide the fluent API to configure concrete endpoints. The `IntegrationFlowBuilder` infrastructure provides common https://www.enterpriseintegrationpatterns.com/[enterprise integration patterns] (EIP) for message-based applications, such as channels, endpoints, pollers, and channel interceptors. +IMPORTANT:: The `IntegrationComponentSpec` is a `FactoryBean` implementation, therefore its `getObject()` method must not be called from bean definitions. +The `IntegrationComponentSpec` implementation must be left as is for bean definitions and the framework will manage its lifecycle. +Bean method parameter injection for the target `IntegrationComponentSpec` type (a `FactoryBean` value) must be used for `IntegrationFlow` bean definitions instead of bean method references. + Endpoints are expressed as verbs in the DSL to improve readability. The following list includes the common DSL method names and the associated EIP endpoint: @@ -163,10 +167,9 @@ The following example shows how to use it: [source,java] ---- @Bean -public MessageChannel priorityChannel() { +public PriorityChannelSpec priorityChannel() { return MessageChannels.priority(this.mongoDbChannelMessageStore, "priorityGroup") - .interceptor(wireTap()) - .get(); + .interceptor(wireTap()); } ---- ==== @@ -181,13 +184,13 @@ The following example shows the possible ways to use the `channel()` EIP method: [source,java] ---- @Bean -public MessageChannel queueChannel() { - return MessageChannels.queue().get(); +public QueueChannelSpec queueChannel() { + return MessageChannels.queue(); } @Bean -public MessageChannel publishSubscribe() { - return MessageChannels.publishSubscribe().get(); +public PublishSubscribeChannelSpec publishSubscribe() { + return MessageChannels.publishSubscribe(); } @Bean @@ -261,7 +264,7 @@ public PollerSpec poller() { See https://docs.spring.io/spring-integration/api/org/springframework/integration/dsl/Pollers.html[`Pollers`] and https://docs.spring.io/spring-integration/api/org/springframework/integration/dsl/PollerSpec.html[`PollerSpec`] in the Javadoc for more information. -IMPORTANT: If you use the DSL to construct a `PollerSpec` as a `@Bean`, do not call the `get()` method in the bean definition. +IMPORTANT: If you use the DSL to construct a `PollerSpec` as a `@Bean`, do not call the `getObject()` method in the bean definition. The `PollerSpec` is a `FactoryBean` that generates the `PollerMetadata` object from the specification and initializes all of its properties. [[java-dsl-reactive]] @@ -833,30 +836,21 @@ For example, we now can configure several subscribers as sub-flows on the `Jms.p [source,java] ---- @Bean -public BroadcastCapableChannel jmsPublishSubscribeChannel() { +public JmsPublishSubscribeMessageChannelSpec jmsPublishSubscribeChannel() { return Jms.publishSubscribeChannel(jmsConnectionFactory()) - .destination("pubsub") - .get(); + .destination("pubsub"); } @Bean -public IntegrationFlow pubSubFlow() { +public IntegrationFlow pubSubFlow(BroadcastCapableChannel jmsPublishSubscribeChannel) { return f -> f - .publishSubscribeChannel(jmsPublishSubscribeChannel(), + .publishSubscribeChannel(jmsPublishSubscribeChannel, pubsub -> pubsub .subscribe(subFlow -> subFlow .channel(c -> c.queue("jmsPubSubBridgeChannel1"))) .subscribe(subFlow -> subFlow .channel(c -> c.queue("jmsPubSubBridgeChannel2")))); } - -@Bean -public BroadcastCapableChannel jmsPublishSubscribeChannel(ConnectionFactory jmsConnectionFactory) { - return (BroadcastCapableChannel) Jms.publishSubscribeChannel(jmsConnectionFactory) - .destination("pubsub") - .get(); -} - ---- ==== diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 9df89de4ec..3ead59b3e4 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -41,6 +41,11 @@ See <<./filter.adoc#filter, Filter>> for more information. - The default timeout for send and receive operations in gateways and replying channel adapters has been changed from infinity to `30` seconds. Only one left as a `1` second is a `receiveTimeout` for `PollingConsumer` to not block a scheduler thread too long and let other queued tasks to be performed with the `TaskScheduler`. + - The `IntegrationComponentSpec.get()` method has been deprecated with removal planned for the next version. +Since `IntegrationComponentSpec` is a `FactoryBean`, its bean definition must stay as is without any target object resolutions. +The Java DSL and the framework by itself will manage the `IntegrationComponentSpec` lifecycle. +See <<./dsl.adoc#java-dsl, Java DSL>> for more information. + [[x6.1-web-sockets]] === Web Sockets Changes