上一篇文章已经写了spring和cxf的整合,这篇文章主要写怎么添加cxf的拦截器(Intercepter)
通过Intercepter可以灵活的设置cxf客户端和服务器端代码而不用修改主业务代码
下面写了一个简单的例子,也可以通过该例子改造成权限验证等
代码如下:
SampleInterceptor
写道
package com.benben.Interceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
@SuppressWarnings("rawtypes")
public class SampleInterceptor extends AbstractPhaseInterceptor {
public SampleInterceptor() {
super(Phase.PRE_INVOKE);
}
public void handleMessage(Message message) throws Fault {
System.out.println("############handleMessage##########");
System.out.println(message);
if (message.getDestination() != null) {
System.out.println(message.getId() + "#" + message.getDestination().getMessageObserver());
}
if (message.getExchange() != null) {
System.out.println(message.getExchange().getInMessage() + "#" + message.getExchange().getInFaultMessage());
System.out.println(message.getExchange().getOutMessage() + "#" + message.getExchange().getOutFaultMessage());
}
}
}
服务器端主要配置文件为:
写道
<?xml version="1.0" encoding="UTF-8"?>
<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" class="com.benben.webservice.service.impl.UserServiceImpl"/>
<bean id="inMessageInterceptor" class="com.benben.Interceptor.SampleInterceptor">
<constructor-arg value="receive"/>
</bean>
<bean id="outLoggingInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<!-- 注意下面的address,这里的address的名称就是访问的WebService的name -->
<jaxws:server id="userService" serviceClass="com.benben.webservice.service.UserService" address="/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>
客户端主要配置文件
写道
<?xml version="1.0" encoding="UTF-8"?>
<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" serviceClass="com.benben.webservice.service.UserService"
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>
分享到:
相关推荐
13.为CXF与Spring整合发布WebService添加拦截器进行权限控制
CXF3.0 Spring3.2 自定义拦截器
WebService小白学习 之 Spring整合CXF,添加拦截器。 博客学习地址:https://blog.csdn.net/qq_37902949/article/details/81262826
Apache Cxf WebService整合Spring 处理Map、非javabean式的复合类等CXF无法自动转化的类型 CXF为服务器端和客户端添加自定义拦截器进行权限检查验证并且控制台打印日志
这个版本是我上次传的CXF整合spring的加强版,增加了上传和下载已经拦截器的功能。如果还有不明白可以在留言里留下联系方式,大家可以一起讨论
完整可用的spring整合CXF示例项目,包括服务发布端和调用端两个项目,包括CXF拦截器的实现的简单的授权校验
CXF 入门实例 CXF对Interceptor拦截器的支持 传递复杂类型对象 CXF整合Spring
webservice 纯jdk,cxf整合,cxf+spring整合 ,cxf+ajax整合 cxf拦截器等,所有依赖的jar包都在lib中
一、CXF WebService准备工作 二、CXF 入门示例 三、CXF对Interceptor拦截器的支持 四、CXF WebService中传递复杂类型对象 五、CXF整合Spring
CXF对Interceptor拦截器的支持 CXF WebService中传递复杂类型对象 CXF整合Spring ANT工具快速构建、部署工程
webservice 纯jdk,cxf整合,cxf+spring整合 ,cxf+ajax整合 cxf拦截器等
一、CXF WebService准备工作 二、CXF 入门示例 三、CXF对Interceptor拦截器的支持 四、CXF WebService中传递复杂类型对象 五、CXF整合Spring
主要介绍了springBoot整合CXF并实现用户名密码校验的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
webservice整合spring的使用,服务器端和客户端均有,jar包都在客户端,服务端自行添加,同时 还有AJAX请求webservcie的demo,包括在CXF上的账户密码拦截器的使用
这是模拟企业用户的开发,在远程调用的时候客户端必须传入密码,这里通过cxf框架 的自定义拦截器实现jax-ws,jax-rs下次在学习下。 创建springboot项目: 导入起步依赖以及junit pom文件如下: org.spring...
day05_CRM权限拦截器_SSH纯注解整合 day06_Easyui&列表展示 10-Oracle数据库(学习4天) Oracle_day01,安装_函数查询and条件查询 Oracle_day02,多表查询_子查询_集合运算 Oracle_day03,DDL,DML,视图,PLSQL编程 ...
在web.xml配置拦截器 在Shiro配置文件上配置在web.xml对应的bean 配置安全管理器 配置自定义的realm Shiro过滤器 anon:例子/admins/**=anon 没有参数,表示可以匿名使用。 authc:例如/admins/...
BPMX3是支持流程管理、监控、优化、再造的全套IT管理开发平台,并且集单点登录、企业单位门户、业务流程管理、开发、整合、业务分析及重构等多重职能于一身的软件开发工具和企业IT架构平台。 BPMX3是企业管理业务...