Search in sources :

Example 1 with SessionID

use of quickfix.SessionID in project camel by apache.

the class FixMessageRouter method getDestinationSessionID.

private SessionID getDestinationSessionID(Message message) {
    Header header = message.getHeader();
    String fixVersion = getField(header, BeginString.FIELD);
    String destinationCompId = getField(header, DeliverToCompID.FIELD);
    if (destinationCompId != null) {
        String destinationSubId = getField(header, DeliverToSubID.FIELD);
        String destinationLocationId = getField(header, DeliverToLocationID.FIELD);
        header.removeField(DeliverToCompID.FIELD);
        header.removeField(DeliverToSubID.FIELD);
        header.removeField(DeliverToLocationID.FIELD);
        String gatewayCompId = getField(header, TargetCompID.FIELD);
        String gatewaySubId = getField(header, TargetSubID.FIELD);
        String gatewayLocationId = getField(header, TargetLocationID.FIELD);
        header.setString(OnBehalfOfCompID.FIELD, getField(header, SenderCompID.FIELD));
        if (header.isSetField(SenderSubID.FIELD)) {
            header.setString(OnBehalfOfSubID.FIELD, getField(header, SenderSubID.FIELD));
        }
        if (header.isSetField(SenderLocationID.FIELD)) {
            header.setString(OnBehalfOfLocationID.FIELD, getField(header, SenderLocationID.FIELD));
        }
        return new SessionID(fixVersion, gatewayCompId, gatewaySubId, gatewayLocationId, destinationCompId, destinationSubId, destinationLocationId, null);
    }
    return null;
}
Also used : Header(quickfix.Message.Header) BeginString(quickfix.field.BeginString) SessionID(quickfix.SessionID)

Example 2 with SessionID

use of quickfix.SessionID 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 3 with SessionID

use of quickfix.SessionID 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 4 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjConsumerTest method setExceptionOnInOutExchange.

@Test
public void setExceptionOnInOutExchange() throws Exception {
    org.apache.camel.Message mockCamelOutMessage = Mockito.mock(org.apache.camel.Message.class);
    org.apache.camel.Message mockCamelInMessage = Mockito.mock(org.apache.camel.Message.class);
    SessionID mockSessionId = Mockito.mock(SessionID.class);
    QuickfixjConsumer consumer = Mockito.spy(new QuickfixjConsumer(mockEndpoint, mockProcessor));
    Mockito.doReturn(null).when(consumer).getSession(mockSessionId);
    Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
    Mockito.when(mockExchange.hasOut()).thenReturn(true);
    Mockito.when(mockExchange.getOut()).thenReturn(mockCamelOutMessage);
    Message outboundFixMessage = new Message();
    Mockito.when(mockCamelOutMessage.getBody(Message.class)).thenReturn(outboundFixMessage);
    Mockito.when(mockExchange.getIn()).thenReturn(mockCamelInMessage);
    Mockito.when(mockCamelInMessage.getHeader("SessionID", SessionID.class)).thenReturn(mockSessionId);
    consumer.start();
    // Simulate a message from the FIX engine
    consumer.onExchange(mockExchange);
    Mockito.verify(mockExchange).setException(Matchers.isA(IllegalStateException.class));
}
Also used : Message(quickfix.Message) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 5 with SessionID

use of quickfix.SessionID in project camel by apache.

the class QuickfixjConsumer method sendOutMessage.

private void sendOutMessage(Exchange exchange) throws QFJException {
    Message camelMessage = exchange.getOut();
    quickfix.Message quickfixjMessage = camelMessage.getBody(quickfix.Message.class);
    log.debug("Sending FIX message reply: {}", quickfixjMessage);
    SessionID messageSessionID = exchange.getIn().getHeader("SessionID", SessionID.class);
    Session session = getSession(messageSessionID);
    if (session == null) {
        throw new IllegalStateException("Unknown session: " + messageSessionID);
    }
    if (!session.send(quickfixjMessage)) {
        throw new CannotSendException("Could not send FIX message reply: " + quickfixjMessage.toString());
    }
}
Also used : Message(org.apache.camel.Message) 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