You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Kriti <kr...@gmail.com> on 2016/05/11 15:44:40 UTC

.choice(), .when() not working as expected in the camel route

Hi,

I have a camel route like this -

public void configure() {

-------------------------
-------------------------
				
from('mina2:tcp://'+ incomingHL7Listener.getIp() + ':' +
incomingHL7Listener.getPort() +'?codec=#rcmhl7codec')
                         .choice()
                                .when(body().isEqualTo("Error decoding
HL7")).to('direct:failure').endChoice()
                                .otherwise().to('direct:success');
                    
                                 from('direct:failure')
                                 .process{
                                       --------------
                                 }
                                 .marshal().hl7();
                             
                                from('direct:success')
                                .process{
                                       --------------
                                 }
                                 .marshal().hl7();

The route is executing the when part i.e from('direct:failure') irrespective
of whether the condition gets satisfied or not. Even if the body is not
equal to 'Error decoding HL7', it is going to the failure part of the route.

I need to get a solution for this as soon as possible. Any suggestions would
be welcome.

Thanks and Regards,
Kriti



--
View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: .choice(), .when() not working as expected in the camel route

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Components differ in how they deal with application errors.

For example, the HL7 codecs for camel-netty4 and camel-mina2 don’t interrogate HL7 acknowledgements so they don’t raise exceptions when an HL7 NACK is received - they just return the acknowledgement in the body.  Since I attempt to resend messages when I receive an HL7 AE NACK, I want an exception so I can use the onException stuff, and that was a little painful using the camel-hl7 codecs.  So camel-mllp raises specific exceptions for the different types of HL7 NACKS, so I can use standard camel error handling more easily.  (BTW - this was one of reasons I wrote camel-mllp in the first place).

If I’m using HAPI to process the message, I still have the unmarshal call and an onException handler for the HAPI HL7Exception to deal with parse errors (and other HAPI errors)

Hope that helps

> On May 23, 2016, at 12:03 PM, sekaijin <je...@aphp.fr> wrote:
> 
> I understood that camel-mllp acquire the message.
> But my purpose is not there.
> I do not know camel-mllp
> what I mean is that usually when a component fails to perform its task, it
> throws an exception. I do not know once that puts an error message in the
> body.
> 
> I therefore think you should use an error handler or an 
> onCompletion.onFailure.
> 
> A+JYT
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452p5782978.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: .choice(), .when() not working as expected in the camel route

Posted by sekaijin <je...@aphp.fr>.
I understood that camel-mllp acquire the message.
But my purpose is not there.
I do not know camel-mllp
what I mean is that usually when a component fails to perform its task, it
throws an exception. I do not know once that puts an error message in the
body.

I therefore think you should use an error handler or an 
onCompletion.onFailure.

A+JYT



--
View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452p5782978.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: .choice(), .when() not working as expected in the camel route

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
Actually, you can (I wrote camel-mllp :-) ).

When the camel-mllp component is used as a consumer (i.e. a TCP listener), the body of the exchange will be a byte[] containing the HL7 message.  You can use the camel-hl7 data format to unmarshal just as you do when you’re using camel-mina2 or camel-netty4 with their codecs from camel-hl7.

Note that you’ll want to be on Camel 2.17.1 if you want to try camel-mllp - I found a couple of issues that were corrected in the 2.17.1 release.

> On May 17, 2016, at 10:34 AM, sekaijin <je...@aphp.fr> wrote:
> 
> Yes
> I'm using mina:tcp and HL7MLLPCodec 
> after the from in doTry
> I'm using unmarshal hapi.
> to convert the hl7 message.
> 
> with camel-mllp (I don't ave trying) yout can use onException in your
> context for handling the parse exception.
> 
> A+JYT
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452p5782714.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: .choice(), .when() not working as expected in the camel route

Posted by sekaijin <je...@aphp.fr>.
Yes
I'm using mina:tcp and HL7MLLPCodec 
after the from in doTry
I'm using unmarshal hapi.
to convert the hl7 message.

with camel-mllp (I don't ave trying) yout can use onException in your
context for handling the parse exception.

A+JYT



--
View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452p5782714.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: .choice(), .when() not working as expected in the camel route

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
OK - then I don’t think you’ll ever get that body from a real system when you’re using Camel (unless you do something to make it happen).

Two of the components that support MLLP (camel-mina2, camel-netty4) do NOT parse/convert the message by default - they just wrap the payload in the MLLP envelope.  Then you’d use a data format to convert the payload to some type of object.  The data format would probably throw an exception if it couldn’t parse the payload (camel-hl7 does)

The camel-mllp component is  a little different - it does parse the message in order to set some message properties.  It will also throw an exception if it can’t understand the message.

So I think what you’re after is an error handler in the case of an invalid message - is that correct?  And what version of Camel are you using?

> On May 17, 2016, at 7:49 AM, sekaijin <je...@aphp.fr> wrote:
> 
> I'm not sure that the body is equal to "error decoding HL7"
> 
> I'm using mina and hl7 to implément mllp protocol.
> 
> 
> A+JYT
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452p5782701.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: .choice(), .when() not working as expected in the camel route

Posted by sekaijin <je...@aphp.fr>.
I'm not sure that the body is equal to "error decoding HL7"

I'm using mina and hl7 to implément mllp protocol.


A+JYT



--
View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452p5782701.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: .choice(), .when() not working as expected in the camel route

Posted by Sashika <sa...@gmail.com>.
Did you try removing . endChoice() and just using end?





On Thu, May 12, 2016 10:13 PM, Quinn Stevenson quinn@pronoia-solutions.com wrote:
I tried this route with a test, and I’m not sure where the body is supposed to
be set to “Error decoding HL7”. Given I can’t make the route set the body to the
required value (unless that’s what I actually send), it looks like the choice is
working correctly.




Can you insert a log statement right after the from to log the body to see what
it actually is?




> On May 11, 2016, at 9:44 AM, Kriti <kr...@gmail.com> wrote:

>

> Hi,

>

> I have a camel route like this -

>

> public void configure() {

>

> -------------------------

> -------------------------

>

> from('mina2:tcp://'+ incomingHL7Listener.getIp() + ':' +

> incomingHL7Listener.getPort() +'?codec=#rcmhl7codec')

> .choice()

> .when(body().isEqualTo("Error decoding

> HL7")).to('direct:failure').endChoice()



>

> from('direct:failure')

> .process{

> --------------

> }



>

> from('direct:success')

> .process{

> --------------

> }



>

> The route is executing the when part i.e from('direct:failure') irrespective

> of whether the condition gets satisfied or not. Even if the body is not

> equal to 'Error decoding HL7', it is going to the failure part of the route.

>

> I need to get a solution for this as soon as possible. Any suggestions would

> be welcome.

>

> Thanks and Regards,

> Kriti

>

>

>

> --

> View this message in context:
http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452.html

> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: .choice(), .when() not working as expected in the camel route

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
I tried this route with a test, and I’m not sure where the body is supposed to be set to “Error decoding HL7”.  Given I can’t make the route set the body to the required value (unless that’s what I actually send), it looks like the choice is working correctly.

Can you insert a log statement right after the from to log the body to see what it actually is?

> On May 11, 2016, at 9:44 AM, Kriti <kr...@gmail.com> wrote:
> 
> Hi,
> 
> I have a camel route like this -
> 
> public void configure() {
> 
> -------------------------
> -------------------------
> 				
> from('mina2:tcp://'+ incomingHL7Listener.getIp() + ':' +
> incomingHL7Listener.getPort() +'?codec=#rcmhl7codec')
>                         .choice()
>                                .when(body().isEqualTo("Error decoding
> HL7")).to('direct:failure').endChoice()
>                                .otherwise().to('direct:success');
> 
>                                 from('direct:failure')
>                                 .process{
>                                       --------------
>                                 }
>                                 .marshal().hl7();
> 
>                                from('direct:success')
>                                .process{
>                                       --------------
>                                 }
>                                 .marshal().hl7();
> 
> The route is executing the when part i.e from('direct:failure') irrespective
> of whether the condition gets satisfied or not. Even if the body is not
> equal to 'Error decoding HL7', it is going to the failure part of the route.
> 
> I need to get a solution for this as soon as possible. Any suggestions would
> be welcome.
> 
> Thanks and Regards,
> Kriti
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: .choice(), .when() not working as expected in the camel route

Posted by souciance <so...@gmail.com>.
Why don't you try with simple("${body} ==blabla") instead of isequalto ?
Den 11 maj 2016 5:44 em skrev "Kriti [via Camel]" <
ml-node+s465427n5782452h75@n5.nabble.com>:

Hi,

I have a camel route like this -

public void configure() {

-------------------------
-------------------------

from('mina2:tcp://'+ incomingHL7Listener.getIp() + ':' +
incomingHL7Listener.getPort() +'?codec=#rcmhl7codec')
                         .choice()
                                .when(body().isEqualTo("Error decoding
HL7")).to('direct:failure').endChoice()
                                .otherwise().to('direct:success');

                                 from('direct:failure')
                                 .process{
                                       --------------
                                 }
                                 .marshal().hl7();

                                from('direct:success')
                                .process{
                                       --------------
                                 }
                                 .marshal().hl7();

The route is executing the when part i.e from('direct:failure')
irrespective of whether the condition gets satisfied or not. Even if the
body is not equal to 'Error decoding HL7', it is going to the failure part
of the route.

I need to get a solution for this as soon as possible. Any suggestions
would be welcome.

Thanks and Regards,
Kriti

------------------------------
If you reply to this email, your message will be added to the discussion
below:
http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452.html
To start a new topic under Camel - Users, email
ml-node+s465427n465428h31@n5.nabble.com
To unsubscribe from Camel - Users, click here
<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
.
NAML
<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452p5782454.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: .choice(), .when() not working as expected in the camel route

Posted by bari <ba...@yahoo.com>.
Replace:
.when(body().isEqualTo("Error decoding
HL7")).to('direct:failure').endChoice() 
                                .otherwise().to('direct:success'); 

by:
.when(body().isEqualTo("Error decoding HL7")).to('direct:failure') 
                               
.otherwise().to('direct:success').endChoice(); 



--
View this message in context: http://camel.465427.n5.nabble.com/choice-when-not-working-as-expected-in-the-camel-route-tp5782452p5782471.html
Sent from the Camel - Users mailing list archive at Nabble.com.