[Quickfix-users] Creating a correctly typed message from a string
Brought to you by:
orenmnero
From: abaraff <ab...@ra...> - 2011-05-23 19:23:15
|
I'm building an application that in the event of a crash or restart can reestablish state based on reprocessing messages that it has previously received. During normal operation messages that arrive are cracked in the fromApp callback. I'd like to be able to use the crack method of the MessageCracker to reprocess my persisted messages. Unfortunately, it appears as though the MessageCracker expects to receive a properly typed message, and I can't figure out how to construct a properly typed message from a string or from key-value pairs without completely reinventing the wheel. If I construct a quickfix.Message object like this: quickfix.Message newMessage = new quickfix.Message(persistedString, true); crack(newMessage, sessionID); will throw an exception stating that: "java.lang.ClassCastException: quickfix.Message cannot be cast to quickfix.fix42.Message" If I construct a quickfix.fix42.Message object like this : quickfix.Message msg = new quickfix.Message(persistedString, true); quickfix.fix42.Message newMessage = new quickfix.fix42.Message(); Iterator fieldIterator = msg.getHeader().iterator(); while(fieldIterator.hasNext()) { Field fld = (Field) fieldIterator.next(); newMessage.getHeader().setString(fld.getField(), fld.getObject().toString()); }fieldIterator = msg.iterator(); while(fieldIterator.hasNext()) { Field fld = (Field) fieldIterator.next(); newMessage.setString(fld.getField(), fld.getObject().toString()); } crack(msg, sessionID); will throw this exception "java.lang.ClassCastException: quickfix.fix42.Message cannot be cast to quickfix.fix42.NewOrderSingle" Obviously, the API is converting a string into a properly typed Message somewhere. Is this machinery accessible? I could certainly do away with the cracker or build my own typed message constructor (which would constitute rewriting a huge chunk of QuickFIX/J) or build some sort of hacked switch statement. Thanks, Anthony (Message also posted to QuickFIX/J) -- View this message in context: http://old.nabble.com/Creating-a-correctly-typed-message-from-a-string-tp31684672p31684672.html Sent from the QuickFIX - User mailing list archive at Nabble.com. |