CXF之五 拦截器Interceptor
拦截器(Interceptor)是CXF功能最主要的扩展点,可以在不对核心模块进行修改的情况下,动态添加很多功能。拦截器和JAX-WS Handler、Filter的功能类似,当服务被调用时,就会创建一个拦截器链(Interceptor Chain),拦截器链在服务输入(IN)或输出(OUT)阶段实现附加功能。
拦截器可以在客户端,也可以在服务端添加。当客户端发起一个WebService请求时,在客户端会创建输出拦截器链,服务端接收到客户端的后,会创建输入拦截器链。当服务端返回响应消息时,响应消息会经过服务端的输出拦截链,客户端接收到服务端的响应时,会创建输入拦截器链,响应消息先经过输入拦截器链处理。拦截器在服务端和客户端的作用如图所示。
拦截器链阶段
拦截器链有多个阶段,每个阶段都有多个拦截器。拦截器在拦截器链的哪个阶段起作用,可以在拦截器的构造函数中声明。
输入拦截器链有如下几个阶段,这些阶段按照在拦截器链中的先后顺序排列。
| 阶段名称 | 阶段功能描述 |
|---|---|
| RECEIVE | Transport level processing(接收阶段,传输层处理) |
| (PRE/USER/POST)_STREAM | Stream level processing/transformations(流处理/转换阶段) |
| READ | This is where header reading typically occurs(SOAPHeader读取) |
| (PRE/USER/POST)_PROTOCOL | Protocol processing, such as JAX-WS SOAP handlers(协议处理阶段,例如JAX-WS的Handler处理) |
| UNMARSHAL | Unmarshalling of the request(SOAP请求解码阶段) |
| (PRE/USER/POST)_LOGICAL | Processing of the umarshalled request(SOAP请求解码处理阶段) |
| PRE_INVOKE | Pre invocation actions(调用业务处理之前进入该阶段) |
| INVOKE | Invocation of the service(调用业务阶段) |
| POST_INVOKE | Invocation of the outgoing chain if there is one(提交业务处理结果,并触发输入连接器) |
输出拦截器链有如下几个阶段,这些阶段按照在拦截器链中的先后顺序排列。
| 阶段名称 | 阶段功能描述 |
|---|---|
| SETUP | Any set up for the following phases(设置阶段) |
| (PRE/USER/POST)_LOGICAL | Processing of objects about to marshalled |
| PREPARE_SEND | Opening of the connection(消息发送准备阶段,在该阶段创建Connection) |
| PRE_STREAM | 流准备阶段 |
| PRE_PROTOCOL | Misc protocol actions(协议准备阶段) |
| WRITE | Writing of the protocol message, such as the SOAP Envelope.(写消息阶段) |
| MARSHAL | Marshalling of the objects |
| (USER/POST)_PROTOCOL | Processing of the protocol message |
| (USER/POST)_STREAM | Processing of the byte level message(字节处理阶段,在该阶段把消息转为字节) |
| SEND | 消息发送 |
在输出拦截器链的SEND阶段后,还会触发以_ENDING结尾阶段,这些ENDING阶段与以上阶段对应,主要用于清理或者关闭资源。ENDING阶段触发的顺序如下:
- SEND_ENDING
- POST_STREAM_ENDING
- USER_STREAM_ENDING
- POST_PROTOCOL_ENDING
- USER_PROTOCOL_ENDING
- MARSHAL_ENDING
- WRITE_ENDING
- PRE_PROTOCOL_ENDING
- PRE_STREAM_ENDING
- PREPARE_SEND_ENDING
- POST_LOGICAL_ENDING
- USER_LOGICAL_ENDING
- PRE_LOGICAL_ENDING
- SETUP_ENDING
CXF默认拦截器链
在CXF中,所有对消息的处理都是通过各种拦截器实现。CXF已经实现了多种拦截器,如操纵消息头、执行认证检查、验证消息数据、日志记录、消息压缩等,有些拦截器在发布服务、访问服务时已经默认添加到拦截器链。
CXF默认输入拦截器链,如果没有添加额外的拦截器,CXF输入会顺序经过以下拦截器:
| 拦截器名称 | 拦截器功能 |
|---|---|
| AttachmentInInterceptor | Parse the mime headers for mime boundaries, finds the “root” part and resets the input stream to it, and stores the other parts in a collection of Attachments |
| StaxInInterceptor | Creates an XMLStreamReader from the transport InputStream on the Message |
| ReadHeadersInterceptor | Parses the SOAP headers and stores them on the Message |
| SoapActionInInterceptor | Parses “soapaction” header and looks up the operation if a unique operation can be found for that action. |
| MustUnderstandInterceptor | Checks the MustUnderstand headers, its applicability and process it, if required |
| SOAPHandlerInterceptor | SOAP Handler as per JAX-WS |
| LogicalHandlerInInterceptor | Logical Handler as per JAX-WS |
| CheckFaultInterceptor | Checks for fault, if present aborts interceptor chain and invokes fault handler chain |
| URIMappingInterceptor | Can handle HTTP GET, extracts operation info and sets the same in the Message |
| DocLiteralnInterceptor | Examines the first element in the SOAP body to determine the appropriate Operation (if soapAction did not find one) and calls the Databinding to read in the data. |
| SoapHeaderInterceptor | Perform databinding of the SOAP headers for headers that are mapped to parameters |
| WrapperClassInInterceptor | For wrapped doc/lit, the DocLiteralInInterceptor probably read in a single JAXB bean. This interceptor pulls the individual parts out of that bean to construct the Object[] needed to invoke the service. |
| SwAInInterceptor | For Soap w/ Attachments, finds the appropriate attachments and assigns them to the correct spot in the parameter list. |
| HolderInInterceptor | For OUT and IN/OUT parameters, JAX-WS needs to create Holder objects. This interceptor creates the Holders and puts them in the parameter list. |
| ServiceInvokerInInterceptor | Actually invokes the service. |
CXF默认输出拦截器链,如果没有添加额外的拦截器,CXF输入会顺序经过以下拦截器:
| 拦截器名称 | 拦截器功能 |
|---|---|
| HolderOutInterceptor | For OUT and IN/OUT params, pulls the values out of the JAX-WS Holder objects (created in HolderInInterceptor) and adds them to the param list for the out message. |
| SwAOutInterceptor | For OUT parts that are Soap attachments, pulls them from the list and holds them for later. |
| WrapperClassOutInterceptor | For doc/lit wrapped, takes the remaining parts and creates a wrapper JAXB bean to represent the whole message. |
| SoapHeaderOutFilterInterceptor | Removes inbound marked headers |
| SoapActionOutInterceptor | Sets the SOAP Action |
| MessageSenderInterceptor | Calls back to the Destination object to have it setup the output streams, headers, etc… to prepare the outgoing transport. |
| SoapPreProtocolOutInterceptor | This interceptor is responsible for setting up the SOAP version and header, so that this is available to any pre-protocol interceptors that require these to be available. |
| AttachmentOutInterceptor | If this service uses attachments (either SwA or if MTOM is enabled), it sets up the Attachment marshallers and the mime stuff that is needed. |
| StaxOutInterceptor | Creates an XMLStreamWriter from the OutputStream on the Message. |
| SoapHandlerInterceptor | JAX-WS SOAPHandler |
| SoapOutInterceptor | Writes start element for soap:envelope and complete elements for other header blocks in the message. Adds start element for soap:body too. |
| LogicalHandlerOutInterceptor | JAX-WS Logical handler stuff |
| WrapperOutInterceptor | If wrapped doc/lit and not using a wrapper bean or if RPC lit, outputs the wrapper element to the stream. |
| BareOutInterceptor | Uses the databinding to write the params out. |
| SoapOutInterceptor$SoapOutEndingInterceptor | Closes the soap:body and soap:envelope |
| StaxOutInterceptor$StaxOutEndingInterceptor | Flushes the stax stream. |
| MessageSenderInt$MessageSenderEnding | Closes the exchange, lets the transport know everything is done and should be flushed to the client. |
CXF之五 拦截器Interceptor的更多相关文章
- 【CXF】- 拦截器 Interceptor
CXF拦截器 拦截动态操作请求和响应数据 拦截器分类 位置:服务器端拦截器,客户端拦截器 消息方向:入拦截器 出拦截器 定义者:系统拦截器 自定义拦截器:LoggingInInteceptor ①:创 ...
- CXF实战之拦截器Interceptor(四)
拦截器(Interceptor)是CXF功能最基本的扩展点,能够在不正确核心模块进行改动的情况下.动态加入非常多功能.拦截器和JAX-WS Handler.Filter的功能相似,当服务被调用时.就会 ...
- 【WebService】WebService之CXF的拦截器(五)
CXF拦截器介绍 CXF拦截器是功能的主要实现单元,也是主要的扩展点,可以在不对核心模块进行修改的情况下,动态添加功能.当服务被调用时,会经过多个拦截器链(Interceptor Chain)处理,拦 ...
- WebService学习总结(五)--CXF的拦截器
拦截器是Cxf的基础,Cxf中很多的功能都是由内置的拦截器来实现的,拦截器在Cxf中由Interceptor表示.拦截器的作用类似axis2中handle.Cxf的拦截器包括入拦截器和出拦截器,所有的 ...
- struts2学习笔记--拦截器(Interceptor)和登录权限验证Demo
理解 Interceptor拦截器类似于我们学过的过滤器,是可以在action执行前后执行的代码.是我们做web开发是经常使用的技术,比如权限控制,日志.我们也可以把多个interceptor连在一起 ...
- struts2拦截器interceptor的三种配置方法
1.struts2拦截器interceptor的三种配置方法 方法1. 普通配置法 <struts> <package name="struts2" extend ...
- SSM-SpringMVC-33:SpringMVC中拦截器Interceptor讲解
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 拦截器Interceptor: 对处理方法进行双向的拦截,可以对其做日志记录等 我选择的是实现Handler ...
- 过滤器(Filter)和拦截器(Interceptor)
过滤器(Filter) Servlet中的过滤器Filter是实现了javax.servlet.Filter接口的服务器端程序.它依赖于servlet容器,在实现上,基于函数回调,它可以对几乎所有请求 ...
- 二十五、过滤器Filter,监听器Listener,拦截器Interceptor的区别
1.Servlet:运行在服务器上可以动态生成web页面.servlet的声明周期从被装入到web服务器内存,到服务器关闭结束.一般启动web服务器时会加载servelt的实例进行装入,然后初始化工作 ...
随机推荐
- Ubuntu环境下手动配置ant
配置ant 1. 下载ant(http://ant.apache.org/bindownload.cgi) 例如我下载的是:apache-ant-1.9.4-bin.tar.gz 解压ant,将文件夹 ...
- hdu 4038 Stone
思路: 如果负数的个数为偶数则不必改变,为奇数就将最大负数变为正: 对于正数,尽量将1,2变为3即可. 代码如下: #include<cstring> #include<iostre ...
- hdu 1812 Count the Tetris
高精度+polya原理可以搞定 思路: 设边长为n的正方形,c种颜色.旋转只有 0,90,180,270度三种旋法.旋0度,则置换的轮换数为n*n旋90度,n为偶数时,则置换的轮换数为n*n/4,n为 ...
- linux设置和查看环境变量的方法
1. 显示环境变量HOME $ echo $HOME /home/redbooks 2. 设置一个新的环境变量hello $ export HELLO="Hello!" ...
- ubuntu 13.10 64bit装BeyondCompare
1. Beyond Compare官网下载amd-64位的,安装失败,依赖于ia32-libs,但是这个文件已经不在源里了: 2. 官网下载tar.gz源码包,解压安装失败: 3. 直接装32位的,可 ...
- 【零基础学习iOS开发】【02-C语言】05-进制
上一讲简单介绍了常量和变量,这讲补充一点计算机的基础知识---进制. 我们先来看看平时是如何表示一个整数的,最常见的肯定是用阿拉伯数字表示,比如“十二”,我们可以用12来表示,其实这种表示方式是基于一 ...
- 李洪强iOS开发之OC[015]#pragma mark的使用
// // main.m // 14 - #pragma mark的使用 // // Created by vic fan on 16/7/10. // Copyright © 2016年 李 ...
- C++:用成员初始化列表对数据成员初始化
1.在声明类时,对数据成员的初始化工作一般在构造函数中用赋值语句进行. 例如: class Complex{ private: double real; double imag; public: Co ...
- LA 6047 Perfect Matching 字符串哈希
一开始我用的Trie+计数,但是不是计多了就是计少了,后来暴力暴过去的…… 看了别人的代码知道是字符串哈希,但是仍有几个地方不理解: 1.26^500溢出问题 2.没考虑哈希碰撞? 跪求指点! #in ...
- 数组 寻找最大的第k个数
int Partion(int asy[],int begin,int end) { int k=begin; int key=asy[end]; for(int i=begin;i<=end; ...