1
votes

I have a servlet and using a camel route to listen request from the servlet as below:

 from("servlet:///basepath?matchOnUriPrefix=true")

There is no problem with that, since matchOnUriPrefix is true, requests for the following url pattern are successfully listened by the route:

host:port/basepath/dynamicSubPath

What I want to have is that, is there any way that I can make the path variable (dynamicSubPath) to bind to an exchange property?

I know that I can get the path as below:

 String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);

But I dont want to do such string parsing. In spring mvc I can inject path variables to the controller as below:

 @RequestMapping(path = "/basepath/{dynamicSubPath}", method = RequestMethod.GET)

and then can get the dynamicSubPath variable as below:

 @PathVariable String dynamicSubPath

Is there a similar thing possible for camel servlet component?

1

1 Answers

1
votes

I don't think that camel supports this.

By default all request headers and query parameters will be set as headers on the in message. The requested path is also present (as you pointed out via the header Exchange.HTTP_PATH) but not split up into its components.

I'm afraid you have to register a custom processor that parses the string and sets the path variables as message headers or exchange properties accordingly.