WSO2Con 2013 CFP Banner

Extraneous Characters Appearing in the Axis2 Generated SOAP Messages

Question: Why do extraneous characters appear in the SOAP messages sent using Apache Axis2, causing my non-Axis2 Web service or Web service client to fail?

Date: Sun, 11th Mar, 2007
Level:
Reads: 7470
Discuss this article on Stack Overflow


Answer: These characters (see the example message traces given below) appear due to HTTP Chunking. This is a feature introduced by the HTTP 1.1 specification [2] to efficiently transfer large HTTP messages without buffering the whole message in the memory. HTTP Chunking transfers the message by breaking it into chunks. If you have a closer look at the message, you will notice a relationship between the extra numbers that appear and the message size (or specifically with the size of the chunks). You will also notice the HTTP header "Transfer-Encoding: chunked" and the absence of the content-length HTTP header. It is advised to use HTTP Chunking with Apache Axis2 whenever possible, especially if you are dealing with large messages like messages with attachments.

HTTP Chunking might not be supported by some (older) servers or clients, which do not support HTTP 1.1. Upon receiving a "chunked" message, those servers might fail while parsing the message. Hence an error message appears. In order to communicate with them, you can disable the HTTP Chunking in Apache Axis2 as follows.

At deployment, commenting out or removing the following in axis2.xml

<parameter name="Transfer-Encoding">chunked</parameter>

At runtime, using Axis2 client side options object

options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);

Example chunked message snapshot 1:

POST /axis2/services/EchoXMLService/echoOMElement HTTP/1.1
Content-Type: text/xml; charset=UTF-8
SOAPAction: "urn:anonOutInOp"
User-Agent: Axis2
Host: 127.0.0.1
Transfer-Encoding: chunked

122
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:echoOM xmlns:ns1="http://org.apache.axis2/xsd">
<ns1:myValue>Isaac Asimov, The Foundation Trilogy</ns1:myValue>
</ns1:echoOM>
</soapenv:Body>
</soapenv:Envelope>0

Example chunked message snapshot 2:

POST /axis2/services/EchoXMLService/echoOMElement HTTP/1.1
Content-Type: multipart/related; boundary=MIMEBoundary; ..............;
User-Agent: Axis2
Host: 127.0.0.1
Transfer-Encoding: chunked

24e4
--MIMEBoundary
content-type: application/xop+xml; charset=UTF-8; type="application/soap+xml"
content-transfer-encoding: binary
content-id: <0.urn:uuid:47174CDCBA7B918E391172168040614@apache.org>

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope.............................</soapenv:Envelope>
--MIMEBoundary
content-type: image/jpeg
content-transfer-encoding: binary
content-id: <1.urn:uuid:47174CDCBA7B918E391172168040620@apache.org>
............
2000
............
3a

--MIMEBoundary--
0

Applies To:

Apache Axis2/Java, 1.0 and above.

More Information:

[1] How to configure Axis2's HTTP Transport Sender at Client Side- http://wso2.org/library/209

[2] Hypertext Transfer Protocol HTTP/1.1 - Section 3.6:Transfer Codings http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html

steffen.bartsch's picture

Printing chunked SOAP message fails

But I got the problem on server side (AXIS2 1.3): I want to access the raw XML message but the function fails because of the extra chunk information. Is this a bug of AXIS2 ? Or how can I do this? Here is my code to access the raw XML message: MessageContext mc = MessageContext.getCurrentMessageContext(); SOAPEnvelope env = mc.getEnvelope(); String rawXmlMsg = env.toString(); My SOAP message: 2d2 <?xml version='1.0' encoding='UTF-8'?>...rest of SOAP message.... 0 It fails reading the extra 0 at the end of the SOAP message. Thanks, Steffen.
blackrose807.gmail.com's picture

Implementation of different

Implementation of different protocols make the productivity harm . and i always suggest . mcpd | comptia a+messageContext mc = MessageContext.getCurrentMessageContext(); SOAPEnvelope env = mc.getEnvelope(); String rawXmlMsg = env.toString(); use this code for redirection of messages .