serviceMix发布webservice服务

利用serviceMix对外发布外部的webservice服务,首先要使用mvn名进行工程打包。

在使用的过程中对xml及wsdl文件进行编程的时候,一定要用xml编辑器或无符号的记事本进行编辑,否则在复制粘贴的过程中会出现意想不到的错误。

mvn命令:

  1.  建立工程目录 :mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-project-root -DgroupId=org.apache.servicemix.samples -DartifactId=servicemix-cxf-bc-demo
  2. 工程发布到我们的本地 Maven repository :mvn install
  3. 建立SU :mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-cxf-bc-service-unit -DgroupId=org.apache.servicemix.samples -DartifactId=cxf-bc-su-demo
  4. 建立SA :mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-assembly -DgroupId=org.apache.servicemix.samples -DartifactId=cxf-bc-sa-demo
  5. 建立好SA组件:mvn install

hello word的例子:

现在已经有的一个hellow word的webservice服务,wsdl如下:

 

首先建立根目录mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-project-root -DgroupId=org.apache.servicemix.samples -DartifactId=servicemix-cxf-bc-demo

然后执行mvn install

 

建立SU

进入新建的目录servicemix-cxf-bc-demo  : cd servicemix-cxf-bc-demo

mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-cxf-bc-service-unit -DgroupId=org.apache.servicemix.samples -DartifactId=cxf-bc-su-demo

用来创建一个标准的CXF-BC-SU组件

现在进入新建的组件的文件夹。

        我们看到一个pom.xml文件,这个是对这个组件进行配置的一个文件。
        打开,我们可以看到详细内容
        现在我们修改这个组件的名字
        将<name>A Cxf BC Service Unit</name>
        改成<name>Cxf-Hello-SU</name>
然后把我们的helloWord.wsdl文件放到 %/cxf-bc-su-demo\src\main\resources下,可以删除service.wsdl文件,然后修改 helloWord.wsdl,修改如下:
    <binding name="HelloWordPortBinding" type="tns:HelloWordI">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="say">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="HelloWordServiceProxy">
        <port name="HelloWordPortProxy" binding="tns:HelloWordPortBinding">
            <soap:address location="http://localhost:8193/HelloWordI/HelloWord"/>
        </port>
    </service>
</definitions>
编辑xbean.xml文件
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0" xmlns:ws="http://service.simple.cxf.guanghua.com/" xmlns:xsi="http://http://www.w3.org/2001/XMLSchema-instance">
    <cxfbc:consumer wsdl="classpath:HelloWord.wsdl" service="ws:HelloWordServiceProxy" endpoint="ws:HelloWordPortProxy" targetService="ws:HelloWordService" targetEndpoint="ws:HelloWordPort" targetInterface="ws:HelloWordI"/>
    <cxfbc:provider wsdl="http://localhost:8084/HelloWordI/HelloWord?wsdl" service="ws:HelloWordService" endpoint="ws:HelloWordPort"/>
</beans>
注意,要添加hellow服务的命名空间 (xmlns:ws="http://service.simple.cxf.guanghua.com/"

修改 su的pom.xml文件,    <groupId>org.apache.servicemix.samples</groupId>
    <artifactId>cxf-bc-su-demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jbi-service-unit</packaging>
    <name>cxf-hello-us </name>
    <url>http://www.myorganization.org</url>
    <build>
这样service unit就建好了,接下来我们建立service assembly
        在我们的工程路目下运行
mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix- service-assembly -DgroupId=org.apache.servicemix.examples -DartifactId=my-cxf-sa 
        现在可以看到工程目录中新建出来了SA的文件夹
        同样,我们修改一个名字
        <name>Cxf-Hello-SA</name>
 
        接下来,我们要在这个SA中注册我们刚才制作的SU
<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.samples</groupId>
            <artifactId>cxf-bc-su-demo</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>jbi-service-unit</type>
        </dependency>
    </dependencies>
好了现在一切就绪,我们在工程目录下面运行
mvn install
        就可以建立好组件了
 
        在build successful之后,我们就可以在
        %\my-cxf-sa\target
        目录下面看到我们建立好的jar包
将这个jar包复制到servicemix目录下 面的\hotdeploy文件夹,来正式发布到servicemix当中
        如此一来,我们就成功的发布了一个服务到servicemix上

如果在serviceMix发布服务的过程中出现 serviceMix-cxf-bc为启动的错误,那么需要将servicemix-cxf-bc-2009.01-installer.zip从hotdeploy中移除,然后在添加进来,这样servicemix-cxf-bc组件就启动了,然后在利用cxf发布服务

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值