Camel
  1. Camel
  2. CAMEL-3254

Cannot set multiple route policies on a route in Spring

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.0
    • Fix Version/s: 2.7.0
    • Component/s: camel-core
    • Labels:
      None

      Description

      The Spring grammar does not seem to provide a way of specifying multiple policies. E.g.

      <route routePolicyRef="myFirstPolicy">
      ...
      </route>

      There is nowhere to inject a second policy, because there is only one attribute provided.

      While it is possible to set multiple unrelated policies (for e.g ScheduledRoutePolicy and say Shiro SecurityPolicy) which necessitate a different Spring XML fragment, it is not possible at the moment to set multiple policy sets in Spring against a route. It is possible to set up different start, stop, suspend & resume times in the same policy.

        Activity

        Hide
        Claus Ibsen added a comment -

        The shiro is actually done on the route

        <route>
           <poiicy ref="shiroStuff"/>
           ..
        </route>
        

        But nevertheless I guess you may want multiple route policies, to throttle and have a "sleep for the night" policy.
        You may also have a "sorry this app is in maintenance mode" policy where you can control it some custom way.

        So a good idea to support.

        An idea could be to support having support for specifying multiple in XML separated using comma

        <route routePolicyRef="myFirstPolicy, mySecondPolicy, myThirdPolicy">
        ...
        </route>
        
        Show
        Claus Ibsen added a comment - The shiro is actually done on the route <route> <poiicy ref= "shiroStuff" /> .. </route> But nevertheless I guess you may want multiple route policies, to throttle and have a "sleep for the night" policy. You may also have a "sorry this app is in maintenance mode" policy where you can control it some custom way. So a good idea to support. An idea could be to support having support for specifying multiple in XML separated using comma <route routePolicyRef= "myFirstPolicy, mySecondPolicy, myThirdPolicy" > ... </route>
        Hide
        Claus Ibsen added a comment -

        And btw we should make sure you can specify multiple in Java DSL
        You may do the same by using comma.

        I think the current logic in the code is that there is only 1 policy supported currently.

        Show
        Claus Ibsen added a comment - And btw we should make sure you can specify multiple in Java DSL You may do the same by using comma. I think the current logic in the code is that there is only 1 policy supported currently.
        Hide
        Ashwin Karpe added a comment - - edited

        Attached a patch for this issue. This fix involves two components camel-core and camel-quartz. The unit tests for the fix are in camel-quartz.

        Added both Spring and code based unit tests for the fix. Ran all tests for core and camel-quartz to verify that there are no side-effects of any kind.

        I will be committing this fix to the 2.7.0 snapshot trunk and update the documentation.

        Cheers,

        Ashwin...

        Show
        Ashwin Karpe added a comment - - edited Attached a patch for this issue. This fix involves two components camel-core and camel-quartz. The unit tests for the fix are in camel-quartz. Added both Spring and code based unit tests for the fix. Ran all tests for core and camel-quartz to verify that there are no side-effects of any kind. I will be committing this fix to the 2.7.0 snapshot trunk and update the documentation. Cheers, Ashwin...
        Hide
        Ashwin Karpe added a comment -

        Committed to the trunk as revision r1064901

        Show
        Ashwin Karpe added a comment - Committed to the trunk as revision r1064901
        Hide
        Claus Ibsen added a comment -

        Great, Ashwin do you mind adding an unit test to camel-spring.

        We should have some existing route policy tests there. Its best when we have unit tests in the "core" components (core,spring) when it comes to testing features on the DSL.
        And we need the documentation to be updated
        http://camel.apache.org/routepolicy.html

        And a note on the release notes about this new improvement
        http://camel.apache.org/camel-270-release.html

        Show
        Claus Ibsen added a comment - Great, Ashwin do you mind adding an unit test to camel-spring. We should have some existing route policy tests there. Its best when we have unit tests in the "core" components (core,spring) when it comes to testing features on the DSL. And we need the documentation to be updated http://camel.apache.org/routepolicy.html And a note on the release notes about this new improvement http://camel.apache.org/camel-270-release.html
        Hide
        Claus Ibsen added a comment -

        A few comments
        =============

        1)
        dont add camel-core-xml or camel-core-osgi as dep. in maven. Those are abstract components which gets embedded into spring / blueprint components.

        2)
        I have modified the logic a bit so RoutePolicyProcessor includes the list of policies. This avoid chaining a new processor for each policy.
        This just makes the runtime route even longer and just a bit more hazzle when debugging etc.

        The processor performs the same work for 1 or N route policy defined. It performs the begin/done callbacks.

        3)
        The DSL should be adjusted in both Java DSL and Spring XML.
        When we added support for multiple route policies you could not set those in the Java DSL using objects. You would have to use the ref.
        So I had added that. Also the javadoc should be updated to indicate that the routePolicyRef accepts multiple refs separated by comma.

        4)
        I will also add the unit test to spring component. Its important that the DSL is tested well in camel-core and camel-spring.

        Show
        Claus Ibsen added a comment - A few comments ============= 1) dont add camel-core-xml or camel-core-osgi as dep. in maven. Those are abstract components which gets embedded into spring / blueprint components. 2) I have modified the logic a bit so RoutePolicyProcessor includes the list of policies. This avoid chaining a new processor for each policy. This just makes the runtime route even longer and just a bit more hazzle when debugging etc. The processor performs the same work for 1 or N route policy defined. It performs the begin/done callbacks. 3) The DSL should be adjusted in both Java DSL and Spring XML. When we added support for multiple route policies you could not set those in the Java DSL using objects. You would have to use the ref. So I had added that. Also the javadoc should be updated to indicate that the routePolicyRef accepts multiple refs separated by comma. 4) I will also add the unit test to spring component. Its important that the DSL is tested well in camel-core and camel-spring.
        Hide
        Claus Ibsen added a comment -

        Implemented the 4 items above

        trunk: 1065012.

        Show
        Claus Ibsen added a comment - Implemented the 4 items above trunk: 1065012.
        Hide
        Ashwin Karpe added a comment - - edited

        Hi Claus,

        I was unsure about camel-core-xml since I was geting a CamelJMX... classloaderexception in eclipse when I tried to junit debug my code in unit tests with eclipse. It seemed to fix it and so I let it stay there. I guess I could have removed the dependency.

        Thanks for the updates and unit tests. I was not sure where to add the unit tests and went with camel-quatz since it was a identified against a JIRA issue there.

        I will be sure to add unit tests in camel-core/camel-spring when I make any changes to core next time.

        Cheers,

        Ashwin...

        Show
        Ashwin Karpe added a comment - - edited Hi Claus, I was unsure about camel-core-xml since I was geting a CamelJMX... classloaderexception in eclipse when I tried to junit debug my code in unit tests with eclipse. It seemed to fix it and so I let it stay there. I guess I could have removed the dependency. Thanks for the updates and unit tests. I was not sure where to add the unit tests and went with camel-quatz since it was a identified against a JIRA issue there. I will be sure to add unit tests in camel-core/camel-spring when I make any changes to core next time. Cheers, Ashwin...

          People

          • Assignee:
            Ashwin Karpe
            Reporter:
            Fintan Bolton
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development