You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by balkishore <ba...@gmail.com> on 2012/09/24 11:59:15 UTC

Using a custom based load balancer.

Hi,
I want to perform a sticky based load balancing based on the SOAP session ID
in the response.
As camel's loadbalance.sticky() just check for the expression in the
request, I have to implement my own custom load balancer.

I gave a look at camel in action book and the information provided in the
section 8.6.4(Custom load balancer section) are two less. 

With the help of the developer(Claus) in the fuse source forum, I decided to
plug in my own custom load balancer.

The Problems I am facing now are:

1. There are two methods in custom based load balancer: Process and other is
choosing a processor: I know I have to plugin my own logic in the choosing
processor method. But how would my logic look like? I want to extract the
session id from the response(Just the response), and match this session id
with the second request I get from the client(If they are same i would
forward the request to same processor).

2.In order to get the session from the response I came up with something
like this:

String expression = (String) exchange.getOut().getHeader("ServiceGroupId",
env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
iceGroupId/text()), 10)", String.class));

If i am not wrong it would pick the session id from the response. (Now where
should I add this code?) In the process method or choose processor method?

3. If I add this code in my choose processor method, how would my process
method look like?

I would really appreciate if anyone could give me an outline "On how to join
the dots in camel".



--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

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

Can you try enabling stream caching
http://camel.apache.org/stream-caching.html



On Wed, Sep 26, 2012 at 11:37 AM, balkishore
<ba...@gmail.com> wrote:
> Hi claus,
> Thanks for replying.
>
> But why do i always get an error invalid xpath expression, when the same
> xpath expression works fine with java API.
>
> I also tried the java API version and again i got an error saying the body
> is empty.
> And in real the body is empty, because the content are present only in the
> soap header.
>
> I tried something like:
>
> if (exchange.hasOut())
> {
> Document payload = exchange.getOut().getBody(Document.class);
> XPath xpath = XPathFactory.newInstance().newXPath();
> XPathExpression expression =
> xpath.compile("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
> 10)");
>
> String id1 = expression.evaluate(payload);
> System.out.println("id 1 is:" + id1);
> map.put(id1 , getProcessors().get(0));
>                 }
>
> But i get an error body is empty and [Fatal Error] :1:1: Premature end of
> file
>
> I don't understand what wrong i am doing here.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5720013.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

Re: Using a custom based load balancer.

Posted by balkishore <ba...@gmail.com>.
Hi claus,
Thanks for replying.

But why do i always get an error invalid xpath expression, when the same
xpath expression works fine with java API. 

I also tried the java API version and again i got an error saying the body
is empty.
And in real the body is empty, because the content are present only in the
soap header.

I tried something like:

if (exchange.hasOut())
{
Document payload = exchange.getOut().getBody(Document.class); 
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expression =
xpath.compile("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
10)");

String id1 = expression.evaluate(payload);
System.out.println("id 1 is:" + id1);
map.put(id1 , getProcessors().get(0));
		}

But i get an error body is empty and [Fatal Error] :1:1: Premature end of
file

I don't understand what wrong i am doing here.



--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5720013.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Sep 26, 2012 at 8:42 AM, balkishore <ba...@gmail.com> wrote:
> Hi claus,
> If i use the Xpath java API, something like this:
>
> XPathExpression expression =
> xpath.compile("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
> 10)");
>
> String id = expression.evaluate(exchange.getContext(), body);
>
> I get an error saying The method evaluate(Object, QName) in the type
> XPathExpression is not applicable for the arguments (CamelContext, String)
>

Google and read some tutorials how to use the xpath api from the JDK.
You should not pass in CamelContext to the evaluate method.

> And if use the Xpathbuilder, it gives me an error saying invalid xpath
> expression. But when i test the same xpath expression using Xapth java API,
> i get the serviceGroup id.
>

If <ServiceGroup> is unique in the XML, then you can just do a simple
String search and grab the text between the start and end tags
Though its a bit of a hack.


> Any help would be really useful.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719999.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

Re: Using a custom based load balancer.

Posted by balkishore <ba...@gmail.com>.
Hi claus,
If i use the Xpath java API, something like this:

XPathExpression expression =
xpath.compile("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
10)");

String id = expression.evaluate(exchange.getContext(), body);

I get an error saying The method evaluate(Object, QName) in the type
XPathExpression is not applicable for the arguments (CamelContext, String)

And if use the Xpathbuilder, it gives me an error saying invalid xpath
expression. But when i test the same xpath expression using Xapth java API,
i get the serviceGroup id.

Any help would be really useful.



--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719999.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Sep 25, 2012 at 3:18 PM, balkishore <ba...@gmail.com> wrote:
> Hi claus,
> How will I add an processor onto the hash map?
> Something like this yields me error
> map.put(id , getProcessors());
>

No put the target processor (eg the result of chooseProcessor)

 map.put(id , target);

> And also My code is as follow:
>
> public void process(Exchange exchange) throws Exception {
>                 Processor target = chooseProcessor(exchange);
>
>                 if (exchange.hasOut())
>                 {
>                         String body = exchange.getOut().getBody(String.class);
>                         XPathBuilder sessionID =
> XPathBuilder.xpath("/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()",
> String.class);
>                         String id = sessionID.evaluate(exchange.getContext(), body);
>                         System.out.println("id is" +id);
>                         map.put(id , getProcessors());
>
>                 }
>                 else{
>                         String body = exchange.getIn().getBody(String.class);
>                         XPathBuilder sessionID =
> XPathBuilder.xpath("/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()",
> String.class);
>                         String id = sessionID.evaluate(exchange.getContext(), body);
>                         System.out.println("id is" +id);
>                         map.put(id , getProcessors());
>                 }
>
>
>                 target.process(exchange);
>         }
>
> Is the logic correct? Because I am still not able to figure out things and
> joining the dots. I would really appreciate if you could tell me if the
> logic is correct.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719943.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

Re: Using a custom based load balancer.

Posted by balkishore <ba...@gmail.com>.
Hi claus,
How will I add an processor onto the hash map?
Something like this yields me error
map.put(id , getProcessors());

And also My code is as follow:

public void process(Exchange exchange) throws Exception {
		Processor target = chooseProcessor(exchange);
		
		if (exchange.hasOut())
		{
			String body = exchange.getOut().getBody(String.class); 
			XPathBuilder sessionID =
XPathBuilder.xpath("/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()",
String.class);
			String id = sessionID.evaluate(exchange.getContext(), body);
			System.out.println("id is" +id);
			map.put(id , getProcessors());
				
		}
		else{
			String body = exchange.getIn().getBody(String.class);
			XPathBuilder sessionID =
XPathBuilder.xpath("/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()",
String.class);
			String id = sessionID.evaluate(exchange.getContext(), body);
			System.out.println("id is" +id);
			map.put(id , getProcessors());
		}
		
		
		target.process(exchange);
	}

Is the logic correct? Because I am still not able to figure out things and
joining the dots. I would really appreciate if you could tell me if the
logic is correct. 



--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719943.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Sep 25, 2012 at 11:37 AM, balkishore
<ba...@gmail.com> wrote:
> Hi claus,
>
> How would i perform xpath evaluation in
>  exchange.getOut().getHeader("ServiceGroupID", String.class);
>
> I did not find any example where xpath is evaluated in the getheader()
> function.
>


You would need to do it on the body as the SOAP message includes
headers+body in the same payload.

You can create a shared builder you can use for the evaluation, as the
xpath expression would be the same
private XPathBuilder xpath = XPathBuilder.xpath("YourXPathExpressionHere");

And then when you have the response you can do.

And make sure exchange.hasOut() return true on the response, to grab
the out message.
eg see the FAQ I send a link to before.



String body = exchange.getOut().getBody(String.class);
String id = xpath.evaluate(exchange.getContext(), body);


Also note that XPath is an API there is in the JDK. So you can google
for xpath examples and use plain API from the JDK if you want.



>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719930.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

Re: Using a custom based load balancer.

Posted by balkishore <ba...@gmail.com>.
Hi claus,

How would i perform xpath evaluation in
 exchange.getOut().getHeader("ServiceGroupID", String.class);

I did not find any example where xpath is evaluated in the getheader()
function.



--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719930.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

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

Check this FAQ
http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html

In the response it may be stored in the OUT message, so you need to
check for that

if (exchange.hasOut()) {
   // get the header from the out message
} else {
  // get the header from the in message
}



On Tue, Sep 25, 2012 at 9:51 AM, balkishore <ba...@gmail.com> wrote:
> Hi claus,
>
> How can I evaluate xpath in both process method and getProcessor method?
>
> I did something like:
>
> Processor target = chooseProcessor(exchange);
>
> XPathBuilder sessionID =
> XPathBuilder.xpath("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
> 10)", String.class);
>
> String session = sessionID.evaluate(exchange, String.class);
>
> System.out.println("The session id is:" +session);
>
> In the process and tried to print out the String session, and it was null.
>
>
> And in the getprocessor something like this:
>
>
> expression = exchange.getIn().getHeader("ServiceGroupID",
> env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
> iceGroupId/text()), 10)", String.class));
>
> System.out.println("The expression is:" +expression);
>
> And the expression term i got is
> xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
> iceGroupId/text()), 10)
>
> And it is not performing the xpath evaluation.
>
> And I am not able to initialize the term expression as string because
> getHeader() function does not accept String as input argument.
>
> I am still struck here.
>
> Please, i would appreciate any help.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719922.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

Re: Using a custom based load balancer.

Posted by balkishore <ba...@gmail.com>.
Hi claus,

How can I evaluate xpath in both process method and getProcessor method?

I did something like:

Processor target = chooseProcessor(exchange);
		
XPathBuilder sessionID =
XPathBuilder.xpath("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
10)", String.class);

String session = sessionID.evaluate(exchange, String.class);
		
System.out.println("The session id is:" +session);

In the process and tried to print out the String session, and it was null.


And in the getprocessor something like this:


expression = exchange.getIn().getHeader("ServiceGroupID",
env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
iceGroupId/text()), 10)", String.class));
		
System.out.println("The expression is:" +expression);

And the expression term i got is
xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
iceGroupId/text()), 10)

And it is not performing the xpath evaluation.

And I am not able to initialize the term expression as string because
getHeader() function does not accept String as input argument.

I am still struck here.

Please, i would appreciate any help. 




--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719922.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

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

In your hashmap, the session id should be the key. And the chosen
processor should be the value.

eg the type should be
Map<String, Processor> map = new ...




On Mon, Sep 24, 2012 at 4:40 PM, balkishore <ba...@gmail.com> wrote:
> Hi claus,
>
> Thanks a lot for replying.
>
> I implemented the idea directed by you(I really appreciate that )
> But due to some reason my requests are not being forwarded, camel is
> continuously retrying.
>
> Here is my code for custom load balancer:
>
> public class MyCustomLoadBalancer extends SimpleLoadBalancerSupport
>
> {
> private final HashMap hm = new HashMap();
>
> public void process(Exchange exchange) throws Exception {
> Processor target = chooseProcessor(exchange);
> XPathBuilder sessionID =
> XPathBuilder.xpath("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
> 10)", String.class);
> String session = sessionID.evaluate(exchange, String.class);
>
> hm.put(getProcessors(),session);
> target.process(exchange);
> }
>
> protected Processor chooseProcessor (Exchange exchange) throws Exception
> {
>         Namespaces env = new Namespaces("soapenv",
> "http://schemas.xmlsoap.org/soap/envelope/");
>         env.add("wsa", "http://www.w3.org/2005/08/addressing");
>         env.add("axis2", "http://ws.apache.org/namespaces/axis2");
>
>         Object expression = exchange.getIn().getHeader("test",
> env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
> iceGroupId/text()), 10)", String.class));
>
>         if (expression.equals(hm.get(getProcessors())))
>         {
>                 return getProcessors().get(0);
>                 } else {
>                 return getProcessors().get(1);
>                 }
> }
> }
>
> And my main is something like this :
>
> from(uri).loadBalance(new MyCustomLoadBalancer()).to(BE1,BE2);
>
> where URI, BE1 and BE2 are the URLs.
>
> Am I doing something wrong in my custom load balancer method?
> I would be glad if you could help me or point out the mistake, I have done.
> I have been struggling on this project for a while now.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719861.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

Re: Using a custom based load balancer.

Posted by balkishore <ba...@gmail.com>.
Hi claus,

Thanks a lot for replying.

I implemented the idea directed by you(I really appreciate that )
But due to some reason my requests are not being forwarded, camel is
continuously retrying.

Here is my code for custom load balancer:

public class MyCustomLoadBalancer extends SimpleLoadBalancerSupport 

{
private final HashMap hm = new HashMap(); 
	
public void process(Exchange exchange) throws Exception {
Processor target = chooseProcessor(exchange);
XPathBuilder sessionID =
XPathBuilder.xpath("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
10)", String.class);
String session = sessionID.evaluate(exchange, String.class);

hm.put(getProcessors(),session);
target.process(exchange);
}

protected Processor chooseProcessor (Exchange exchange) throws Exception   
{
	Namespaces env = new Namespaces("soapenv",
"http://schemas.xmlsoap.org/soap/envelope/");
	env.add("wsa", "http://www.w3.org/2005/08/addressing");
	env.add("axis2", "http://ws.apache.org/namespaces/axis2");

	Object expression = exchange.getIn().getHeader("test",
env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
iceGroupId/text()), 10)", String.class));
	
	if (expression.equals(hm.get(getProcessors())))
	{
		return getProcessors().get(0);
		} else {
		return getProcessors().get(1);
		}
}
}

And my main is something like this :

from(uri).loadBalance(new MyCustomLoadBalancer()).to(BE1,BE2);

where URI, BE1 and BE2 are the URLs.

Am I doing something wrong in my custom load balancer method?
I would be glad if you could help me or point out the mistake, I have done.
I have been struggling on this project for a while now.



--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719861.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

Posted by Claus Ibsen <cl...@gmail.com>.
Your load balancer should be stateful, so create a map as a variable
at the class level.
Then the map can be shared between the methods.

public class ... {
 // stateful map to keep track of session id -> processors
private final Map map = new HashMap();

 // methods here
}

On Mon, Sep 24, 2012 at 3:19 PM, balkishore <ba...@gmail.com> wrote:
> Hi claus,
> I tried implementing your logic and it is as follow:
>
> public class MyCustomLoadBalancer extends SimpleLoadBalancerSupport
>
> {
>
> public void process(Exchange exchange) throws Exception {
> Processor target = chooseProcessor(exchange);
> XPathBuilder sessionID =
> XPathBuilder.xpath("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
> 10)", String.class);
> String session = sessionID.evaluate(exchange, String.class);
> HashMap hm = new HashMap();
> hm.put(getProcessors(),session);
> target.process(exchange);
> }
>
> protected Processor chooseProcessor (Exchange exchange) throws Exception
> {
>         Namespaces env = new Namespaces("soapenv",
> "http://schemas.xmlsoap.org/soap/envelope/");
>         env.add("wsa", "http://www.w3.org/2005/08/addressing");
>         env.add("axis2", "http://ws.apache.org/namespaces/axis2");
>
>         Object expression = exchange.getIn().getHeader("test",
> env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
> iceGroupId/text()), 10)", String.class));
>
>         if (expression.equals()
>
> }
> }
>
> Now the problem is how can I call the hashmap object in my choose procesor
> method? I cannot extend my choose processor method.
>
> I am struck in the if part of the choose processor.
>
> Could you please assist me in this?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719857.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

Re: Using a custom based load balancer.

Posted by balkishore <ba...@gmail.com>.
Hi claus,
I tried implementing your logic and it is as follow:

public class MyCustomLoadBalancer extends SimpleLoadBalancerSupport 

{
	
public void process(Exchange exchange) throws Exception {
Processor target = chooseProcessor(exchange);
XPathBuilder sessionID =
XPathBuilder.xpath("substring(string(/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='ReplyTo']/*[local-name()='ReferenceParameters']/*[local-name()='ServiceGroupId']/text()),
10)", String.class);
String session = sessionID.evaluate(exchange, String.class);
HashMap hm = new HashMap(); 
hm.put(getProcessors(),session);
target.process(exchange);
}

protected Processor chooseProcessor (Exchange exchange) throws Exception   
{
	Namespaces env = new Namespaces("soapenv",
"http://schemas.xmlsoap.org/soap/envelope/");
	env.add("wsa", "http://www.w3.org/2005/08/addressing");
	env.add("axis2", "http://ws.apache.org/namespaces/axis2");

	Object expression = exchange.getIn().getHeader("test",
env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
iceGroupId/text()), 10)", String.class));
	
	if (expression.equals() 
	
}
}

Now the problem is how can I call the hashmap object in my choose procesor
method? I cannot extend my choose processor method.

I am struck in the if part of the choose processor.

Could you please assist me in this?



--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719857.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 24, 2012 at 1:11 PM, balkishore <ba...@gmail.com> wrote:
> Hi claus,
> Thanks a ton for replying.
>
> 1) try to get the session id from the soap header (would not be there
> on the initial call) : How should I tell camel to skip the initial call and
> do not search for session id in the first request?
>

You cannot. You would always need to try to get the session id. If its
null then its initial call.
If its != null then its 2nd+ call.



>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719848.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

Re: Using a custom based load balancer.

Posted by balkishore <ba...@gmail.com>.
Hi claus,
Thanks a ton for replying.

1) try to get the session id from the soap header (would not be there
on the initial call) : How should I tell camel to skip the initial call and
do not search for session id in the first request?



--
View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841p5719848.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using a custom based load balancer.

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Sep 24, 2012 at 11:59 AM, balkishore
<ba...@gmail.com> wrote:
> Hi,
> I want to perform a sticky based load balancing based on the SOAP session ID
> in the response.
> As camel's loadbalance.sticky() just check for the expression in the
> request, I have to implement my own custom load balancer.
>
> I gave a look at camel in action book and the information provided in the
> section 8.6.4(Custom load balancer section) are two less.
>
> With the help of the developer(Claus) in the fuse source forum, I decided to
> plug in my own custom load balancer.
>
> The Problems I am facing now are:
>
> 1. There are two methods in custom based load balancer: Process and other is
> choosing a processor: I know I have to plugin my own logic in the choosing
> processor method. But how would my logic look like? I want to extract the
> session id from the response(Just the response), and match this session id
> with the second request I get from the client(If they are same i would
> forward the request to same processor).
>
> 2.In order to get the session from the response I came up with something
> like this:
>
> String expression = (String) exchange.getOut().getHeader("ServiceGroupId",
> env.xpath("substring(string(/soapenv:Envelope/soapenv:Header/wsa:ReplyTo/wsa:ReferenceParameters/axis2:Serv‌
> iceGroupId/text()), 10)", String.class));
>
> If i am not wrong it would pick the session id from the response. (Now where
> should I add this code?) In the process method or choose processor method?
>

Your custom load balancer would need to keep state, so you can map the
initial request with the session id you get from the response
afterwards. So eg you need to store the session id in a map, so you
can pick the same processor the next time.

So pseudo logic would be

In the choose process method

1) try to get the session id from the soap header (would not be there
on the initial call)
2) if you got a session id, lookup in your map to find the processor to choose
3) if there is no session id (= initial call) then pick for example a
random processor, as you need to pick one

In the process method
4) after call the process method on the chosen processor, do the xpath
to get the session id (the code you have above)
5) store the session id -> processor (to remember the chosen processor)

Now you would need to use a timeout based map etc to have the map
cleanup itself when the client goes away. Camel has a timeout based
map you can use. Otherwise your map will keep a reference to the old
sessions forever.






> 3. If I add this code in my choose processor method, how would my process
> method look like?
>
> I would really appreciate if anyone could give me an outline "On how to join
> the dots in camel".
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-a-custom-based-load-balancer-tp5719841.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