Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using Path Variables in Apache Camel Rest

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);
}
like image 493
H W Avatar asked Oct 08 '15 06:10

H W


People also ask

What is URI in Apache Camel?

Camel makes extensive use of URIs to allow you to refer to Endpoints. This endpoint is created by the Kafka component. The URI contains endpoint configurations as context-path and query parameters.

What is DSL in camel?

Camel uses a Java Domain Specific Language or DSL for creating Enterprise Integration Patterns or Routes in a variety of domain-specific languages (DSL) as listed below: Java DSL - A Java based DSL using the fluent builder style.

What is bridgeEndpoint true?

camel-http's bridgeEndpoint=true If a route consumes from restlet/servlet, then later calls a different web endpoint (using the “http:” or “https:” components), you have to include the “? bridgeEndpoint=true” query param on that call's URI.


1 Answers

Turns out that this is really easy:

public Customer customerDetail(Exchange exchange){
    String id = exchange.getIn().getHeader("id").toString();
    return getCustomer(id);
}
like image 112
H W Avatar answered Sep 23 '22 04:09

H W