You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by james555 <lu...@gmx.net> on 2014/02/20 16:05:58 UTC

Split in combination with aggregation and dynamicRouter

Hello,

I would like to offer a main webservice which gets a http request with xml
payload.
After unmarshalling with JAXB I want to split (splitterBusinessLogic) the
request into 2 subservice requests with dynamic target url's.
Therefore I use a dynamicRouter (with MyDynamicRouter.class). 
Finally I have to aggregate both subservice responses
(MyAggregationStrategy) and process the aggregated Objects with
businessLogic4 to a major response of the main webservice.

Sorry I'm a newbie, I didn't get it working. Here is my approach. Is that
the right strategy, at the moment I get:

org.apache.camel.NoSuchEndpointException: No endpoint could be found for:
[here comes result of businessLogic6], please check your classpath contains
the needed Camel component jar.

I think the routing back from dynamikRouting to main route doesn't work ?

Any help would be great !

	james
		
...

.to("direct:splitterBusinessLogic")			
.split(body(ArrayList.class), new MyAggregationStrategy())
	.stopOnException()
	.parallelProcessing()
	.executorService(Executors.newFixedThreadPool(5))
	.dynamicRouter(method(MyDynamicRouter.class, "slip"))
.end()
.to("direct:businessLogic4")
...


from("direct:call_ws_a")
	.to("direct:businessLogic5")
	.setHeader(Exchange.HTTP_METHOD, constant("POST"))
	.to("http://aaa...")
	.unmarshal().custom("jaxbDataFormatInternal2")
	.to("direct:businessLogic6");

from("direct:call_ws_b")
	.to("direct:businessLogic5")
	.setHeader(Exchange.HTTP_METHOD, constant("POST"))	
	.to("http://bbb...")
	.unmarshal().custom("jaxbDataFormatInternal3")
	.to("direct:businessLogic6");	
	
----------------------------------------	
	
	
splitterBusinessLogic:


public class SplitterBusinessLogicRouteBuilder extends RouteBuilder {

	@Override
	public void configure() throws Exception {		
		from("direct:splitterBusinessLogic")
		.process(
			new Processor() {
				public void process(Exchange exchange) throws Exception {
					
					...					


					ArrayList<Map&lt;String, String>> list = new ArrayList<Map&lt;String,
String>>();

					Map<String, String> map1 = new HashMap<String, String>();					
					map1.put("A", "<SUB-REQUEST-AAA>aaa</SUB-REQUEST-AAA>");
					list.add(map1);

					Map<String, String> map2 = new HashMap<String, String>();
					map2.put("B", "<SUB-REQUEST-BBB>bbb</SUB-REQUEST-BBB>");
					list.add(map2);


					exchange.getOut().setBody(list, ArrayList.class);
				}
			}
		);		
	}		
}


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

MyAggregationStrategy:


public class MyAggregationStrategy implements AggregationStrategy {	
	
    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
	    Object newBody = newExchange.getIn().getBody();
	    ArrayList list = null;
	    
	    if(oldExchange == null) {
	    	list = new ArrayList();
	        list.add(newBody);
	        newExchange.getIn().setBody(list);
	        return newExchange;
	    }
	    else {
	    	list = oldExchange.getIn().getBody(ArrayList.class);
	        list.add(newBody);
	        return oldExchange;
	    }
    }
}

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

MyDynamikRouter:


public class MyDynamicRouter {

	public String slip(Map<String, String> body) {
	    if(body.containsKey("A")) {	    	
	        return "direct:call_ws_a";
	    }
	    else if(body.containsKey("B")) {
	        return "direct:call_ws_b";
	    }

	    return null;
	}	
}


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


businessLogic6:

public class BusinessLogic6RouteBuilder extends RouteBuilder {
		
	@Override
	public void configure() throws Exception {		
		from("direct:businessLogic6")
		.process(
			new Processor() {
				public void process(Exchange exchange) throws Exception {
							
					Object obj = exchange.getIn().getBody();
					String result = null;		
					
					...
					
					exchange.getOut().setBody(result);
				}
			}
		);		
	}		
}


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

businessLogic4:

public class BusinessLogic4RouteBuilder extends RouteBuilder {
		
	@Override
	public void configure() throws Exception {		
		from("direct:businessLogic4")
		.process(
			new Processor() {
				public void process(Exchange exchange) throws Exception {
					
					ArrayList list = exchange.getIn().getBody(ArrayList.class);
					
					...
				}
			}
		);		
	}		
}




--
View this message in context: http://camel.465427.n5.nabble.com/Split-in-combination-with-aggregation-and-dynamicRouter-tp5747671.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Split in combination with aggregation and dynamicRouter

Posted by james555 <lu...@gmx.net>.
Hello,

ok, now I've found a solution which works but only in standalone mode


from("direct:start")
	...

	.to("direct:splitterBusinessLogic")				
	.split(body(ArrayList.class))
		.stopOnException()
		.parallelProcessing()
		.executorService(Executors.newFixedThreadPool(5))
		.recipientList().method(MyDynamicDelegater.class, "delegate")									
	.end()			
	.aggregate(header("result"), new
MyAggregationStrategy()).completionSize(2).completionTimeout(15000)		
	.to("direct:businessLogic4")
	
	...
.end();		
						
			
from("direct:call_ws_a")
	.to("direct:businessLogic5")
	.setHeader(Exchange.HTTP_METHOD, constant("POST"))
	.to("http://aaa...")
	.unmarshal().custom("jaxbDataFormatInternal2")
	.to("direct:businessLogic6");


from("direct:call_ws_b")
	.to("direct:businessLogic5")
	.setHeader(Exchange.HTTP_METHOD, constant("POST"))
	.to("http://bbb...")
	.unmarshal().custom("jaxbDataFormatInternal3")
	.to("direct:businessLogic6");




Now the problem is that I need to use this route in a web application
context (Web Logic Server 11g). 
After testing this route as a servlet it seems that the calling web service
client gets returned not the aggregated result, but the Input of
direct:splitterBusinessLogic

Is it the same effect reportet in Thread
http://camel.465427.n5.nabble.com/Premature-servlet-response-td5728936.html
?

How do I have to change the route so that the aggregated response will be
returned to the web service client ?

Does anyone has an example of a servlet with a Composed Message Processor
EIP ?

	james
	


PS: Camel version in use is 2.12.1





--
View this message in context: http://camel.465427.n5.nabble.com/Split-in-combination-with-aggregation-and-dynamicRouter-tp5747671p5748424.html
Sent from the Camel - Users mailing list archive at Nabble.com.