cxf jax-rs client 笔记
来源:互联网 发布:杨百万炒股软件 编辑:程序博客网 时间:2024/05/16 17:03
参考:http://cxf.apache.org/docs/jax-rs-client-api.html
第一步:
根据WS服务端提供的信息 编写一个Service接口
例如:
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import com.dotwconnect.us.xsd.getallcountries.Customer;
- import com.dotwconnect.us.xsd.getallcountries_response.ResultType;
- @Path("/gateway.dotw")
- public interface CountriesService {
- @POST
- ResultType getAllCountries(Customer customer);
- }
第二步:
通过JAXRSClientFactory 工厂对象创建Service
- CountriesService cs = JAXRSClientFactory.create("http://localhost:8888",
- CountriesService.class);
- Customer c = new Customer() ; //请求参数
- ResultType xxx = cs.getAllCountries(c); //访问WS
注释:
发送出去的XML消息,如果要去掉namespace 信息 ,可以将生成的客户端对象中的package-info对象中的@XmlSchema注解中的 namespace 属性删掉。
如果返回过来的xml消息。节点名称与我们类名不符合。
如:返回过来的消息为
<result>…</result>
但是我们生成的类名为 ResultType 。
那么使用JAXb Unmarshaller 的时候,就有问题 。解决办法就是给ResultType加上一个@XmlRootElement(name="result")注解
在Spring中配置
在项目中加入jaxrs-https.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:jaxrs="http://cxf.apache.org/jaxrs"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
- <jaxrs:client id="countriesClient"
- serviceClass="com.zf.service.CountriesService"
- address="http://localhost:8888"
- inheritHeaders="true">
- <jaxrs:headers>
- <entry key="Accept" value="text/xml" />
- </jaxrs:headers>
- </jaxrs:client>
- </beans>
然后就可以通过下面的方式获取服务接口了
- ApplicationContext cxt = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","jaxrs-https.xml"});
- CountriesService countriesService = (CountriesService)cxt.getBean("countriesClient");
0 0
- cxf jax-rs client 笔记。
- cxf jax-rs client 笔记
- cxf jax-rs spring client
- CXF JAX-RS is causing BusException
- 基于CXF的JAX-WS、JAX-RS(RESTful)的webService
- 基于CXF的JAX-WS、JAX-RS(RESTful)的webService
- 基于CXF的JAX-WS、JAX-RS(RESTful)的webService
- jws jax-ws jax-rs jaxb cxf axis2 关系
- jws jax-ws jax-rs jaxb cxf axis2 关系
- 基于CXF的JAX-WS、JAX-RS(RESTful)的webService
- JAX-RS入门,学习笔记
- 使用cxf 发布 jax-rs 风格webservice 。并客户端测试。
- CXF+Maven+Eclipse开发基于jax-rs规范的WebService
- 比较各JAX-RS实现:Jersey,Restlet,CXF,RESTEasy
- REST,JAX-RS与Jersey,CXF,RESTEasy之间的关系
- 使用cxf、JAX-RS编写restful风格的webservice
- JAX-RS
- JAX-RS
- mom”透明座椅 鼓励儿童动手收纳
- @Override覆盖不了spring-web.jar中的方法
- 设计模式学习书推荐
- leetcode 8. String to Integer (atoi)
- 多层次资本市场
- cxf jax-rs client 笔记
- 2.7-1 Android Studio 相关的配置信息,未整理
- Android使用java的Math.Random获取随机色值
- 快速掌握Lua 5.3 —— "table"库
- UML--状态图、活动图
- svn checkout单个文件(refers to a file, not a directory)
- 【SPOJ-MIFF】Matrix inverse【高斯消元】
- 动态加载JavaScript文件
- mysql创建函数示例