Grokbase Groups Camel users May 2011
FAQ
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&parameter[0]=header(first)&aprameter[2]=header(other)&result=header(out)").to(...)

- Romain

Search Discussions

  • Romain Manni-Bucau at May 8, 2011 at 10:14 am
    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 <rmannibucau@gmail.com>:
    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&parameter[0]=header(first)&aprameter[2]=header(other)&result=header(out)").to(...)

    - Romain
  • Romain Manni-Bucau at May 8, 2011 at 8:28 pm
    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 <rmannibucau@gmail.com>:
    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 <rmannibucau@gmail.com>:
    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&parameter[0]=header(first)&aprameter[2]=header(other)&result=header(out)").to(...)
    - Romain
  • Romain Manni-Bucau at May 10, 2011 at 1:39 pm
    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 <rmannibucau@gmail.com>
    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 <rmannibucau@gmail.com>:
    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 <rmannibucau@gmail.com>:
    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&parameter[0]=header(first)&aprameter[2]=header(other)&result=header(out)").to(...)
    - Romain
  • Claus Ibsen at May 11, 2011 at 9:01 am

    On Tue, May 10, 2011 at 3:38 PM, Romain Manni-Bucau wrote:
    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.
    Could you create a ticket in JIRA for this new feature. Then we can track it.

    - Romain

    2011/5/8 Romain Manni-Bucau <rmannibucau@gmail.com>
    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 <rmannibucau@gmail.com>:
    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 <rmannibucau@gmail.com>:
    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&parameter[0]=header(first)&aprameter[2]=header(other)&result=header(out)").to(...)
    - Romain


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    CamelOne 2011: http://fusesource.com/camelone2011/
    Twitter: davsclaus
    Blog: http://davsclaus.blogspot.com/
    Author of Camel in Action: http://www.manning.com/ibsen/
  • Romain Manni-Bucau at May 11, 2011 at 9:17 am
    done here https://issues.apache.org/jira/browse/CAMEL-3961

    - Romain

    2011/5/11 Claus Ibsen <claus.ibsen@gmail.com>
    On Tue, May 10, 2011 at 3:38 PM, Romain Manni-Bucau
    wrote:
    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.
    Could you create a ticket in JIRA for this new feature. Then we can track
    it.

    - Romain

    2011/5/8 Romain Manni-Bucau <rmannibucau@gmail.com>
    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 <rmannibucau@gmail.com>:
    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 <rmannibucau@gmail.com>:
    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&parameter[0]=header(first)&aprameter[2]=header(other)&result=header(out)").to(...)
    - Romain


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    CamelOne 2011: http://fusesource.com/camelone2011/
    Twitter: davsclaus
    Blog: http://davsclaus.blogspot.com/
    Author of Camel in Action: http://www.manning.com/ibsen/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedMay 6, '11 at 11:41a
activeMay 11, '11 at 9:17a
posts6
users2
websitecamel.apache.org

2 users in discussion

Romain Manni-Bucau: 5 posts Claus Ibsen: 1 post

People

Translate

site design / logo © 2022 Grokbase