如何从 axis2 故障响应中排除堆栈跟踪
我有一个 Axis2 Web 服务,它在故障响应中抛出不同的详细消息,以指示调用中的问题。
在某些时候,由于服务器错误(除了 Web 服务处理的错误),在错误详细信息字符串中,我获得了所发生事件的完整堆栈跟踪。我不希望客户端看到堆栈跟踪,因此(作为捕获所有错误)我想输出一个简单的“服务器错误”消息,没有堆栈跟踪,什么也没有。
拦截故障响应和更改故障消息的最简单方法是什么?模块是(复杂的)执行此操作的唯一方法吗?
或者,Axis2 中是否有一个配置表示不显示错误的堆栈跟踪?
谢谢!
I have an Axis2 web service which throws different detail messages in the fault response to signal problems in the call.
At some point, due to server errors (others than the ones treated by the web service), in the fault detail string I get the full stacktrace of what happened. I do not want the client to see the stack trace, so (as a catch all errors) I want to output a simple "Server error" message with no stacktrace, no nothing.
What is the simplest way of intercepting fault responses and changing the fault message. Are modules the only way of (complicated) doing this?
Or, is there a configuration in Axis2 that says not to display stacktrace in fault?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我曾经遇到过类似的问题。不确定是否有一些配置可以关闭堆栈跟踪显示,至少当时我找不到任何配置(这将是最好的解决方案)。相反,我选择了一种快速而肮脏的方法,主要是因为缺乏时间。
我所做的就是亲自向 Axis2 提供故障的详细信息。 Axis2 servlet 有一个名为
handleFault
的方法,用于处理生成故障。更准确地说(在调用的更深处),MessageContextBuilder.createFaultEnvelope
方法用于构造故障元素。在详细信息中包含堆栈跟踪是默认行为,但有多种方法可以指定自定义详细信息。一种方法是使用
AxisFault
的detail
字段,您可以在其中添加OMElement
(请参阅 AXIOM) 被放入故障中。因此,您可以执行以下操作:现在,将添加您的详细信息,而不是异常堆栈跟踪。
I once had a similar problem. Not sure if there is some config to turn off the stacktrace showing, at least none that I could find at that moment (that would have been the best solution). Instead, I opted for a quick and dirty approach, mostly due to lack of time.
What I did was to provide Axis2 with the detail of the fault myself. The Axis2 servlet has a method called
handleFault
which deals with generating the fault. More exactly (deeper in the call) theMessageContextBuilder.createFaultEnvelope
method is used to construct the fault element.Having the stacktrace in the detail is the default behavior, but there are ways to specify your custom detail. One way is to use the the
AxisFault
'sdetail
field in which you can add anOMElement
(refer to AXIOM) to be placed into the fault. So you do something like:Now, instead of the exception stacktrace, your detail will be added instead.
Axis2 使用 Apache commons 日志记录,您看到的 AxisFault 消息是由 Axis2 中的代码生成的,类似于:
[此代码段来自 org.apache.axis2.transport.http.HTTPSender]
因此请参考 apache commons 日志记录用户指南 了解如何设置日志记录级别和消息目标的说明。
希望这有帮助。
Axis2 uses Apache commons logging and the AxisFault messages that you are seeing are generated by code in Axis2 that looks similar to:
[This code segment comes from org.apache.axis2.transport.http.HTTPSender]
So refer to apache commons logging user guide for instructions on how to set the logging levels and destination of the messages.
Hope this helps.
你能不能只抓住 AxisFault
Can you not just catch the AxisFault