[QFJ-955] getHeader() and getTrailer() not behaving correctly Created: 27/Sep/18  Updated: 28/Sep/18  Resolved: 28/Sep/18

Status: Closed
Project: QuickFIX/J
Component/s: None
Affects Version/s: 2.1.0
Fix Version/s: None

Type: Bug Priority: Default
Reporter: Simon Assignee: Christoph John
Resolution: Won't Fix Votes: 0
Labels: QuickfixJ
Environment:

Windows, JDK8


Attachments: Java Source File NewFixMessagePrinter .java     Java Source File OldFixMessagePrinter.java    

 Description   

Hi,
Don't know if this a bug or we are not using the API correctly.
But since 2.1.0 we observe strange behavior concering the checksum and bodylength field.

JUnit Test:

@Test
public void testBodyLengthAndChecksum() throws FieldNotFound

{ TradeCaptureReport tradeCaptureReport = new TradeCaptureReport(); tradeCaptureReport.set(new Instrument(new Symbol("[N/A]"))); System.out.println(tradeCaptureReport.toString()); Header header = tradeCaptureReport.getHeader(); System.out.println(header.getString(9)); Trailer trailer = tradeCaptureReport.getTrailer(); System.out.println(trailer.getString(10)); }

2.0.0 ====>>>

8=FIX.4.49=1535=AE55=[N/A]10=072
15
072

2.1.0 ====>>>

8=FIX.4.49=1535=AE55=[N/A]10=072
100
000

Any help would be much appreciated.

Greetings,
Simon.



 Comments   
Comment by Simon [ 27/Sep/18 ]

Please correct description: -behavong + behaving
Thx

Comment by Christoph John [ 27/Sep/18 ]

Thanks for including a quick test!

The calculation of length and checksum has been changed to be calculated in a StringBuffer instead of changing the Message instance every time when calling toString(). This works without problems since the result of toString() will be sent on the wire. Also you can retrieve body length and checksum when you receive a message since then the message will be parsed using Message.fromString().
See https://github.com/quickfix-j/quickfixj/pull/39 and https://github.com/quickfix-j/quickfixj/pull/42

Here is how you could retrieve body length and checksum from a message that you created:

    @Test
    public void testBodyLengthAndChecksum() throws FieldNotFound, InvalidMessage {
        TradeCaptureReport tradeCaptureReport = new TradeCaptureReport();
        tradeCaptureReport.set(new Instrument(new Symbol("[N/A]")));
        System.out.println(tradeCaptureReport.toString());
        
        Message newMessage = new Message();
        newMessage.fromString(tradeCaptureReport.toString(), null, false);
        System.out.println(newMessage.getHeader().getString(9));
        System.out.println(newMessage.getTrailer().getString(10));
        System.out.println(MessageUtils.checksum(tradeCaptureReport.toString()));
    }

This might look a little cumbersome but actually I wonder what the use case behind this is? Why do you need to know the body lenght and checksum of a message that you just created?

Cheers,
Chris.

P.S.: Please use the mailing list if unsure if it is a bug or not. Thanks

Comment by Simon [ 27/Sep/18 ]

Hi Chris,

thanks for that fast reply.

The use case is we save a pretty print version of a fix message in the database, therefore we have a "prettyPrinter" utility class that wasn't working correctly after update to 2.1.0.
I found it a while ago by googling and adapted it a bit. Attached it to issue, if anyone is interested. (the code is pretty ugly, but does the job)
Also attached the new version...

Greetings,
Simon.

Comment by Simon [ 27/Sep/18 ]

Hi Chris,

could you remove the file "FixMessagePrinter.java" ?

Thanks

Comment by Christoph John [ 28/Sep/18 ]

Done.
Will close this ticket now.

For further discussion please use the mailing list (maybe with a link to this issue).

Thanks,
Chris.

Comment by Christoph John [ 28/Sep/18 ]

P.S.: I found a slightly nicer alternative...

        System.out.println(MessageUtils.getStringField( tradeCaptureReport.toString(), 9 ));
        System.out.println(MessageUtils.getStringField( tradeCaptureReport.toString(), 10 ));
Generated at Sat Nov 23 11:14:11 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.