5

How can i access PathVariables in the Apache Camel Rest module?

I defined a route like this (following "using base path" from the documentation):

rest("/customers/")
.get("/{id}").to("direct:customerDetail")

How can i get a hold on the {id}-Parameter in the following route?

Basically i would like to know what camel offers instead of @PathVariable (see following example)

@RequestMapping(value="/customers/{id}", method = RequestMethod.GET)
public Customer customerDetail(@PathVariable String cId) {
    return getCustomer(cId);
}

2 Answers 2

7

Turns out that this is really easy:

public Customer customerDetail(Exchange exchange){
    String id = exchange.getIn().getHeader("id").toString();
    return getCustomer(id);
}
Sign up to request clarification or add additional context in comments.

Comments

0

${header.id} works.

try using log: .log(LoggingLevel.INFO, "${header.id}");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.