You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lost_in <re...@gmail.com> on 2013/03/29 10:47:32 UTC

in camel-example-cxf-proxy demo which in camel distribution, how EnrichBean.enrich method was called

hi all,

I have post this issue on 
http://camel.465427.n5.nabble.com/in-camel-example-cxf-proxy-demo-which-in-camel-distribution-how-EnrichBean-enrich-method-was-called-td5729745.html
<http://camel.465427.n5.nabble.com/in-camel-example-cxf-proxy-demo-which-in-camel-distribution-how-EnrichBean-enrich-method-was-called-td5729745.html>  

thanks Claus Ibsen-2's replay,he is a nice gay!!
 
I follow his suggestion and read corresponding section, but i still can't
find the answer.
I also read cxf's data format's tips on
http://camel.apache.org/cxf.html <http://camel.apache.org/cxf.html>  

following is my previous post's content:
I am a newbie in camel,when I read the camel-example-cxf-proxy demo which in
camel distribution,
 I confuse with EnrichBean.java file 

the source code of EnrichBean.java is very simple as follows: 

public class EnrichBean { 

    public Document enrich(Document doc) { 
        Node node = doc.getElementsByTagName("incidentId").item(0); 
        String incident = node.getTextContent(); 

        // here we enrich the document by changing the incident id to
another value
         // you can of course do a lot more in your use-case 
        node.setTextContent("456"); 
        System.out.println("Incident was " + incident + ", changed to 456"); 

        return doc; 
    } 
} 

it was used in camel_config.xml as follows: 

  
  <bean id="enrichBean"
class="org.apache.camel.example.cxf.proxy.EnrichBean"/>
  

  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <endpoint id=&quot;callRealWebService&quot; uri=&quot;&lt;a
href=&quot;http://localhost:$&quot;>http://localhost:${real.port}/real-webservice?throwExceptionOnFailure=false"/>
    <route>
      
      <from uri="cxf:bean:reportIncident?dataFormat=MESSAGE"/>
      
      <to uri="log:input"/>
      
      <to uri="bean:enrichBean"/>
      
      <to ref="callRealWebService"/>
      
      <to uri="log:output"/>
    </route>

  </camelContext>

my question is: how EnrichBean.enrich method was called and why the
parameter to enrich() is Document type?
 
any reply is appriciate! 



--
View this message in context: http://camel.465427.n5.nabble.com/in-camel-example-cxf-proxy-demo-which-in-camel-distribution-how-EnrichBean-enrich-method-was-called-tp5730076.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: in camel-example-cxf-proxy demo which in camel distribution, how EnrichBean.enrich method was called

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Mar 29, 2013 at 10:47 AM, lost_in <re...@gmail.com> wrote:
> hi all,
>
> I have post this issue on
> http://camel.465427.n5.nabble.com/in-camel-example-cxf-proxy-demo-which-in-camel-distribution-how-EnrichBean-enrich-method-was-called-td5729745.html
> <http://camel.465427.n5.nabble.com/in-camel-example-cxf-proxy-demo-which-in-camel-distribution-how-EnrichBean-enrich-method-was-called-td5729745.html>
>
> thanks Claus Ibsen-2's replay,he is a nice gay!!
>
> I follow his suggestion and read corresponding section, but i still can't
> find the answer.
> I also read cxf's data format's tips on
> http://camel.apache.org/cxf.html <http://camel.apache.org/cxf.html>
>
> following is my previous post's content:
> I am a newbie in camel,when I read the camel-example-cxf-proxy demo which in
> camel distribution,
>  I confuse with EnrichBean.java file
>
> the source code of EnrichBean.java is very simple as follows:
>
> public class EnrichBean {
>
>     public Document enrich(Document doc) {
>         Node node = doc.getElementsByTagName("incidentId").item(0);
>         String incident = node.getTextContent();
>
>         // here we enrich the document by changing the incident id to
> another value
>          // you can of course do a lot more in your use-case
>         node.setTextContent("456");
>         System.out.println("Incident was " + incident + ", changed to 456");
>
>         return doc;
>     }
> }
>
> it was used in camel_config.xml as follows:
>
>
>   <bean id="enrichBean"
> class="org.apache.camel.example.cxf.proxy.EnrichBean"/>
>
>
>   <camelContext xmlns="http://camel.apache.org/schema/spring">
>     <endpoint id=&quot;callRealWebService&quot; uri=&quot;&lt;a
> href=&quot;http://localhost:$&quot;>http://localhost:${real.port}/real-webservice?throwExceptionOnFailure=false"/>
>     <route>
>
>       <from uri="cxf:bean:reportIncident?dataFormat=MESSAGE"/>
>
>       <to uri="log:input"/>
>
>       <to uri="bean:enrichBean"/>
>
>       <to ref="callRealWebService"/>
>
>       <to uri="log:output"/>
>     </route>
>
>   </camelContext>
>
> my question is: how EnrichBean.enrich method was called and why the
> parameter to enrich() is Document type?
>

You can omit specifying a method, and if you do so, then Camel has to
pick the method to use.
And for that it has an algorithm to do so. See those links I posted
before. Or check out Camel in Action, chapter 4, we have a diagram of
this algorithm explaining it in details.

 <to uri="bean:enrichBean"/>

If the bean has only 1 method, its easy to pick, but when it has more
methods its harder. You can tell Camel which method to use, eg

 <to uri="bean:enrichBean?method=enrich"/>


The type Document is from JDK which is an Object representation of
XML. We could also have used String instead, then we would get the XML
in a String. Camel uses its type converter to convert to the types of
the method signature.

But the Document type allows us to DOM API to enrich the message as
the code does.

But its your chose, you can do as you want.




> any reply is appriciate!
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/in-camel-example-cxf-proxy-demo-which-in-camel-distribution-how-EnrichBean-enrich-method-was-called-tp5730076.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen