use of org.springframework.integration.transformer.Transformer in project spring-integration by spring-projects.
the class TransformerFactoryBean method createExpressionEvaluatingHandler.
@Override
protected MessageHandler createExpressionEvaluatingHandler(Expression expression) {
Transformer transformer = new ExpressionEvaluatingTransformer(expression);
MessageTransformingHandler handler = this.createHandler(transformer);
handler.setPrimaryExpression(expression);
return handler;
}
use of org.springframework.integration.transformer.Transformer in project spring-integration by spring-projects.
the class TransformerFactoryBean method createMethodInvokingHandler.
@Override
protected MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) {
Assert.notNull(targetObject, "targetObject must not be null");
Transformer transformer = null;
if (targetObject instanceof Transformer) {
transformer = (Transformer) targetObject;
} else {
this.checkForIllegalTarget(targetObject, targetMethodName);
if (StringUtils.hasText(targetMethodName)) {
transformer = new MethodInvokingTransformer(targetObject, targetMethodName);
} else {
transformer = new MethodInvokingTransformer(targetObject);
}
}
return this.createHandler(transformer);
}
use of org.springframework.integration.transformer.Transformer 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.Transformer in project spring-integration by spring-projects.
the class InboundEndpointTests method testInt2809JavaTypePropertiesToAmqp.
@Test
public void testInt2809JavaTypePropertiesToAmqp() 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);
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(container);
adapter.setMessageConverter(new Jackson2JsonMessageConverter());
PollableChannel channel = new QueueChannel();
adapter.setOutputChannel(channel);
adapter.setBeanFactory(mock(BeanFactory.class));
adapter.afterPropertiesSet();
Object payload = new Foo("bar1");
Transformer objectToJsonTransformer = new ObjectToJsonTransformer();
Message<?> jsonMessage = objectToJsonTransformer.transform(new GenericMessage<Object>(payload));
MessageProperties amqpMessageProperties = new MessageProperties();
amqpMessageProperties.setDeliveryTag(123L);
org.springframework.amqp.core.Message amqpMessage = new SimpleMessageConverter().toMessage(jsonMessage.getPayload(), amqpMessageProperties);
DefaultAmqpHeaderMapper.inboundMapper().fromHeadersToRequest(jsonMessage.getHeaders(), amqpMessageProperties);
ChannelAwareMessageListener listener = (ChannelAwareMessageListener) container.getMessageListener();
Channel rabbitChannel = mock(Channel.class);
listener.onMessage(amqpMessage, rabbitChannel);
Message<?> result = channel.receive(1000);
assertEquals(payload, result.getPayload());
assertSame(rabbitChannel, result.getHeaders().get(AmqpHeaders.CHANNEL));
assertEquals(123L, result.getHeaders().get(AmqpHeaders.DELIVERY_TAG));
}
use of org.springframework.integration.transformer.Transformer in project spring-integration by spring-projects.
the class IntegrationFlowDefinition method transform.
/**
* Populate the {@link MessageTransformingHandler} instance for the provided {@link GenericTransformer}
* for the specific {@code payloadType} to convert at runtime.
* In addition accept options for the integration endpoint using {@link GenericEndpointSpec}.
* @param payloadType the {@link Class} for expected payload type.
* @param genericTransformer the {@link GenericTransformer} to populate.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @param <P> the payload type - 'transform from'.
* @param <T> the target type - 'transform to'.
* @return the current {@link IntegrationFlowDefinition}.
* @see MethodInvokingTransformer
* @see LambdaMessageProcessor
* @see GenericEndpointSpec
*/
public <P, T> B transform(Class<P> payloadType, GenericTransformer<P, T> genericTransformer, Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) {
Assert.notNull(genericTransformer, "'genericTransformer' must not be null");
Transformer transformer = genericTransformer instanceof Transformer ? (Transformer) genericTransformer : (isLambda(genericTransformer) ? new MethodInvokingTransformer(new LambdaMessageProcessor(genericTransformer, payloadType)) : new MethodInvokingTransformer(genericTransformer));
return addComponent(transformer).handle(new MessageTransformingHandler(transformer), endpointConfigurer);
}
Aggregations