You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Peter J Nelson <pe...@ci.stpaul.mn.us> on 2017/03/08 16:46:56 UTC

Using method inside a choice/when

I am trying to use a custom predicate inside of a choice in Spring XML, but
I'm finding my predicate is always being treated as "false" - the bean
itself does not seem to be called.

            <choice>
                <when>&lt;!-- TODO: figure out why this never is evaluated
-->
                    <method ref="openCNPredicate" method="matches"/>
                    <to uri="file:/srv/tritech/data/closedcns"/>
                </when>
                <otherwise>
                    <to uri="file:/srv/tritech/data/foqtemp"/>
                </otherwise>
            </choice>

I've added debugging to my openCNPredicate bean, but I never see it turn up
in the log (all other debug messages do).  I only added the
'method="matches"' part after I found it was not being evaluated.

Can you not use "method" inside of "when"?  I see a lot of documentation
using it inside of "<filter>", but not inside the "<when>".

Thanks for the assistance,

 - Pete



--
View this message in context: http://camel.465427.n5.nabble.com/Using-method-inside-a-choice-when-tp5795092.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using method inside a choice/when

Posted by Peter J Nelson <pe...@ci.stpaul.mn.us>.
I found the root cause of my issue.  I previously had been setting a header,
and simply forgot to set it here.  Once the header is added back in, the
predicate works as advertised.  

I obviously need a test for null in my code.



--
View this message in context: http://camel.465427.n5.nabble.com/Using-method-inside-a-choice-when-tp5795092p5795099.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using method inside a choice/when

Posted by Peter J Nelson <pe...@ci.stpaul.mn.us>.
public class OpenCNPredicate implements Predicate {

    private static Logger logger =
LoggerFactory.getLogger(OpenCNPredicate.class);

    /**
     * Checks RMS to see if the CN in the STPCaseNo header exists in RMS or
not
     *
     * @param exchange the exchange object subject to the test
     * @return true if the CN exists in RMS, false otherwise
     * @see Predicate#matches(Exchange)
     */
    @Override
    public boolean matches(Exchange exchange) {
        logger.trace("Method matches(Exchange) called.");
        Message inMsg = exchange.getIn();
        String cn = inMsg.getHeader("STPCaseNo", String.class);
        RMSDAO dao = new RMSDAO();
        boolean result = false;
        try {
            result = dao.cnIsInRMS(cn);
            logger.debug(MessageFormat.format("CN {0} {1} in RMS", cn,
(result ? "is" : "is not")));
        } catch(CADException ex) {
            logger.error("Exception thrown trying to match a CN", ex);
        }
        return result;
    }
}




--
View this message in context: http://camel.465427.n5.nabble.com/Using-method-inside-a-choice-when-tp5795092p5795094.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using method inside a choice/when

Posted by souciance <so...@gmail.com>.
Can you share your bean code?

Den 8 mars 2017 5:46 em skrev "Peter J Nelson [via Camel]" <
ml-node+s465427n5795092h15@n5.nabble.com>:

> I am trying to use a custom predicate inside of a choice in Spring XML,
> but I'm finding my predicate is always being treated as "false" - the bean
> itself does not seem to be called.
>
>             <choice>
>                 <when><!-- TODO: figure out why this never is evaluated
> -->
>                     <method ref="openCNPredicate" method="matches"/>
>                     <to uri="file:/srv/tritech/data/closedcns"/>
>                 </when>
>                 <otherwise>
>                     <to uri="file:/srv/tritech/data/foqtemp"/>
>                 </otherwise>
>             </choice>
>
> I've added debugging to my openCNPredicate bean, but I never see it turn
> up in the log (all other debug messages do).  I only added the
> 'method="matches"' part after I found it was not being evaluated.
>
> Can you not use "method" inside of "when"?  I see a lot of documentation
> using it inside of "<filter>", but not inside the "<when>".
>
> Thanks for the assistance,
>
>  - Pete
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/Using-method-inside-a-
> choice-when-tp5795092.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/Using-method-inside-a-choice-when-tp5795092p5795093.html
Sent from the Camel - Users mailing list archive at Nabble.com.