Apache CXF Interceptors

Apache CXF provides many built-in Interceptors that provide core services to the message that is being exchanged between consumer and service endpoint. These interceptors do the work of marshalling and unmarshalling, manipulating message headers, performing authorization checks, validating the message data, and so on. You can also create your own Interceptors which are able to process incoming and outgoing messages. However before that, you need to learn how Interceptors work: Interceptors are invoked in chain and organized in phases. When a CXF client invokes a CXF server, there is an outgoing interceptor chain for the client and an incoming chain for the server. When the server sends the response back to the client, there is an outgoing chain for the server and an incoming one for the client. Additionally, in the case of SOAPFaults, a CXF web service will create a separate outbound error handling chain and the client will create an inbound error handling chain.



 

Writing an interceptor is relatively simple. Your interceptor needs to extend from either the AbstractPhaseInterceptor or one of its many subclasses such as AbstractSoapInterceptor.

1. public class MyPhaseInterceptor extends AbstractPhaseInterceptor {
2. public MyPhasedInterceptor() {
3. super(Phase.INVOKE); // Put this interceptor in this phase
4. }
5. public void handleMessage(Message msg) throws Fault {
6. // process the message
7. }
8. }



The most important thing you should notice is the constructor: it defines the phase name for your interceptor. When you specify the phase, your interceptor is ordered according to the phase in the chain.

Most of the time you will want to extend from sub-classes of AbstractPhaseInterceptor. For example, using the SoapHeaderInterceptoryou can access more specific information such as the SOAP Header.  

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值