I have a Java server that accepts SSL connections using JSSE and uses a simple XML message format inside the stream. I would like the server to read a complete message and then send a reply. This turns out to be quite difficult because org.xml.sax.XMLReader wants to read the entire stream and then call close(). I know it seems strange, but in Java 6 with the Sun JSSE provider this really does close both ends of the SSLSocket so no message can go back. I tried using the shutdownOutput() method of Socket on the client side, but this is unsupported with JSSE.
My solution was to pass an InputStream wrapped in a custom class that silently ignores close requests and indicates that the stream is closed when it encounters the first blank line. This constrains the XML beyond what is normally valid, but the client can easily filter out blank lines in the input if necessary. Is there a better solution?