Unmarshalling a Socket's InputStream closes the Socket?

Viewed 5428

I have a server-client architecture where the client sends an XML to the server who reads it and generates a PDF out of it and sends that back to the client.

On the client side:

JAXBElement<Xml> xml = ...
Socket sock = ...
Marshaller marshaller = ...
marshaller.marshal(xml, sock.getOutputStream());
sock.shutdownOuput();    

Meanwhile on the server side:

ServerSocket server = ...
Socket client = server.accept();
Unmarshaller unmarshaller = ...
// client.isClosed() -> false
JAXBElement<Xml> xml =
  (JAXBElement<Xml>)) unmarshaller.unmarshall(client.getInputStream());
// client.isClosed() -> true
Pdf pdf = new Pdf(xml);
client.getOutputStream().write(pdf.toBytes());
// "socket is closed" IOException is thrown

If I don't unmarshall the client's InputStream (on the server side) and just send back a dummy PDF then everything's goes smoothly. So, I have to assume that the Unmarshaller closes the InputStream it is given, thus implicitly closing the client Socket ruining my day...

Any idea on solving this?

2 Answers
Related