[ 
https://issues.apache.org/activemq/browse/CAMEL-2914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60471#action_60471
 ] 

Claus Ibsen commented on CAMEL-2914:
------------------------------------

Hadrian Camel already have an API for manipulating the routes before they are 
created
{{CamelContext.getRouteDefinition}} gives your the route in which you can 
manipulate all the way you like.

Its just that out of the box Camel will auto start the routes and there is not 
a super duper easy way of adding a hook which allows you to easily manipulate 
the route definitions.
See the discussion on the mailing list for a better alternative.

Hacking the policy is not the way to go. 

I am cooking up the {{ProcessorFactory}} SPI now so we have a easy way to 
register a custom hook.

For example this is from an unit test I got so far, which does what the 
PolicyAware stuff did.


{code}

    @Override
    protected CamelContext createCamelContext() throws Exception {
        CamelContext context = super.createCamelContext();
        // register our custom factory
        context.setProcessorCreatorFactory(new MyFactory());
        return context;
    }

    public static class MyFactory implements ProcessorFactory {

        public Processor createChildProcessor(RouteContext routeContext, 
ProcessorDefinition definition, boolean mandatory) throws Exception {
            return null;
        }

        public Processor createProcessor(RouteContext routeContext, 
ProcessorDefinition definition) throws Exception {
            if (definition instanceof SetBodyDefinition) {
                SetBodyDefinition set = (SetBodyDefinition) definition;
                set.setExpression(new ConstantExpression("body was altered"));
            }

            // return null to let the default implementation create the 
processor, we just wanted to alter the definition
            // before the processor was created
            return null;
        }
    }



> ProcessorDefinition aware Policy
> --------------------------------
>
>                 Key: CAMEL-2914
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2914
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>            Assignee: Hadrian Zbarcea
>             Fix For: 2.4.0
>
>         Attachments: DefinitionAwarePolicy.diff
>
>
> Currently a Policy cannot change the child processor definitions, and the 
> processor instances are created prior to wrap being called. I would like to 
> see the child Processsor defintions passed to wrap, and the processor 
> instances created afterwards.
> As discussed in this mailing list post:
> http://camel.465427.n5.nabble.com/Using-Policy-to-alter-Definitions-before-building-tt696567.html#a696567

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to