2015年7月13日星期一

Fuse_016:基础入门之五:使用OSGi Config Admin service配置应用

环境:JBoss Fuse 6.2.0 + Maven 3.2.2

本实验跟上一个实验有关。

1. 学习重点
(1)动态配置服务的IP地址和端口

2. 修改 cxf-basic/src/main/resources/OSGI-INF/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:jaxws="http://cxf.apache.org/blueprint/jaxws"
           xmlns:cxf="http://cxf.apache.org/blueprint/core"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
           xsi:schemaLocation="
      http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
      http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd">

    <cxf:bus>
        <!--
           In this example, we're enabling the logging feature.  This will ensure that both the inbound and outbound
           XML message are being logged for every web service invocation.
        -->
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus>

    <!-- osgi blueprint property placeholder -->
    <cm:property-placeholder id="placeholder"
                             persistent-id="org.fusesource.example.get.started">
        <cm:default-properties>
            <cm:property name="portNumber" value="8181"/>
        </cm:default-properties>
    </cm:property-placeholder>

    <jaxws:endpoint id="helloWorld"
                    implementor="org.fusesource.example.HelloWorldImpl"
                    address="http://0.0.0.0:${portNumber}/cxf/HelloWorld">
    </jaxws:endpoint>

</blueprint>

3. 创建文件 etc/org.fusesource.example.get.started.cfg,内容如下:
portNumber=8182

4.  构建、部署、测试、卸载
(1)在 cxf-basic 目录下执行 mvn clean install
(2)如果原来安装了 get-started-basic feature,要将其卸载:features:uninstall get-started-basic
(3)features:install get-started-cxf
(4)cxf:list-endpoints
应该能看到 [HelloWorldImplPort     ] [Started ] [http://0.0.0.0:8182/cxf/HelloWorld                        ]
(5)修改  cxf-basic/src/test/java/org/fusesource/example/SoapTest.java
URLConnection connection = new URL("http://localhost:8182/cxf/HelloWorld").openConnection();
(6)在 cxf-basic 目录下执行 mvn -Ptest
(7)features:uninstall get-started-cxf

参考文献:
1. Red_Hat_JBoss_Fuse-6.2-Getting_Started-en-US.pdf

没有评论: