首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

CXF跟Spring整合,并且添加拦截器

2012-09-14 
CXF和Spring整合,并且添加拦截器上一篇文章已经写了spring和cxf的整合,这篇文章主要写怎么添加cxf的拦截器

CXF和Spring整合,并且添加拦截器

上一篇文章已经写了spring和cxf的整合,这篇文章主要写怎么添加cxf的拦截器(Intercepter)

?

通过Intercepter可以灵活的设置cxf客户端和服务器端代码而不用修改主业务代码

?

下面写了一个简单的例子,也可以通过该例子改造成权限验证等

?

代码如下:

SampleInterceptor

}
if (message.getExchange() != null) {
System.out.println(message.getExchange().getInMessage() + "#" + message.getExchange().getInFaultMessage());
System.out.println(message.getExchange().getOutMessage() + "#" + message.getExchange().getOutFaultMessage());
}
}

}

?

服务器端主要配置文件为:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>


<bean id="userServiceBean" serviceaddress="/Users">
<jaxws:serviceBean>
<!-- 要暴露的 bean 的引用 -->
<ref bean="userServiceBean"/>
</jaxws:serviceBean>
<jaxws:inInterceptors>
<ref bean="inMessageInterceptor"/>?
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="outLoggingInterceptor"/>
</jaxws:outInterceptors>
</jaxws:server>



</beans>

?客户端主要配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

<jaxws:client id="userWsClient" service
address="http://localhost/cxfTest/services/Users">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean class="com.benben.Interceptor.SampleInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="com.benben.Interceptor.SampleInterceptor"/>
<!--<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>-->
</jaxws:outInterceptors>

</jaxws:client>
</beans>

?

热点排行