I’m trying to send java bean instances over a network stream. I want to marshal/unmarshal java instances with JAXB and a normal OutputStream to push it over the network.
The servers wait at the unmarshal point but the client is already alot further.
Server:
inputStream = new BufferedInputStream(this.socket.getInputStream());
outputStream = new BufferedOutputStream(this.socket.getOutputStream());
JAXBContext requestContext = JAXBContext.newInstance(this.requestClass);
Unmarshaller unmarshaller = requestContext.createUnmarshaller();
@SuppressWarnings("unchecked")
K request = (K) unmarshaller.unmarshal(inputStream); //blocks here
respond();
Client:
JAXBContext messageContext = JAXBContext.newInstance(message.getClass());
Marshaller marshaller = messageContext.createMarshaller();
out = new BufferedOutputStream(socket.getOutputStream());
marshaller.marshal(message, out);
out.flush();
waitForResponse();// blocks here
EDIT: I switched to a normal output stream but it still blocks. Do I have to send some special signal to tell JAXB to stop unmarshalling? If I close the client output stream the message arrives at the server side.
I switched to
XMLEventWriterandXMLEventWriterand it works. I’ve got the feelingXMLStreamReaderis buggy. It gets stuck on someskipSpaces()method. The code ofXMLStreamReaderlooks as if it should return as soon as a end of document appears.