0
我正在使用CXF动态客户端,并且想要执行一些日志记录。我想记录传入和传出的soap xml。我需要使用拦截器来做到这一点,但不知道如何连线它们以便客户端使用它。使用CXF动态客户端记录请求/响应
示例代码:
MyWebservice ws = new MyWebservice_Service().getChargePointServiceSoap12();
我如何可以添加拦截此客户端?
我正在使用CXF动态客户端,并且想要执行一些日志记录。我想记录传入和传出的soap xml。我需要使用拦截器来做到这一点,但不知道如何连线它们以便客户端使用它。使用CXF动态客户端记录请求/响应
示例代码:
MyWebservice ws = new MyWebservice_Service().getChargePointServiceSoap12();
我如何可以添加拦截此客户端?
要结果的信息创建一个拦截器是这样的:
import java.io.InputStream;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
public class LogInterceptor extends AbstractPhaseInterceptor<Message> {
public LogInterceptor() {
super(Phase.PRE_INVOKE);
}
@Override
public void handleMessage(Message message) throws Fault {
InputStream contentInputStream = message.get(InputStream.class);
// Do whatever you want with the content (the soap xml)
}
public void addInterceptor(Object portType) {
Client client = ClientProxy.getClient(portType);
client.getInInterceptors().add(this);
}
}
你的代码应该调用addInterceptor:
MyWebservice ws = new MyWebservice_Service().getChargePointServiceSoap12();
LogInterceptor logInterceptor = new LogInterceptor();
logInterceptor.addInterceptor(ws);
最后的收入信息,你改变拦截器的构造阶段。