quickfixJ Getting Session settings from the session object

4.4k views Asked by At

I would like to customize the sent Login message in the toAdmin method by adding the Username and Password values from the current session settings. Something like that:

@Override
public void toAdmin(Message message, SessionID sessionId) {
    Header header = message.getHeader();
    if (!header.isSetField(MsgType.FIELD) || !header.getString(MsgType.FIELD).equals(MsgType.LOGON))
    {
        // not a logon message: do not modify it
        return;
    }

    Session session = Session.lookupSession(sessionId);           

    message.setField(new Username(seesion.getSettingValue("Username")));
    message.setField(new Password(seesion.getSettingValue("Password")));
}

The getSettingValue method doesn't exist. Is there any way to do this in quickfixJ? BTW this is possible in quickfixn.

3

There are 3 answers

0
Grant Birchmeier On BEST ANSWER

I assume you mean that you want to define custom Username/Password settings in your config file. (QF does not have these built-in.)

This link will show you how to use custom settings. http://www.quickfixj.org/confluence/display/qfj/Using+Custom+Settings
(Ignore the bit in the prose about getSessionSettings(); this method does not appear to actually exist in the current build.)

In case that page goes down, in a nutshell the process is this:

Somehow give your MessageCracker app a reference to your SessionSettings object (whether by constructor or get/set or however).

In your toAdmin(), do something like this:

final String msgType = msg.getHeader().getString(MsgType.FIELD);
if(MsgType.LOGON.compareTo(msgType) == 0)
{
    msg.setString(quickfix.fields.Username.FIELD,
      mySettings.getString(sessionID, "Username");
    msg.setString(quickfix.fields.Password.FIELD,
      mySettings.getString(sessionID, "Password");
}

(I haven't compiled this code; please let me know if I have a syntax error and I'll fix it.)

I literally just added the C# equivalent to the QF/n User FAQ yesterday. You must be on the QF/n mail list, or else just have really great timing.

(I should probably add this to the QF/j User FAQ as well.)

0
Frank Smith On

You can do something similar to this in QuickFIX/J. Take a look at the QFJ wiki for an example. Rather than accessing the session settings through the Session you can provide a SessionSettings instance to your Application implementation and then use that object to get your custom settings.

1
DumbCoder On

Are you sure you are looking in the right direction. I just checked the Session class in the QuickfixJ documentation. It doesn't have any data members username or password. So you cannot extract any values, which it doesn't contain.

Or are you using your special version of Session class ? I don't believe Session should be holding any of those data either, it is unecessary and open to malicious use. I am not sure how the same side can have multiple userid and passwords to connect to another side(same one and I am assuming so because you are trying to use the same session id to fetch the user id and password), opens up all issues once again.

So if you have a single userid/password, better take it from your DB or other source you might be using rather than trying to fetch it from the session.