Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-12683

When lookup the registry, Camel should support more complex expressions like 'myBean.property'

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • 2.21.1
    • None
    • camel-spring
    • None
    • Unknown

    Description

      Currently, only simple Spring beans lookup is supported, like #myBean. Deeper lookup is currently not supported. As a workaround, you could specify several Spring beans which then maps to the properties of the original bean.
      Following code snipped would, for instance, make possible more complex queries:

      public class MyApplicationContextRegistry extends ApplicationContextRegistry {
      
          private final BeanResolver beanResolver;
          private final PropertyAccessor propertyAccessor;
          private final BeanExpressionContext beanExpressionContext;
      
          MyApplicationContextRegistry(ApplicationContext applicationContext) {
              super(applicationContext);
              beanResolver = new BeanFactoryResolver(applicationContext);
              propertyAccessor = new BeanExpressionContextAccessor();
              beanExpressionContext = createExpressionContext(applicationContext);
          }
      
          @Override
          public Object lookupByName(final String name) {
              assert name != null : "Unspecified name";
              final ExpressionParser parser = new SpelExpressionParser();
              Expression expression = parser.parseExpression(name);
              Object expressionValue = expression.getValue(createEvaluationContext(), beanExpressionContext);
              return expressionValue;
          }
      
          private static BeanExpressionContext createExpressionContext(ApplicationContext applicationContext) {
              assert applicationContext instanceof ConfigurableApplicationContext : String.format("MUST be an instance of '%s'.", ConfigurableApplicationContext.class.getName());
              ConfigurableBeanFactory configurableBeanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
              return new BeanExpressionContext(configurableBeanFactory, null);
          }
      
          private EvaluationContext createEvaluationContext() {
              StandardEvaluationContext context = new StandardEvaluationContext();
              context.setBeanResolver(beanResolver);
              context.addPropertyAccessor(propertyAccessor);
              return context;
          }
      }
      

      And this code uses out-of-the-box Spring functionalities (I think...).

      Attachments

        Activity

          People

            zregvart Zoran Regvart
            christianr Christian Ribeaud
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: