WebService -- Java 实现之 CXF ( 添加系统预定义的拦截器)
1. 概述
CXF允许我们在webservice的in/out位置添加拦截器。拦截器有两大分类,一类是系统预定义的;另一类是自定义拦截器。
2. 在server端添加拦截器。
JaxWsServerFactoryBean wsSvrFactoryBean = new JaxWsServerFactoryBean();
String address = "http://127.0.0.1/helloWorld";
wsSvrFactoryBean.setAddress(address);
wsSvrFactoryBean.setServiceClass(HelloWorld.class);
HelloWorld implementor = new HelloWorldImpl();
wsSvrFactoryBean.setServiceBean(implementor);
// add in out logging Interceptors
wsSvrFactoryBean.getInInterceptors().add(new LoggingInInterceptor());
wsSvrFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor());
wsSvrFactoryBean.create();
3. 在client端添加拦截器。
3.1 在client项目中添加CXF引用
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.1.5</version>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.5</version>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.1.5</version>
</dependency>
</dependencies>
3.2 使用ClientProxy对象添加拦截器
HelloWorld helloWorldClient = new HelloWorldService().getHelloWorldPort();
// add on inteceptors
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(helloWorldClient);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
4. client/server output information
--client--
十二月 30, 2016 11:25:45 下午 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
信息: Creating Service {http://webservice.tuo.example.com/}HelloWorldService from WSDL: http://127.0.0.1/helloWorld?wsdl
十二月 30, 2016 11:25:46 下午 org.apache.cxf.services.HelloWorldService.HelloWorldPort.HelloWorld
信息: Outbound Message
---------------------------
ID: 1
Address: http://127.0.0.1/helloWorld
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml
Headers: {Accept=[*/*], SOAPAction=[""]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHello xmlns:ns2="http://webservice.tuo.example.com/"><arg0>Tony</arg0></ns2:sayHello></soap:Body></soap:Envelope>
--------------------------------------
十二月 30, 2016 11:25:47 下午 org.apache.cxf.services.HelloWorldService.HelloWorldPort.HelloWorld
信息: Inbound Message
----------------------------
ID: 1
Response-Code: 200
Encoding: UTF-8
Content-Type: text/xml; charset=UTF-8
Headers: {content-type=[text/xml; charset=UTF-8], Date=[Fri, 30 Dec 2016 15:25:46 GMT], Server=[Jetty(9.2.11.v20150529)], transfer-encoding=[chunked]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHelloResponse xmlns:ns2="http://webservice.tuo.example.com/"><return>Hello world,Tony</return></ns2:sayHelloResponse></soap:Body></soap:Envelope>
--------------------------------------
Hello world,Tony
--server--
信息: Inbound Message
----------------------------
ID: 1
Address: http://127.0.0.1/helloWorld?wsdl
Http-Method: GET
Content-Type: text/xml
Headers: {Accept=[*/*], Cache-Control=[no-cache], connection=[keep-alive], content-type=[text/xml], Host=[127.0.0.1], Pragma=[no-cache], User-Agent=[Apache CXF 3.1.5]}
--------------------------------------
十二月 30, 2016 11:25:46 下午 org.apache.cxf.services.HelloWorldService.HelloWorldPort.HelloWorld
信息: Inbound Message
----------------------------
ID: 2
Address: http://127.0.0.1/helloWorld
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=UTF-8
Headers: {Accept=[*/*], Cache-Control=[no-cache], connection=[keep-alive], Content-Length=[202], content-type=[text/xml; charset=UTF-8], Host=[127.0.0.1], Pragma=[no-cache], SOAPAction=[""], User-Agent=[Apache CXF 3.1.5]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHello xmlns:ns2="http://webservice.tuo.example.com/"><arg0>Tony</arg0></ns2:sayHello></soap:Body></soap:Envelope>
--------------------------------------
十二月 30, 2016 11:25:47 下午 org.apache.cxf.services.HelloWorldService.HelloWorldPort.HelloWorld
信息: Outbound Message
---------------------------
ID: 2
Response-Code: 200
Encoding: UTF-8
Content-Type: text/xml
Headers: {}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHelloResponse xmlns:ns2="http://webservice.tuo.example.com/"><return>Hello world,Tony</return></ns2:sayHelloResponse></soap:Body></soap:Envelope>
--------------------------------------
WebService -- Java 实现之 CXF ( 添加系统预定义的拦截器)的更多相关文章
- .NET中那些所谓的新语法之三:系统预定义委托与Lambda表达式
开篇:在上一篇中,我们了解了匿名类.匿名方法与扩展方法等所谓的新语法,这一篇我们继续征程,看看系统预定义委托(Action/Func/Predicate)和超爱的Lambda表达式.为了方便码农们,. ...
- 系统预定义委托与Lambda表达式
NET中那些所谓的新语法之三:系统预定义委托与Lambda表达式 开篇:在上一篇中,我们了解了匿名类.匿名方法与扩展方法等所谓的新语法,这一篇我们继续征程,看看系统预定义委托(Action/Fun ...
- 整理 - .Net系统预定义的委托们
大部分情况下,我们可以使用系统预定义的委托类型,而不需要自己再来手动定义. 以下委托都位于System命名空间下. 传入参数.返回值的类型,大都被声明为泛型. 1.Action系列 有0-16个参数, ...
- SendMessage函数与MSDN系统预定义消息
SendMessage function https://msdn.microsoft.com/en-us/library/windows/desktop/ms644950%28v=vs.85%29. ...
- WebService -- Java 实现之 CXF ( 使用:Spring+CXF+Tomcat发布webService)
1. 新建一个Maven项目,选择webapp模板,命名为WS_Spring_CXF_Tomcat 2. 在POM.xml中添加Spring和CXF的依赖 <!-- 添加 Spring depe ...
- 系统开发中使用拦截器校验是否登录并使用MD5对用户登录密码进行加密
项目名称:客户管理系统 项目描述: 项目基于javaEE平台,B/S模式开发.使用Struts2.Hibernate/Spring进行项目框架搭建.使用Struts中的Action 控制器进行用户访问 ...
- WebService -- Java 实现之 CXF ( 使用Spring添加拦截器)
最重要的就是在ApplicationContext.xml下面添加配置 <!-- service provider --> <jaxws:endpoint implementor=& ...
- WebService -- Java 实现之 CXF ( 使用CXF工具生成client 程序)
1. 下载CXF 工具解压到磁盘 2.添加工具bin目录到PATH环境变量 3.创建一个CXF client新项目 4. run -> cmd 到指定目录,并运行工具目录下的批处理 “wadl2 ...
- WebService -- Java 实现之 CXF (WebService 服务器端接口)
1. 使用Maven创建一个quickstart项目 2. 引入依赖的Jar包 <dependency> <groupId>org.apache.cxf</groupId ...
随机推荐
- 使用UITableView展示数据
TableView主要用于展示数据,类似于Android中的ListView. 我们可以通过两个方式使用TableView.第一种是直接使用TableView类.第二种是通过UITableViewCo ...
- python基础-异常处理
一.错误和异常 程序中难免出现错误,而错误分成两种 1.1.语法错误(这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正) #语法错误示范一 if #语法错误示范二 def te ...
- C++ 数组array与vector的比较
转:http://blog.csdn.net/yukin_xue/article/details/7391897 1. array 定义的时候必须定义数组的元素个数;而vector 不需要: 且只能包 ...
- Java的修饰符
转自:http://blog.csdn.net/manyizilin/article/details/51926230#L42 修饰符: 像其他语言一样,Java可以使用修饰符来修饰类中方法和属性.主 ...
- c# 读取mck码
private List<string> GetMac() { List<string> macs = new List<string>(); try { var ...
- 漫谈C++:良好的编程习惯与编程要点
以良好的方式编写C++ class 假设现在我们要实现一个复数类complex,在类的实现过程中探索良好的编程习惯. ① Header(头文件)中的防卫式声明 complex.h: # ifndef ...
- iOS10权限设置问题以及xcdoe8更新细节问题
<key>NSVideoSubscriberAccountUsageDescription</key> <string></string> <ke ...
- java 的public private protected作用域
- UVA1368
用一个二维数组装m个字符串,然后用一个数组装每个字符串的hamming距离.找到最小的hanming距离即可 #include<stdio.h> #include<string.h& ...
- SWMM模型子汇水区划分的几种方法
子汇水区的划分是SWMM模型建模的主要步骤之一,划分的好坏对结果精度有比较大的影响.概括来讲,子汇水区的划分有以下几种思路: (1)根据管网走向.建筑物和街道分布,直接人工划分子汇水区.这个方法适用于 ...