...
Notice that in the REST service we route directly to a Camel endpoint using the to(). This is because the Rest DSL has a short-hand for routing directly to an endpoint using to(). An alternative is to embed a Camel route directly using route() - there is such an example further below.
camel-example-spark-rest-tomcat
We provide an example that uses the REST DSL with the Spark Rest component that can be deployed in web containers such as Apache Tomcat. This example defines a The example below defines a single REST service which offers a GET operation that accepts 3 different types: plain text, json, and xml.
Code Block |
---|
public class MySparkRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { // configure we want to use spark-rest as the component for the rest DSL restConfiguration().component("spark-rest"); // use the rest DSL to define rest services, and use embedded routes rest("/hello/{me}") .get().consumes("text/plain") .route() .to("log:input") .transform().simple("Hello ${header.me}").endRest() .get().consumes("application/json") .route() .to("log:input") .transform().simple("{ \"message\": \"Hello ${header.me}\" }").endRest() .get().consumes("text/xml") .route() .to("log:input") .transform().simple("<message>Hello ${header.me}</message>"); } } |
...