Apache CXF:-如何使用cxf拦截器提取有效载荷数据 [英] Apache CXF :- How do i extract the payload data using cxf interceptors
本文介绍了Apache CXF:-如何使用cxf拦截器提取有效载荷数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该遵循哪些步骤来使用Apache CXF拦截器提取有效载荷?
What steps should I follow to extract the payload using Apache CXF interceptors?
推荐答案
您的拦截器需要从AbstractPhaseInterceptor
或子类扩展
Your interceptor needs to extend from the AbstractPhaseInterceptor
or a subclass
public class MyInterceptor extends AbstractPhaseInterceptor<Message> {
public MyInterceptor () {
super(Phase.RECEIVE);
}
public void handleMessage(Message message) {
//Get the message body into payload[] and set a new non-consumed inputStream into Message
InputStream in = message.getContent(InputStream.class);
byte payload[] = IOUtils.readBytesFromStream(in);
ByteArrayInputStream bin = new ByteArrayInputStream(payload);
message.setContent(InputStream.class, bin);
}
public void handleFault(Message messageParam) {
//Invoked when interceptor fails
}
}
以编程方式添加拦截器
MyInterceptor myInterceptor = new MyInterceptor();
Server server = serverFactoryBean.create();
server.getEndpoint().getInInterceptor().add(myInterceptor);
或使用配置
<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://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<bean id="MyInterceptor" class="demo.interceptor.MyInterceptor"/>
<!-- We are adding the interceptors to the bus as we will have only one endpoint/service/bus. -->
<cxf:bus>
<cxf:inInterceptors>
<ref bean="MyInterceptor"/>
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="MyInterceptor"/>
</cxf:outInterceptors>
</cxf:bus>
</beans>
在此处
这篇关于Apache CXF:-如何使用cxf拦截器提取有效载荷数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文