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 ( 添加系统预定义的拦截器)的更多相关文章

  1. .NET中那些所谓的新语法之三:系统预定义委托与Lambda表达式

    开篇:在上一篇中,我们了解了匿名类.匿名方法与扩展方法等所谓的新语法,这一篇我们继续征程,看看系统预定义委托(Action/Func/Predicate)和超爱的Lambda表达式.为了方便码农们,. ...

  2. 系统预定义委托与Lambda表达式

    NET中那些所谓的新语法之三:系统预定义委托与Lambda表达式   开篇:在上一篇中,我们了解了匿名类.匿名方法与扩展方法等所谓的新语法,这一篇我们继续征程,看看系统预定义委托(Action/Fun ...

  3. 整理 - .Net系统预定义的委托们

    大部分情况下,我们可以使用系统预定义的委托类型,而不需要自己再来手动定义. 以下委托都位于System命名空间下. 传入参数.返回值的类型,大都被声明为泛型. 1.Action系列 有0-16个参数, ...

  4. SendMessage函数与MSDN系统预定义消息

    SendMessage function https://msdn.microsoft.com/en-us/library/windows/desktop/ms644950%28v=vs.85%29. ...

  5. WebService -- Java 实现之 CXF ( 使用:Spring+CXF+Tomcat发布webService)

    1. 新建一个Maven项目,选择webapp模板,命名为WS_Spring_CXF_Tomcat 2. 在POM.xml中添加Spring和CXF的依赖 <!-- 添加 Spring depe ...

  6. 系统开发中使用拦截器校验是否登录并使用MD5对用户登录密码进行加密

    项目名称:客户管理系统 项目描述: 项目基于javaEE平台,B/S模式开发.使用Struts2.Hibernate/Spring进行项目框架搭建.使用Struts中的Action 控制器进行用户访问 ...

  7. WebService -- Java 实现之 CXF ( 使用Spring添加拦截器)

    最重要的就是在ApplicationContext.xml下面添加配置 <!-- service provider --> <jaxws:endpoint implementor=& ...

  8. WebService -- Java 实现之 CXF ( 使用CXF工具生成client 程序)

    1. 下载CXF 工具解压到磁盘 2.添加工具bin目录到PATH环境变量 3.创建一个CXF client新项目 4. run -> cmd 到指定目录,并运行工具目录下的批处理 “wadl2 ...

  9. WebService -- Java 实现之 CXF (WebService 服务器端接口)

    1. 使用Maven创建一个quickstart项目 2. 引入依赖的Jar包 <dependency> <groupId>org.apache.cxf</groupId ...

随机推荐

  1. Redis集群(九):Redis Sharding集群Redis节点主从切换后客户端自动重新连接

    上文介绍了Redis Sharding集群的使用,点击阅读 本文介绍当某个Redis节点的Master节点发生问题,发生主从切换时,Jedis怎样自动重连新的Master节点 ​一.步骤如下: 1.配 ...

  2. javaMd5加密

    package com.md5Test; import java.security.MessageDigest; public class Md5Test { public void toMD5(St ...

  3. BZOJ 2424: [HAOI2010]订货

    2424: [HAOI2010]订货 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 915  Solved: 639[Submit][Status][ ...

  4. js修改伪类的值

    css文件 p.change:after { content: attr(data-content); } js文件 $(this).addClass('change').attr('data-con ...

  5. div内容溢出时显示滚动条

    在style中添加overflow:scroll属性即可.

  6. VPS服务商

    1.vpsee http://www.vpsee.com 2.vps侦探 http://www.vpser.net/

  7. php中trait(性状)与generator(生成器)

    PHP中trait(性状)与generator(生成器) 一.trait (性状) 最近在看Josh Lockhat的<Modern PHP>,这本书很薄.但是其中给出了一个很重要的学习方 ...

  8. ThinkPhp 3.2 数据的连贯操作

    ThinkPHP模型基础类提供的连贯操作方法(也有些框架称之为链式操作),可以有效的提高数据存取的代码清晰度和开发效率,并且支持所有的CURD操作. 使用也比较简单, 假如我们现在要查询一个User表 ...

  9. excellent cushioning and also vitality go back with this boot

    The particular manufactured fine mesh higher almost addresses the complete boot. Here is the sort of ...

  10. centos 查看脚本

    centos 查看脚本 #!/bin/bash date >>info.txt echo "本机centos版本为" >>info.txt cat /etc ...