[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... Option Default Description component The Camel Rest component to use for the REST transport, such as restlet, spark-rest. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if aorg.apache.camel.spi.RestConsumerFactoryis registered in the registry. If either one is found, then that is being used. scheme http The scheme to use for exposing the REST service. Usually http or https is supported hostname The hostname to use for exposing the REST service. port The port number to use for exposing the REST service. contextPath Sets a leading context-path the REST services will be using. This can be used when using components such as SERVLET where the deployed web application is deployed using a context-path. restHostNameResolver localHostName If no hostname has been explicit configured, then this resolver is used to compute the hostname the REST service will be using. The resolver supports localHostName or localIp. bindingMode off Whether binding is in use. See further above for more
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... Tip title Configuring route options In the embedded route you can configure the route settings such as routeId, autoStartup and various other options you can set on routes today. .get().route().routeId(myRestRoute).autoStartup(false).transform().constant(Hello World); Managing Rest services Each of the rest service becomes a Camel route, so in the first example we have 2 x get and 1 x post REST service, which each become a Camel route. This makes itthe same from Camel to manage and run these services - as they are just Camel routes. This means any tooling and API today that deals with Camel routes, also work with the REST services. This means you can use JMX to stop/start routes, and also get the JMX metrics about the routes, such as number of message processed, and their performance statistics. There is also a Rest Registry JMX MBean that contains a registry of all REST services which has been defined. Binding to POJOs using The Rest DSL supports automatic binding json/xml contents to/from POJOs using CamelsData Format. By default the binding mode is off, meaning there is no automatic binding happening for incoming and outgoing messages. ... Option Default Description component
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... Code Block language java protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { rest(/say/hello) .get(/hello).to(direct:hello); rest(/say/bye) .get(/bye).consumes(application/json).to(direct:bye) .post(/bye).to(mock:update); from(direct:hello) .transform().constant(Hello World); from(direct:bye) .transform().constant(Bye World); } }; } ... This defines a REST service with the following url mappings: Base Path Uri template Verb Consumes /say /hello get all /say /bye get application/json
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... See Also DSL Rest Spark-rest How do I import rests from other XML files View Online Like View Changes Stop watching space Manage Notifications This message was sent by Atlassian Confluence 5.0.3, Team Collaboration Software
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... The following Camel components supports the Rest DSL. See the bottom of this page for how to integrate a component with the Rest DSL. camel-netty-http camel-jetty camel-restlet camel-servlet camel-spark-rest Rest DSL with Java To use the Rest DSL in Java then just do as with regular Camel routes by extending theRouteBuilder and define the routes in theconfigure method. ... Any Apache Camel component can integrate with the Rest DSL if they can be used as a REST service (eg as a REST consumer in Camel lingo). To integrate with the Rest DSL, then the component should implement theorg.apache.camel.spi.RestConsumerFactory. The Rest DSL will then invoke thecreateConsumer method when it setup the Camel routes from the defined DSL. The component should then implement logic to create a Camel consumer that exposes the REST services based on the given parameters, such as path, verb, and other options. For example see the source code for camel-restlet, camel-spark-rest. See Also DSL Rest Restlet Spark-rest View Online Like View Changes Stop watching space Manage Notifications This message was sent by Atlassian Confluence 5.0.3, Team Collaboration Software
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... The Rest DSL is a facade that builds Restendpoints as consumers for Camel routes. The actual REST transport is leveraged by using Camel REST components such asRestlet,Spark-rest, and others that has native REST integration. Components supporting Rest DSL The following Camel components supports the Rest DSL. See the bottom of this page for how to integrate a component with the Rest DSL. camel-jetty camel-restlet camel-spark-rest Rest DSL with Java To use the Rest DSL in Java then just do as with regular Camel routes by extending theRouteBuilder and define the routes in theconfigure method. ... View Online Like View Changes Stop watching space Manage Notifications This message was sent by Atlassian Confluence 5.0.3, Team Collaboration Software
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... This means you can use JMX to stop/start routes, and also get the JMX metrics about the routes, such as number of message processed, and their performance statistics. Example - 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 definesa single REST service which offers a GET operation that accepts 3 different types: plain text, json, and xml. ... Binding to POJOs using The Rest DSL supports automatic binding json/xml contents to/from POJOs using CamelsData Format. By default the binding mode is off, meaning there is no automatic binding happening for incoming and outgoing messages. You may want to use binding if you develop POJOs that maps to your REST services request and response types. This allows you as a developer to work with the POJOs in Java code. The binding modes are: Binding Mode Description off Binding is turned off. This is the default option. auto Binding is enabled and Camel is relaxed and support json, xml or both if the needed data formats are included in the classpath. Notice that if for example camel-jaxb is not on the classpath, then XML binding is not enabled. json Binding to/from json is enabled, and requires a json capabile data format on the classpath. By default Camel will use json-jackson as the data format. xml Binding to/from xml is enabled, and requires camel-jaxb on the classpath. json_xml Biding to/from json and xml is enabled and requires both data formats to be on the classpath.
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... Option Default Description component The Camel Rest component to use for the REST transport, such as restlet, spark-rest. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if aorg.apache.camel.spi.RestConsumerFactoryis registered in the registry. If either one is found, then that is being used. scheme http The scheme to use for exposing the REST service. Usually http or https is supported hostname 0.0.0.0 The hostname to use for exposing the REST service. port The port number to use for exposing the REST service. bindingMode off Whether binding is in use. See further above for more details. jsonDataFormat Name of specific json data format to use. By default json-jackson will be used. Notice: Currently Jackson is what we recommend and are using for testing. xmlDataFormat Name of specific XML data format to use. By default jaxb will be used. Notice: Currently only jaxb is supported.
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... Option Default Description component The Camel Rest component to use for the REST transport, such as restlet, spark-rest. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if aorg.apache.camel.spi.RestConsumerFactoryis registered in the registry. If either one is found, then that is being used. scheme http The scheme to use for exposing the REST service. Usually http or https is supported hostname 0.0.0.0 The hostname to use for exposing the REST service. port The port number to use for exposing the REST service. bindingMode off Whether binding is in use. See further above for more details. jsonDataFormat Name of specific json data format to use. By default json-jackson will be used. Notice: Currently Jackson is what we recommend and are using for testing. xmlDataFormat Name of specific XML data format to use. By default jaxb will be used. Notice: Currently only jaxb is supported.
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... To define the REST services we use therest method, where we can setup the path, which is /hello/{me}. Where me refers the a wildcard that is mapped to Camel message header with the same key. Notice how we can refer to this header in the embedded Camel routes where we do message transformation.And because we used embedded routes, we need to define this using .route(), and to denote the end of the route, we use .endRest() to go back to the Rest DSL, where we can then add the 2nd, and 3rd get service. ... See Also DSL Rest Restlet Spark-rest View Online Like View Changes Stop watching space Manage Notifications This message was sent by Atlassian Confluence 5.0.3, Team Collaboration Software
[CONF] Apache Camel Rest DSL
Claus Ibsen created a page: Rest DSL Rest DSL Available as of Camel 2.14 Apache Camel offers a REST styled DSL which can be used with Java or XML. The intention is to allow end users to define REST services using a REST style with verbs such as get, post, delete etc. How it works The Rest DSL is a facade that builds Restendpoints as consumers for Camel routes. The actual REST transport is leveraged by using Camel REST components such asRestlet,Spark-rest, and others that has native REST integration. Rest DSL with Java To use the Rest DSL in Java then just do as with regular Camel routes by extending theRouteBuilder and define the routes in theconfigure method. A simple REST service can be define as follows, where we use rest() to define the services as shown below: protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { rest(/say/hello) .get().to(direct:hello); rest(/say/bye) .get().consumes(application/json).to(direct:bye) .post().to(mock:update); from(direct:hello) .transform().constant(Hello World); from(direct:bye) .transform().constant(Bye World); } }; } This defines a REST service with the following url mappings: Uri template Verb Consumes /say/hello get all /say/bye get application/json /say/bye post all Notice that in the REST service we route directly to a Camel endpoint using the to(). This is
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... 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. Rest DSL with XML The REST DSL supports the XML DSL also using either Spring or Blueprint. The example above can be define in XML as shown below: Code Block camelContext xmlns=http://camel.apache.org/schema/spring rest uri=/say/hello get to uri=direct:hello/ /get /rest rest uri=/say/bye get consumes=application/json to uri=direct:bye/ /get post to uri=mock:update/ /post /rest route from uri=direct:hello/ transform constantHello World/constant /transform /route route from uri=direct:bye/ transform constantBye World/constant /transform /route /camelContext Using path prefixes The REST DSL allows to define path prefixes to make the DSL a bit more DRY. For example to define a customer path, we can set the prefix in rest(/customer) and then provide the past postfix in the verbs, as shown below: Code Block rest(/customers/) .get(/{id}).to(direct:customerDetail) .get(/{id}/orders).to(direct:customerOrders) .post(/neworder).to(direct:customerNewOrder); And using XML DSL it becomes: Code Block rest
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... Tip The REST DSL will take care of duplicate path separators when using path prefixes. In the example above the rest path prefix ends with a slash ( / ) and the verb starts with a slash ( / ). But Apache Camel will take care of this and remove the duplicated slash. camel-example-spark-rest-tomcat ... Option Default Description component The Camel Rest component to use for the REST transport, such as restlet, spark-rest. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. If either one is found, then that is being used. scheme http The scheme to use for exposing the REST service. Usually http or https is supported hostname 0.0.0.0 The hostname to use for exposing the REST service. port The port number to use for exposing the REST service. property
[CONF] Apache Camel Rest DSL
Claus Ibsen edited the page: Rest DSL ... Option Default Description component The Camel Rest component to use for the REST transport, such as restlet, spark-rest. If no component has been explicit configured, then Camel will lookup if there is a Camel component that integrates with the Rest DSL, or if aorg.apache.camel.spi.RestConsumerFactoryis registered in the registry. If either one is found, then that is being used. scheme http The scheme to use for exposing the REST service. Usually http or https is supported hostname 0.0.0.0 The hostname to use for exposing the REST service. port The port number to use for exposing the REST service. propertycomponentProperty Allows to configure as many additional properties. This is used to configure component specific options such as forRestlet/Spark-Restetc. endpointProperty Allows to configure as many additional properties. This is used to configure endpoint specific options for Restlet/Spark-Restetc. consumerProperty Allows to configure as many additional properties. This is used to configure consumer specific options for Restlet/Spark-Restetc.