spring-boot - axis2客户端记录请求响应spring boot
问题描述
我们如何记录从 Spring 引导服务类调用的Axis2 SOAP 请求和响应。Spring logback looging 不记录客户端请求和响应。
解决方案
我不知道从 Spring 调用是否会改变任何内容,但您可以将 hadlers 添加到您的axis2客户端。Axis2 分阶段处理消息。您可以获得所有这些阶段并将您的自定义处理程序添加到您想要的任何阶段。这样的处理程序可以用消息做所有事情,包括记录整个内容或修改它。
// get AxisConfiguration from client
AxisConfiguration axisConf = stub._getServiceClient().getAxisConfiguration();
// create your custom phase
Phase phase = new Phase(OUT_LOGGER);
// add your custom handler to your custom phase
phase.addHandler(new MessageContentLoggerHandler());
// get all phases processed when message is sent away
// and add your custom phase
axisConf.getOutFlowPhases().add(phase);
// get all phases for incoming messages
//and add handler to Security phase
// (that's where security headers are added to SOAP message)
List<Phase> phasesIn = axisConf.getInFlowPhases();
addHandlerToSecurity(phasesIn);
// similar to above but now these are phases processed
// when there is fault in incoming communication
List<Phase> phasesInFault = axisConf.getInFaultFlowPhases();
phasesInFault.add(0, phase);
addHandlerToSecurity(phasesInFault);
添加到安全阶段:
public void addHandlerToSecurity(List<Phase> phases) {
try {
for (Phase p : phases) {
if ("Security".equals(p.getName())) {
p.addHandler(new MessageContentLoggerHandler());
}
}
} catch (Exception e) {
// TODO
}
}
您的自定义处理程序必须实现 invoke(MessageContext msgContext) 方法。MessageContent 包含整个 SOAP 信封,即来自 Web 服务的请求和响应。
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
String envelope = msgContext.getEnvelope().toString();
// do something with content of SOAP envelope
return InvocationResponse.CONTINUE;
}
推荐阅读
- javascript - 用玩笑模拟条件 window.open 函数调用
- python - 过滤 Pandas DataFrame 中的特定值
- angular - 将 *ngFor 动态添加到 HTML 元素
- python-3.x - 使用 tf-coreml 将 Tensorflow 转换为 CoreML
- java - Spring boot 2 embed tomcat 9.0.26 无法加载jks文件流关闭
- ruby-on-rails - 通过 created_at 对关联模型进行分组和计数
- c++ - 如何简化模板模板参数中的 enable_if 别名
- multithreading - 如何在不创建静态函数的情况下调用线程
- android - Android - Searchview 只能进行一次搜索
- heroku - Heroku-18 w/.NET Core GDI+:无法加载 DLL 'libgdiplus':找不到指定的模块