/** * Create a header value processor for the given Expression and the * expected type of the expression evaluation result. The expectedType * may be null if unknown. * * @param expression the {@link Expression} to evaluate. * @param expectedType the type for return value of {@code expression} evaluation result. */ public ExpressionEvaluatingHeaderValueMessageProcessor(Expression expression, Class<T> expectedType) { this.targetProcessor = new ExpressionEvaluatingMessageProcessor<T>(expression, expectedType); }
protected String generateExchangeName(Message<?> requestMessage) { String exchange = this.exchangeName; if (this.exchangeNameGenerator != null) { exchange = this.exchangeNameGenerator.processMessage(requestMessage); } return exchange; }
BeanFactory beanFactory = getBeanFactory(); if (this.exchangeNameExpression != null) { this.exchangeNameGenerator = new ExpressionEvaluatingMessageProcessor<String>(this.exchangeNameExpression, String.class); if (beanFactory != null) { this.exchangeNameGenerator.setBeanFactory(beanFactory); "Either a routingKey or a routingKeyExpression can be provided, but not both"); if (this.routingKeyExpression != null) { this.routingKeyGenerator = new ExpressionEvaluatingMessageProcessor<String>(this.routingKeyExpression, String.class); if (beanFactory != null) { this.routingKeyGenerator.setBeanFactory(beanFactory); new ExpressionEvaluatingMessageProcessor<Object>(this.confirmCorrelationExpression, Object.class); if (beanFactory != null) { this.correlationDataGenerator.setBeanFactory(beanFactory); this.delayGenerator = new ExpressionEvaluatingMessageProcessor<Integer>(this.delayExpression, Integer.class); if (beanFactory != null) { this.delayGenerator.setBeanFactory(beanFactory);
@Test public void testProcessMessage() { Expression expression = expressionParser.parseExpression("payload"); ExpressionEvaluatingMessageProcessor<String> processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); assertEquals("foo", processor.processMessage(new GenericMessage<>("foo"))); }
@Test public void testProcessMessageWithVoidResult() throws Exception { @SuppressWarnings("unused") class TestTarget { public void ping(String input) { } } Expression expression = expressionParser.parseExpression("#target.ping(payload)"); ExpressionEvaluatingMessageProcessor<String> processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); processor.afterPropertiesSet(); EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); evaluationContext.setVariable("target", new TestTarget()); assertEquals(null, processor.processMessage(new GenericMessage<>("2"))); }
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (beanFactory != null) { this.processor.setBeanFactory(beanFactory); } }
@Override protected void onInit() { if (this.destinationExpressionProcessor != null) { this.destinationExpressionProcessor.setBeanFactory(getBeanFactory()); ConversionService conversionService = getConversionService(); if (conversionService != null) { this.destinationExpressionProcessor.setConversionService(conversionService); } } this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); }
/** * Processes the Message by evaluating the expression with that Message as the * root object. The expression evaluation result Object will be returned. * @param message The message. * @return The result of processing the message. */ @Override public T processMessage(Message<?> message) { return evaluateExpression(this.expression, message, this.expectedType); }
@Test public void testProcessMessageWithDollarPropertyAccess() { Expression expression = expressionParser.parseExpression("headers.$foo_id"); ExpressionEvaluatingMessageProcessor<String> processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); Message<String> message = MessageBuilder.withPayload("foo").setHeader("$foo_id", "xyz").build(); assertEquals("xyz", processor.processMessage(message)); }
@Test public void testProcessMessageWithParameterCoercion() throws Exception { @SuppressWarnings("unused") class TestTarget { public String stringify(int number) { return number + ""; } } Expression expression = expressionParser.parseExpression("#target.stringify(payload)"); ExpressionEvaluatingMessageProcessor<String> processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); processor.afterPropertiesSet(); EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); evaluationContext.setVariable("target", new TestTarget()); assertEquals("2", processor.processMessage(new GenericMessage<>("2"))); }
public void setBeanFactory(BeanFactory beanFactory) { this.targetProcessor.setBeanFactory(beanFactory); }
ConversionService conversionService = getConversionService(); if (this.requestDestinationExpressionProcessor != null) { this.requestDestinationExpressionProcessor.setBeanFactory(getBeanFactory()); if (conversionService != null) { this.requestDestinationExpressionProcessor.setConversionService(conversionService); this.replyDestinationExpressionProcessor.setBeanFactory(getBeanFactory()); if (conversionService != null) { this.replyDestinationExpressionProcessor.setConversionService(conversionService);
/** * Processes the Message by evaluating the expression with that Message as the * root object. The expression evaluation result Object will be returned. * @param message The message. * @return The result of processing the message. */ @Override public T processMessage(Message<?> message) { return evaluateExpression(this.expression, message, this.expectedType); }
@Test public void testProcessMessageWithStaticKey() { Expression expression = expressionParser.parseExpression("headers[headers.ID]"); ExpressionEvaluatingMessageProcessor<UUID> processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); GenericMessage<String> message = new GenericMessage<>("foo"); assertEquals(message.getHeaders().getId(), processor.processMessage(message)); }
/** * Specify a SpEL expression for files renaming during transfer. * @param renameExpression the expression to use. * @since 4.3 */ public void setRenameExpression(Expression renameExpression) { this.renameProcessor = new ExpressionEvaluatingMessageProcessor<String>(renameExpression); }
@Test public void testProcessMessageWithBeanAsMethodArgument() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinition beanDefinition = new RootBeanDefinition(String.class); beanDefinition.getConstructorArgumentValues().addGenericArgumentValue("bar"); context.registerBeanDefinition("testString", beanDefinition); context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, new RootBeanDefinition(IntegrationEvaluationContextFactoryBean.class)); context.refresh(); Expression expression = expressionParser.parseExpression("payload.concat(@testString)"); ExpressionEvaluatingMessageProcessor<String> processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(context); processor.afterPropertiesSet(); GenericMessage<String> message = new GenericMessage<>("foo"); assertEquals("foobar", processor.processMessage(message)); }
protected String generateRoutingKey(Message<?> requestMessage) { String key = this.routingKey; if (this.routingKeyGenerator != null) { key = this.routingKeyGenerator.processMessage(requestMessage); } return key; }
@Override protected MessageHandler createExpressionEvaluatingHandler(Expression expression) { ExpressionEvaluatingMessageProcessor<Object> processor = new ExpressionEvaluatingMessageProcessor<Object>(expression); processor.setBeanFactory(this.getBeanFactory()); ServiceActivatingHandler handler = new ServiceActivatingHandler(processor); handler.setPrimaryExpression(expression); return this.configureHandler(handler); }
@Override public void afterPropertiesSet() { if (this.beanFactory != null) { if (this.directoryExpressionProcessor != null) { this.directoryExpressionProcessor.setBeanFactory(this.beanFactory); } if (this.temporaryDirectoryExpressionProcessor != null) { this.temporaryDirectoryExpressionProcessor.setBeanFactory(this.beanFactory); } if (!this.fileNameGeneratorSet && this.fileNameGenerator instanceof BeanFactoryAware) { ((BeanFactoryAware) this.fileNameGenerator).setBeanFactory(this.beanFactory); } if (this.fileNameProcessor != null) { this.fileNameProcessor.setBeanFactory(this.beanFactory); } } if (this.autoCreateDirectory) { Assert.hasText(this.remoteFileSeparator, "'remoteFileSeparator' must not be empty when 'autoCreateDirectory' is set to 'true'"); } if (this.hasExplicitlySetSuffix && !this.useTemporaryFileName) { this.logger.warn("Since 'use-temporary-file-name' is set to 'false' " + "the value of 'temporary-file-suffix' has no effect"); } }
@Override protected void onInit() { if (this.destinationExpressionProcessor != null) { this.destinationExpressionProcessor.setBeanFactory(getBeanFactory()); ConversionService conversionService = getConversionService(); if (conversionService != null) { this.destinationExpressionProcessor.setConversionService(conversionService); } } this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); }