camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9345 , Migrate example to rest-dsl
Date Fri, 18 Dec 2015 15:14:30 GMT
Repository: camel
Updated Branches:
  refs/heads/master 200c1fb25 -> 1950e7785


CAMEL-9345 , Migrate example to rest-dsl

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1950e778
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1950e778
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1950e778

Branch: refs/heads/master
Commit: 1950e7785b9a5744d6fd7bebbfaf7255f8ee656c
Parents: 200c1fb
Author: gautric <gautric@redhat.com>
Authored: Fri Dec 18 15:57:47 2015 +0100
Committer: gautric <gautric@redhat.com>
Committed: Fri Dec 18 15:59:40 2015 +0100

----------------------------------------------------------------------
 examples/camel-example-restlet-jdbc/README.md   | 43 ++++++----
 .../example/restlet/jdbc/MyRouteConfig.java     | 49 +++++++-----
 .../src/main/resources/camel-context.xml        |  2 +-
 .../src/main/resources/java-dsl.xml             | 35 ---------
 .../src/main/resources/java-rest-dsl.xml        | 35 +++++++++
 .../src/main/resources/xml-dsl.xml              | 83 --------------------
 6 files changed, 92 insertions(+), 155 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1950e778/examples/camel-example-restlet-jdbc/README.md
----------------------------------------------------------------------
diff --git a/examples/camel-example-restlet-jdbc/README.md b/examples/camel-example-restlet-jdbc/README.md
index 57320f0..ddaf6e8 100644
--- a/examples/camel-example-restlet-jdbc/README.md
+++ b/examples/camel-example-restlet-jdbc/README.md
@@ -1,7 +1,12 @@
 # Camel Restlet and JDBC Example
 
 ### Introduction
-An example which shows how to expose CRUD operations with REST interface and JDBC implementation
+An example which shows how to expose CRUD operations with REST DSL interface and JDBC implementation
+
+Two implementations are available
+
+* XML Rest DSL (default)
+* Java Rest DSL
 
 
 ### Build
@@ -12,15 +17,10 @@ You will need to compile this example first:
 	
 ### Run
 
-To run the example type
-Run the application using XML-DSL:
-
-	mvn jetty:run
-
-### Run Java-DS
-To run with Java-DSL use: 
+### Run Java-REST-DSL
+To run with Java-REST-DSL use: 
 	
-	mvn jetty:run -Dimpl=java-dsl
+	mvn jetty:run -Dimpl=java-rest-dsl
 
 ### Run XML-REST-DSL
 To run with XML-REST-DSL use: 
@@ -30,23 +30,36 @@ To run with XML-REST-DSL use:
 ### Check
 To create an person, make a http POST request with firstName and lastName parameters:
 
-	curl -d "firstName=test&lastName=person" http://localhost:8080/rs/persons/
+	curl -X POST -d "firstName=test&lastName=person" http://localhost:8080/rs/persons
+	
+*Result :*
+	
+	[{ID=1, FIRSTNAME=test, LASTNAME=person}]
 
 To update an existing person, make a http PUT request with firstName and lastName parameters:
 
-	curl -X PUT -d "firstName=updated&lastName=person" http://localhost:8080/rs/persons/2
+	curl -X PUT -d "firstName=updated&lastName=person" http://localhost:8080/rs/persons/1
 
 To retrieve an existing person, make a http GET request with the personId as part of the
url:
 
-	curl -X GET  http://localhost:8080/rs/persons/1
+	curl http://localhost:8080/rs/persons/1
 
-To delete an existing person, make a http DELETE request with the personId as part of the
url:
+*Result :*		
+	
+	[{ID=1, FIRSTNAME=updated, LASTNAME=person}]
 
-	curl -X DELETE  http://localhost:8080/rs/persons/1
 
 To retrieve all the existing persons, make a http GET request to persons url:
 
-	curl -X GET  http://localhost:8080/rs/persons
+	curl http://localhost:8080/rs/persons
+	
+*Result :*
+	
+	[{ID=1, FIRSTNAME=updated, LASTNAME=person}]
+	
+To delete an existing person, make a http DELETE request with the personId as part of the
url:
+
+	curl -X DELETE  http://localhost:8080/rs/persons/1	
 
 ### Forum, Help, etc 
 

http://git-wip-us.apache.org/repos/asf/camel/blob/1950e778/examples/camel-example-restlet-jdbc/src/main/java/org/apache/camel/example/restlet/jdbc/MyRouteConfig.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-restlet-jdbc/src/main/java/org/apache/camel/example/restlet/jdbc/MyRouteConfig.java
b/examples/camel-example-restlet-jdbc/src/main/java/org/apache/camel/example/restlet/jdbc/MyRouteConfig.java
index 689e909..b8262dc 100644
--- a/examples/camel-example-restlet-jdbc/src/main/java/org/apache/camel/example/restlet/jdbc/MyRouteConfig.java
+++ b/examples/camel-example-restlet-jdbc/src/main/java/org/apache/camel/example/restlet/jdbc/MyRouteConfig.java
@@ -23,28 +23,35 @@ public class MyRouteConfig extends RouteBuilder {
 
     @Override
     public void configure() {
-        from("restlet:/persons?restletMethod=POST")
-                .setBody(simple("insert into person(firstName, lastName) values('${header.firstName}','${header.lastName}')"))
-                .to("jdbc:dataSource")
-                .setBody(simple("select * from person where id in (select max(id) from person)"))
-                .to("jdbc:dataSource");
 
-        from("restlet:/persons/{personId}?restletMethods=GET,PUT,DELETE")
-                .choice()
-                    .when(simple("${header.CamelHttpMethod} == 'GET'"))
-                        .setBody(simple("select * from person where id = ${header.personId}"))
-                    .when(simple("${header.CamelHttpMethod} == 'PUT'"))
-                        .setBody(simple("update person set firstName='${header.firstName}',
lastName='${header.lastName}' where id = ${header.personId}"))
-                    .when(simple("${header.CamelHttpMethod} == 'DELETE'"))
-                        .setBody(simple("delete from person where id = ${header.personId}"))
-                    .otherwise()
-                        .stop()
-                .end()
-                .to("jdbc:dataSource");
+        rest("/persons")
+            .post().to("direct:postPersons")
+            .get().to("direct:getPersons")
+            .get("/{personId}").to("direct:getPersonId")
+            .put("/{personId}").to("direct:putPersonId")
+            .delete("/{personId}").to("direct:deletePersonId");
+        
+        from("direct:postPersons")
+            .setBody(simple("insert into person(firstName, lastName) values('${header.firstName}','${header.lastName}')"))
+            .to("jdbc:dataSource")
+            .setBody(simple("select * from person where id in (select max(id) from person)"))
+            .to("jdbc:dataSource");
 
-        from("restlet:/persons?restletMethod=GET")
-                .setBody(simple("select * from person"))
-                .to("jdbc:dataSource");
+        from("direct:getPersons")
+            .setBody(simple("select * from person"))
+            .to("jdbc:dataSource");
+        
+        from("direct:getPersonId")
+            .setBody(simple("select * from person where id = ${header.personId}"))  
+            .to("jdbc:dataSource");
+        
+        from("direct:putPersonId")            
+            .setBody(simple("update person set firstName='${header.firstName}', lastName='${header.lastName}'
where id = ${header.personId}"))              
+            .to("jdbc:dataSource");
+
+        from("direct:deletePersonId")
+            .setBody(simple("delete from person where id = ${header.personId}"))
+            .to("jdbc:dataSource");
+        
     }
 }
-

http://git-wip-us.apache.org/repos/asf/camel/blob/1950e778/examples/camel-example-restlet-jdbc/src/main/resources/camel-context.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-restlet-jdbc/src/main/resources/camel-context.xml b/examples/camel-example-restlet-jdbc/src/main/resources/camel-context.xml
index f3e24a6..b9c1f15 100755
--- a/examples/camel-example-restlet-jdbc/src/main/resources/camel-context.xml
+++ b/examples/camel-example-restlet-jdbc/src/main/resources/camel-context.xml
@@ -20,5 +20,5 @@ limitations under the License.
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 
-    <import resource="${impl:xml-dsl}.xml" />
+    <import resource="${impl:xml-rest-dsl}.xml" />
 </beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/1950e778/examples/camel-example-restlet-jdbc/src/main/resources/java-dsl.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-restlet-jdbc/src/main/resources/java-dsl.xml b/examples/camel-example-restlet-jdbc/src/main/resources/java-dsl.xml
deleted file mode 100644
index dd88e44..0000000
--- a/examples/camel-example-restlet-jdbc/src/main/resources/java-dsl.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?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">
-
-    <import resource="common.xml" />
-
-    <bean id="myRouteConfig" class="org.apache.camel.example.restlet.jdbc.MyRouteConfig"
/>
-
-    <camel:camelContext id="defaultCamelContext">
-        <camel:routeBuilder ref="myRouteConfig"/>
-    </camel:camelContext>
-
-</beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/1950e778/examples/camel-example-restlet-jdbc/src/main/resources/java-rest-dsl.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-restlet-jdbc/src/main/resources/java-rest-dsl.xml b/examples/camel-example-restlet-jdbc/src/main/resources/java-rest-dsl.xml
new file mode 100644
index 0000000..dd88e44
--- /dev/null
+++ b/examples/camel-example-restlet-jdbc/src/main/resources/java-rest-dsl.xml
@@ -0,0 +1,35 @@
+<?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">
+
+    <import resource="common.xml" />
+
+    <bean id="myRouteConfig" class="org.apache.camel.example.restlet.jdbc.MyRouteConfig"
/>
+
+    <camel:camelContext id="defaultCamelContext">
+        <camel:routeBuilder ref="myRouteConfig"/>
+    </camel:camelContext>
+
+</beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/1950e778/examples/camel-example-restlet-jdbc/src/main/resources/xml-dsl.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-restlet-jdbc/src/main/resources/xml-dsl.xml b/examples/camel-example-restlet-jdbc/src/main/resources/xml-dsl.xml
deleted file mode 100644
index 1ed18a0..0000000
--- a/examples/camel-example-restlet-jdbc/src/main/resources/xml-dsl.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-<?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:jdbc="http://www.springframework.org/schema/jdbc"
-
-       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
-       http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
-
-    <import resource="common.xml" />
-
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
-        <route>
-            <from uri="restlet:/persons?restletMethod=POST"/>
-
-            <setBody>
-                <simple>insert into person(firstName, lastName) values('${header.firstName}','${header.lastName}')
-                </simple>
-            </setBody>
-            <to uri="jdbc:dataSource"/>
-
-            <setBody>
-                <!--<simple>select * from person ORDER BY id desc OFFSET 1 ROWS</simple>-->
-                <simple>select * from person where id in (select max(id) from person)</simple>
-            </setBody>
-            <to uri="jdbc:dataSource"/>
-        </route>
-
-        <route>
-            <from uri="restlet:/persons/{personId}?restletMethods=GET,PUT,DELETE"/>
-            <choice>
-                <when>
-                    <simple>${header.CamelHttpMethod} == 'GET'</simple>
-                    <setBody>
-                        <simple>select * from person where id = ${header.personId}</simple>
-                    </setBody>
-                </when>
-                <when>
-                    <simple>${header.CamelHttpMethod} == 'PUT'</simple>
-                    <setBody>
-                        <simple>update person set firstName='${header.firstName}',
lastName='${header.lastName}' where id = ${header.personId}</simple>
-                    </setBody>
-                </when>
-                <when>
-                    <simple>${header.CamelHttpMethod} == 'DELETE'</simple>
-                    <setBody>
-                        <simple>delete from person where id = ${header.personId}</simple>
-                    </setBody>
-                </when>
-                <otherwise>
-                    <stop/>
-                </otherwise>
-            </choice>
-            <to uri="jdbc:dataSource"/>
-        </route>
-
-        <route>
-            <from uri="restlet:/persons?restletMethod=GET"/>
-            <setBody>
-                <constant>select * from person</constant>
-            </setBody>
-            <to uri="jdbc:dataSource"/>
-        </route>
-
-    </camelContext>
-</beans>
\ No newline at end of file


Mime
View raw message