如何从 axis2 故障响应中排除堆栈跟踪

发布于 2024-09-18 01:12:19 字数 281 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黯然 2024-09-25 01:12:20

我曾经遇到过类似的问题。不确定是否有一些配置可以关闭堆栈跟踪显示,至少当时我找不到任何配置(这将是最好的解决方案)。相反,我选择了一种快速而肮脏的方法,主要是因为缺乏时间。

我所做的就是亲自向 Axis2 提供故障的详细信息。 Axis2 servlet 有一个名为 handleFault 的方法,用于处理生成故障。更准确地说(在调用的更深处),MessageContextBuilder.createFaultEnvelope 方法用于构造故障元素。

在详细信息中包含堆栈跟踪是默认行为,但有多种方法可以指定自定义详细信息。一种方法是使用 AxisFaultdetail 字段,您可以在其中添加 OMElement(请参阅 AXIOM) 被放入故障中。因此,您可以执行以下操作:

public class MyServlet extends AxisServlet {
  ...
  public void handleFault(MessageContext msgContext, OutputStream out, AxisFault e) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement detail = factory.createElement(...);
    e.setDetail(detail);
    // now let axis do its thing with the new improved AxisFault
    super.handleFault(msgContext, out, e);
  }
}

现在,将添加您的详细信息,而不是异常堆栈跟踪。

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) the MessageContextBuilder.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's detail field in which you can add an OMElement (refer to AXIOM) to be placed into the fault. So you do something like:

public class MyServlet extends AxisServlet {
  ...
  public void handleFault(MessageContext msgContext, OutputStream out, AxisFault e) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement detail = factory.createElement(...);
    e.setDetail(detail);
    // now let axis do its thing with the new improved AxisFault
    super.handleFault(msgContext, out, e);
  }
}

Now, instead of the exception stacktrace, your detail will be added instead.

瀞厅☆埖开 2024-09-25 01:12:20

Axis2 使用 Apache commons 日志记录,您看到的 AxisFault 消息是由 Axis2 中的代码生成的,类似于:

<前><代码>尝试{
执行方法(httpClient,msgContext,url,getMethod);
处理响应(msgContext,getMethod);
} catch (IOException e) {
log.info("无法发送ViaGet到url[" + url + "]", e);
抛出 AxisFault.makeFault(e);
} 最后 {
清理(​​msgContext,getMethod);
}

[此代码段来自 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:

try {
    executeMethod(httpClient, msgContext, url, getMethod);
    handleResponse(msgContext, getMethod);
} catch (IOException e) {
    log.info("Unable to sendViaGet to url[" + url + "]", e);
    throw AxisFault.makeFault(e);
} finally {
    cleanup(msgContext, getMethod);
}

[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.

日记撕了你也走了 2024-09-25 01:12:20

你能不能只抓住 AxisFault

try {
    // do stuff
} catch (AxisFault f) {
    log.error("Encountered error doing stuff", f);
    throw new IOException("Server error");
}

Can you not just catch the AxisFault

try {
    // do stuff
} catch (AxisFault f) {
    log.error("Encountered error doing stuff", f);
    throw new IOException("Server error");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文