web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/beans.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <display-name>CXF Servlet</display-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>/*</url-pattern> </servlet-mapping> </web-app>
服务端入参POJO:
package demo.order; public class Order { private String customerID; private String itemID; private int qty; private double price; // Contructor public Order() { } public String getCustomerID() { return customerID; } public void setCustomerID(String customerID) { this.customerID = customerID; } public String getItemID() { return itemID; } public void setItemID(String itemID) { this.itemID = itemID; } public int getQty() { return qty; } public void setQty(int qty) { this.qty = qty; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } }
SEI:
package demo.order; import javax.jws.WebService; @WebService public interface OrderProcess { String processOrder(Order order); }
实现类:
package demo.order; import javax.jws.WebService; @WebService public class OrderProcessImpl implements OrderProcess { public String processOrder(Order order) { String orderID = validate(order); return orderID; } /** * Validates the order and returns the order ID **/ private String validate(Order order) { String custID = order.getCustomerID(); String itemID = order.getItemID(); int qty = order.getQty(); double price = order.getPrice(); if (custID != null && itemID != null && !custID.equals("") && !itemID.equals("") && qty > 0 && price > 0.0) { return "ORD1234"; } return null; } }
通过spring发布服务配置:
<?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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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" /> <jaxws:endpoint id="orderProcess" implementor="demo.order.OrderProcessImpl" address="/OrderProcess" /> </beans>
客户端:
package demo.order.client; import demo.order.OrderProcess; import demo.order.Order; import org.springframework.context.support.ClassPathXmlApplicationContext; public final class Client { public Client() { } public static void main(String args[]) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"demo/order/client/client-beans.xml"}); OrderProcess client = (OrderProcess) context.getBean("orderClient"); Order order = new Order(); order.setCustomerID("C001"); order.setItemID("I001"); order.setQty(100); order.setPrice(200.00); String orderID = client.processOrder(order); String message = (orderID == null) ? "Order not approved" : "Order approved; order ID is " + orderID; System.out.println(message); } }
客户端spring配置:
<?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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:client id="orderClient" serviceClass="demo.order.OrderProcess" address="http://localhost:8080/orderapp/OrderProcess" > </jaxws:client> </beans>
相关推荐
使用cxf+spring框架开发webservice的客户端与服务端代码,用于连接两个项目
ibatis+spring+cxf+mysql搭建webservice的客户端,文章地址在http://blog.csdn.net/cenyi2013/article/details/17315755. 服务端源码的下载地址在http://download.csdn.net/detail/cenyi2012/6712729
内容为CXF整合spring的服务端和客户端开发例子,注释不太详尽,网上的教程比较多,但是多跑不起来,特地把整个工程都打包给大家做参考,程序内容均来自网上整理,均可以运行。
CXF+Spring+MyBatis+Maven项目整合,包含服务端和客户端。
基于CXF的WebService服务端和客户端示例,CXF+Spring,希望能为WebService开发者提供帮助。WebService,CXF,Spring.
完整整合spring4、cxf3和maven3的服务端和客户端项目。
cxf 与 Spring 结合,此例子中包含服务端和客户端, 2个工程都是与SSH 结合使用。相信对刚接触的朋友有用!
CXF+Spring+Hibernate实现WebService,实现的方法比较简单,只有一个增加的方法,没有用到Struts 有服务端代码和客户端测试代码
使用cxf和spring开发基于https的webservice服务端以及客户端样例
针对目前网上的很多cxf相关的服务开发源码不能使用,自己做的cxf与spring的整合,里面包含了服务端和客户端代码,还有说明文档,这个demo使用的是cxf的服务端,axis2的客户端,希望能够帮到cxf初学者们。
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。
webservice=maven+spring+cxf we服务端+java客户端代码
所以先要下载“CXF和Spring结合的例子”,并将服务器(tomcat)运行起来,在利用本客户端测试,本客户端是根据服务端发布的WSDL文件,用wsdl2java直接生成java代码,加入到工程使用。
WebService+Spring客户端和服务端程序,实现了多数据源动态切换 测试的麻油们,依次打开客户端和服务端的main方法就可以测试了
cxf webservice 实例(包括服务端及客户端代码),亲测可用,项目采用spring与cxf结合的,附件解压后看到两个项目,分部是服务端项目和客户端项目,启动tomcat服务器部署后,通过客户端右键运行java 的 mian方法代码...
使用CXF+spring开发的实现文件的上传下载,可以进行视频音频的传输。可供学习使用。
NULL 博文链接:https://javastudyeye.iteye.com/blog/1297557
绝对可运行,里面有客户端和服务端还有对应的操作文档,导入eclipse或者MyEclipse十分钟内就搞定,虽然贵点但是绝对物有所值.
使用cxf和spring开发基于https的webservice服务端以及客户端样例源码.rar
NULL 博文链接:https://huangjiateng.iteye.com/blog/2195585