Skip to content

allow sending unchanged message in Session#send #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions quickfixj-core/src/main/java/quickfix/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -2685,8 +2685,29 @@ private void resetState() {
* @return a status flag indicating whether the write to the network layer was successful.
*/
public boolean send(Message message) {
message.getHeader().removeField(PossDupFlag.FIELD);
message.getHeader().removeField(OrigSendingTime.FIELD);
return send(message, false);
}

/**
* Send a message to a counterparty. Sequence numbers and information about the sender
* and target identification will be added automatically (or overwritten if that
* information already is present).
*
* The returned status flag is included for
* compatibility with the JNI API but it's usefulness is questionable.
* In QuickFIX/J, the message is transmitted using asynchronous network I/O so the boolean
* only indicates the message was successfully queued for transmission. An error could still
* occur before the message data is actually sent.
*
* @param message the message to send
* @param allowPosDup whether to allow PossDupFlag and OrigSendingTime in the message
* @return a status flag indicating whether the write to the network layer was successful.
*/
public boolean send(Message message, boolean allowPosDup) {
if (!allowPosDup) {
message.getHeader().removeField(PossDupFlag.FIELD);
message.getHeader().removeField(OrigSendingTime.FIELD);
}
return sendRaw(message, 0);
}

Expand Down
32 changes: 32 additions & 0 deletions quickfixj-core/src/test/java/quickfix/SessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2982,4 +2982,36 @@ public void disconnect() {
}
}

@Test
public void testSendWithoutAllowPosDupDropsFlagAndOrigSendingTime() throws Exception {
final UnitTestApplication application = new UnitTestApplication();
final SessionID sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "SENDER", "TARGET");
final Session session = SessionFactoryTestSupport.createSession(sessionID, application, false, false, true, true, null);
UnitTestResponder responder = new UnitTestResponder();
session.setResponder(responder);
logonTo(session);

session.send(createPossDupAppMessage(1), false);

final Message sentMessage = new Message(responder.sentMessageData);

assertFalse(sentMessage.getHeader().isSetField(PossDupFlag.FIELD));
assertFalse(sentMessage.getHeader().isSetField(OrigSendingTime.FIELD));
}

@Test
public void testSendWithAllowPosDupKeepsFlagAndOrigSendingTime() throws Exception {
final UnitTestApplication application = new UnitTestApplication();
final SessionID sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "SENDER", "TARGET");
final Session session = SessionFactoryTestSupport.createSession(sessionID, application, false, false, true, true, null);
UnitTestResponder responder = new UnitTestResponder();
session.setResponder(responder);
logonTo(session);
session.send(createPossDupAppMessage(1), true);

final Message sentMessage = new Message(responder.sentMessageData);

assertTrue(sentMessage.getHeader().isSetField(PossDupFlag.FIELD));
assertTrue(sentMessage.getHeader().isSetField(OrigSendingTime.FIELD));
}
}