Search in sources :

Example 1 with SessionSettings

use of quickfix.SessionSettings in project camel by apache.

the class QuickfixjComponentTest method messagePublication.

@Test
public void messagePublication() throws Exception {
    setUpComponent();
    // Create settings file with both acceptor and initiator
    SessionSettings 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);
    SessionID acceptorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "ACCEPTOR", "INITIATOR");
    settings.setString(acceptorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
    settings.setLong(acceptorSessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 1234);
    setSessionID(settings, acceptorSessionID);
    SessionID initiatorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "INITIATOR", "ACCEPTOR");
    settings.setString(initiatorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
    settings.setLong(initiatorSessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);
    settings.setLong(initiatorSessionID, Initiator.SETTING_RECONNECT_INTERVAL, 1);
    setSessionID(settings, initiatorSessionID);
    writeSettings(settings, true);
    Endpoint endpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
    // Start the component and wait for the FIX sessions to be logged on
    final CountDownLatch logonLatch = new CountDownLatch(2);
    final CountDownLatch messageLatch = new CountDownLatch(2);
    Consumer consumer = endpoint.createConsumer(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            QuickfixjEventCategory eventCategory = (QuickfixjEventCategory) exchange.getIn().getHeader(QuickfixjEndpoint.EVENT_CATEGORY_KEY);
            if (eventCategory == QuickfixjEventCategory.SessionLogon) {
                logonLatch.countDown();
            } else if (eventCategory == QuickfixjEventCategory.AppMessageReceived) {
                messageLatch.countDown();
            }
        }
    });
    ServiceHelper.startService(consumer);
    // will start the component
    camelContext.start();
    assertTrue("Session not created", logonLatch.await(5000, TimeUnit.MILLISECONDS));
    Endpoint producerEndpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), acceptorSessionID));
    Producer producer = producerEndpoint.createProducer();
    // FIX message to send
    Email email = new Email(new EmailThreadID("ID"), new EmailType(EmailType.NEW), new Subject("Test"));
    Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(email);
    producer.process(exchange);
    // Produce with no session ID specified, session ID must be in message
    Producer producer2 = endpoint.createProducer();
    email.getHeader().setString(SenderCompID.FIELD, acceptorSessionID.getSenderCompID());
    email.getHeader().setString(TargetCompID.FIELD, acceptorSessionID.getTargetCompID());
    producer2.process(exchange);
    assertTrue("Messages not received", messageLatch.await(5000, TimeUnit.MILLISECONDS));
}
Also used : Processor(org.apache.camel.Processor) Email(quickfix.fix44.Email) EmailType(quickfix.field.EmailType) EmailThreadID(quickfix.field.EmailThreadID) CountDownLatch(java.util.concurrent.CountDownLatch) SessionSettings(quickfix.SessionSettings) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Subject(quickfix.field.Subject) Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) Producer(org.apache.camel.Producer) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 2 with SessionSettings

use of quickfix.SessionSettings in project camel by apache.

the class QuickfixjConfigurationTest method testConfiguration.

@Test
public void testConfiguration() throws Exception {
    QuickfixjConfiguration factory = new QuickfixjConfiguration();
    Map<Object, Object> defaultSettings = new HashMap<Object, Object>();
    defaultSettings.put("value1", 1);
    defaultSettings.put("value2", 2);
    factory.setDefaultSettings(defaultSettings);
    Map<Object, Object> session1Settings = new HashMap<Object, Object>();
    session1Settings.put("value1", 10);
    session1Settings.put("value3", 30);
    Map<SessionID, Map<Object, Object>> sessionSettings = new HashMap<SessionID, Map<Object, Object>>();
    SessionID sessionID = new SessionID("FIX.4.2:SENDER->TARGET");
    sessionSettings.put(sessionID, session1Settings);
    factory.setSessionSettings(sessionSettings);
    SessionSettings settings = factory.createSessionSettings();
    Properties sessionProperties = settings.getSessionProperties(sessionID, true);
    Assert.assertThat(sessionProperties.get("value1").toString(), CoreMatchers.is("10"));
    Assert.assertThat(sessionProperties.get("value2").toString(), CoreMatchers.is("2"));
    Assert.assertThat(sessionProperties.get("value3").toString(), CoreMatchers.is("30"));
}
Also used : HashMap(java.util.HashMap) Properties(java.util.Properties) SessionID(quickfix.SessionID) Map(java.util.Map) HashMap(java.util.HashMap) SessionSettings(quickfix.SessionSettings) Test(org.junit.Test)

Example 3 with SessionSettings

use of quickfix.SessionSettings in project camel by apache.

the class QuickfixjConvertersTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    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);
    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));
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) SessionSettings(quickfix.SessionSettings) Before(org.junit.Before)

Example 4 with SessionSettings

use of quickfix.SessionSettings in project camel by apache.

the class TestSupport method createSession.

public static Session createSession(SessionID sessionID) throws ConfigError, IOException {
    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);
    DefaultSessionFactory factory = new DefaultSessionFactory(Mockito.mock(Application.class), mockMessageStoreFactory, Mockito.mock(LogFactory.class));
    SessionSettings settings = new SessionSettings();
    settings.setLong(Session.SETTING_HEARTBTINT, 10);
    settings.setString(Session.SETTING_START_TIME, "00:00:00");
    settings.setString(Session.SETTING_END_TIME, "00:00:00");
    settings.setString(SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
    settings.setBool(Session.SETTING_USE_DATA_DICTIONARY, false);
    return factory.create(sessionID, settings);
}
Also used : MessageStore(quickfix.MessageStore) LogFactory(quickfix.LogFactory) DefaultSessionFactory(quickfix.DefaultSessionFactory) MessageStoreFactory(quickfix.MessageStoreFactory) Application(quickfix.Application) Date(java.util.Date) SessionSettings(quickfix.SessionSettings)

Example 5 with SessionSettings

use of quickfix.SessionSettings 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)

Aggregations

SessionSettings (quickfix.SessionSettings)10 SessionID (quickfix.SessionID)6 URL (java.net.URL)3 URLClassLoader (java.net.URLClassLoader)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Date (java.util.Date)2 Properties (java.util.Properties)2 LogFactory (quickfix.LogFactory)2 MessageStore (quickfix.MessageStore)2 MessageStoreFactory (quickfix.MessageStoreFactory)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Consumer (org.apache.camel.Consumer)1 Endpoint (org.apache.camel.Endpoint)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1