Repository: camel Updated Branches: refs/heads/master 09bd4db06 -> 27a77fbaa
CAMEL-7354: Added XML dsl to the rest tomcat example. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/27a77fba Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/27a77fba Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/27a77fba Branch: refs/heads/master Commit: 27a77fbaa2850212da0ab80e8d54dd1aca32ab85 Parents: 09bd4db Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jul 29 10:34:32 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jul 29 10:34:32 2014 +0200 ---------------------------------------------------------------------- .../README.txt | 8 ++- .../src/main/resources/camel-config-xml.xml | 59 ++++++++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 6 ++ .../src/main/webapp/index.html | 10 +++- 4 files changed, 79 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/27a77fba/examples/camel-example-servlet-rest-tomcat/README.txt ---------------------------------------------------------------------- diff --git a/examples/camel-example-servlet-rest-tomcat/README.txt b/examples/camel-example-servlet-rest-tomcat/README.txt index 6f77cd5..fc32e6e 100644 --- a/examples/camel-example-servlet-rest-tomcat/README.txt +++ b/examples/camel-example-servlet-rest-tomcat/README.txt @@ -3,11 +3,15 @@ Camel Servlet REST and Apache Tomcat example This example shows how to use Servlet REST to define REST endpoints in Camel routes using the Rest DSL +This example is implemented in both the Java and XML DSLs. By default the Java DSL is in use. +You can change this in the src/main/webapps/WEB-INF/web.xml file + +For Java DSL the routes are defined in Java code, in the org.apache.camel.example.rest.UserRouteBuilder class. +And for XML DSL the routes are define in XML code, in the src/main/resources/camel-config-xml.xml file. + You will need to package this example first: mvn package -Spark requires Java 8, so you will need to use Java 8. - To run the example deploy it in Apache Tomcat by copying the .war to the deploy folder of Apache Tomcat. http://git-wip-us.apache.org/repos/asf/camel/blob/27a77fba/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml ---------------------------------------------------------------------- diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml b/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml new file mode 100755 index 0000000..ccb9a15 --- /dev/null +++ b/examples/camel-example-servlet-rest-tomcat/src/main/resources/camel-config-xml.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:camel="http://camel.apache.org/schema/spring" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <!-- a bean for user services --> + <bean id="userService" class="org.apache.camel.example.rest.UserService"/> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <!-- configure rest to use the camel-servlet component, and use json binding mode --> + <!-- and tell to output json in pretty print mode --> + <restConfiguration component="servlet" bindingMode="json"> + <dataFormatProperty key="prettyPrint" value="true"/> + </restConfiguration> + + <!-- defines the rest services using the context-path /user --> + <rest uri="/user" consumes="application/json" produces="application/json"> + + <!-- this is a rest GET to view an user by the given id --> + <get uri="/view/{id}" outType="org.apache.camel.example.rest.User"> + <to uri="bean:userService?method=getUser(${header.id})"/> + </get> + + <!-- this is a rest GET to view all users --> + <get uri="/list" outList="true" outType="org.apache.camel.example.rest.User"> + <to uri="bean:userService?method=listUsers"/> + </get> + + <!-- this is a rest PUT to create/update an user --> + <put uri="/update" type="org.apache.camel.example.rest.User" outType="org.apache.camel.example.rest.User"> + <to uri="bean:userService?method=updateUser"/> + </put> + + </rest> + + </camelContext> + +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/27a77fba/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml index 4244072..1c48f59 100755 --- a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml +++ b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml @@ -25,7 +25,13 @@ <!-- location of Camel Spring xml files --> <context-param> <param-name>contextConfigLocation</param-name> + + <!-- to use Java DSL --> <param-value>classpath:camel-config.xml</param-value> + + <!-- to use XML DSL, then enable me, and disable Java DSL above + <param-value>classpath:camel-config-xml.xml</param-value> + --> </context-param> <!-- the listener that kick-starts Spring --> http://git-wip-us.apache.org/repos/asf/camel/blob/27a77fba/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html index bfad504..beccdc1 100644 --- a/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html +++ b/examples/camel-example-servlet-rest-tomcat/src/main/webapp/index.html @@ -19,10 +19,16 @@ <body> <h2>Servlet REST and Apache Tomcat example</h2> -This example shows how to use Servlet REST to define REST endpoints in Camel routes using Java DSL +This example shows how to use Servlet REST to define REST endpoints in Camel routes using the Rest DSL <br/> -The routes are defined in Java code, in the <tt>org.apache.camel.example.rest.UserRouteBuilder</tt> class. + +This example is implemented in both the Java and XML DSLs. By default the Java DSL is in use. +You can change this in the src/main/webapps/WEB-INF/web.xml file + +<br/> +For Java DSL the routes are defined in Java code, in the <tt>org.apache.camel.example.rest.UserRouteBuilder</tt> class. +And for XML DSL the routes are define in XML code, in the <tt>src/main/resources/camel-config-xml.xml</tt> file. <p/> There is a <i>user</i> REST service that supports the following operations