├── .gitignore ├── README ├── src └── main │ ├── resources │ ├── sql │ │ └── init.sql │ ├── camel-config.xml │ ├── log4j.properties │ ├── java-dsl.xml │ ├── common.xml │ └── xml-dsl.xml │ ├── webapp │ └── WEB-INF │ │ └── web.xml │ └── java │ └── org │ └── test │ └── router │ └── TestRouteBuilder.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | *.ipr 5 | *.iws 6 | 7 | /org.eclipse.wst.validation.prefs 8 | /.settings/ 9 | /.project 10 | /.classpath 11 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Camel Restlet and JDBC example 2 | ======================================= 3 | 4 | An example which shows how to expose CRUD operations with REST interface and JDBC implementation 5 | 6 | Compile: mvn clean install 7 | Run the application: 8 | 9 | mvn jetty:run 10 | 11 | or to use java DSL use 12 | mvn jetty:run -Dimpl=java-dsl 13 | 14 | To create an user, make a http POST request with firstName and lastName parameters 15 | curl -d "firstName=test&lastName=user" http://localhost:8080/rs/user/ 16 | 17 | To update an existing user, make a http PUT request with firstName and lastName parameters 18 | curl -X PUT -d "firstName=updated&lastName=user" http://localhost:8080/rs/user/2 19 | 20 | To retrieve an existing user, make a http GET request with the userId as part of the url 21 | curl -X GET http://localhost:8080/rs/user/0 22 | 23 | To delete an existing user, make a http DELETE request with the userId as part of the url 24 | curl -X DELETE http://localhost:8080/rs/user/0 25 | 26 | To retrieve all the existing users, make a http GET request to users url 27 | curl -X GET http://localhost:8080/rs/users 28 | 29 | -------------------------------------------------------------------------------- /src/main/resources/sql/init.sql: -------------------------------------------------------------------------------- 1 | -- ------------------------------------------------------------------------ 2 | -- Licensed to the Apache Software Foundation (ASF) under one or more 3 | -- contributor license agreements. See the NOTICE file distributed with 4 | -- this work for additional information regarding copyright ownership. 5 | -- The ASF licenses this file to You under the Apache License, Version 2.0 6 | -- (the "License"); you may not use this file except in compliance with 7 | -- the License. You may obtain a copy of the License at 8 | -- 9 | -- http://www.apache.org/licenses/LICENSE-2.0 10 | -- 11 | -- Unless required by applicable law or agreed to in writing, software 12 | -- distributed under the License is distributed on an "AS IS" BASIS, 13 | -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | -- See the License for the specific language governing permissions and 15 | -- limitations under the License. 16 | -- ------------------------------------------------------------------------ 17 | 18 | DROP TABLE user IF EXISTS; 19 | 20 | CREATE TABLE user( 21 | id IDENTITY, 22 | firstName VARCHAR(100) DEFAULT NULL, 23 | lastName VARCHAR(100) DEFAULT NULL 24 | ); -------------------------------------------------------------------------------- /src/main/resources/camel-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | ## ------------------------------------------------------------------------ 2 | ## Licensed to the Apache Software Foundation (ASF) under one or more 3 | ## contributor license agreements. See the NOTICE file distributed with 4 | ## this work for additional information regarding copyright ownership. 5 | ## The ASF licenses this file to You under the Apache License, Version 2.0 6 | ## (the "License"); you may not use this file except in compliance with 7 | ## the License. You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, software 12 | ## distributed under the License is distributed on an "AS IS" BASIS, 13 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ## See the License for the specific language governing permissions and 15 | ## limitations under the License. 16 | ## ------------------------------------------------------------------------ 17 | 18 | # default properties to initialise log4j 19 | log4j.rootLogger=INFO, console 20 | 21 | # settings for specific packages 22 | #log4j.logger.org.apache.camel.component.http=DEBUG 23 | #log4j.logger.org.apache.camel.component.servlet=DEBUG 24 | #log4j.logger.org.apache.camel=DEBUG 25 | 26 | # Console appender 27 | log4j.appender.console=org.apache.log4j.ConsoleAppender 28 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 29 | log4j.appender.console.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n 30 | log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer -------------------------------------------------------------------------------- /src/main/resources/java-dsl.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/common.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | My Web Application 24 | 25 | 26 | contextConfigLocation 27 | classpath:camel-config.xml 28 | 29 | 30 | 31 | org.springframework.web.context.ContextLoaderListener 32 | 33 | 34 | 35 | RestletServlet 36 | org.restlet.ext.spring.SpringServerServlet 37 | 38 | org.restlet.component 39 | RestletComponent 40 | 41 | 42 | 43 | 44 | RestletServlet 45 | /rs/* 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/java/org/test/router/TestRouteBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.test.router; 19 | 20 | import org.apache.camel.builder.RouteBuilder; 21 | 22 | public class TestRouteBuilder extends RouteBuilder { 23 | 24 | @Override 25 | public void configure() { 26 | from("restlet:/user?restletMethod=POST") 27 | .setBody(simple("insert into user(firstName, lastName) values('${header.firstName}','${header.lastName}'); CALL IDENTITY();")) 28 | .to("jdbc:dataSource") 29 | .setBody(simple("select * from user ORDER BY id desc LIMIT 1")) 30 | .to("jdbc:dataSource"); 31 | 32 | from("restlet:/user/{userId}?restletMethods=GET,PUT,DELETE") 33 | .choice() 34 | .when(simple("${header.CamelHttpMethod} == 'GET'")) 35 | .setBody(simple("select * from user where id = ${header.userId}")) 36 | .when(simple("${header.CamelHttpMethod} == 'PUT'")) 37 | .setBody(simple("update user set firstName='${header.firstName}', lastName='${header.lastName}' where id = ${header.userId}")) 38 | .when(simple("${header.CamelHttpMethod} == 'DELETE'")) 39 | .setBody(simple("delete from user where id = ${header.userId}")) 40 | .otherwise() 41 | .stop() 42 | .end() 43 | .to("jdbc:dataSource"); 44 | 45 | from("restlet:/users") 46 | .setBody(simple("select * from user")) 47 | .to("jdbc:dataSource"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/resources/xml-dsl.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | insert into user(firstName, lastName) values('${header.firstName}','${header.lastName}'); 35 | CALL IDENTITY(); 36 | 37 | 38 | 39 | 40 | 41 | select * from user ORDER BY id desc LIMIT 1 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | ${header.CamelHttpMethod} == 'GET' 51 | 52 | select * from user where id = ${header.userId} 53 | 54 | 55 | 56 | ${header.CamelHttpMethod} == 'PUT' 57 | 58 | update user set firstName='${header.firstName}', lastName='${header.lastName}' where id = ${header.userId} 59 | 60 | 61 | 62 | ${header.CamelHttpMethod} == 'DELETE' 63 | 64 | delete from user where id = ${header.userId} 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | select * from user 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 21 | 4.0.0 22 | 23 | org.apache.camel 24 | camel-example-restlet-jdbc 25 | 2.10-SNAPSHOT 26 | Camel :: Example :: Restlet jdbc 27 | An example using Camel Restlet with jdbc 28 | war 29 | 30 | 31 | 2.11.1 32 | 2.0.15 33 | 2.0.0 34 | 6.1.25 35 | 3.1.4.RELEASE 36 | 1.7.5 37 | 38 | 39 | 40 | 41 | maven-restlet 42 | Public online Restlet repository 43 | http://maven.restlet.org 44 | 45 | 46 | 47 | 48 | 49 | org.apache.camel 50 | camel-core 51 | ${camel-version} 52 | 53 | 54 | org.apache.camel 55 | camel-spring 56 | ${camel-version} 57 | 58 | 59 | org.apache.camel 60 | camel-jdbc 61 | ${camel-version} 62 | 63 | 64 | org.springframework 65 | spring-jdbc 66 | ${spring-version} 67 | 68 | 69 | org.springframework 70 | spring-expression 71 | ${spring-version} 72 | 73 | 74 | org.hsqldb 75 | hsqldb 76 | ${hsqldb-version} 77 | 78 | 79 | org.apache.camel 80 | camel-restlet 81 | ${camel-version} 82 | 83 | 84 | org.restlet.jee 85 | org.restlet.ext.spring 86 | ${restlet-version} 87 | 88 | 89 | org.slf4j 90 | slf4j-log4j12 91 | ${slf4j-version} 92 | 93 | 94 | 95 | 96 | 97 | 98 | org.mortbay.jetty 99 | maven-jetty-plugin 100 | ${maven-jetty-plugin-version} 101 | 102 | ${basedir}/target/${project.artifactId}.war 103 | / 104 | 105 | 106 | 107 | 108 | 109 | 110 | --------------------------------------------------------------------------------