diff --git a/quickfixj-core/src/main/java/quickfix/Session.java b/quickfixj-core/src/main/java/quickfix/Session.java index 847f5c2885..61e6e716d8 100644 --- a/quickfixj-core/src/main/java/quickfix/Session.java +++ b/quickfixj-core/src/main/java/quickfix/Session.java @@ -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 { @@ -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, @@ -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) : "") diff --git a/quickfixj-core/src/test/java/quickfix/SessionTest.java b/quickfixj-core/src/test/java/quickfix/SessionTest.java index 35303ffba3..7e23003aba 100644 --- a/quickfixj-core/src/test/java/quickfix/SessionTest.java +++ b/quickfixj-core/src/test/java/quickfix/SessionTest.java @@ -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"); } }; @@ -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()); @@ -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()); @@ -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()); }