Java 使用 Apache Axis 时如何打印 SOAP 消息内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20349772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 01:16:00  来源:igfitidea点击:

How to print SOAP message contents when using Apache Axis

javaweb-servicessoapaxis2

提问by R11G

I am using Apache Axis for web service automation.

我正在使用 Apache Axis 进行 Web 服务自动化。

I am preparing SOAP requests via Axis and hitting the web service further. What I am looking for is how to print the SOAP request content which is getting compiled and hitting the webservice.

我正在通过 Axis 准备 SOAP 请求并进一步访问 Web 服务。我正在寻找的是如何打印正在编译并访问 web 服务的 SOAP 请求内容。

I found that log4j can help but I am struggling how to use it.

我发现 log4j 可以提供帮助,但我正在努力如何使用它。

回答by Ratha

Use an axis2handlerand try to log the messages.

使用axis2handler并尝试记录消息。

  msgcontext.getEnvelope().getBody()
  msgcontext.getEnvelope().getBody()

回答by Paulo Rodrigues

You probably don't need this answer anymore, but stays here for anyone else that ends right up here with the same problem.

您可能不再需要这个答案,但是对于其他遇到相同问题的人,请留在这里。

The easiest way to retrieve both the request and the response is to get them from the call you are making. In the axis generated stub, after invoking a call do this:

检索请求和响应的最简单方法是从您正在进行的调用中获取它们。在轴生成的存根中,调用调用后执行以下操作:

String requestXML = _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
String responseXML = _call.getMessageContext().getResponseMessage().getSOAPPartAsString();

Hope it helps. It helped me when I needed to print the request too.

希望能帮助到你。当我需要打印请求时,它也帮助了我。

回答by Brian

I was having trouble figuring this out as well. The problem for me was my _call.invoke() was failing. I was able to surround this in a try-catch clause and still get the request message for debugging:

我也很难弄清楚这一点。我的问题是我的 _call.invoke() 失败了。我能够将其包含在 try-catch 子句中,并且仍然获得用于调试的请求消息:

Example:

例子:

try{
    _call.invoke();
catch(Exception e){
    _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
}