OSGI中bundle之间的桥梁是blueprint.xml
所以,一切从blueprint开始。
一、创建一个blueprint.xml文件,此文件必须符合规范
<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd" > </blueprint>
<bean id="Service" class="XXX.Common.TimeStamp.Impl.Service"> <property name="tsaUrl" value="${TimeStamp.tsaUrl}" /> <property name="username" value="${TimeStamp.username}" /> <property name="password" value="${TimeStamp.password}" /> </bean> <bean id="processorBean" class="XXX.Common.TimeStamp.Processor.TimeStampProcessor"> <property name="service" ref="Service"/> </bean>
<cm:property-placeholder persistent-id="com.xxxx.TimeStamp" update-strategy="reload"> <cm:default-properties> <cm:property name="TimeStamp.tsaUrl" value="http://test.test.cn/test" /> <cm:property name="TimeStamp.username" value="test" /> <cm:property name="TimeStamp.password" value="test" /> </cm:default-properties> </cm:property-placeholder>这样子就有了常量了。
注意,一般把程序发布到生产环境,都不需要修改CM这里的配置,为什么呢?这些常量明明是测试数据,正式环境不修改也可以?答案是肯定的,我们还是有办法的,所以我们先不管怎么样,先创建一个com.xxxx.TimeStamp.cfg文件,文件中内容设置为
TimeStamp.tsaUrl=http://release.test.cn/test TimeStamp.username=test TimeStamp.password=test点击保存到ServiceMix中的etc目录下即可。
五、前期工作都准备好了,那么我们就可以发布一个restful服务了,废话少说,直接上代码好了
<camelContext xmlns="http://camel.apache.org/schema/blueprint" > <restConfiguration component="restlet" port="9089" host="0.0.0.0" > <componentProperty key="restletMethods" value="GET,POST,PUT,DELETE"/> </restConfiguration> <rest path="/test"> <!-- http://0.0.0.0:9089/test --> <post uri="/{resources}"> <to uri="vm:tsaProcessor"/> </post> ......<!-- 支持get put delete...--> </rest> </camelContext> <camelContext id="camel-authmgtAuth" xmlns="http://camel.apache.org/schema/blueprint" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> <route> <from uri="vm:testProcessor"/> <to uri="bean:testProcessorBean"/> </route> </camelContext>