You should NOT register the processor yourself, this is done by the template bean thingy automatically
On Thu, Sep 8, 2022 at 1:39 PM ski n <raymondmees...@gmail.com> wrote: > OK, sorry, I actually read the documentation on bindings and did use > {{MyProcessor}} as the bean name. > > But it didn't work. > > I register my bean/processor as: > > registry.bind("MyProcessor", new MyProcessor("")); > > But when I run it, I got: > > Failed to resolve endpoint: bean://MyProcessor-1?method=process due to: No > bean could be found in the registry for: MyProcessor-1 > > Don't know where the "-1" comes from. However when I register it with that > > registry.bind("MyProcessor-1", new MyProcessor("")); > > Then the route works but not with the routetemplate parameter (because it's > already iniaitized. So I tried it with > > registry.bind("MyProcessor-1", MyProcessor.class); > > > Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to > resolve endpoint: bean://MyProcessor-1?method=process due to: > java.lang.NoSuchMethodException: > > I also tried it with method parameters, instead of the constructor. I first > tried to put an extra parameter on the process method, but the interface > for Processor doesn't allow that. So I tried to use method overloading, but > then it's unclear how to pass the exchange object as a parameter. > > Raymond > > > > > On Thu, Sep 8, 2022 at 12:06 PM Claus Ibsen <claus.ib...@gmail.com> wrote: > > > Hi > > > > No you cannot - you mix standard Java with Camel "parsing" the model when > > it calls the configure() method. > > It would be the same in regular Camel route. > > You basically do standard Java code with a new constructor and pass in a > > string literal. Camel is not in use at that point. > > > > In your template bean example, then you need to use {{MyProcessor}} as > the > > bean name. > > See the IMPORTANT note at: > > > > > https://camel.apache.org/manual/route-template.html#_binding_beans_to_route_template > > > > > > > > On Thu, Sep 8, 2022 at 11:53 AM ski n <raymondmees...@gmail.com> wrote: > > > > > Hi, > > > > > > I have a routetemplate as follows: > > > > > > routeTemplate("processortemplate") > > > .templateParameter("out") > > > .from("direct:in") > > > .process("MyProcessor") > > > .to("{{out}}"); > > > > > > This works. > > > > > > The processor is registered an the called by reference. Now I added a > > > constructor argument to the processor and I tried to call it like this: > > > > > > routeTemplate("processortemplate") > > > .templateParameter("processerParam") > > > .templateParameter("out") > > > .from("direct:in") > > > .process(new MyProcessor("{{processorParam}}")) > > > .to("{{out}}"); > > > > > > This doesn't work, because the parameter of the processor is parsed > > before > > > the template parameter is parsed. Result is that the parameter > > > {{myProcessorParam}} is passed as literal param. > > > > > > I tried to come with up something like this: > > > > > > routeTemplate("processortemplate") > > > .templateParameter("processerparam") > > > .templateParameter("out") > > > .templateBean("MyProcessor") > > > .typeClass("com.foo.MyProcessor") > > > .property("processerparam", "{{processerparam}}") > > > .end() > > > .from("direct:in") > > > .to("bean:MyProcessor?method=process") > > > .to("{{out}}"); > > > > > > But this didn't pass the parameter as well. As a workaround I set > > > constructor argument as a header and then get the header within the > > > processor. > > > > > > Question: > > > > > > Is there a way to pass constructor arguments to a processor in another > > way? > > > I couldn't find anything at the routeTemplate page on how to handle > > > processors. > > > > > > Raymond > > > > > > > > > -- > > Claus Ibsen > > ----------------- > > http://davsclaus.com @davsclaus > > Camel in Action 2: https://www.manning.com/ibsen2 > > > -- Claus Ibsen ----------------- http://davsclaus.com @davsclaus Camel in Action 2: https://www.manning.com/ibsen2