servicemix应用小记

 

前一段时间,研究了一下Apache的ServiceMix(3.3.2)的应用,作为一个ESB(基于SOA和EDA)应用,牵涉的内容和知识很多,在整个建立的过程中,感觉有几个概念比较重要:

一、JBI(Java Business Integration)是什么意思。

二、ServiceMix中的BC和SE概念。

三、Provider和Consumer的理解。

2010.07.28

这两天一直在研究利用cxf-bc进行服务代理的实验,今天终于做通了,具体的步骤如下:

1、在ServiceMix外部发布一个webservice,这里我利用cxf,发布了一个HelloWorld的服务,在HelloWorld.wsdl文件中的targetNamespace=”http://spring.demo/“、service name “HelloWorldImplService”、port type “HelloWorld”、port binding name “HelloWorldImplPort”在后面的配置中,将会用到。

 <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="HelloWorldImplService" targetNamespace="http://spring.demo/" xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://spring.demo/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://spring.demo/" version="1.0" xmlns:tns="http://spring.demo/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sayHi" type="tns:sayHi"/>
<xs:element name="sayHiResponse" type="tns:sayHiResponse"/>
<xs:complexType name="sayHi">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="sayHiResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
  </wsdl:types>
  <wsdl:message name="sayHiResponse">
    <wsdl:part element="tns:sayHiResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="sayHi">
    <wsdl:part element="tns:sayHi" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="HelloWorld">
    <wsdl:operation name="sayHi">
      <wsdl:input message="tns:sayHi" name="sayHi">
    </wsdl:input>
      <wsdl:output message="tns:sayHiResponse" name="sayHiResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:HelloWorld">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="sayHi">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="sayHi">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="sayHiResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="HelloWorldImplService">
    <wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort">
      <soap:address location="http://localhost:8080/cxf_spring_web/HelloWorld"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

2、cxf_bc中的配置

    在cxf_bc中需要配置两个endpoint,一个为provider,利用它来连接外部的service:

     <cxfbc:provider wsdl="classpath:HelloWorld.wsdl"
           locationURI="http://localhost:8080/cxf_spring_web/HelloWorld"
                       service="hello:HelloWorldImplService"
                      endpoint="HelloWorldImplPortProxy"
                      interfaceName="hello:HelloWorld"
                    / >

    需要注意的是service的名字为hello:HelloWorldImplService要和wsdl中定义的一致,hello为文件头中定义的namespace=“http://spring.demo/"。

利用一个consumer的endpoint连接这个provider,从而形成一个webService发布的桥:

      <cxfbc:consumer wsdl="classpath:HelloWorld.wsdl"
                      locationURI="http://localhost:19000/CalculatorService/SoapPort"
                      service="hello:HelloWorldImplService"
                      endpoint="HelloWorldImplPort"
                      targetEndpoint="HelloWorldImplPortProxy"
                      targetService="hello:HelloWorldImplService"
                      targetInterface="hello:HelloWorld"/>

这里需要注意的一是locationURI要和原始的service发布路径不一致,否则就会产生混淆;二是service和provider中定义的一致;三是endpoint名字是wsdl中定义的port binding name。

经过测试,以上配置就实现了在ServiceMix中发布WebService的功能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值