Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 25B0610193 for ; Tue, 28 Jan 2014 02:06:59 +0000 (UTC) Received: (qmail 85054 invoked by uid 500); 28 Jan 2014 02:06:58 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 84984 invoked by uid 500); 28 Jan 2014 02:06:58 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 84976 invoked by uid 99); 28 Jan 2014 02:06:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jan 2014 02:06:57 +0000 X-ASF-Spam-Status: No, hits=2.3 required=5.0 tests=SPF_SOFTFAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: softfail (athena.apache.org: transitioning domain of mnusry@gmail.com does not designate 216.139.236.26 as permitted sender) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jan 2014 02:06:53 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1W7y4O-0006ng-Lt for users@camel.apache.org; Mon, 27 Jan 2014 18:06:32 -0800 Date: Mon, 27 Jan 2014 18:06:32 -0800 (PST) From: mnusry To: users@camel.apache.org Message-ID: <1390874792671-5746514.post@n5.nabble.com> Subject: Routing on REST URL patterns MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org I am struggling to get the following going, I want to route REST url patterns to different services based on the URL pattern, 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, /resource/23432/?clientId=2342 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, /client/add,/client/*/?resourceId=*"; 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); exchange.getOut().setHeaders(exchange.getIn().getHeaders()); exchange.getOut().setBody(exchange.getIn().getBody(String.class), String.class); } } RouteBuilder class --> @Override public void configure() throws Exception { String AUrl = System.getProperty("A_URL"); String BUrl = System.getProperty("B_URL"); String CUrl = System.getProperty("C_URL"); from("servlet:///?matchOnUriPrefix=true") .process(customProcessor) .choice() .when(simple("${in.headers.ARestURN} contains ${in.headers.CamelHttpUri}")) .to("http4://" + AUrl + "?bridgeEndpoint=true&throwExceptionOnFailure=false") .when(simple("${in.headers.BRestURN} contains ${in.headers.CamelHttpUri}")) .to("http4://" + BUrl + "?bridgeEndpoint=true&throwExceptionOnFailure=false") .when(simple("${in.headers.CRestURN} contains ${in.headers.CamelHttpUri}")) .to("http4://" + CUrl + "?bridgeEndpoint=true&throwExceptionOnFailure=false") .otherwise() .to("http4://" + DUrl + "?bridgeEndpoint=true&throwExceptionOnFailure=false"); } 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: http://camel.465427.n5.nabble.com/Routing-on-REST-URL-patterns-tp5746514.html Sent from the Camel - Users mailing list archive at Nabble.com.