Search in sources :

Example 6 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjEngine method isConnectorRole.

private boolean isConnectorRole(SessionSettings settings, String connectorRole) throws ConfigError {
    boolean hasRole = false;
    Iterator<SessionID> sessionIdItr = settings.sectionIterator();
    while (sessionIdItr.hasNext()) {
        try {
            if (connectorRole.equals(settings.getString(sessionIdItr.next(), SessionFactory.SETTING_CONNECTION_TYPE))) {
                hasRole = true;
                break;
            }
        } catch (FieldConvertError e) {
            throw new ConfigError(e);
        }
    }
    return hasRole;
}
Also used : ConfigError(quickfix.ConfigError) FieldConvertError(quickfix.FieldConvertError) SessionID(quickfix.SessionID)

Example 7 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjProducer method sendMessage.

void sendMessage(Exchange exchange, org.apache.camel.Message camelMessage) throws Exception {
    Message message = camelMessage.getBody(Message.class);
    log.debug("Sending FIX message: {}", message);
    SessionID messageSessionID = getEndpoint().getSessionID();
    if (messageSessionID == null) {
        messageSessionID = MessageUtils.getSessionID(message);
    }
    Session session = getSession(messageSessionID);
    if (session == null) {
        throw new IllegalStateException("Unknown session: " + messageSessionID);
    }
    Callable<Message> callable = null;
    if (exchange.getPattern().isOutCapable()) {
        MessageCorrelator messageCorrelator = getEndpoint().getEngine().getMessageCorrelator();
        callable = messageCorrelator.getReply(getEndpoint().getSessionID(), exchange);
    }
    if (!session.send(message)) {
        throw new CannotSendException("Cannot send FIX message: " + message.toString());
    }
    if (callable != null) {
        Message reply = callable.call();
        exchange.getOut().getHeaders().putAll(camelMessage.getHeaders());
        exchange.getOut().setBody(reply);
    }
}
Also used : Message(quickfix.Message) SessionID(quickfix.SessionID) Session(quickfix.Session)

Example 8 with SessionID

use of quickfix.SessionID in project camel by apache.

the class TestSupport method createEngine.

public static QuickfixjEngine createEngine(boolean lazy) throws ConfigError, FieldConvertError, IOException, JMException {
    SessionID sessionID = new SessionID("FIX.4.4:SENDER->TARGET");
    MessageStoreFactory mockMessageStoreFactory = Mockito.mock(MessageStoreFactory.class);
    MessageStore mockMessageStore = Mockito.mock(MessageStore.class);
    Mockito.when(mockMessageStore.getCreationTime()).thenReturn(new Date());
    Mockito.when(mockMessageStoreFactory.create(sessionID)).thenReturn(mockMessageStore);
    SessionSettings settings = new SessionSettings();
    settings.setLong(sessionID, Session.SETTING_HEARTBTINT, 10);
    settings.setString(sessionID, Session.SETTING_START_TIME, "00:00:00");
    settings.setString(sessionID, Session.SETTING_END_TIME, "00:00:00");
    settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
    settings.setLong(sessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 8000);
    settings.setBool(sessionID, Session.SETTING_USE_DATA_DICTIONARY, false);
    return new QuickfixjEngine("", settings, mockMessageStoreFactory, Mockito.mock(LogFactory.class), Mockito.mock(MessageFactory.class), lazy);
}
Also used : MessageStore(quickfix.MessageStore) LogFactory(quickfix.LogFactory) MessageFactory(quickfix.MessageFactory) MessageStoreFactory(quickfix.MessageStoreFactory) SessionID(quickfix.SessionID) Date(java.util.Date) SessionSettings(quickfix.SessionSettings)

Example 9 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjEngineTest method setUp.

@Before
public void setUp() throws Exception {
    settingsFile = File.createTempFile("quickfixj_test_", ".cfg");
    tempdir = settingsFile.getParentFile();
    URL[] urls = new URL[] { tempdir.toURI().toURL() };
    contextClassLoader = Thread.currentThread().getContextClassLoader();
    ClassLoader testClassLoader = new URLClassLoader(urls, contextClassLoader);
    Thread.currentThread().setContextClassLoader(testClassLoader);
    sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "FOO", "BAR");
    settings = new SessionSettings();
    settings.setString(Acceptor.SETTING_SOCKET_ACCEPT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
    settings.setString(Initiator.SETTING_SOCKET_CONNECT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
    settings.setBool(Session.SETTING_USE_DATA_DICTIONARY, false);
    settings.setBool(QuickfixjEngine.SETTING_USE_JMX, false);
    TestSupport.setSessionID(settings, sessionID);
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) SessionID(quickfix.SessionID) URL(java.net.URL) SessionSettings(quickfix.SessionSettings) Before(org.junit.Before)

Example 10 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjEngineTest method doLogonEventsTest.

private void doLogonEventsTest(SessionID acceptorSessionID, SessionID initiatorSessionID, QuickfixjEngine quickfixjEngine) throws Exception {
    final List<EventRecord> events = new ArrayList<EventRecord>();
    final CountDownLatch logonLatch = new CountDownLatch(2);
    QuickfixjEventListener logonListener = new QuickfixjEventListener() {

        @Override
        public synchronized void onEvent(QuickfixjEventCategory eventCategory, SessionID sessionID, Message message) {
            events.add(new EventRecord(eventCategory, sessionID, message));
            if (eventCategory == QuickfixjEventCategory.SessionLogon) {
                logonLatch.countDown();
            }
        }
    };
    quickfixjEngine.addEventListener(logonListener);
    quickfixjEngine.start();
    assertTrue("Logons not completed", logonLatch.await(5000, TimeUnit.MILLISECONDS));
    quickfixjEngine.removeEventListener(logonListener);
    assertThat(events.size(), is(8));
    // The session events will arrive out of order as the event callbacks happen in the context of different threads so that the asserts
    // below must cater for that, that's do not assert on the order of the arrived events but just do assert on their existence. for this
    // to work we have've defined a relaxed comparison about the messages being sent, see the EventRecord.equals() method
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionCreated, acceptorSessionID, null)));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionCreated, initiatorSessionID, null)));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.AdminMessageSent, initiatorSessionID, new Message())));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.AdminMessageReceived, acceptorSessionID, new Message())));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.AdminMessageSent, acceptorSessionID, new Message())));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.AdminMessageReceived, initiatorSessionID, new Message())));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionLogon, initiatorSessionID, null)));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionLogon, acceptorSessionID, null)));
}
Also used : Message(quickfix.Message) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) SessionID(quickfix.SessionID)

Aggregations

SessionID (quickfix.SessionID)27 Test (org.junit.Test)13 Message (quickfix.Message)13 Session (quickfix.Session)7 Exchange (org.apache.camel.Exchange)6 SessionSettings (quickfix.SessionSettings)6 DefaultExchange (org.apache.camel.impl.DefaultExchange)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 DataDictionary (quickfix.DataDictionary)4 ArrayList (java.util.ArrayList)3 NoHops (quickfix.fix44.Message.Header.NoHops)3 IOException (java.io.IOException)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 Properties (java.util.Properties)2 Before (org.junit.Before)2 BeginString (quickfix.field.BeginString)2 Email (quickfix.fix42.Email)2 MalformedURLException (java.net.MalformedURLException)1 Date (java.util.Date)1