Serializing a DOM - Java

Soldato
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
OK this might be lacking in some details, simply because I don't know all of them. I have a DOM in XML format, the length of the String that makes up the DOM is 89,424,168, less than the theoretical limit of the length of a string (2,147,483,647)

This XML is a Jasper report exported to XML format, I am trying to serialize this XML and add it to my response XML (client->server architecture).

The problem is the response XML (which includes the serialized DOM) has been truncated, so the client has issues reading it.

Is there a limit to how much can be serialized? For info serializing is done by a org.apache.xml.serialize.XMLSerializer, it looks like it can throw an IOException which stupidly is being caught but not dealt with! (I didn't write this) I have however added an IOException breakpoint caught and uncaught to Eclipse and that isn't triggered.

EDIT: Ok seems there is a "java.net.SocketException: Broken pipe" when sending the response from the Server, so the client is closing the connection before the server has finished responding!
 
Last edited:
Soldato
OP
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
As is usually the case, I'm answering my own question! :p

Basically the issue was the client receiving the response read the length of the response from the first 8 bytes, so a maximum of 99,999,999 bytes. The response I was sending was larger than that, up the header size to 9 bytes and the issue goes away.
 
Associate
Joined
9 Jun 2004
Posts
423
The explanation sounds a bit weird:

1. 8 bytes / 64 bits can hold numbers a lot larger than 99,999,999
2. the response you're sending is >= 100 megabytes?!
 
Soldato
OP
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
Sorry yeah missing a bit from that explanation, yes it is reading the first 8 bytes, but it's reading it from an InputStream using read(). Which returns an int in the range 0-255, that int is converted to a char representing a digit, so a max of 8 digits.

And yes, yes it was. Lots of serialized XML in the response!

Had to abandon it anyway as it was just causing too much memory to be consumed on the heap when the response was being decoded! A change in architecture would be needed to get it working properly. Perhaps by dividing the response up in to chunks.
 
Soldato
Joined
23 Feb 2009
Posts
4,976
Location
South Wirral
Its a bit of a hack, but why not just do some string substitution if all you want to do is add this big XML into some XML you control. If you don't need to validate the well-formedness or content there is no need to parse it.

Marshal your XML reponse into a string with a magic placeholder string, then use string.replace() to replace the placeholder with the big lump.

Or even: output up to the placeholder, output the big XML, then output everything after the placeholder.
 
Back
Top Bottom