@@ -1313,7 +1313,7 @@ private boolean resetOrDisconnectIfRequired(Message msg) {
13131313
13141314 private void nextReject (Message reject ) throws FieldNotFound , RejectLogon , IncorrectDataFormat ,
13151315 IncorrectTagValue , UnsupportedMessageType , IOException , InvalidMessage {
1316- if (!verify (reject , false , validateSequenceNumbers )) {
1316+ if (!validateAndDispatchMsg (reject , false , validateSequenceNumbers )) {
13171317 return ;
13181318 }
13191319 if (getExpectedTargetNum () == reject .getHeader ().getInt (MsgSeqNum .FIELD )) {
@@ -1332,7 +1332,7 @@ private void nextResendRequest(Message resendRequest) throws IOException, Reject
13321332 // ResendRequest to be satisfied in order to process the queued ResendRequest of the counterparty.
13331333 // Instead, send out the requested messages and afterwards enqueue the ResendRequest in order to
13341334 // later increase the target seqnum in method nextQueued(int).
1335- if (!verify (resendRequest , false , validateSequenceNumbers )) {
1335+ if (!validateAndDispatchMsg (resendRequest , false , validateSequenceNumbers )) {
13361336 return ;
13371337 }
13381338 final int msgSeqNum = resendRequest .getHeader ().getInt (MsgSeqNum .FIELD );
@@ -1456,7 +1456,7 @@ private void logApplicationException(String location, Throwable t) {
14561456
14571457 private void nextLogout (Message logout ) throws IOException , RejectLogon , FieldNotFound ,
14581458 IncorrectDataFormat , IncorrectTagValue , UnsupportedMessageType {
1459- if (!verify (logout , false , false )) {
1459+ if (!validateAndDispatchMsg (logout , false , false )) {
14601460 return ;
14611461 }
14621462
@@ -1543,7 +1543,7 @@ private void nextSequenceReset(Message sequenceReset) throws IOException, Reject
15431543 isGapFill = sequenceReset .getBoolean (GapFillFlag .FIELD ) && validateSequenceNumbers ;
15441544 }
15451545
1546- if (!verify (sequenceReset , isGapFill , isGapFill )) {
1546+ if (!validateAndDispatchMsg (sequenceReset , isGapFill , isGapFill )) {
15471547 return ;
15481548 }
15491549
@@ -1797,6 +1797,29 @@ private void nextHeartBeat(Message heartBeat) throws FieldNotFound, RejectLogon,
17971797 nextQueued ();
17981798 }
17991799
1800+ private boolean validateAndDispatchMsg (Message msg , boolean checkTooHigh , boolean checkTooLow )
1801+ throws RejectLogon , FieldNotFound , IncorrectDataFormat , IncorrectTagValue ,
1802+ UnsupportedMessageType , IOException {
1803+ try {
1804+ if (!verify (msg , checkTooHigh , checkTooLow )) {
1805+ return false ;
1806+ }
1807+
1808+ final Message .Header header = msg .getHeader ();
1809+ final String msgType = header .getString (MsgType .FIELD );
1810+
1811+ fromCallback (msgType , msg , sessionID );
1812+
1813+ return true ;
1814+ } catch (final FieldNotFound e ) {
1815+ throw e ;
1816+ } catch (final Exception e ) {
1817+ getLog ().onErrorEvent (e .getClass ().getName () + " " + e .getMessage ());
1818+ disconnect ("Verifying message failed: " + e , true );
1819+ return false ;
1820+ }
1821+ }
1822+
18001823 private boolean verify (Message msg , boolean checkTooHigh , boolean checkTooLow )
18011824 throws RejectLogon , FieldNotFound , IncorrectDataFormat , IncorrectTagValue ,
18021825 UnsupportedMessageType , IOException {
@@ -1869,7 +1892,6 @@ private boolean verify(Message msg, boolean checkTooHigh, boolean checkTooLow)
18691892 return false ;
18701893 }
18711894
1872- fromCallback (msgType , msg , sessionID );
18731895 return true ;
18741896 }
18751897
@@ -1940,7 +1962,7 @@ private synchronized boolean validLogonState(String msgType) {
19401962
19411963 private boolean verify (Message message ) throws RejectLogon , FieldNotFound , IncorrectDataFormat ,
19421964 IncorrectTagValue , UnsupportedMessageType , IOException {
1943- return verify (message , validateSequenceNumbers , validateSequenceNumbers );
1965+ return validateAndDispatchMsg (message , validateSequenceNumbers , validateSequenceNumbers );
19441966 }
19451967
19461968 /**
@@ -2202,7 +2224,7 @@ private void nextLogon(Message logon) throws FieldNotFound, RejectLogon, Incorre
22022224 state .setResetReceived (true );
22032225 }
22042226
2205- if (!verify (logon , false , validateSequenceNumbers )) {
2227+ if (!validateAndDispatchMsg (logon , false , validateSequenceNumbers )) {
22062228 return ;
22072229 }
22082230
0 commit comments