作用:BUS是cxf的支架,它主要担当扩展及拦截器提供者的角色。

在这里主要讲讲 bus的interceptor的功能

目前配置cxf的interceptor主要有2中方法:

1、通过xml配置文件的方法,使用<cxf:bus>
2、通过在java代码中使用编码的方式来添加拦截器

下面来看2个例子

1 配置文件方式配置 cxf bus interceptor

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> <cxf:bus>
<cxf:outInterceptors>
<ref bean="logOutbound"/>
</cxf:outInterceptors>
</cxf:bus>
</beans>

注意:在使用<cxf:bus>时候,一定要引入 命名空间xmlns:cxf=http://cxf.apache.org/core,及其对应的模式http://cxf.apache.org/schemas/core.xsd
2、java代码硬编码方式添加拦截器

在服务端添加拦截

import javax.xml.ws.Endpoint;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.EndpointImpl; Object implementor = new GreeterImpl();
EndpointImpl ep = (EndpointImpl) Endpoint.publish("http://localhost/service", implementor); ep.getServiceFactory().getBus().getInInterceptors().add(new LoggingInInterceptor());
ep.getServiceFactory().getBus().getOutInterceptors().add(new LoggingOutInterceptor());

在客户端添加拦截

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor; public class WSClient {
public static void main (String[] args) {
MyService ws = new MyService();
MyPortType port = ws.getPort(); Client client = ClientProxy.getClient(port);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());

另外在java代码中也可以通过使用注解的方式添加拦截器

在SEI及SEI的实现类中添加注解有着不同的含义,若在SEI中添加拦截器注解,则表示其会在client及server端都起作用,若在SEI的实现类中添加注解,则只会在server端起作用,例子:

SEI 实现类

@javax.jws.WebService(portName = "MyWebServicePort", serviceName = "MyWebService", ...)
@Features(features = "org.apache.cxf.feature.LoggingFeature")
public class MyWebServicePortTypeImpl implements MyWebServicePortType {

效果等同于如下代码

import org.apache.cxf.interceptor.InInterceptors;
import org.apache.cxf.interceptor.OutInterceptors; @javax.jws.WebService(portName = "WebServicePort", serviceName = "WebServiceService", ...)
@InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor")
@OutInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingOutInterceptor")
public class WebServicePortTypeImpl implements WebServicePortType {

CXF bus interceptor配置的更多相关文章

  1. CXF对Interceptor拦截器的支持

    前面在Axis中介绍过Axis的Handler,这里CXF的Interceptor就和Handler的功能类似.在每个请求响应之前或响应之后,做一些事情.这里的Interceptor就和Filter. ...

  2. 在cxf中使用配置避免增加字段导致客户端必须更新、同步实体属性的问题

    在使用cxf实现webservice时,经常碰到的问题就是如果在服务端,修改了一个接口的签名实现,如增加一个字段,或者删除一个字段.在这种情况下,在默认的配置中,就会报以下的错误信息: org.apa ...

  3. CXF Service Interceptor请求,响应报文之控制台输出

    一:定义接口 @WebService(targetNamespace = "http://www.unionpay.com/client/appprovider", name = ...

  4. cxf之Exception in thread "main" java.lang.NoSuchMethodError: org.apache.cxf.jaxrs.provider.ProviderFactory.<init>(Lorg/apache/cxf/Bus;)V

    pom.xml中关于cxf的配置jar包冲突??? 1.http://blog.csdn.net/yzl_8877/article/details/53216923 2.https://www.cnb ...

  5. spring cloud 系列第8篇 —— config+bus 分布式配置中心与配置热刷新 (F版本)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.config 简介 spring cloud config 分为服务端 ...

  6. spring cloud config 结合 spring cloud bus实现配置自定的刷新

    在线上环境中,有时候我们希望系统中的某些配置参数在修改后,可以立即生效而不用重新启动服务.由上一节我们知道,我们可以把配置文件统一放到配置服务中进行管理,这一节我们在配置中心中整合spring clo ...

  7. Spring mvc interceptor配置拦截器,没有登录跳到登录页

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. CXF安装和配置时出现Exception in thread "main" java.lang.UnsupportedClassVersionError:异常?

    异常信息: C:\Users\>wsdl2java -h Exception in thread "main" java.lang.UnsupportedClassVersi ...

  9. [转]Spring mvc interceptor配置拦截器,没有登录跳到登录页

    <?xml  version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.s ...

随机推荐

  1. PL/SQL Developer连接本地64位Oracle数据库

    1.安装oracle Clinet 首先到Oracle官网上去下载一个Oracle 11g Client(我的是11g的oracle),不过需要先申请一个Oracle 帐号,才能下载. 目前下载地址: ...

  2. ml的线性回归应用(python语言)

    线性回归的模型是:y=theta0*x+theta1   其中theta0,theta1是我们希望得到的系数和截距. 下面是代码实例: 1. 用自定义数据来看看格式: # -*- coding:utf ...

  3. Android热身:通过网络获取资源并更新UI组件

    Android热身:通过网络获取资源并更新UI组件 目标 点击"发送请求"按钮,下载某网页的html源码,并显示在TextView控件上:点击"清空",清除Te ...

  4. 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1573   ...

  5. Hadoop设置环境变量注意事项

    路径是/etc/profile. 这个东西不能再普通下设置,打开是彩色的,即便是“:wq!”也不能保存,必须去root下,黑白的. 然后root下source /etc/profile,然后exit, ...

  6. SQLServer2012自增列值跳跃的问题

    2012引入的新特性,重启之后会出现值跳跃的问题,如: 解决的方案: 1.使用序列(Sequence),2012引入的和Oracle一样的特性. 2.更改SQLServer启动服务的启动参数,增加[- ...

  7. hdu 5017 模拟退火

    题意:给出椭球面的立体解析式,要求椭球面上距离原点最近的点的距离 sol:这题要想推公式就

  8. HC-05初探

    catalogue . 蓝牙嗅探抓包 . HC05蓝牙模块AT模式设置 . USB转串口芯片CH340 . 蓝牙小车 1. 蓝牙嗅探抓包 针对蓝牙通信包的嗅探抓包不能直接使用wincap+wiresh ...

  9. bash的配置

    Bash的启动文件 启动文件也是一种脚本,不过它是在Bash在启动之初就执行它的.不同的启动方式使用的启动文件也有不同. 1. 作为交互的登录脚本环境“交互的”是指你可以再这个环境下输入命令.而所谓的 ...

  10. jQuery—选择器

    摘抄自<锋利的jQuery> 一.基本选择器 $("#one").css("background","#bbffaa"); 选取 ...