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 ?

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
user2694734
  • 401
  • 2
  • 7
  • 14

2 Answers2

1

Your question is basically meaningless. There is no such concept as "length" for a SOAP body, or more generally for an XML element. Here is one reason (among many others):

The Body element in a SOAP message is in the namespace http://schemas.xmlsoap.org/soap/envelope/ (for SOAP 1.1) or http://www.w3.org/2003/05/soap-envelope (for SOAP 1.2). If you use the toString method to serialize the SOAPBody instance to a string, Axiom will therefore generate a namespace declaration on the Body element, so that the result is well formed with respect to namespaces. However, when the message is sent over the wire, the SOAP body will be the child of an Envelope element which is in the same namespace. In that case, the namespace declaration will be generated on the Envelope element and not repeated on the Body element.

That means that the number of characters effectively taken by the Body element depends on the context in which it is serialized.

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
0

I believe you can use the message context to get the content-length:

org.apache.axis2.context.MessageContext.getCurrentMessageContext().getInboundContentLength()
Grady G Cooper
  • 1,044
  • 8
  • 19