[QFJ-370] Sending two logon messages when I only mean to send one? Created: 12/Nov/08  Updated: 26/Nov/08  Resolved: 26/Nov/08

Status: Closed
Project: QuickFIX/J
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Other Priority: Default
Reporter: Herman Hung Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None


 Description   

Hi,

I have a FIX initiator that implements the Application interface, and uses the code below to log on to sessions. I connect just fine...however, I've noticed that I keep sending two logon messages instead of just one. Is there something that I am doing incorrectly?

[code]
// Method to determine messages that we send to the FIX Exchange (Administrator class messages)
public void toAdmin(Message message, SessionID sessionId)
{
if(isMessageOfType(message, MsgType.LOGON) && (loginsent == false))
{
loginsent = true;

// Get information from properties
String user = "user";
String password = "password";
UserNameField usefield = new UserNameField(user);
PasswordField passfield = new PasswordField(password);

// Set Message References
Message msgToMod = message;
msgToMod.setField(usefield);
msgToMod.setField(passfield);

// Send Message
try

{ Session.sendToTarget(msgToMod,sessionId); }

catch(Exception ex)

{ System.out.println("SESSION NOT FOUND!"); ex.printStackTrace(); }

}
}
[/code]

Thanks and regards,
hhung



 Comments   
Comment by Herman Hung [ 12/Nov/08 ]

Also, I am using FIX4.2. The code for the "isMessageOfType" method is:

private boolean isMessageOfType(Message message, String type) {
try

{ return type.equals(message.getHeader().getField(new MsgType()).getValue()); }

catch (FieldNotFound e)

{ e.printStackTrace(); return false; }

}

Thanks.

Comment by Laurent Danesi [ 12/Nov/08 ]

Hi Herman,

Your code seems ok but you don't need to send the message after added the username and password. The callback toAdmin is just an interceptor while sending the message.

So just try this:

[code]
// Method to determine messages that we send to the FIX Exchange (Administrator class messages)
public void toAdmin(Message message, SessionID sessionId)
{
if(isMessageOfType(message, MsgType.LOGON) && (loginsent == false))
{
loginsent = true;

// Get information from properties
String user = "user";
String password = "password";
UserNameField usefield = new UserNameField(user);
PasswordField passfield = new PasswordField(password);

// Set Message References
message.setField(usefield);
message.setField(passfield);
}
[/code]

Comment by Herman Hung [ 12/Nov/08 ]

That worked wonders...thanks for your help!

Regards,
Herman

Comment by Laurent Danesi [ 12/Nov/08 ]

You are welcome.

Laurent

Comment by Herman Hung [ 13/Nov/08 ]

This issue is resolved and can now be closed.

Regards,
Herman

Generated at Tue Jul 01 07:47:18 UTC 2025 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.