use of org.springframework.integration.transformer.MessageTransformingHandler in project spring-integration by spring-projects.
the class ChainParserTests method testInt2755SubComponentsIdSupport.
@Test
public void testInt2755SubComponentsIdSupport() {
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1.handler"));
assertTrue(this.beanFactory.containsBean("filterChain$child.filterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("filterChain$child.serviceActivatorWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.aggregatorWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.filterWithinNestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain$child.filterWithinDoubleNestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain2.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.aggregatorWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain.handler"));
assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain$child.filterWithinNestedChain.handler"));
assertTrue(this.beanFactory.containsBean("payloadTypeRouterChain$child.payloadTypeRouterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("headerValueRouterChain$child.headerValueRouterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckInWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckOutWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("outboundChain$child.outboundChannelAdapterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("logChain$child.transformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("logChain$child.loggingChannelAdapterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.splitterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.resequencerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.enricherWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.headerFilterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.payloadSerializingTransformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.payloadDeserializingTransformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.gatewayWithinChain.handler"));
// INT-3117
GatewayProxyFactoryBean gatewayProxyFactoryBean = this.beanFactory.getBean("&subComponentsIdSupport1$child.gatewayWithinChain.handler", GatewayProxyFactoryBean.class);
assertEquals("strings", TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestChannelName"));
assertEquals("numbers", TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyChannelName"));
assertEquals(1000L, TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestTimeout", Expression.class).getValue());
assertEquals(100L, TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyTimeout", Expression.class).getValue());
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.objectToStringTransformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler"));
Object transformerHandler = this.beanFactory.getBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler");
Object transformer = TestUtils.getPropertyValue(transformerHandler, "transformer");
assertThat(transformer, instanceOf(ObjectToMapTransformer.class));
assertFalse(TestUtils.getPropertyValue(transformer, "shouldFlattenKeys", Boolean.class));
assertSame(this.beanFactory.getBean(JsonObjectMapper.class), TestUtils.getPropertyValue(transformer, "jsonObjectMapper"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.mapToObjectTransformerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.controlBusWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.routerWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("exceptionTypeRouterChain$child.exceptionTypeRouterWithinChain.handler"));
assertTrue(this.beanFactory.containsBean("recipientListRouterChain$child.recipientListRouterWithinChain.handler"));
MessageHandlerChain chain = this.beanFactory.getBean("headerEnricherChain.handler", MessageHandlerChain.class);
List<?> handlers = TestUtils.getPropertyValue(chain, "handlers", List.class);
assertTrue(handlers.get(0) instanceof MessageTransformingHandler);
assertEquals("headerEnricherChain$child.headerEnricherWithinChain", TestUtils.getPropertyValue(handlers.get(0), "componentName"));
assertEquals("headerEnricherChain$child.headerEnricherWithinChain.handler", TestUtils.getPropertyValue(handlers.get(0), "beanName"));
assertTrue(this.beanFactory.containsBean("headerEnricherChain$child.headerEnricherWithinChain.handler"));
assertTrue(handlers.get(1) instanceof ServiceActivatingHandler);
assertEquals("headerEnricherChain$child#1", TestUtils.getPropertyValue(handlers.get(1), "componentName"));
assertEquals("headerEnricherChain$child#1.handler", TestUtils.getPropertyValue(handlers.get(1), "beanName"));
assertFalse(this.beanFactory.containsBean("headerEnricherChain$child#1.handler"));
}
use of org.springframework.integration.transformer.MessageTransformingHandler in project spring-integration by spring-projects.
the class GroovyTransformerTests method testInt2433VerifyRiddingOfMessageProcessorsWrapping.
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovyTransformerMessageHandler instanceof MessageTransformingHandler);
Transformer transformer = TestUtils.getPropertyValue(this.groovyTransformerMessageHandler, "transformer", Transformer.class);
assertTrue(transformer instanceof AbstractMessageProcessingTransformer);
@SuppressWarnings("rawtypes") MessageProcessor messageProcessor = TestUtils.getPropertyValue(transformer, "messageProcessor", MessageProcessor.class);
// before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
use of org.springframework.integration.transformer.MessageTransformingHandler in project spring-integration by spring-projects.
the class FileToStringTransformerParserTests method checkDeleteFilesValue.
@Test
public void checkDeleteFilesValue() {
DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(endpoint);
MessageTransformingHandler handler = (MessageTransformingHandler) endpointAccessor.getPropertyValue("handler");
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
FileToStringTransformer transformer = (FileToStringTransformer) handlerAccessor.getPropertyValue("transformer");
DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer);
assertEquals(Boolean.TRUE, transformerAccessor.getPropertyValue("deleteFiles"));
}
use of org.springframework.integration.transformer.MessageTransformingHandler in project spring-integration-samples by spring-projects.
the class DBoot method transform.
@Transformer(inputChannel = "foo")
@Bean
public MessageHandler transform() {
MessageTransformingHandler transformingHandler = new MessageTransformingHandler(new MethodInvokingTransformer(helpers(), "duplicate"));
transformingHandler.setOutputChannel(bar());
return transformingHandler;
}
use of org.springframework.integration.transformer.MessageTransformingHandler in project spring-integration by spring-projects.
the class InboundEndpointTests method testMessageConverterJsonHeadersHavePrecedenceOverMessageHeaders.
@Test
public void testMessageConverterJsonHeadersHavePrecedenceOverMessageHeaders() throws Exception {
Connection connection = mock(Connection.class);
doAnswer(invocation -> mock(Channel.class)).when(connection).createChannel(anyBoolean());
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
when(connectionFactory.createConnection()).thenReturn(connection);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
DirectChannel channel = new DirectChannel();
final Channel rabbitChannel = mock(Channel.class);
channel.subscribe(new MessageTransformingHandler(message -> {
assertSame(rabbitChannel, message.getHeaders().get(AmqpHeaders.CHANNEL));
assertEquals(123L, message.getHeaders().get(AmqpHeaders.DELIVERY_TAG));
return MessageBuilder.fromMessage(message).setHeader(JsonHeaders.TYPE_ID, "foo").setHeader(JsonHeaders.CONTENT_TYPE_ID, "bar").setHeader(JsonHeaders.KEY_TYPE_ID, "baz").build();
}));
RabbitTemplate rabbitTemplate = spy(new RabbitTemplate());
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
CountDownLatch sendLatch = new CountDownLatch(1);
Mockito.doAnswer(invocation -> {
org.springframework.amqp.core.Message message = invocation.getArgument(2);
Map<String, Object> headers = message.getMessageProperties().getHeaders();
assertTrue(headers.containsKey(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertNotEquals("foo", headers.get(JsonHeaders.TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertFalse(headers.containsKey(JsonHeaders.CONTENT_TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertFalse(headers.containsKey(JsonHeaders.KEY_TYPE_ID.replaceFirst(JsonHeaders.PREFIX, "")));
assertFalse(headers.containsKey(JsonHeaders.TYPE_ID));
assertFalse(headers.containsKey(JsonHeaders.KEY_TYPE_ID));
assertFalse(headers.containsKey(JsonHeaders.CONTENT_TYPE_ID));
sendLatch.countDown();
return null;
}).when(rabbitTemplate).send(anyString(), anyString(), any(org.springframework.amqp.core.Message.class), isNull());
AmqpInboundGateway gateway = new AmqpInboundGateway(container, rabbitTemplate);
gateway.setMessageConverter(new Jackson2JsonMessageConverter());
gateway.setRequestChannel(channel);
gateway.setBeanFactory(mock(BeanFactory.class));
gateway.setDefaultReplyTo("foo");
gateway.afterPropertiesSet();
Object payload = new Foo("bar1");
MessageProperties amqpMessageProperties = new MessageProperties();
amqpMessageProperties.setDeliveryTag(123L);
org.springframework.amqp.core.Message amqpMessage = new Jackson2JsonMessageConverter().toMessage(payload, amqpMessageProperties);
ChannelAwareMessageListener listener = (ChannelAwareMessageListener) container.getMessageListener();
listener.onMessage(amqpMessage, rabbitChannel);
assertTrue(sendLatch.await(10, TimeUnit.SECONDS));
}
Aggregations