Search in sources :

Example 21 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjEngineTest method sessionEvents.

@Test
public void sessionEvents() throws Exception {
    SessionID acceptorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "MARKET", "TRADER");
    SessionID initiatorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "TRADER", "MARKET");
    quickfixjEngine = new QuickfixjEngine("quickfix:test", "examples/inprocess.cfg");
    doLogonEventsTest(acceptorSessionID, initiatorSessionID, quickfixjEngine);
    doApplicationMessageEventsTest(acceptorSessionID, initiatorSessionID, quickfixjEngine);
    doLogoffEventsTest(acceptorSessionID, initiatorSessionID, quickfixjEngine);
}
Also used : SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 22 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjEngineTest method doApplicationMessageEventsTest.

private void doApplicationMessageEventsTest(SessionID acceptorSessionID, SessionID initiatorSessionID, QuickfixjEngine quickfixjEngine) throws SessionNotFound, InterruptedException, FieldNotFound {
    final List<EventRecord> events = new ArrayList<EventRecord>();
    final CountDownLatch messageLatch = new CountDownLatch(1);
    QuickfixjEventListener messageListener = new QuickfixjEventListener() {

        @Override
        public synchronized void onEvent(QuickfixjEventCategory eventCategory, SessionID sessionID, Message message) {
            EventRecord event = new EventRecord(eventCategory, sessionID, message);
            events.add(event);
            if (eventCategory == QuickfixjEventCategory.AppMessageReceived) {
                messageLatch.countDown();
            }
        }
    };
    quickfixjEngine.addEventListener(messageListener);
    Email email = TestSupport.createEmailMessage("Test");
    Session.sendToTarget(email, initiatorSessionID);
    assertTrue("Application message not received", messageLatch.await(5000, TimeUnit.MILLISECONDS));
    quickfixjEngine.removeEventListener(messageListener);
    assertThat(events.size(), is(2));
    EventRecord sendEvent = new EventRecord(QuickfixjEventCategory.AppMessageSent, initiatorSessionID, new Message());
    assertTrue(events.contains(sendEvent));
    int sendEventIndex = events.indexOf(sendEvent);
    assertThat(events.get(sendEventIndex).message.getHeader().getString(MsgType.FIELD), is(MsgType.EMAIL));
    EventRecord receiveEvent = new EventRecord(QuickfixjEventCategory.AppMessageReceived, acceptorSessionID, new Message());
    assertTrue(events.contains(receiveEvent));
    int receiveEventIndex = events.indexOf(receiveEvent);
    assertThat(events.get(receiveEventIndex).message.getHeader().getString(MsgType.FIELD), is(MsgType.EMAIL));
}
Also used : Email(quickfix.fix42.Email) Message(quickfix.Message) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) SessionID(quickfix.SessionID)

Example 23 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjEngineTest method doLogoffEventsTest.

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

        @Override
        public synchronized void onEvent(QuickfixjEventCategory eventCategory, SessionID sessionID, Message message) {
            EventRecord event = new EventRecord(eventCategory, sessionID, message);
            events.add(event);
            if (eventCategory == QuickfixjEventCategory.SessionLogoff) {
                logoffLatch.countDown();
            }
        }
    };
    quickfixjEngine.addEventListener(logoffListener);
    quickfixjEngine.stop();
    assertTrue("Logoffs not received", logoffLatch.await(5000, TimeUnit.MILLISECONDS));
    quickfixjEngine.removeEventListener(logoffListener);
    assertThat(events.size(), is(2));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionLogoff, acceptorSessionID, null)));
    assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionLogoff, initiatorSessionID, null)));
}
Also used : Message(quickfix.Message) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) SessionID(quickfix.SessionID)

Example 24 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjEngineTest method minimalInitiatorAndAcceptor.

@Test
public void minimalInitiatorAndAcceptor() throws Exception {
    settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
    settings.setLong(sessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 1234);
    SessionID initiatorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "FARGLE", "BARGLE");
    settings.setString(initiatorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
    TestSupport.setSessionID(settings, initiatorSessionID);
    writeSettings();
    quickfixjEngine = new QuickfixjEngine("quickfix:test", settingsFile.getName());
    assertThat(quickfixjEngine.getInitiator(), notNullValue());
    assertThat(quickfixjEngine.getAcceptor(), notNullValue());
    assertDefaultConfiguration(quickfixjEngine);
}
Also used : SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 25 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjEventJsonTransformer method transform.

public String transform(Exchange exchange) {
    SessionID sessionID = exchange.getIn().getHeader(QuickfixjEndpoint.SESSION_ID_KEY, SessionID.class);
    Session session = Session.lookupSession(sessionID);
    DataDictionary dataDictionary = session.getDataDictionary();
    if (dataDictionary == null) {
        throw new IllegalStateException("No Data Dictionary. Exchange must reference an existing session");
    }
    StringBuilder sb = new StringBuilder();
    sb.append("\"event\": {\n");
    org.apache.camel.Message in = exchange.getIn();
    for (String key : in.getHeaders().keySet()) {
        sb.append("  \"").append(key).append("\": ").append(in.getHeader(key)).append(",\n");
    }
    sb.append(renderer.transform(in.getBody(Message.class), "  ", dataDictionary)).append("\n");
    sb.append("}\n");
    return sb.toString();
}
Also used : Message(quickfix.Message) DataDictionary(quickfix.DataDictionary) SessionID(quickfix.SessionID) Session(quickfix.Session)

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