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

Property placeholders do not work for CDI injection

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.11.1
    • 2.17.0
    • camel-cdi
    • None
    • Unknown

    Description

      Camel-CDI offers a mechanism to resolve property placeholders like {{property1}} in an endpoint URI as described in camel documentation
      These placeholders could come from ConfigSource loaded via the deltaspike configuration CDI extension and its ConfigResolver class according comments on class org.apache.camel.cdi.component.properties.CdiPropertiesParser
      Anyway this choice is surprising because the documentation of the org.apache.deltaspike.core.api.config.PropertyFileConfig specifies the following:

       *  <p>Please note that the configuration will only be available
       *  after the boot is finished. This means that you cannot use
       *  this configuration inside a CDI Extension before the boot
       *  is finished!</p>
      

      camel-cdi maven module contains a test class org.apache.camel.cdi.component.properties.PropertiesComponentTest which IMHO does not illustrate the real use we would need in a CDI container.
      It shows placeholders replaced after the boot of the CDI container, which is inline with the javadoc above but probably not really useful.

      context.resolvePropertyPlaceholders("{{directEndpoint}}_{{directEndpoint}}");
      

      But from my standpoint the real benefit would be to use such a feature as follows:

      @RunWith(Arquillian.class)
      @ApplicationScoped
      public class CamelCdiCamel5986Test {
      
          @Inject
          @Mock("mock:{{property1}}")
          private MockEndpoint mockEndpoint;
      
          @Deployment
          public static Archive<?> createDeployment() {
              JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
                              .addClass(TestRouteBuilder.class)
                              .addClass(CdiConfigFile.class)
                              .addAsResource("META-INF/camel.properties")//according CdiConfigFile
                              .addPackages(true, ConfigurationExtension.class.getPackage())
                              .addPackages(true, CdiCamelContext.class.getPackage())
                              .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
              return jar;
          }
      
          //test crashes with a org.jboss.weld.exceptions.DeploymentException (...) Could not add Routes: [Route[[From[direct:begin]] -> [To[mock:{{property1}}]]]]
          @Test
          public void testConfiguration() {
              assertNotNull("mockEndpoint is null", mockEndpoint);
          }
      
          @ContextName
          public static class TestRouteBuilder extends RouteBuilder {
      
              @Override
              public void configure() throws Exception {
                  from("direct:begin").to("mock:{{property1}}");
              }
      
          }
      
          /**
           * Copy of class from camel-cdi test class org.apache.camel.cdi.support.CdiConfigFile
           */
          public static class CdiConfigFile implements PropertyFileConfig {
      
              private static final long serialVersionUID = 1L;
      
              @Override
              public String getPropertyFileName() {
                  return "META-INF/camel.properties";
              }
      
          }
      
      }
      

      But the test crashes failing to resolve the placeholder {{property1}} with the complete stack stack attached.
      Obviously I have a camel.properties file in my classpath, but it is ignored.
      Just adding the attached META-INF/apache-deltaspike.properties file in the classpath makes the test green.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            antonin.stefanutti Antonin Stefanutti
            kawork Karim de Fombelle
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment