gpt4 book ai didi

CXF 故障拦截器 : log useful information

转载 作者:行者123 更新时间:2023-12-04 00:45:21 25 4
gpt4 key购买 nike

我想记录一些信息以备不时之需。特别是我想记录与服务器联系的客户端的 IP 地址和端口,如果安全处于事件状态,则记录用户名,如果可能,还记录传入的消息。

我在端点的 getOutFaultInterceptors 链中添加了一个拦截器,但在 handleMessage 中我不知道我可以使用哪些属性。

一些想法?

谢谢

最佳答案

在您的端点 xml 定义中,您可以添加以下内容来记录传入消息:

<bean id="logInInterceptor" 
class="org.apache.cxf.interceptor.LoggingInInterceptor" />
<jaxws:inInterceptors>
<ref bean="logInInterceptor"/>
</jaxws:inInterceptors>

然后使用总线限制要记录的字符数:

<cxf:bus>
<cxf:features>
<cxf:logging limit="102400"/>
</cxf:features>
<cxf:bus>

您没有提到您的身份验证方法是什么,所以如果您使用的是 UsernameTokenValidator 的实现,您可以在那里记录传入的用户名。

要记录客户端的 IP 地址和端口等详细信息,请扩展 LoggingInInterceptor,然后在 handleMessage() 中使用以下代码:

handleMessage() {
HttpServletRequest request =
(HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
if (null != request) {
String clientAddress = request.getRemoteAddr();
int remotePort = request.getRemotePort();
// log them
}
}

另请查看 this线程。

关于CXF 故障拦截器 : log useful information,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11264792/

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