You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Bruno Dusausoy <bd...@yp5.be> on 2010/07/20 10:23:57 UTC

Processor explanation

Hi,

I'm a little confused by the use of a processor when consuming message (in
POJO mode) from a CXF endpoint.
Basically, what I want to do is consuming messages from the latter : just
knowing what the operation is and do some processing depending on it,
returning the result to the caller (the producer) and then let the message
continue its journey through the routes I've configured.

public class CareerRouteBuilder extends SpringRouteBuilder {

    // ...
    @Override
    public void configure() throws Exception {
        
        from("cxf://bean:myService").process(new Processor() {
            public void process(Exchange exchange) throws Exception {
                String operation =
exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class);
                /*
                 * Maybe I could use reflection on a bean implementing the
interface 
                 * automatically generated by CXF's codegen-maven-plugin
instead of using "if" statements.
                 */
                if (operation.equals("SomeOperation")) {
                    MyResponse res =
someBean.process(exchange.getIn().getBody(SomeClazz.class);
                    exchange.getOut().setBody(res);
                } else if (operation.equals("AnotherOperation")) {
                    // ...
                } else {
                    // ...
                }
            }
        });
    }
}

It works fine, but is it the best way to do what I want ?
Of course I could also use CXF directly and then route manually the result
to the desired endpoint.
But it would definitely be nicer if I could directly use a bean to process
the desired operation.
I've read the CXF Component documentation but haven't found anything like
this.
Am I missing something ?

Regards.
-- 
Bruno Dusausoy
YP5 Software
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.

Re: Processor explanation

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can set the header Exchange.BEAN_METHOD_NAME on the Exchange and
then invoke a bean.
The bean could then have the same method names as the CXF. Then Camel
will pick the appropriate method.

You may even just copy the CXF operations header to the method name header.
from(cxf)
.setHeader(Exchange.BEAN_METHOD_NAME, header(CxfConstants.OPXXX)
.to(bean:someBean);



On Tue, Jul 20, 2010 at 10:23 AM, Bruno Dusausoy <bd...@yp5.be> wrote:
> Hi,
>
> I'm a little confused by the use of a processor when consuming message (in
> POJO mode) from a CXF endpoint.
> Basically, what I want to do is consuming messages from the latter : just
> knowing what the operation is and do some processing depending on it,
> returning the result to the caller (the producer) and then let the message
> continue its journey through the routes I've configured.
>
> public class CareerRouteBuilder extends SpringRouteBuilder {
>
>    // ...
>    @Override
>    public void configure() throws Exception {
>
>        from("cxf://bean:myService").process(new Processor() {
>            public void process(Exchange exchange) throws Exception {
>                String operation =
> exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class);
>                /*
>                 * Maybe I could use reflection on a bean implementing the
> interface
>                 * automatically generated by CXF's codegen-maven-plugin
> instead of using "if" statements.
>                 */
>                if (operation.equals("SomeOperation")) {
>                    MyResponse res =
> someBean.process(exchange.getIn().getBody(SomeClazz.class);
>                    exchange.getOut().setBody(res);
>                } else if (operation.equals("AnotherOperation")) {
>                    // ...
>                } else {
>                    // ...
>                }
>            }
>        });
>    }
> }
>
> It works fine, but is it the best way to do what I want ?
> Of course I could also use CXF directly and then route manually the result
> to the desired endpoint.
> But it would definitely be nicer if I could directly use a bean to process
> the desired operation.
> I've read the CXF Component documentation but haven't found anything like
> this.
> Am I missing something ?
>
> Regards.
> --
> Bruno Dusausoy
> YP5 Software
> --
> Pensez environnement : limitez l'impression de ce mail.
> Please don't print this e-mail unless you really need to.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Processor explanation

Posted by Willem Jiang <wi...@gmail.com>.
You can use producerTemplate to send original message into a JMS queue.
Please check out the camel-example-reportincident[1] for more information.

[1]http://camel.apache.org/tutorial-example-reportincident-part5.html

Willem
----------------------------------
  Apache Camel, Apache CXF committer
  Open Source Integration http://www.fusesource.com
  Blog http://willemjiang.blogspot.com
  Tiwtter http://twitter.com/willemjiang

Bruno Dusausoy wrote:
> On Tue, 20 Jul 2010 16:46:41 +0800, Willem Jiang <wi...@gmail.com>
> wrote:
>> If we can map the CXF operation name to the bean's method, then camel 
>> can invoke the bean as you want.
>>
>> You can use CXF directly by setting the implementor with your bean.
>>
>> If you already has the response, I don't know what you want to do next 
>> with the camel route. Can you tell me your user story?
>>
> Well, the response is indeed sent back to the caller, but I have to send
> the original message to a JMS queue for further processing (logging and
> statistics stuff, internal use only).
> 


Re: Processor explanation

Posted by Bruno Dusausoy <bd...@yp5.be>.
On Tue, 20 Jul 2010 16:46:41 +0800, Willem Jiang <wi...@gmail.com>
wrote:
> If we can map the CXF operation name to the bean's method, then camel 
> can invoke the bean as you want.
> 
> You can use CXF directly by setting the implementor with your bean.
> 
> If you already has the response, I don't know what you want to do next 
> with the camel route. Can you tell me your user story?
> 
Well, the response is indeed sent back to the caller, but I have to send
the original message to a JMS queue for further processing (logging and
statistics stuff, internal use only).

-- 
Bruno Dusausoy
YP5 Software
--
Pensez environnement : limitez l'impression de ce mail.
Please don't print this e-mail unless you really need to.

Re: Processor explanation

Posted by Willem Jiang <wi...@gmail.com>.
If we can map the CXF operation name to the bean's method, then camel 
can invoke the bean as you want.

You can use CXF directly by setting the implementor with your bean.

If you already has the response, I don't know what you want to do next 
with the camel route. Can you tell me your user story?

Willem
----------------------------------
  Apache Camel, Apache CXF committer
  Open Source Integration http://www.fusesource.com
  Blog http://willemjiang.blogspot.com
  Tiwtter http://twitter.com/willemjiang


Bruno Dusausoy wrote:
> Hi,
> 
> I'm a little confused by the use of a processor when consuming message (in
> POJO mode) from a CXF endpoint.
> Basically, what I want to do is consuming messages from the latter : just
> knowing what the operation is and do some processing depending on it,
> returning the result to the caller (the producer) and then let the message
> continue its journey through the routes I've configured.
> 
> public class CareerRouteBuilder extends SpringRouteBuilder {
> 
>     // ...
>     @Override
>     public void configure() throws Exception {
>         
>         from("cxf://bean:myService").process(new Processor() {
>             public void process(Exchange exchange) throws Exception {
>                 String operation =
> exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class);
>                 /*
>                  * Maybe I could use reflection on a bean implementing the
> interface 
>                  * automatically generated by CXF's codegen-maven-plugin
> instead of using "if" statements.
>                  */
>                 if (operation.equals("SomeOperation")) {
>                     MyResponse res =
> someBean.process(exchange.getIn().getBody(SomeClazz.class);
>                     exchange.getOut().setBody(res);
>                 } else if (operation.equals("AnotherOperation")) {
>                     // ...
>                 } else {
>                     // ...
>                 }
>             }
>         });
>     }
> }
> 
> It works fine, but is it the best way to do what I want ?
> Of course I could also use CXF directly and then route manually the result
> to the desired endpoint.
> But it would definitely be nicer if I could directly use a bean to process
> the desired operation.
> I've read the CXF Component documentation but haven't found anything like
> this.
> Am I missing something ?
> 
> Regards.