作用: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. 【USACO 1.5】SuperPrime Rib

    /* TASK: sprime LANG: C++ SOLVE: dfs,后面每增加一位,判断当前是否为素数. 第一位不能为0 */ #include<cstdio> int n; voi ...

  2. 【BZOJ-1952】城市规划 [坑题] 仙人掌DP + 最大点权独立集(改)

    1952: [Sdoi2010]城市规划 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 23[Submit][Status][ ...

  3. spring-HelloWorld

    准备工作,安装SpringIDE,找到SpringSource-tool-suit,然后按照, 关键的一部在与找到之后该安转那些呢,答案是只安转带有SpringIDE的, 有四个,且不要点击联网进行更 ...

  4. 【poj3122】 Pie

    http://poj.org/problem?id=3122 (题目链接) 题意 给出N个pie的半径和F个friend,每个friend得到的pie必须一样,求每个人能得到的pie的最大大小. so ...

  5. bzoj1102: [POI2007]山峰和山谷Grz

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  6. Linux的#和$区别

    [#]代表 root权限[$]代表普通用户 如果更改了/etc/profile , 或~/.bashrc等文档,可以用任何符号来代替它们. linux窗口下的[root@locate~]其中的[~]代 ...

  7. asp.net项目发布打包研究

    有几种思路: 1.[推荐]直接发布,然后手动打包成压缩包,需要的时候直接上传到服务器,或者在本地解压出来手动上传到虚拟空间(支持绝大多数的虚拟空间,自由度高,DZ也是采用这样的打包,FTP上传操作比较 ...

  8. ListView的使用-模拟微博随便看看栏目【执行与优化】

    今天我们来讲述一下如何使用ListView来模仿微博随便看看栏目(ps:这是老师布置的作业,所以…),在前篇博客中,我们讲述了细解ListView之自定义适配器的使用,所以本篇我们不以特别详细的讲述( ...

  9. 移动端web app自适应布局探索与总结

    要掌握的知识点: iphone6 屏幕尺寸为 375*667 (pt)也就是 网页 全屏显示时候 document.documentElement.clientWidth------可以理解为屏幕越大 ...

  10. Servlet —— 避免Servlet的并发同步问题

    Servlet的生命周期是由Servlet容器来负责的. Servlet容器通常采用单实例多线程的方式,减少Servlet创建实例的开销,提高效率. 当客户端第一次请求某个Servlet时,Servl ...