camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mnusry <>
Subject Routing on REST URL patterns
Date Tue, 28 Jan 2014 02:06:32 GMT
I am struggling to get the following going,

I want to route REST url patterns to different services based on the URL
Ideally I would like to, based on different REST url patterns combine
results from different services as well and 
forward the result to the calling service.

The part I am struggling is where I need to find the URL of the incoming
request (CamelHttpUri) and match it against different patterns to identify
which REST service should be invoked based on the URL and forward it to that
REST service and return the returned result. 
(Simple URLS without parameters are fine, but if parameters/query parameter
are included this doesn't work)

eg: i have modules as follows, 
Service			REST Urls
Clint Service      -  /client/1232/?resourceId=1222, /client/1 , 
/client/32342/resource, /patner/add, /client/add
Resource Service    - /resource/1, /resource/add, /resource/2342/client,
Finance Service     - /price/resource/2, /resourceprice/32323?clientId=109

so different services have different REST patterns, Currently I can handle
static REST patterns, but when parameters or query parameters get introduced
it seems I need to find a different strategy.

When the request comes to the router module based on the Request URL it has
to be routed to the relevant service,
I should be able to add more REST urls to the relevant module later as well.

I have done as follows for simple REST URLs but for
"/client/1232/?resourceId=3243" how do I match and forward to relevant
module ?
Is there a better way of doing this ?

I have RouteBuilder and a CustomProcessor which does the following,

CustomProcessor -->
public class CustomProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {

	// Note: the last uRL pattern doesnt work
        String a = "/client/,/patner/add,
        String b = System.getProperty("B_REST_URLS");
        String c = System.getProperty("C_REST_URLS");
        exchange.getIn().setHeader("ARestURN", a);
        exchange.getIn().setHeader("BRestURN", b);
        exchange.getIn().setHeader("CRestURN", c);

RouteBuilder class -->
    public void configure() throws Exception {
        String AUrl = System.getProperty("A_URL");
        String BUrl = System.getProperty("B_URL");
        String CUrl = System.getProperty("C_URL");
      		.when(simple("${in.headers.ARestURN} contains
       			.to("http4://" + AUrl +
       		.when(simple("${in.headers.BRestURN} contains
       			.to("http4://" + BUrl +
       		.when(simple("${in.headers.CRestURN} contains
       			.to("http4://" + CUrl +
       			.to("http4://" + DUrl +

Note System properties are defined so that it is easy to add more url
patterns and make things configurable a little.

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message