Skip to content
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

Populate Text(58) field when rejectMessageOnUnhandledException=true #851

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 13 additions & 3 deletions quickfixj-core/src/main/java/quickfix/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,13 +1214,13 @@ ignore the message and let the problem correct itself (optimistic approach).
}
if (!(MessageUtils.isAdminMessage(msgType))
&& (sessionBeginString.compareTo(FixVersions.BEGINSTRING_FIX42) >= 0)) {
generateBusinessReject(message, BusinessRejectReason.APPLICATION_NOT_AVAILABLE,
generateBusinessReject(message, t.getMessage(), BusinessRejectReason.APPLICATION_NOT_AVAILABLE,
0);
} else {
if (MsgType.LOGON.equals(msgType)) {
disconnect("Problem processing Logon message", true);
} else {
generateReject(message, SessionRejectReason.OTHER, 0);
generateReject(message, t.getMessage(), SessionRejectReason.OTHER, 0);
}
}
} else {
Expand Down Expand Up @@ -1732,6 +1732,11 @@ private void setRejectReason(Message reject, int field, String reason,

private void generateBusinessReject(Message message, int err, int field) throws FieldNotFound,
IOException {
generateBusinessReject(message, null, err, field);
}

private void generateBusinessReject(Message message, String text, int err, int field) throws FieldNotFound,
IOException {
final Header header = message.getHeader();
ApplVerID targetDefaultApplicationVersionID = getTargetDefaultApplicationVersionID();
final Message reject = messageFactory.create(sessionID.getBeginString(), targetDefaultApplicationVersionID,
Expand All @@ -1746,7 +1751,12 @@ private void generateBusinessReject(Message message, int err, int field) throws
reject.setInt(BusinessRejectReason.FIELD, err);
state.incrNextTargetMsgSeqNum();

final String reason = BusinessRejectReasonText.getMessage(err);
final String reason;
if (text != null) {
reason = text;
} else {
reason = BusinessRejectReasonText.getMessage(err);
}
setRejectReason(reject, field, reason, field != 0);
getLog().onErrorEvent(
"Reject sent for message number " + msgSeqNum + (reason != null ? (": " + reason) : "")
Expand Down
8 changes: 7 additions & 1 deletion quickfixj-core/src/test/java/quickfix/SessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ public void fromApp(Message message, SessionID sessionId)
throws FieldNotFound, IncorrectDataFormat,
IncorrectTagValue, UnsupportedMessageType {
super.fromApp(message, sessionId);
throw new Error("TEST");
throw new Error("TESTApp");
}
};

Expand All @@ -1788,6 +1788,8 @@ public void fromApp(Message message, SessionID sessionId)
.getHeader().getString(MsgType.FIELD));
assertEquals(MsgType.BUSINESS_MESSAGE_REJECT, application
.lastToAppMessage().getHeader().getString(MsgType.FIELD));
assertEquals("TESTApp", application.lastToAppMessage()
.getString(Text.FIELD));

session.next(createHeartbeatMessage(3));
assertEquals(4, session.getExpectedTargetNum());
Expand All @@ -1796,6 +1798,8 @@ public void fromApp(Message message, SessionID sessionId)
.getHeader().getString(MsgType.FIELD));
assertEquals(MsgType.REJECT, application.lastToAdminMessage()
.getHeader().getString(MsgType.FIELD));
assertEquals("TESTAdmin", application.lastToAdminMessage()
.getString(Text.FIELD));

session.next(createAdminMessage(4));
assertEquals(5, session.getExpectedTargetNum());
Expand All @@ -1805,6 +1809,8 @@ public void fromApp(Message message, SessionID sessionId)
.getString(MsgType.FIELD));
assertEquals(MsgType.HEARTBEAT, application.lastToAdminMessage()
.getHeader().getString(MsgType.FIELD));
assertFalse(application.lastToAdminMessage()
.isSetField(Text.FIELD));
} catch (final Throwable t) {
fail("Error was thrown: " + t.getMessage());
}
Expand Down