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

CamelContext fails to start using placeholder in "simple" in conjunction with BridgePropertyPlaceholder

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Won't Fix
    • 2.11.0
    • Future
    • camel-spring
    • None
    • Unknown
    • Regression

    Description

      Recently after upgrading from 2.10.3 to 2.11.0 I have encountered the following bug.
      The problematic part was looking like this:

      from("direct:start")
          .setHeader(Exchange.FILE_NAME, simple("{{file.rootdir}}/${in.header.CamelFileName}"))
          .to("mock:result");
      

      Camel was failing to start with the following exception

      org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> SetHeader[CamelFileName, simple{Simple: {{file.rootdir}}/${in.header.CamelFileName}}] <<< in route: Route(route1)[[From[direct:start]] -> [SetHeader[CamelFileNa... because of Could not resolve placeholder 'in.header.CamelFileName' in string value "/root/dir/${in.header.CamelFileName}"
      	at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:883)
      	at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:176)
      	at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:755)
      	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1857)
      	at org.apache.camel.impl.DefaultCamelContext.addRouteDefinitions(DefaultCamelContext.java:692)
      	at org.apache.camel.builder.RouteBuilder.populateRoutes(RouteBuilder.java:337)
      	at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:264)
      	at org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:654)
      	at org.apache.camel.ContextTestSupport.setUp(ContextTestSupport.java:115)
      	at org.apache.camel.spring.SpringTestSupport.setUp(SpringTestSupport.java:54)
      	at org.apache.camel.TestSupport.runBare(TestSupport.java:58)
      	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
      Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'in.header.CamelFileName' in string value "/root/dir/${in.header.CamelFileName}"
      	at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:173)
      	at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125)
      	at org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer.springResolvePlaceholders(BridgePropertyPlaceholderConfigurer.java:180)
      	at org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer.parseUri(BridgePropertyPlaceholderConfigurer.java:143)
      	at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:161)
      	at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:120)
      	at org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:1100)
      	at org.apache.camel.model.ProcessorDefinition.resolvePropertyPlaceholders(ProcessorDefinition.java:556)
      	at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:471)
      	at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:197)
      	at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:880)
      	... 22 more
      

      I have created a small test to reproduce the bug, and thanks to git bisect I found the commit that introduced this bug. It is commit ea4c0ab5 "CAMEL-6233: BridgePropertyPlaceholderConfigurer does not support nested Spring properties". The problem is that it is trying to resolve the whole simple with the property resolver but after resolving the spring property it treats ${in.header.CamelFileName} as a spring placeholder and fails to find it.
      There is a workaround. If {{file.rootdir}} is replaced by ${properties:file.rootdir} then Camel starts just fine.

      The test to reproduce is attached.

      Attachments

        1. tests_to_reproduce_bug.patch
          6 kB
          Nerses Aznauryan

        Issue Links

          Activity

            People

              Unassigned Unassigned
              nerses_am Nerses Aznauryan
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: