CXF bus interceptor配置
作用: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配置的更多相关文章
- CXF对Interceptor拦截器的支持
前面在Axis中介绍过Axis的Handler,这里CXF的Interceptor就和Handler的功能类似.在每个请求响应之前或响应之后,做一些事情.这里的Interceptor就和Filter. ...
- 在cxf中使用配置避免增加字段导致客户端必须更新、同步实体属性的问题
在使用cxf实现webservice时,经常碰到的问题就是如果在服务端,修改了一个接口的签名实现,如增加一个字段,或者删除一个字段.在这种情况下,在默认的配置中,就会报以下的错误信息: org.apa ...
- CXF Service Interceptor请求,响应报文之控制台输出
一:定义接口 @WebService(targetNamespace = "http://www.unionpay.com/client/appprovider", name = ...
- 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 ...
- spring cloud 系列第8篇 —— config+bus 分布式配置中心与配置热刷新 (F版本)
源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.config 简介 spring cloud config 分为服务端 ...
- spring cloud config 结合 spring cloud bus实现配置自定的刷新
在线上环境中,有时候我们希望系统中的某些配置参数在修改后,可以立即生效而不用重新启动服务.由上一节我们知道,我们可以把配置文件统一放到配置服务中进行管理,这一节我们在配置中心中整合spring clo ...
- Spring mvc interceptor配置拦截器,没有登录跳到登录页
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- CXF安装和配置时出现Exception in thread "main" java.lang.UnsupportedClassVersionError:异常?
异常信息: C:\Users\>wsdl2java -h Exception in thread "main" java.lang.UnsupportedClassVersi ...
- [转]Spring mvc interceptor配置拦截器,没有登录跳到登录页
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.s ...
随机推荐
- [Noi2016十连测第三场]线段树
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- WPF弹出取消确定框
MessageBoxResult dr = MessageBox.Show("是否在"+ConfigHelper.GetAppSetting("SourceDBName& ...
- CSS文件开头到底声明@charset "utf-8"
@charset "utf-8" 这个声明是告诉浏览器[我的CSS文件是UTF-8编码的],但实际上这个文件可以不用是UTF-8编码的,所以这个声明能达到欺骗浏览器的作用. 但实践 ...
- Spring mvc web 配置
Spring Framework本身没有Web功能, Spring MVC使用WebApplicationContext类扩展ApplicationContext ,使得拥有web功能.那么,Spri ...
- jQuery—选择器
摘抄自<锋利的jQuery> 一.基本选择器 $("#one").css("background","#bbffaa"); 选取 ...
- 【Alpha版本】 第五天 11.11
一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 周末+下周一要做任务 问题困难 心得体会 胡泽善 完成了账户信息修改界面 完成管理员的三大界面框架.完成管理 ...
- 【Alpha版本】 第九天 11.17
一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 完成我要应聘的详情显示,解决头像不能显示的问题,完成了报名及取消操 ...
- POJ - 2253 Frogger(Dijkstra变形题)
题意: 题目撰写者的英语真是艰难晦涩,看了别人题解,才知道这题题意. 两个forger 一个froger 要蹦到另外一个froger处,他们的最短距离是这样定义的 : The frog distanc ...
- PHP面向对象之朝花夕拾
虽然平时都在用面向对象的思维编程.但是都是基于框架,很多技术细节一段时间不用就会逐渐模糊.拾遗部分:面向对象的三大特称:继承多态封装. 构造方法.__construct() 构造方法.再new的时候 ...
- Docker入门教程(三)Dockerfile
Docker入门教程(三)Dockerfile [编者的话]DockerOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第三篇,介绍了Dockerfile的语法,DockerOn ...