OSGI-INF.blueprint.camel-context.xml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quickstart-karaf-camelrest Show documentation
Show all versions of quickstart-karaf-camelrest Show documentation
Camel Example using Rest DSL with SQL Database
<?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. --> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd "> <!-- to setup camel servlet with OSGi HttpService --> <reference id="httpService" interface="org.osgi.service.http.HttpService"/> <bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer" init-method="register" destroy-method="unregister"> <property name="alias" value="/camel-rest-sql"/> <property name="httpService" ref="httpService"/> <property name="servlet" ref="camelServlet"/> </bean> <bean id="camelServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/> <!-- this is the JDBC data source which uses an in-memory only Apache Derby database --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver"/> <property name="url" value="jdbc:derby:memory:orders;create=true"/> <property name="username" value=""/> <property name="password" value=""/> </bean> <!-- bean which creates/destroys the database table for this example --> <bean id="initDatabase" class="org.apache.camel.example.sql.DatabaseBean" init-method="create" destroy-method="destroy"> <property name="dataSource" ref="dataSource"/> </bean> <!-- configure the Camel SQL component to use the JDBC data source --> <bean id="sql" class="org.apache.camel.component.sql.SqlComponent"> <property name="dataSource" ref="dataSource"/> </bean> <!-- order bean is our business logic bean that creates new orders --> <bean id="orderBean" class="org.apache.camel.example.sql.OrderBean"/> <!-- here is Camel configured with a number of routes --> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <!-- use Camel property placeholder loaded from the given file --> <propertyPlaceholder id="placeholder" location="classpath:sql.properties"/> <restConfiguration component="servlet" bindingMode="json" contextPath="/camel-rest-sql" port="{{env:HTTP_PORT:8181}}"/> <!-- rest service for books --> <rest path="/books" consumes="application/json" produces="application/json"> <!-- rest service that fetches names of all books --> <get uri="/" outType="org.apache.camel.example.sql.model.Book"> <to uri="sql:{{sql.selectBooks}}?outputType=SelectList&outputClass=org.apache.camel.example.sql.model.Book"/> </get> <!-- rest service that fetches an order by id --> <get uri="order/{id}" outType="org.apache.camel.example.sql.model.Order"> <to uri="sql:{{sql.selectOrder}}?outputType=SelectOne&outputClass=org.apache.camel.example.sql.model.Order"/> </get> </rest> <!-- route that generate new orders and insert them in the database --> <route id="generateOrder-route"> <from uri="timer:foo?delay=1s&period=10s"/> <transform> <method ref="orderBean" method="generateOrder"/> </transform> <to uri="sql:{{sql.insertOrder}}"/> <log message="Inserted new order ${body.id}"/> </route> <!-- route that process the orders by picking up new rows from the database and when done processing then update the row to mark it as processed --> <route id="processOrder-route"> <from uri="sql:{{sql.selectUnprocessedOrders}}?consumer.onConsume={{sql.markOrder}}"/> <transform> <method ref="orderBean" method="rowToOrder"/> </transform> <to uri="bean:orderBean?method=processOrder"/> <log message="${body}"/> </route> </camelContext> </blueprint>
© 2015 - 2024 Weber Informatics LLC | Privacy Policy