Uploaded image for project: 'QuickFIX/J'
  1. QuickFIX/J
  2. QFJ-955

getHeader() and getTrailer() not behaving correctly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Default
    • Resolution: Won't Fix
    • Affects Version/s: 2.1.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Environment:
      Windows, JDK8

      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.

        Attachments

          Activity

          Hide
          zophyreus Simon added a comment - - edited

          Please correct description: -behavong + behaving
          Thx

          Show
          zophyreus Simon added a comment - - edited Please correct description: -behavong + behaving Thx
          Hide
          chrjohn Christoph John added a comment -

          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

          Show
          chrjohn Christoph John added a comment - 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
          Hide
          zophyreus Simon added a comment - - edited

          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.

          Show
          zophyreus Simon added a comment - - edited 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.
          Hide
          zophyreus Simon added a comment -

          Hi Chris,

          could you remove the file "FixMessagePrinter.java" ?

          Thanks

          Show
          zophyreus Simon added a comment - Hi Chris, could you remove the file "FixMessagePrinter.java" ? Thanks
          Hide
          chrjohn Christoph John added a comment -

          Done.
          Will close this ticket now.

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

          Thanks,
          Chris.

          Show
          chrjohn Christoph John added a comment - Done. Will close this ticket now. For further discussion please use the mailing list (maybe with a link to this issue). Thanks, Chris.
          Hide
          chrjohn Christoph John added a comment -

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

                  System.out.println(MessageUtils.getStringField( tradeCaptureReport.toString(), 9 ));
                  System.out.println(MessageUtils.getStringField( tradeCaptureReport.toString(), 10 ));
          
          Show
          chrjohn Christoph John added a comment - P.S.: I found a slightly nicer alternative... System .out.println(MessageUtils.getStringField( tradeCaptureReport.toString(), 9 )); System .out.println(MessageUtils.getStringField( tradeCaptureReport.toString(), 10 ));

            People

            • Assignee:
              chrjohn Christoph John
              Reporter:
              zophyreus Simon
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: