Thanks Ravi for your insight,
I did the following, just like to know how I can send the request to two
modules get the result and send it back if the url pattern is in a specific
form. 
Currently I am directing traffic based on the REST url pattern, now I want
to send to two or more modules requests and process the request and return
the result if the REST url pattern is in a specific form.

My RouteBuilder is:
public class CustomRouteBuilder extends RouteBuilder {
   @Autowired
    Processor                                       customProcessor;
   
    @Override
    public void configure() throws Exception {
        
        String aUrl = System.getProperty("A_URL");
        String bUrl = System.getProperty("B_URL");
        
        from("servlet:///?matchOnUriPrefix=true") 
        .process(customProcessor) 
        .recipientList(header("restUrl"));
     }
}
My CustomProcessor is:

        public void process(Exchange exchange) throws Exception {

                String aRestServices = System.getProperty("A_REST_URLS");
                String bRestServices = System.getProperty("B_REST_URLS");

                String aUrl = System.getProperty("A_URL");
                String bUrl = System.getProperty("B_URL");
                String cUrl = System.getProperty("C_URL");

                String CamelHttpUri = (String) 
exchange.getIn().getHeader("CamelHttpUri");
                String CamelHttpQuery = (String)
exchange.getIn().getHeader("CamelHttpQuery");
                String urlReceived = CamelHttpUri;
                if (CamelHttpUri.indexOf("/servicebus/camel") > -1) {
                        urlReceived = CamelHttpUri.substring(17);
                } else {
                        if (CamelHttpUri.indexOf("/camel") > -1) {
                                urlReceived = CamelHttpUri.substring(6);
                        }
                }
                String urlToMatch = urlReceived;
                if (!StringUtils.isEmpty(CamelHttpQuery)) {
                        urlToMatch = urlToMatch + "?" + CamelHttpQuery;
                }
                // get aRestServiceEndPointURL if it matches to incoming URL
                String endpointUrl = getEndPointUrl(aRestServices, aUrl, 
urlToMatch);

                if (StringUtils.isEmpty(endpointUrl)) {
                        endpointUrl = getEndPointUrl(bServices, bUrl, 
urlToMatch);
                }
                if (StringUtils.isEmpty(endpointUrl)) {
                        endpointUrl = "http4://" + cUrl +
"?bridgeEndpoint=true&throwExceptionOnFailure=false";
                }

                exchange.getIn().setHeader("CamelHttpUri", urlReceived);
                exchange.getIn().setHeader("CamelHttpQuery", CamelHttpQuery);
                exchange.getIn().setHeader("restUrl", endpointUrl);

                exchange.getOut().setHeaders(exchange.getIn().getHeaders());
                
exchange.getOut().setBody(exchange.getIn().getBody(String.class),
String.class);
        }

        private String getEndPointUrl(String restServiceUrls, String restUrl,
String urlToMatch) {
                List<String> restServiceUrlList =
Arrays.asList(restServiceUrls.split("\\s*,\\s*"));
                for (String restUrlPattern : restServiceUrlList) {
                        Pattern pattern = Pattern.compile(restUrlPattern);
                        Matcher matcher = pattern.matcher(urlToMatch);
                        if (matcher.matches()) {
                                return "http4://" + restUrl +
"?bridgeEndpoint=true&throwExceptionOnFailure=false";
                        }
                }
                return "";
        }



--
View this message in context: 
http://camel.465427.n5.nabble.com/Routing-on-REST-URL-patterns-tp5746514p5747055.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to