} else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) { getLog().onEvent("Timed out waiting for logon response");
state.incrNextTargetMsgSeqNum(); } } catch (FieldException e) { generateReject(message, e.getSessionRejectReason(), e.getField()); } catch (FieldNotFound e) { if (sessionID.getBeginString().compareTo(FixVersions.BEGINSTRING_FIX42) >= 0 && message.isApp()) { generateBusinessReject(message, BusinessRejectReason.CONDITIONALLY_REQUIRED_FIELD_MISSING); } else { generateReject(message, SessionRejectReason.REQUIRED_TAG_MISSING, e.field); if (msgType.equals(MsgType.LOGON)) { getLog().onEvent("Required field missing from logon"); disconnect(); } } } catch (IncorrectTagValue e) { generateReject(message, SessionRejectReason.VALUE_IS_INCORRECT, e.field); } catch (InvalidMessage e) { getLog().onEvent("Skipping invalid message: " + e.getMessage()); } catch (RejectLogon e) { String rejectMessage = e.getMessage() != null ? (": " + e.getMessage()) : ""; getLog().onEvent("Logon rejected" + rejectMessage); generateLogout(e.getMessage()); disconnect(); } catch (UnsupportedMessageType e) { if (sessionID.getBeginString().compareTo(FixVersions.BEGINSTRING_FIX42) >= 0) { generateBusinessReject(message, BusinessRejectReason.UNSUPPORTED_MESSAGE_TYPE); } else { generateReject(message, "Unsupported message type"); } } catch (UnsupportedVersion e) { if (msgType.equals(MsgType.LOGOUT)) { nextLogout(message); } else { generateLogout("Incorrect BeginString"); state.incrNextTargetMsgSeqNum();
    public synchronized void next() throws IOException {        if (!enabled) {            if (isLoggedOn()) {                if (!state.isLogoutSent()) {                    getLog().onEvent("Initiated logout request");                    generateLogout(state.getLogoutReason());                }            } else {                return;            }        }        if (!checkSessionTime()) {            reset();            return;        }        if (!state.isLogonReceived()) {            if (state.isLogonSendNeeded()) {                if (generateLogon()) {                    getLog().onEvent("Initiated logon request");                } else {                    getLog().onEvent("Error during logon request initiation");                }            } else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) {                getLog().onEvent("Timed out waiting for logon response");                disconnect();            }            return;        }        if (state.getHeartBeatInterval() == 0) {            return;        }        if (state.isLogoutTimedOut()) {            getLog().onEvent("Timed out waiting for logout response");            disconnect();        }        if (state.isWithinHeartBeat()) {            return;        }        if (state.isTimedOut()) {            getLog().onEvent("Timed out waiting for heartbeat");            disconnect();        } else {            if (state.isTestRequestNeeded()) {                generateTestRequest("TEST");                state.incrementTestRequestCounter();                getLog().onEvent("Sent test request TEST");            } else if (state.isHeartBeatNeeded()) {                generateHeartbeat();            }        }    }