这个例子主要是通过在tomcat 中发布一个WebService,然后通过在ServiceMix 中部署
servicemix-cxf-bc组件来代理tomcat中WebService的访问。
1.创建一个Dynamic Web project,名为HelloWorld
2.在src中新建package,包名为net.kentop.ws
3.在net.kentop.ws包中新建class,类名为HelloWorld
- package net.kentop.ws;
- public class HelloWorld {
- public String sayHello(String name) {
- return "Hello " + name;
- }
- }
5.为HelloWorld项目创建Server,并启动Server
6.为HelloWorld.java文件创建WebService
7.测试webservice
点击Operations Name为sayHello的链接
在文本框中输入数据,点击“GO”按钮
下方会显示如下信息,表示测试成功
8.创建名为servicemix-cxf-bc-demo的Maven Project项目根目录
9.在根项目下创建名为cxf-bc-su-demo的servicemix-cxf-bc-service-unit
10.将HelloWorld项目下WebContent/wsdl/HelloWorld.wsdl文件拷贝到cxf-bc-su-demo/resources目录下,并将service.wsdl删除
11.将HelloWorld.wsdl如下代码
- <wsdl:service name="HelloWorldService">
- <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld">
- <wsdlsoap:address location="http://localhost:8080/HelloWorld/services/HelloWorld"/>
- </wsdl:port>
- </wsdl:service>
修改成
- <wsdl:service name="HelloWorldServiceProxy">
- <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorldProxy">
- <wsdlsoap:address location="http://localhost:8193/HelloWorld/"/>
- </wsdl:port>
- </wsdl:service>
12.修改resources目录下的xbean.xml文件如下
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns:ws="http://ws.kentop.net" xmlns="http://www.springframework.org/schema/beans"
- xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0" xmlns:xsi="http://http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://servicemix.apache.org/cxfbc/1.0 http://servicemix.apache.org/schema/servicemix-cxfbc-3.2.3.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
- <cxfbc:consumer wsdl="classpath:HelloWorld.wsdl"
- service="ws:HelloWorldServiceProxy" endpoint="ws:HelloWorldProxy"
- targetEndpoint="ws:HelloWorld" targetService="ws:HelloWorldService" />
- <cxfbc:provider
- wsdl="http://localhost:8080/HelloWorld/services/HelloWorld?wsdl"
- service="ws:HelloWorldService" endpoint="ws:HelloWorld" />
- </beans>
13.在根项目下创建名为cxf-bc-sa-demo的servicemix-service-assembly
14.在cxf-bc-sa-demo目录下pom.xml文件的dependencies节点添加依赖
<dependency>
<groupId>org.apache.servicemix.samples</groupId>
<artifactId>cxf-bc-su-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jbi-service-unit</type>
</dependency>
15.执行mvn install,如果BUILD SUCCESSFUL,则将servicemix-cxf-bc-demo/cxf-bc-sa-demo/target/cxf-bc-sa-demo-0.0.1-SNAPSHOT.jar拷贝到ServiceMix-Home/hotdeloy目录下,启动ServiceMix,部署成功后,在浏览器中浏览http://localhost:8193/HelloWorld/?wsdl判断是否能访问成功.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。