伙计们!我正在尝试获取SOAPBody对象请求的String。我将axis2和Tomcat9用于web服务。
public static String getXMLSoapBody()
{
log.getLogger().debug("TEST - getXmlSoapBody - START");
String soapBody;
SOAPBody body;
MessageContext messageContext = MessageContext.getCurrentMessageContext();
try {
SOAPEnvelope env = messageContext.getEnvelope();
body = env.getBody();
}
catch(Exception e)
{
log.getLogger().error("SOAP Exception :" + e.toString());
e.printStackTrace();
return null;
}
soapBody = body.toString();
return soapBody;
但当我发送请求时,我会收到以下错误:catalina.out:10:41:26.935[http-nio-8080-exec-2]错误org.apache.axis2.transport.http.AxisServlet-processAxisFault()在MessageContext实例中发现一个空http状态,将HttpServlet响应状态设置为:axis2.http.response.state
我的日志文件:2022-12-01 10:41:26[http-nio-8080-exec-2](TransUtils.java:287)调试测试-getXmlSoapBody-启动
我试图看到这方面的完整堆栈,但当我尝试对soapBody=body.toString()使用try/catch时;行我得到了这个错误,但上一个不是:
org.apache.axiom.om.NodeUnavailableException
at org.apache.axiom.om.impl.common.AxiomExceptionTranslator.translate(AxiomExceptionTranslator.java:35)
at org.apache.axiom.om.impl.llom.AxiomContainerImpl.serialize(Unknown Source)
at org.apache.axiom.om.impl.llom.AxiomContainerImpl.serializeAndSurfaceIOException(Unknown Source)
at org.apache.axiom.om.impl.llom.AxiomContainerImpl.serialize(Unknown Source)
at org.apache.axiom.om.impl.llom.AxiomContainerImpl.serialize(Unknown Source)
at org.apache.axiom.om.impl.llom.AxiomContainerImpl.serialize(Unknown Source)
at org.apache.axiom.om.impl.llom.AxiomElementImpl.toString(Unknown Source)
at uk.co.celesio.orders.server.TransUtils.getXMLSoapBody(TransUtils.java:304)
我的请求:
<?xml version='1.0' encoding='windows-1252'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<MyTestRequest xmlns="...">
...
</MyTestRequest>
</soapenv:Body>
</soapenv:Envelope>
尝试使用try/catch查看完整错误,也尝试记录此错误,但在这两种情况下,我都得到NodeUnavailable Exception
NodeUnavailableException
表示SOAP消息的正文已经被使用,很可能是由将其转换为Java对象的数据绑定使用的(不幸的是,您只显示了堆栈跟踪的一部分,因此无法从提供的信息中看出这一点)。
关于这个问题的正确解决方案:这取决于你实际想要实现的目标(这可能是一个XY问题)。