作用: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:, 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 {
分享到:
相关推荐
* Bus是CXF的主干, 为共享资源提供一个可配置的场所,作用类似于Spring的ApplicationContext,这些共享资源包括 * WSDl管理器、绑定工厂等。通过对BUS进行扩展,可以方便地容纳自己的资源,或者替换现有的资源。...
spring-cxf日志记录配置
文中讲解了CXF服务端的库文件,文件配置要求;客户端、服务端的访问示例;CXF的整合;拦截器的使用;等CXF常用的操作。
https://passport.csdn.net/account/active?user=u013039415&active=2b31b0c422c9bd196f500721a0e85301&from=http%3a%2f%2fdownload.csdn.net%2fdownload%2fxuzhipenghao%2f1130729
NULL 博文链接:https://reymont.iteye.com/blog/1532463
这时干净的cxf的核心配置文件·
CXF 入门实例 CXF对Interceptor拦截器的支持 传递复杂类型对象 CXF整合Spring
这里的Interceptor就和Filter、Struts的Interceptor很类似,提供它的主要作用就是为了很好的降低代码的耦合性,提供代码的内聚性。以HelloWorldService为例子。 参照网址:...
apache-cxf-2.2.10安装包和如何配置到环境变量的说明,放心使用
讲解了cxf实现拦截器的原因、核心API及使用方法
ssh2-interceptor拦截器(权限管理).
通过CXF方式创建带用户认证的Webservice接口(含调用程序)与SSH框架完美整合。
Spring+cxf配置接口+mybatis配置
一、CXF WebService准备工作 二、CXF 入门示例 三、CXF对Interceptor拦截器的支持 四、CXF WebService中传递复杂类型对象 五、CXF整合Spring
cxf配置swagger2
CXF对Interceptor拦截器的支持 CXF WebService中传递复杂类型对象 CXF整合Spring ANT工具快速构建、部署工程
cxf配置的详情信息说明,与springMVC的集成,以及相关文档配置
WebService环境配置 CXF环境搭建
配置cxf ws security的教程
一、CXF WebService准备工作 二、CXF 入门示例 三、CXF对Interceptor拦截器的支持 四、CXF WebService中传递复杂类型对象 五、CXF整合Spring