You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Eugeniu <eu...@hotmail.com> on 2012/04/24 19:49:40 UTC

Understanding Request-Reply EIP in Spring DSL

Hi

Here is the listing 7.6 from Camel in Action book:

<camelContext xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="cxf:bean:orderEndpoint" />
    <to uri="seda:incomingOrders" />
    <transform>
      <constant>OK</constant>
    </transform>
  </route>
</camelContext>

Here the 'transform' construct changes the message body to string 'OK' and
sends this back to the web service as reply. How in general do you send
replies in such cases. Is there a rule that in Request-Reply scenarios the
last message in the route is sent as a reply? I mean there is not visual
hint that the 'transform' refers to the initial web service request..
A related question: How to find out the default MEP supported by a given
Camel Component?

--
View this message in context: http://camel.465427.n5.nabble.com/Understanding-Request-Reply-EIP-in-Spring-DSL-tp5662809p5662809.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Understanding Request-Reply EIP in Spring DSL

Posted by Eugeniu <eu...@hotmail.com>.
Thanks everybody for help so far. The scenario I described previously was
implemented just by throwing the exceptions from corresponding validator
Java beans at step 2 and 3. It seems that Camel wraps that exception and
sends it to the web service client without any additional code.
There is one downside: the logs contain the exception stack trace although
this is some sort of expected business exception and from this point of view
should be treated as expected execution scenario. If I call
setBody(exception) inside some of the validator beans, the Jaxb marshaller
complains that the exception class is not known to the context.

The Camel related question would be: how Camel does that magic of properly
sending the web service exception to the client when it is thrown inside the
validation bean, since it obviously doesn't set it as the body of the in/out
message? Could I somehow do this myself inside the validation bean so as to
avoid the exception being logged?

By the way this code: 

     <onException>
        <exception>order.InvalidRequest</exception>
        <handled>
            <constant>true</constant>
        </handled>
         <setBody>
             <simple>${exception}</simple>
         </setBody>
        <stop/>
    </onException>

causes the same Jaxb marshaller exception to the thrown...

--
View this message in context: http://camel.465427.n5.nabble.com/Understanding-Request-Reply-EIP-in-Spring-DSL-tp5662809p5670749.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Understanding Request-Reply EIP in Spring DSL

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Apr 26, 2012 at 8:16 PM, Eugeniu <eu...@hotmail.com> wrote:
> I think your advice won't work in my case since I am trying to send different
> replies based on some conditions.
> Here is the scenario I am trying to implement in a route:
> 1. <from> is a cxf endpoint which gets order requests.
> 2. Perform first validation stage. If error - construct a error message,
> send to the client and stop. If not go to third step.
> 3. Perform second validation stage. If error - construct a different error
> message, send it to the client and stop. If validation passed go to step 4.
> 4. Send a message to an activemq queue and send the webservice client an
> acknowledgement of successful order receipt.
>
> Can I somehow specify that the error messages I am building at step 2 or 3
> should be sent as a reply to the initial web service request?
>

Yes it depends if you validate and throw an exception, you can use
onException and handle the exception to construct a custom reply
message to the cxf client.

Some links
http://java.dzone.com/articles/camel-exception-handling?mz=62823-enterprise-integration
http://camel.apache.org/exception-clause.html
http://camel.apache.org/error-handling-in-camel.html

And there is examples in the Camel in Action book on page 146.




> --
> View this message in context: http://camel.465427.n5.nabble.com/Understanding-Request-Reply-EIP-in-Spring-DSL-tp5662809p5668306.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Understanding Request-Reply EIP in Spring DSL

Posted by Eugeniu <eu...@hotmail.com>.
I think your advice won't work in my case since I am trying to send different
replies based on some conditions. 
Here is the scenario I am trying to implement in a route:
1. <from> is a cxf endpoint which gets order requests.
2. Perform first validation stage. If error - construct a error message,
send to the client and stop. If not go to third step.
3. Perform second validation stage. If error - construct a different error
message, send it to the client and stop. If validation passed go to step 4.
4. Send a message to an activemq queue and send the webservice client an
acknowledgement of successful order receipt.

Can I somehow specify that the error messages I am building at step 2 or 3
should be sent as a reply to the initial web service request?

--
View this message in context: http://camel.465427.n5.nabble.com/Understanding-Request-Reply-EIP-in-Spring-DSL-tp5662809p5668306.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Understanding Request-Reply EIP in Spring DSL

Posted by Willem Jiang <wi...@gmail.com>.
You use the wire-tap to send the message to other endpoint and set the 
response in the end of the route.

[1]http://camel.apache.org/wire-tap.html
On Wed Apr 25 17:08:09 2012, Eugeniu wrote:
> Is there a way to send back a reply to the client and continue processing the
> message in the same route afterwards?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Understanding-Request-Reply-EIP-in-Spring-DSL-tp5662809p5664277.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Willem
----------------------------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
         http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang


Re: Understanding Request-Reply EIP in Spring DSL

Posted by Eugeniu <eu...@hotmail.com>.
Is there a way to send back a reply to the client and continue processing the
message in the same route afterwards?

--
View this message in context: http://camel.465427.n5.nabble.com/Understanding-Request-Reply-EIP-in-Spring-DSL-tp5662809p5664277.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Understanding Request-Reply EIP in Spring DSL

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Apr 24, 2012 at 7:49 PM, Eugeniu <eu...@hotmail.com> wrote:
> Hi
>
> Here is the listing 7.6 from Camel in Action book:
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>  <route>
>    <from uri="cxf:bean:orderEndpoint" />
>    <to uri="seda:incomingOrders" />
>    <transform>
>      <constant>OK</constant>
>    </transform>
>  </route>
> </camelContext>
>
> Here the 'transform' construct changes the message body to string 'OK' and
> sends this back to the web service as reply. How in general do you send
> replies in such cases. Is there a rule that in Request-Reply scenarios the
> last message in the route is sent as a reply? I mean there is not visual
> hint that the 'transform' refers to the initial web service request..
> A related question: How to find out the default MEP supported by a given
> Camel Component?
>

Yes the consumer sends back the reply based on what the Camel message
"looks like" at the end of the routing.
So in general the last step of the route is for the reply message.



> --
> View this message in context: http://camel.465427.n5.nabble.com/Understanding-Request-Reply-EIP-in-Spring-DSL-tp5662809p5662809.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/