java - Object conversion from InputStream - Spring integration -
i trying send object on tcp serialization in client-server application. tcp client written on android system , use objectoutputstream send object. tcp server written spring integration , try read object using deserializer. this:
<int-ip:tcp-connection-factory id="hosserver" serializer="connectionserializedeserialize" deserializer="connectionserializedeserialize" ..... >
in class implements serializer , deserializer interfaces createing objectinputstream inputsream argument in deserializer method. working fine moment try connect 1 more time server. receive eofexception during reading object form objectinputstream readobject() method.
public class commandconverter implements serializer<command>, deserializer<command>{ private objectinputstream ois = null; private objectoutputstream oos = null; private commandbuilder commandbuilder = new commandbuilder(); public command deserialize(inputstream inputstream) throws ioexception { if (ois == null) ois = new objectinputstream(inputstream); command cmd = null; try { cmd = (command) ois.readobject(); } catch (classnotfoundexception e) { commandbuilder.setcommandbuilder(new impropercommandbuilder()); commandbuilder.createcommand(); cmd = commandbuilder.getcommand(); } catch (invalidclassexception e) { commandbuilder.setcommandbuilder(new impropercommandbuilder()); commandbuilder.createcommand(); cmd = commandbuilder.getcommand(); } return cmd; }
what best way object sending on tcp in spring integration?
the serializer
, deserializer
implementations must thread-safe. simplest way reach make implementation stateless.
since have properties in class, become shared between different calls. , having such state makes behavior unpredictable.
the objectinputstream
, objectoutputstream
not designed sharing state.
so, have create objectinputstream
time deserialize()
called:
objectinputstream ois = new objectinputstream(inputstream);
and on.
Comments
Post a Comment