spring中发布基于cxf的webservice
2014-08-13 16:48
411 查看
以自己写的回写预约记录状态服务为例
服务器端:
1.编写web服务接口:
<!-- CXF Servlet 的定义,以及它的映射 -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
<!-- CXF Servlet 的定义,以及它的映射end -->
4.在spring 配置发布WEB服务接口:applicationcontext-csf-server.xml
ok 一个服务器端配置完毕。
测试:在浏览器中输入:
客户端配置:
1.web接口拷到对应项目里:
spring中配置该接口:applicationcontext-csf-client.xml
package com.jlit.hrs.ws.test;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.jlit.mms.webservice.IOrdersService;
import com.jlit.model.Orders;
public class WebServiceTest {
private IOrdersService iOrdersService;
@Before
public void init(){
ApplicationContext ctx=new ClassPathXmlApplicationContext("com/jlit/hrs/resources/applicationContext-cxf-client.xml");
iOrdersService=(IOrdersService) ctx.getBean("iOrdersService");
}
@Test
public void test(){
Orders orders=iOrdersService.createRegRecourdOrder("1111", "lisanxiang", 20.56, "挂号预约订单");
System.out.println("订单号:"+orders.getOrderNo());
}
}
服务器端:
1.编写web服务接口:
IRegRecordService.java
package com.jlit.hrs.webservice; import javax.jws.WebParam; import javax.jws.WebService; import com.jlit.uums.webservice.bean.UserMenus; /** * 预约记录service * @author xuht * @time 2014-5-28 下午3:26:15 * @file IRegRecordService.java */ @WebService public interface IRegRecordService { /**更新订单状态 * @param orderId 订单id * @param status 更改的状态 * @return void */ public void updateRecordStatus(@WebParam(name="orderId") String orderId,@WebParam(name="status")String status); /** * 根据订单流水号判断是否该订单有效 * @param orderNo 订单流水号 * @return 返回是该订单是否有效的字符串:"valid"有效,"invalid"无效 */ public String isValid(@WebParam(name="orderNo")String orderNo); }2.编写服务接口实现类:
package com.jlit.hrs.webservice.impl; import org.apache.log4j.Logger; import com.jlit.hrs.service.RegRecordService; import com.jlit.hrs.webservice.IRegRecordService; public class IRegRecordServiceImpl implements IRegRecordService { private final static Logger logger=Logger.getLogger(IRegRecordServiceImpl.class); private RegRecordService rdService; public RegRecordService getRdService() { return rdService; } public void setRdService(RegRecordService rdService) { this.rdService = rdService; } @Override public void updateRecordStatus(String orderId, String status) { // TODO Auto-generated method stub rdService.updateRecordStatus(orderId, status); } @Override public String isValid(String orderNo) { return rdService.isValid(orderNo); } }3.在web。xml中配置cxf 前端servlet
<!-- CXF Servlet 的定义,以及它的映射 -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
<!-- CXF Servlet 的定义,以及它的映射end -->
4.在spring 配置发布WEB服务接口:applicationcontext-csf-server.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <!-- Import apache CXF bean definition --> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!-- 预约 web service --> <bean id="ws_regRecordService" class="com.jlit.hrs.webservice.impl.IRegRecordServiceImpl"> <property name="rdService" ref="regRecordService"></property> </bean> <jaxws:endpoint id="ws_serService_rd" implementor="#ws_regRecordService" address="/regRecordWebService" /> </beans>
ok 一个服务器端配置完毕。
测试:在浏览器中输入:
客户端配置:
1.web接口拷到对应项目里:
spring中配置该接口:applicationcontext-csf-client.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!-- CXF webservices 客户端配置 --> <!-- 预约service --> <jaxws:client id="regRecordWebService" serviceClass="com.jlit.hrs.webservice.IRegRecordService" address="http://127.0.0.1:8090/hrs/ws/regRecordWebService"> </jaxws:client> </beans>java测试:WebServiceTest.java
package com.jlit.hrs.ws.test;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.jlit.mms.webservice.IOrdersService;
import com.jlit.model.Orders;
public class WebServiceTest {
private IOrdersService iOrdersService;
@Before
public void init(){
ApplicationContext ctx=new ClassPathXmlApplicationContext("com/jlit/hrs/resources/applicationContext-cxf-client.xml");
iOrdersService=(IOrdersService) ctx.getBean("iOrdersService");
}
@Test
public void test(){
Orders orders=iOrdersService.createRegRecourdOrder("1111", "lisanxiang", 20.56, "挂号预约订单");
System.out.println("订单号:"+orders.getOrderNo());
}
}
相关文章推荐
- 基于spring3.0的cxf发布webservice+client的源码
- webservice 基于spring的cxf发布
- Web应用中使用CXF不基于Spring的WebService发布
- Web应用中使用CXF不基于Spring的WebService发布
- Spring CXF 整合 发布WebService
- CXF+Spring发布WebService 以及 对WebService的调用
- Spring整合CXF,发布RSETful 风格WebService
- Spring整合CXF,发布RSETful 风格WebService--编写客户端代码,调用RESTful WebService
- 使用cxf发布WebService(Spring)
- cxf基于spring的webservice启动报错EndpointReference 的解决办法
- cxf+spring发布webservice服务(客户端)
- cxf+spring发布webservice接口及接口的调用
- 解决cxf+spring发布的webservice缺少<wsdl:types>和<wsdl:message>标签的问题
- Spring整合CXF,发布RSETful 风格WebService
- spring整合cxf 发布restFul风格的webservice
- CXF Spring开发WebService,基于SOAP和REST方式
- Spring整合CXF,发布RSETful 风格WebService-准备工作
- Spring整合CXF,发布RSETful 风格WebService
- 基于Spring+CXF实现用户文件上传的WebService
- WebService介绍(WebService基础知识、XFire、CXF(基于XFire和Celtix项目整合而来,与Spring融合好)、AXIS1、AXIS2(有AXIS1转换而来,有Java)