You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "m.jimen.blazquez" <m....@gmail.com> on 2011/12/12 16:07:45 UTC

Dynamic Routing

Hello

I would like to implement a system that receives a series of calls with a
variable number of arguments. I would like to dynamically create the route
depending on the number of arguments received.

Given the route:

from (cxfrs: / exchange ...). beanRef ("orderServiceRest", "buy ($ {body
[0]}, $ {body [1]}, $ {body [2]}), $..." .) to (direct: otherRoute)

As the number of the received arguments is variable, I would like to create
that part of the route dynamically with something like:

public class RouteHelper{
public String slip (MessageContentsList body) {

     String route = "";
     if (condition) {
            message = "beanRef (\" orderServiceRest \ ", \" buy (\ "";

            for (int i = 0; i <body.size (); i + +) {
                    route + route = &quot;$ {body [&quot; + i +
&quot;]},&quot;;
            }
            route.substring route = (0, route.lastIndexOf (','));
            route = route + &quot;\ &quot;))&quot;;
            return route;                    / / returns &quot;beanRef
(&quot; orderServiceRest  &quot;, &quot; buy ($ {body [0]}, $ {body [1]}, $
{body [2]}) \ )&quot;
     }else
            return null;
}
}

&lt;camelContext id=&quot;camel&quot;
xmlns=&quot;http://camel.apache.org/schema/spring&quot;>
	<route>
		<camel:from uri="cxfrs:/exchange..." />
		<camel:dynamicRouter>
			<method ref="routeHelper" method="slip" />
		</camel:dynamicRouter>
		<camel:to uri="vm:standardizeResponse" />
	</route>
</camelContext>

But in execution I get this exception:

WebApplicationException've Been Caught: No endpoint Could Be found for:
beanRef ("orderServiceRest", please check your classpath contains the needed
camel component jar.

Is it possible to do what I am trying to implement?

thank you very much
kindest regards

--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-Routing-tp5068570p5068570.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic Routing

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Dec 13, 2011 at 11:48 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> I can reproduce the issue and have created a ticket
> https://issues.apache.org/jira/browse/CAMEL-4773
>

Fixed today, and will be part of the Camel 2.9.0 release.


>
>
> On Tue, Dec 13, 2011 at 10:45 AM, m.jimen.blazquez
> <m....@gmail.com> wrote:
>> Hi,
>>
>> I have reduced my code to the simplest code.
>>
>> This code goes perfectly:
>>
>> <route>
>>        <camel:from uri="cxfrs:/exchange2...." />
>>        <camel:bean ref="orderServiceRest" method="buy('symbol', 'quantity',
>> 'price')" />
>> </route>
>>
>> but this one goes wrong:
>>
>> <route>
>>        <camel:from uri="cxfrs:/exchange2...." />
>>        <camel:dynamicRouter>
>>                <method ref="routeHelper" method="slip" />
>>        </camel:dynamicRouter>
>> </route>
>>
>> public class RouteHelper{
>>        int i = 0;
>>        public String slip(MessageContentsList body){
>>                if (i==0){
>>                        i  ;
>>                        return
>> "bean:orderServiceRest?method=buy('symbol','quantity','price')";
>>                }
>>                else
>>                        return null;
>> }}
>>
>> throwing the exception:
>>
>> WebApplicationException has been caught : Name must have both starting and
>> ending parenthesis, was: buy('symbol'
>>
>> I have also tested this case:
>>
>> <route>
>>        <camel:from uri="cxfrs:/exchange2...." />
>>        <camel:dynamicRouter>
>>                <method ref="routeHelper" method="slip" />
>>        </camel:dynamicRouter>
>> </route>
>>
>> public class RouteHelper{
>>        int i = 0;
>>        public String slip(MessageContentsList body){
>>                if (i==0){
>>                        i  ;
>>                        return "bean:orderServiceRest?method=buy('symbol')";
>>                }
>>                else
>>                        return null;
>> }}
>>
>> and it goes perfectly.
>>
>> I don't know what I am doing wrong, but I would be very grateful I you could
>> help me.
>>
>> Kindest regards
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Dynamic-Routing-tp5068570p5070967.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> 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/



-- 
Claus Ibsen
-----------------
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: Dynamic Routing

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

I can reproduce the issue and have created a ticket
https://issues.apache.org/jira/browse/CAMEL-4773



On Tue, Dec 13, 2011 at 10:45 AM, m.jimen.blazquez
<m....@gmail.com> wrote:
> Hi,
>
> I have reduced my code to the simplest code.
>
> This code goes perfectly:
>
> <route>
>        <camel:from uri="cxfrs:/exchange2...." />
>        <camel:bean ref="orderServiceRest" method="buy('symbol', 'quantity',
> 'price')" />
> </route>
>
> but this one goes wrong:
>
> <route>
>        <camel:from uri="cxfrs:/exchange2...." />
>        <camel:dynamicRouter>
>                <method ref="routeHelper" method="slip" />
>        </camel:dynamicRouter>
> </route>
>
> public class RouteHelper{
>        int i = 0;
>        public String slip(MessageContentsList body){
>                if (i==0){
>                        i  ;
>                        return
> "bean:orderServiceRest?method=buy('symbol','quantity','price')";
>                }
>                else
>                        return null;
> }}
>
> throwing the exception:
>
> WebApplicationException has been caught : Name must have both starting and
> ending parenthesis, was: buy('symbol'
>
> I have also tested this case:
>
> <route>
>        <camel:from uri="cxfrs:/exchange2...." />
>        <camel:dynamicRouter>
>                <method ref="routeHelper" method="slip" />
>        </camel:dynamicRouter>
> </route>
>
> public class RouteHelper{
>        int i = 0;
>        public String slip(MessageContentsList body){
>                if (i==0){
>                        i  ;
>                        return "bean:orderServiceRest?method=buy('symbol')";
>                }
>                else
>                        return null;
> }}
>
> and it goes perfectly.
>
> I don't know what I am doing wrong, but I would be very grateful I you could
> help me.
>
> Kindest regards
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Dynamic-Routing-tp5068570p5070967.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
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: Dynamic Routing

Posted by "m.jimen.blazquez" <m....@gmail.com>.
Hi,

I have reduced my code to the simplest code.

This code goes perfectly:

<route>
	<camel:from uri="cxfrs:/exchange2...." />
	<camel:bean ref="orderServiceRest" method="buy('symbol', 'quantity',
'price')" />
</route>

but this one goes wrong:

<route>
	<camel:from uri="cxfrs:/exchange2...." />
	<camel:dynamicRouter>
		<method ref="routeHelper" method="slip" />
	</camel:dynamicRouter>
</route>

public class RouteHelper{
        int i = 0;
	public String slip(MessageContentsList body){
		if (i==0){
			i  ;
                        return
"bean:orderServiceRest?method=buy('symbol','quantity','price')";
         	}
		else
			return null;
}}

throwing the exception:

WebApplicationException has been caught : Name must have both starting and
ending parenthesis, was: buy('symbol' 

I have also tested this case:

<route>
	<camel:from uri="cxfrs:/exchange2...." />
	<camel:dynamicRouter>
		<method ref="routeHelper" method="slip" />
	</camel:dynamicRouter>
</route>

public class RouteHelper{
        int i = 0;
	public String slip(MessageContentsList body){
		if (i==0){
			i  ;
                        return "bean:orderServiceRest?method=buy('symbol')";
         	}
		else
			return null;
}}

and it goes perfectly.

I don't know what I am doing wrong, but I would be very grateful I you could
help me.

Kindest regards

--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-Routing-tp5068570p5070967.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic Routing

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

You must have build the method wrong, in the for loop.
Make sure its built correctly.

I just added a test to trunk that works with 3 parameters
http://svn.apache.org/viewvc?rev=1213597&view=rev

On Mon, Dec 12, 2011 at 5:49 PM, m.jimen.blazquez
<m....@gmail.com> wrote:
> Hi,
>
> I have converted the route to an endpoint route:
>
> public String slip(MessageContentsList body){
>
>        String route = "";
>        if (condition){
>                message = "bean:orderServiceRest?method=buy(";
>
>                for (int i = 0 ; i < body.size() ; i++){
>                        route = route + "${body[" + i + "]},";
>                }
>                route = route.substring(0, route.lastIndexOf(','));
>                route = route + "\")";
>                return route;     // returns
> "bean:orderServiceRest?method=buy(${body[0]},${body[1]},${body[2]})"
>        }
>
> but I obtain this error:
>
> WebApplicationException has been caught : Name must have both starting and
> ending parenthesis, was: buy(${body[0]}
>
> I have checked several times the parenthesis and they are ok.
>
> I have simulated a call with no arguments and it worked fine, but with
> several arguments it throws the exception.
>
> I am using the 2.9 release candidate of camel.
>
> I am missing something?
>
> Kindest regards
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Dynamic-Routing-tp5068570p5068896.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
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: Dynamic Routing

Posted by "m.jimen.blazquez" <m....@gmail.com>.
Hi,

I have converted the route to an endpoint route:

public String slip(MessageContentsList body){
	
	String route = "";
        if (condition){
		message = "bean:orderServiceRest?method=buy(";
		
		for (int i = 0 ; i < body.size() ; i++){
			route = route + "${body[" + i + "]},";
		}
		route = route.substring(0, route.lastIndexOf(','));
		route = route + "\")";
		return route;     // returns
"bean:orderServiceRest?method=buy(${body[0]},${body[1]},${body[2]})"
	}

but I obtain this error:

WebApplicationException has been caught : Name must have both starting and
ending parenthesis, was: buy(${body[0]} 

I have checked several times the parenthesis and they are ok.

I have simulated a call with no arguments and it worked fine, but with
several arguments it throws the exception.

I am using the 2.9 release candidate of camel.

I am missing something?

Kindest regards



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-Routing-tp5068570p5068896.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic Routing

Posted by suman <pr...@gmail.com>.
Also if you want to use dynamic consumers/receivers in the URI,have a look at
this
http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-Routing-tp5068570p5068672.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic Routing

Posted by suman <pr...@gmail.com>.
Hello,
As far as iam aware from this url,
http://camel.apache.org/dynamic-router.html
the return value from your method should be camel endpoint URI  so that the
dynamic router can route message to that endpoint.
http://camel.apache.org/uris.html

Also have a look at FAQ.Its quite good
http://camel.apache.org/faq.html


HTH

--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-Routing-tp5068570p5068669.html
Sent from the Camel - Users mailing list archive at Nabble.com.