Hello,

At this moment we're replacing restlet by the servlet component.

In the spring camel configuration there are two routes defined (see below
for the URI) with overlapping URI parts. The client uses for example the
uri: http://localhost:8080/contextroot/servlet/ui/api/a/b/c/d.

The restlet component is capable of matching the above example on /ui/api
consumer. The servlet component matches the client call on the /ui consumer.

I created a extension on the HttpServletResolveConsumerStrategy for the
support on matching overlapping URI. May be this can be integrated in the
HttpServletResolveConsumerStrategy it self. See below for the changes


---- URI in camel configuration ----
servlet:///ui?matchOnUriPrefix=true&httpMethodRestrict=GET,POST
servlet:///ui/api?matchOnUriPrefix=true&httpMethodRestrict=GET,POST

---- CHANGED Code ---
public class HttpServletResolveConsumerStrategy implements
ServletResolveConsumerStrategy {

    @Override
    public HttpConsumer resolve(HttpServletRequest request, Map<String,
HttpConsumer> consumers) {
        String path = request.getPathInfo();
        if (path == null) {
            return null;
        }
        HttpConsumer answer = consumers.get(path);

        Map<String, HttpConsumer> matchedConsumers = new HashMap<String,
HttpConsumer>();
        if (answer == null) {
            for (String key : consumers.keySet()) {
                //We need to look up the consumer path here
                String consumerPath = consumers.get(key).getPath();
                HttpConsumer consumer = consumers.get(key);
                // Just make sure the we get the right consumer path first
                if (consumerPath.equals(path) ||
(consumer.getEndpoint().isMatchOnUriPrefix() &&
path.startsWith(consumerPath))) {
                    matchedConsumers.put(consumerPath, consumers.get(key));
                }
            }
        }

        int pathParts = 0;
        HttpConsumer bestMatchedConsumer = null;
        for(String consumerPath: matchedConsumers.keySet()){
            String[] consumerPathParts = consumerPath.split("/");
            if(consumerPathParts.length > pathParts){
                pathParts = consumerPathParts.length;
                bestMatchedConsumer = matchedConsumers.get(consumerPath);
            }
        }
        if(bestMatchedConsumer != null){
            answer = bestMatchedConsumer;
        }

        return answer;
    }

}






--
View this message in context: 
http://camel.465427.n5.nabble.com/HttpServletResolveConsumerStrategy-improvement-tp5763993.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to