gpt4 book ai didi

java - Apache CXF :- How do i extract the payload data using cxf interceptors

转载 作者:行者123 更新时间:2023-11-29 04:42:34 26 4
gpt4 key购买 nike

我应该遵循哪些步骤来使用 Apache CXF 拦截器提取有效载荷?

最佳答案

您的拦截器需要从 AbstractPhaseInterceptor 或子类扩展

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>

检查文档 here

关于java - Apache CXF :- How do i extract the payload data using cxf interceptors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38586259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com