2

I want to get the length of a SOAPBody object. My current implementation is

String mBody = body.toString();
int len= mBody.length();

Using org.apache.axiom.soap.SOAPBody;

This takes huge time of the my whole operational time as my SOAP body is very large. This way is very inefficient. How can I take this length in efficient t way ?

4

2 回答 2

1

你的问题基本上没有意义。对于 SOAP 主体,或更一般地,对于 XML 元素,没有“长度”这样的概念。这是一个原因(除其他外):

SOAP 消息中的Body元素位于名称空间中http://schemas.xmlsoap.org/soap/envelope/(对于 SOAP 1.1)或http://www.w3.org/2003/05/soap-envelope(对于 SOAP 1.2)。如果您使用该toString方法将SOAPBody实例序列化为字符串,则 Axiom 将因此在元素上生成命名空间声明Body,以便结果与命名空间相关。但是,当通过网络发送消息时,SOAP 主体将Envelope是位于同一名称空间中的元素的子元素。在这种情况下,命名空间声明将在元素上生成,Envelope并且不会在元素上重复Body

这意味着Body元素有效占用的字符数取决于它被序列化的上下文。

于 2015-06-13T17:23:00.130 回答
0

我相信您可以使用消息上下文来获取内容长度:

org.apache.axis2.context.MessageContext.getCurrentMessageContext().getInboundContentLength()
于 2015-04-30T23:28:44.797 回答