- 浏览: 134824 次
文章分类
最新评论
-
wangyudong:
很有帮助的代码实例,测试Spring Boot REST AP ...
1、springboot入门案例helloworld与集成hibernate -
wangyudong:
学习了,的确是一个非常好的Spring boot实例,很快就写 ...
1、springboot入门案例helloworld与集成hibernate
cxf简单java项目案例
IHelloWorld.java
实现类HelloWorldImpl.java
发布服务demo.java
客户端
通过cmd,到指定目录执行 wsdl2java http://132.126.1.98/helloDemo?wsdl
得到客户端相关代码
客户端调用服务Demo.java
cxf+spring
服务器端
applicationContext.xml
客户端
applicationContext.xml
测试demo.java
详情看源码
IHelloWorld.java
package com.chen.ws; import java.util.List; import java.util.Map; import javax.jws.WebService; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import com.chen.adapter.AuthXmlAdapter; import com.chen.pojo.Pet; import com.chen.pojo.User; @WebService public interface IHelloWorld { public String hello(); public List<Pet> getPetsByUser(User user); /* * cxf不直接Map<String,Pet>类型,需要自己实现转换器 */ @XmlJavaTypeAdapter(AuthXmlAdapter.class)public Map<String,Pet> getAllPets(); }
实现类HelloWorldImpl.java
package com.chen.ws.impl; import java.util.Date; import java.util.List; import java.util.Map; import javax.jws.WebService; import com.chen.pojo.Pet; import com.chen.pojo.User; import com.chen.service.UserService; import com.chen.ws.IHelloWorld; @WebService(endpointInterface="com.chen.ws.IHelloWorld", serviceName="HelloWorldImpl") public class HelloWorldImpl implements IHelloWorld { @Override public String hello() { return "hello world! date:"+new Date(); } @Override public List<Pet> getPetsByUser(User user) { UserService userService = new UserService(); return userService.getPetsByUser(user); } @Override public Map<String, Pet> getAllPets() { UserService userService = new UserService(); return userService.getAllPets(); } }
发布服务demo.java
package com.chen.demo; import java.io.IOException; import java.io.PrintWriter; import javax.xml.ws.Endpoint; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.EndpointImpl; import com.chen.interceptor.AuthInterceptor; import com.chen.ws.IHelloWorld; import com.chen.ws.impl.HelloWorldImpl; public class ServiceMain { public static void main(String[] args) throws IOException{ IHelloWorld hw = new HelloWorldImpl(); EndpointImpl ep = (EndpointImpl) Endpoint.publish("http://132.126.1.98/helloDemo", hw); //PrintWriter pi = new PrintWriter("D:/chen/work/framework/cxf_demo01/src/in.txt"); //PrintWriter po = new PrintWriter("D:/chen/work/framework/cxf_demo01/src/out.txt"); //添加拦截器 //ep.getInInterceptors().add(new LoggingInInterceptor()); //ep.getOutInterceptors().add(new LoggingOutInterceptor()); ep.getInInterceptors().add(new AuthInterceptor()); System.out.println("发布成功!"); } }
客户端
通过cmd,到指定目录执行 wsdl2java http://132.126.1.98/helloDemo?wsdl
得到客户端相关代码
客户端调用服务Demo.java
package com.chen.demo; import java.util.List; import org.apache.cxf.endpoint.Client; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.interceptor.LoggingOutInterceptor; import com.chen.interceptor.AuthInterceptor; import com.chen.ws.Entry; import com.chen.ws.IHelloWorld; import com.chen.ws.Pet; import com.chen.ws.StringPet; import com.chen.ws.User; import com.chen.ws.impl.HelloWorldImpl; public class ClientMain { public static void main(String[] args) { HelloWorldImpl factory = new HelloWorldImpl(); IHelloWorld hw = factory.getHelloWorldImplPort(); //添加拦截器 Client client = ClientProxy.getClient(hw); //client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); client.getOutInterceptors().add(new AuthInterceptor("chen","chen")); System.out.println(hw.hello()); User u1 = new User(); u1.setId(1L); u1.setName("chen1"); List<Pet> pets = hw.getPetsByUser(u1); for(Pet obj : pets){ System.out.println(obj.getName()); } StringPet res = hw.getAllPets(); for(Entry entry : res.getEntries()){ System.out.println(entry.getKey()+": "+entry.getValue().getId()+" "+entry.getValue().getName()); } } }
cxf+spring
服务器端
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/context" 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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> <!-- (4)、导入cxf提供的Schema,XML配置文件 jaxws--> <!-- web应用的类加载路径classpath有两类: A、WEB-INF/classes目录 B、WEB-INF/lib目录下 --> <!-- (5)、导入cxf配置文件 --> <import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <!-- (6)、配置endpoint implementor 服务提供者 两种形式 A:直接给定服务提供者的类名(不能使spring自动注入) com.chen.ws.impl.HelloWorldImpl B:设置为一个bean引用,要在bean的id前加上# address 发布地址 --> <bean id="helloWorld" class="com.chen.ws.impl.HelloWorldImpl"> <property name="userService" ref="userService" /> </bean> <jaxws:endpoint implementor="#helloWorld" address="/helloDemo"> <!-- (8)、添加拦截器 --> <jaxws:inInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean> <bean class="com.chen.interceptor.AuthInterceptor"></bean> </jaxws:inInterceptors> </jaxws:endpoint> <!-- (7)、配置业务层service bean --> <bean id="userService" class="com.chen.service.UserService"/> </beans>
客户端
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/context" 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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> <!-- (4)、导入cxf提供的Schema,XML配置文件 jaxws--> <!-- web应用的类加载路径classpath有两类: A、WEB-INF/classes目录 B、WEB-INF/lib目录下 --> <!-- (5)、导入cxf配置文件 --> <import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <!-- (6)、配置client --> <jaxws:client id="hw" serviceClass="com.chen.ws.IHelloWorld" address="http://132.126.1.98/helloDemo"> <jaxws:outInterceptors> <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean> <bean class="com.chen.interceptor.AuthInterceptor"> <constructor-arg value="chen"/> <constructor-arg value="chen"/> </bean> </jaxws:outInterceptors> </jaxws:client> </beans>
测试demo.java
package com.chen.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.chen.ws.IHelloWorld; @Controller @RequestMapping("/demo") public class DemoController { @Autowired private IHelloWorld hw ; @RequestMapping("hello") public String hello(){ hw.hello(); return "hello"; } }
详情看源码
- cxf_demo01.rar (15.8 KB)
- 下载次数: 0
- cxf_demo02_client.rar (24.5 KB)
- 下载次数: 0
- cxf_spring_demo03_server.rar (8.2 MB)
- 下载次数: 0
- cxf_spring_demo04_client.rar (8.9 MB)
- 下载次数: 0
发表评论
-
tomcat学习一(简单web服务器示例)
2016-09-20 17:14 452Request.java package com.chen ... -
8、在docker上部署简单javaweb应用
2016-04-24 19:12 8491、创建容器javaweb1,并添加数据卷便于将安装文件共享到 ... -
7、Docker容器的数据管理
2016-04-24 17:56 1102一、Docker容器的数据卷 ... -
6、Docker容器的网络连接
2016-04-24 17:54 1675一、Docker容器的网络基础 dock ... -
4、Docker镜像
2016-04-22 09:05 780一、什么是Docker镜像 ... -
5、Docker客户端和守护进程
2016-04-22 09:04 966一、Docker的C/S模式 ... -
3、Docker容器常用命令与在容器中部署静态网站
2016-04-22 09:04 856一、容器的基本操作 ... -
2、Docker简介及docker组成部分
2016-04-22 09:03 17201、Docker提供了一个容器 ... -
1、Ubuntu14.04安装docker
2016-04-22 09:02 644一、安装前检查 1、内核版本 uname - ... -
6、java连接redis集群
2016-04-18 18:26 25851、使用Jedis 连接集群会报 MOVED错误 packag ... -
redis集群搭建
2016-04-18 16:15 552redis-cli -h 127.0.0.1 -p 6749 ... -
ubuntu14.04卸载redis并手动安装redis-3.0
2016-04-18 16:14 11221、ubuntu 卸载redis 1)卸载软件 ... -
redis五种数据类型常用基本命令总结
2016-04-14 19:00 717redis-cli 启动redis客户端,连接到redis服务 ... -
java连接远程服务器redis常遇问题
2016-04-14 18:58 32161、先在本地CMD命令中ping IP地址,网络是否正常 2、 ... -
redis虚拟机环境搭建与安装redis
2016-04-12 09:14 1747下载VMware 下载ubuntu14.iso 在VMware ... -
dubbo入门案例
2016-04-07 19:47 1171windows安装zookeeper 把下载的zookeepe ... -
spring mvc教程视频
2016-01-18 17:29 7771. 韩顺平 Spring视频教程 http://www.yu ... -
Redis与Memcached比较
2016-01-13 11:01 789作为内存数据缓冲 ... -
Redis原理与简述
2016-01-13 10:46 12627Redis是一个开源的key-value存储系统。 ... -
Redis配置文件参数
2016-01-13 09:55 7352.1 Redis配置文件 为了对Redis的系统实现有一个直 ...
相关推荐
这是一个webservice(Apache CXF) 简单案例
cxf 小案例 java webservice
第一天: 什么是webservice? 从案例(便民查询网站)分析如何实现? 使用socket实现。 使用jaxws开发webservice。 Webservice三要素 ... CXF发布rest的webservice。(重点) 综合案例: 实现便民查询网站
CXF搭建webservice案例,适合初学者
通过JDK+CXF结合开发一个简单的webservice学习案例,下载下来后需要自己修改发布的IP地址为自己的端口,然后发布,以及通过新的WSDL文件从新生成客户端代码才能实现客户端、服务端的交互
结合网上资源用cxf实现的webservice实例。 参考 http://blog.csdn.net/hu_shengyang/article/details/38384597
ssh框架整合cxf(webservice),ssh案例(增、删、改、查),发布webservice,客户端调用,该工程自带jar包,mysql连接池,自动建库、建表。 ①直接解压,导入ssh2cxf项目 ②用tomcat启动ssh2cxf项目 ③在浏览器输入...
CXF webservice 使用实例,CXF创建webservice以及调用示例;WEBSERVICE输入、输出拦截器设置;用户验证;文件上传等。附带所有使用到的JAR包。
WebService入门案例,使用CXF框架,与Spring进行整合,包括客户端工程和服务端工程。
cxf webservice能运行起来的简单案例,包括jar包都在里面。
该工程代码包含基于使用CXF框架开发的入门案例 和进阶案例(与Spring进行整合)
Spring是目前最流行的JavaEE Framework,但是使用Spring的Spring-WS开发WebService却...CXF是一个简化WebService开发的开源项目,通过Spring和CXF的结合可以大大简化基于Spring Framework的应用中的WebService开发。
基于maven的webservice例子,服务端发布和客户端调用代码,实现对mysql数据库表的curd操作
本书主要介绍Apache CXF在构建SOA架构各个方面的应用说明和编程案例。覆盖以下内容:基于JAX-WS规范和CXF自身的前端模式实现,CXF支持的数据绑定(DataBindings),CXF支持的WSDL绑定,CXF支持的传输协议绑定。CXF的...
完整的cxf-3.0.15webservice服务端jar包。包含使用案例。
这是一个cxf的webservice接口。 简单,可以直接用。 当时自己搭框架的时候,出现了各种问题,最后自己处理了一个。感觉还可以。 这是一个xml的处理项目。 可伸展性强