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 ...
随机推荐
- ServerSocket的介绍
导语 仅仅只有Socket类是不足以编写服务器的.要创建一个Socket,你需要知道希望连接哪个Internet主机.编写服务器程序时,无法预先了解哪个主机会联系你,即使确实知道,你也不清楚那个主机希 ...
- Dubbo_异常_Service启动时默认将方法注册到内网IP
一.背景 一般Dubbo服务都是通过内网调用,Dubbo服务启动时默认会将服务注册到内网IP,消费端就无法从外网访问. 二.解决过程 1.Linux的hosts中设置外网IP a) 通过hostnam ...
- oracle--游标--bai
--复制表 create table emp as(select * from scott.emp); select * from emp; --(1) 最简单的游标 declare --声明并初始化 ...
- 微软unity 注入mvc
首先获取开源unity ,引用, 新建UnityDependencyResolver 继承IDependencyResolver,代码如下: public class UnityDependencyR ...
- jquery 返回顶部 兼容web移动
返回顶部图片 http://hovertree.com/texiao/mobile/6/tophovertree.gif 具体实现代码 <span id="tophovertree&q ...
- 第四章 --- 关于Javascript 设计模式 之 迭代器模式
今天我先写 两个常用的迭代器的 例子.(同学们先自行体会这二种迭代器的优缺点) 需求:比较两个数组是否相等 tips: 当数组的下标不为数字的时候,默认为 该键值对 为 对象. 然后迭代器的原理基本来 ...
- js删除数组指定元素
删除js数组中制定的元素,这里用到了jquery. var a = new Array("a","b","cc","d3" ...
- 关于Window Server2008 服务器上无法播放音频文件的解决方案
在偌大的百度当中查找我所需要的资源信息,但网络上所描述的都不能解决,发生此类问题的人很多,但是都没有得到准确的解决方法!经个人各方面的尝试,其实非常简单的解决了无法播放音频文件的问题,如果各位今后也遇 ...
- Autoit3 获取WinForm下的ToolTip
相比Autohotkey,在我看来,Autoit最实用的就是对于WinForm Application的良好支持 然而,要想将鼠标放在WinForm的ToolTip上,简直无异于自己把自己举起来,故而 ...
- Linux中检索文件
1 , Use locate command It is a fast way to find the files location, but if a file just created ,it w ...