3

I am trying to intercept an endpoint where the value of the URI matches some information in the exchange header.

Let say I have a field in the header called DatabaseName. I want to enforce that a specific route is only writing to the database specified in the header.

Can I do something like this?

interceptSendToEndpoint("mock:${in.header.DatabaseName}")

I tried that but it does not seem to work. What are my options?

I was also thinking of doing something like:

interceptSendToEndpoint("mock:*").when(...)?

But in this case, I am not sure if I can reference the URI of the intercepted node in the when expression.

Thanks

Alpesh Gediya
  • 3,706
  • 1
  • 25
  • 38
Klaus
  • 2,328
  • 5
  • 41
  • 62

2 Answers2

5

You can intercept using a wildcard and combine that with when to do what you want, see details at: http://camel.apache.org/intercept

The is a header on the Message with the key Exchange.INTERCEPTED_ENDPOINT (CamelInterceptedEndpoint) that has the endpoint uri that was intercepted. You can use that in the when to match the predicate. Something a like:

interceptSendToEndpoint("mock:*")
  .when(simple("${header.CamelInterceptedEndpoint} == ${in.header.DatabaseName}"))
  ...
Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • Thanks. Here is what I tried following your input. `interceptSendToEndpoint("mock://del*").when(simple("${header.CamelInterceptedEnd‌​point} == ${in.header.DatabaseName}")).skipSendToOriginalEndpoint().to("mock:detour").tran‌​sform(constant("Route interrupted Bye World"));` Then I have a script looking like this: `from("direct:start").setHeader("DatabaseName",constant("mock://delta")).to("mock:detournement").transform(constant("Route not interrupted"))", headers)`. However, what ever I do, I keep hitting "Route not interrupted". Any clue? – Klaus Sep 24 '13 at 14:44
  • Found the issue. Had to use stop() to terminate the intercepted route. – Klaus Sep 25 '13 at 12:37
0

Use the recipientList instruction for this: http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html

Alexander Durnev
  • 341
  • 2
  • 13