Imported from previous forum
Hello,
I made a mistake to send this Q&A to "Report this".
Anyway my question is as follows.
I had a trouble when I sent a message to an acceptor.
The message is "News" with encoded fields.
Making the FIX message is done correctly by checking the "FileStore". (An attached document show this)
After that I wanted to send this message through "sendToTarget" method, but due to an exception the message couldn't be sent.
I tried to replace UTF-8 characters with simple ascii characters, the message was sent successfully.
If someone has experianced this kind of trouble, let me knoe pls.
Caused exception is ...
2013/09/03 21:25:51 quickfix.mina.AbstractIoHandler exceptionCaught
fatal: Protocol handler exception: org.apache.mina.filter.codec.ProtocolEncoderException: java.nio.BufferOverflowException
org.apache.mina.filter.codec.ProtocolEncoderException: java.nio.BufferOverflowException
at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:224)
at org.apache.mina.common.support.AbstractIoFilterChain.callPreviousFilterWrite(AbstractIoFilterChain.java:361)
at org.apache.mina.common.support.AbstractIoFilterChain.access$1300(AbstractIoFilterChain.java:53)
at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.filterWrite(AbstractIoFilterChain.java:659)
at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.filterWrite(AbstractIoFilterChain.java:587)
at org.apache.mina.common.support.AbstractIoFilterChain.callPreviousFilterWrite(AbstractIoFilterChain.java:361)
at org.apache.mina.common.support.AbstractIoFilterChain.fireFilterWrite(AbstractIoFilterChain.java:355)
at org.apache.mina.transport.socket.nio.SocketSessionImpl.write0(SocketSessionImpl.java:166)
at org.apache.mina.common.support.BaseIoSession.write(BaseIoSession.java:177)
at org.apache.mina.common.support.BaseIoSession.write(BaseIoSession.java:168)
at quickfix.mina.IoSessionResponder.send(IoSessionResponder.java:47)
at quickfix.Session.send(Session.java:2483)
at quickfix.Session.sendRaw(Session.java:2426)
at quickfix.Session.send(Session.java:2473)
at quickfix.Session.sendToTarget(Session.java:645)
at quickfix.Session.sendToTarget(Session.java:621)
at quickfix.Session.sendToTarget(Session.java:602)
at tcs.tfx.fixtest.FixTest.execute(FixTest.java:390)
at tcs.tfx.fixtest.FixTest.main(FixTest.java:1482)
Caused by: java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:165)
at org.apache.mina.common.support.BaseByteBuffer.put(BaseByteBuffer.java:209)
at org.apache.mina.common.ByteBuffer.put(ByteBuffer.java:539)
at quickfix.mina.message.FIXMessageEncoder.encode(FIXMessageEncoder.java:76)
at org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory$ProtocolEncoderImpl.encode(DemuxingProtocolCodecFactory.java:189)
at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:214)
... 18 more
Best Regards,
Osamu
Additional comment ...
I checked FIX4.4 spec.
In it the length of an encoded field is the length of bytes.
But BodyLength tag (tag = 9) showed the number of character bytes.
In the attached document 9=425 should be replaced by 9=645.
Because I use 110 "UTF-8" characters.
Also each length field for encoded fields has no meaning in QuickFIX/J.
I gave up to fix about sending "UTF-8" characters.
This is not important for us.
Because we only read "News" from acceptor side.
I've arranged the receiving data and tried to read.
And finally I could get "News" written in Japanese.
There are some problems according to the translation.
First
quickfix.Message.extraceField method assume the following.
If the field has count field, next "point" is calculated using this count.
This is not good idea for multibyte environment.
For example, acceptor send one "UTF-8" character and we want it to be translated into "Windows-31J".
Acceptor send count=3 for length and position is moved to 3+1(SOH).
But making a message is done by using the translated string. Not pre-tranlated string.
In "Windows-31J" this character has 2 bytes length.
Second
Almost same above.
This is checksum problem.
Acceptor calculate it from pre-translated string.
And QuickFIX/J calculate it after-translated string.