利用serviceMix对外发布外部的webservice服务,首先要使用mvn名进行工程打包。
在使用的过程中对xml及wsdl文件进行编程的时候,一定要用xml编辑器或无符号的记事本进行编辑,否则在复制粘贴的过程中会出现意想不到的错误。
mvn命令:
- 建立工程目录 :mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-project-root -DgroupId=org.apache.servicemix.samples -DartifactId=servicemix-cxf-bc-demo
- 工程发布到我们的本地 Maven repository :mvn install
- 建立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
- 建立SA :mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-assembly -DgroupId=org.apache.servicemix.samples -DartifactId=cxf-bc-sa-demo
- 建立好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组件
<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>
<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/" )
<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>
<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>
就可以建立好组件了