Пример #1
0
func (s *Session) doReject(msg Message, rej MessageRejectError) {
	reply := msg.reverseRoute()

	if s.sessionID.BeginString >= fix.BeginString_FIX42 {

		if rej.IsBusinessReject() {
			reply.Header().Set(field.NewMsgType("j"))
			reply.Body().Set(field.NewBusinessRejectReason(int(rej.RejectReason())))
		} else {
			reply.Header().Set(field.NewMsgType("3"))
			switch {
			default:
				reply.Body().Set(field.NewSessionRejectReason(int(rej.RejectReason())))
			case rej.RejectReason() > rejectReasonInvalidMsgType && s.sessionID.BeginString == fix.BeginString_FIX42:
				//fix42 knows up to invalid msg type
			}
		}
		reply.Body().Set(field.NewText(rej.Error()))

		var msgType field.MsgTypeField
		if err := msg.Header.Get(&msgType); err == nil {
			reply.Body().Set(field.NewRefMsgType(msgType.Value))
		}

		if refTagID := rej.RefTagID(); refTagID != nil {
			reply.Body().Set(field.NewRefTagID(int(*refTagID)))
		}
	} else {
		reply.Header().Set(field.NewMsgType("3"))

		if refTagID := rej.RefTagID(); refTagID != nil {
			reply.Body().Set(field.NewText(fmt.Sprintf("%s (%d)", rej.Error(), *refTagID)))
		} else {
			reply.Body().Set(field.NewText(rej.Error()))
		}
	}

	var seqNum field.MsgSeqNumField
	if err := msg.Header.Get(&seqNum); err == nil {
		reply.Body().Set(field.NewRefSeqNum(seqNum.Value))
	}

	s.send(reply)
	s.log.OnEventf("Message Rejected: %v", rej.Error())
}
Пример #2
0
func (state *inSession) generateLogoutWithReason(session *Session, reason string) {
	reply := NewMessageBuilder()
	reply.Header().Set(field.NewMsgType("5"))
	reply.Header().Set(field.NewBeginString(session.sessionID.BeginString))
	reply.Header().Set(field.NewTargetCompID(session.sessionID.TargetCompID))
	reply.Header().Set(field.NewSenderCompID(session.sessionID.SenderCompID))

	if reason != "" {
		reply.Body().Set(field.NewText(reason))
	}

	session.send(reply)
	session.log.OnEvent("Sending logout response")
}