after having talked with Claus on IRC i tried to look how to implement his
idea:
from(...).bean(XXX.class, "myMethod(${header.myHeader}, ${body}").to(...).
But i don't understand something: method are managed from BeanInfo and
MethodInfo. Where is the link with the route?
In other word how can i get the "myMethod(${header.myHeader}, ${body}"
string from BeanInfo?
I think BeanInfo should have another cached (method, expressions) list to
manage it.
- Romain
2011/5/8 Romain Manni-Bucau <[email protected]>
> i did a poc,
>
> i need a modification in camel-core, here is the diff:
>
> Index: src/main/java/org/apache/camel/component/bean/BeanInfo.java
> ===================================================================
> --- src/main/java/org/apache/camel/component/bean/BeanInfo.java (révision
> 1100337)
> +++ src/main/java/org/apache/camel/component/bean/BeanInfo.java (copie de
> travail)
> @@ -289,7 +289,7 @@
> @SuppressWarnings("unchecked")
> protected MethodInfo createMethodInfo(Class clazz, Method method) {
> Class[] parameterTypes = method.getParameterTypes();
> - Annotation[][] parametersAnnotations =
> method.getParameterAnnotations();
> + Annotation[][] parametersAnnotations = getAnnotationsFor(method);
>
> List<ParameterInfo> parameters = new ArrayList<ParameterInfo>();
> List<ParameterInfo> bodyParameters = new
> ArrayList<ParameterInfo>();
> @@ -338,6 +338,10 @@
> return new MethodInfo(camelContext, clazz, method, parameters,
> bodyParameters, hasCustomAnnotation, hasHandlerAnnotation);
> }
>
> + protected Annotation[][] getAnnotationsFor(Method method) {
> + return method.getParameterAnnotations();
> + }
> +
> /**
> * Lets try choose one of the available methods to invoke if we can
> match
> * the message body to the body parameter
>
>
> It is simply adding getAnnotationsFor(Method method) method to allow me to
> override it in a child class.
>
> After this modification i did a component reading a file containing the
> annotation description:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <methods>
> <method class="org.apache.camel.component.bean.FooBean" name="foo">
> <parameter index="0" type="java.lang.String">
> <annotation class="org.apache.camel.Header">
> <annotation-parameter name="value" value="bar" />
> </annotation>
> </parameter>
> <parameter index="1" type="java.lang.String">
> <annotation class="org.apache.camel.Body" />
> </parameter>
> </method>
> </methods>
>
>
> and i change the behavior of the method i started my mail with to test if
> annotations are defined in a file before returning the array.
>
> To avoid to load the file each time i need it i created a service to do it.
>
> Finally i can do what i want: to use a pojo without any camel import and
> avoiding to create an array to set parameters.
>
> My questions are now:
>
> 1) do you think the method can be created in the trunk?
> 2) i didn't find how to register my service in camel (i added it manually
> in my unit test)
> 3) any thoughts?
>
> PS: i'll upload the code in my repository very soon (
> http://code.google.com/p/rmannibucau/ )
>
> - Romain
>
> 2011/5/8 Romain Manni-Bucau <[email protected]>:
>
> > Hi,
> >
> > maybe another solution to this problem could be to add a kind of
> > descriptor file:
> >
> > in camel a bean can extract parameters from headers or something else
> > with annotations, if there is a file saying the same thing the bean
> > could not use any camel imports but do the same.
> >
> > what do you think of a file like:
> >
> > <methods>
> > <method class="aaa" method="bbb">
> > <parameter index="ccc">
> > <annotation class="ddd">
> > <annotation-parameter name="eee" value="fff" />
> > </annotation>
> > </parameter>
> > </method>
> > </methods>
> >
> > - Romain
> >
> > 2011/5/6 Romain Manni-Bucau <[email protected]>:
> >> Hi,
> >>
> >> i would like to do a route with a bit more bean invocations than
> >> usually and i realise the use of array body to specify parameters is
> >> not very nice, i always have something like:
> >>
> >> from(...).to(<create my array>).to("bean:...").to(<save my output in
> >> headers and replace the body to continue>)....
> >>
> >> do you think it could be improved specifying in the bean component
> >> input/output from headers for example?
> >>
> >> example:
> from(...).to("bean:foo.bar.MyClass?method=hello¶meter[0]=header(first)&aprameter[2]=header(other)&result=header(out)").to(...)
> >>
> >> - Romain
> >>
> >
>
>