Search in sources :

Example 1 with DataDictionary

use of quickfix.DataDictionary in project camel by apache.

the class TradeExecutor method sendMessage.

private void sendMessage(SessionID sessionID, Message message) {
    try {
        Session session = Session.lookupSession(sessionID);
        if (session == null) {
            throw new SessionNotFound(sessionID.toString());
        }
        DataDictionaryProvider provider = session.getDataDictionaryProvider();
        if (provider != null) {
            try {
                ApplVerID applVerID = getApplVerID(session, message);
                DataDictionary appDataDictionary = provider.getApplicationDataDictionary(applVerID);
                appDataDictionary.validate(message, true);
            } catch (Exception e) {
                LogUtil.logThrowable(sessionID, "Outgoing message failed validation: " + e.getMessage(), e);
                return;
            }
        }
        for (QuickfixjMessageListener listener : listeners) {
            try {
                listener.onMessage(sessionID, message);
            } catch (Throwable e) {
                LogUtil.logThrowable(sessionID, "Error while dispatching message", e);
            }
        }
    } catch (SessionNotFound e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : ApplVerID(quickfix.field.ApplVerID) DataDictionary(quickfix.DataDictionary) DataDictionaryProvider(quickfix.DataDictionaryProvider) Session(quickfix.Session) SessionNotFound(quickfix.SessionNotFound)

Example 2 with DataDictionary

use of quickfix.DataDictionary in project camel by apache.

the class QuickfixjConverters method getDataDictionary.

private static DataDictionary getDataDictionary(Exchange exchange) throws ConfigError {
    Object dictionaryValue = exchange.getProperties().get(QuickfixjEndpoint.DATA_DICTIONARY_KEY);
    DataDictionary dataDictionary = null;
    if (dictionaryValue instanceof DataDictionary) {
        dataDictionary = (DataDictionary) dictionaryValue;
    } else if (dictionaryValue instanceof String) {
        dataDictionary = new DataDictionary((String) dictionaryValue);
    } else {
        SessionID sessionID = exchange.getIn().getHeader(QuickfixjEndpoint.SESSION_ID_KEY, SessionID.class);
        if (sessionID != null) {
            Session session = Session.lookupSession(sessionID);
            dataDictionary = session != null ? session.getDataDictionary() : null;
        }
    }
    return dataDictionary;
}
Also used : DataDictionary(quickfix.DataDictionary) SessionID(quickfix.SessionID) Session(quickfix.Session)

Example 3 with DataDictionary

use of quickfix.DataDictionary in project camel by apache.

the class QuickfixjConverters method toMessage.

@Converter
public static Message toMessage(byte[] value, Exchange exchange) throws InvalidMessage, ConfigError, UnsupportedEncodingException {
    DataDictionary dataDictionary = getDataDictionary(exchange);
    String charsetName = IOHelper.getCharsetName(exchange);
    String message;
    if (charsetName != null) {
        message = new String(value, charsetName);
    } else {
        message = new String(value);
    }
    // if message ends with any sort of newline trim it so QuickfixJ's doesn't fail while parsing the string
    if (message.endsWith("\r\n")) {
        message = message.substring(0, message.length() - 2);
    } else if (message.endsWith("\r") || message.endsWith("\n")) {
        message = message.substring(0, message.length() - 1);
    }
    return new Message(message, dataDictionary, false);
}
Also used : InvalidMessage(quickfix.InvalidMessage) Message(quickfix.Message) DataDictionary(quickfix.DataDictionary) Converter(org.apache.camel.Converter)

Example 4 with DataDictionary

use of quickfix.DataDictionary in project camel by apache.

the class QuickfixjConvertersTest method convertMessageWithRepeatingGroupsUsingExchangeDictionary.

@Test
public void convertMessageWithRepeatingGroupsUsingExchangeDictionary() throws Exception {
    SessionID sessionID = new SessionID("FIX.4.4", "FOO", "BAR");
    createSession(sessionID);
    try {
        String data = "8=FIX.4.4\0019=40\00135=A\001" + "627=2\001628=FOO\001628=BAR\001" + "98=0\001384=2\001372=D\001385=R\001372=8\001385=S\00110=230\001";
        Exchange exchange = new DefaultExchange(context);
        exchange.setProperty(QuickfixjEndpoint.DATA_DICTIONARY_KEY, new DataDictionary("FIX44.xml"));
        exchange.getIn().setBody(data);
        Message message = exchange.getIn().getBody(Message.class);
        NoHops hop = new NoHops();
        message.getHeader().getGroup(1, hop);
        assertEquals("FOO", hop.getString(HopCompID.FIELD));
        message.getHeader().getGroup(2, hop);
        assertEquals("BAR", hop.getString(HopCompID.FIELD));
    } finally {
        quickfixjEngine.stop();
    }
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) NoHops(quickfix.fix44.Message.Header.NoHops) Message(quickfix.Message) DataDictionary(quickfix.DataDictionary) SessionID(quickfix.SessionID) Test(org.junit.Test)

Example 5 with DataDictionary

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

DataDictionary (quickfix.DataDictionary)6 Session (quickfix.Session)4 SessionID (quickfix.SessionID)4 Message (quickfix.Message)3 Converter (org.apache.camel.Converter)1 Exchange (org.apache.camel.Exchange)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1 Test (org.junit.Test)1 DataDictionaryProvider (quickfix.DataDictionaryProvider)1 InvalidMessage (quickfix.InvalidMessage)1 SessionNotFound (quickfix.SessionNotFound)1 ApplVerID (quickfix.field.ApplVerID)1 NoHops (quickfix.fix44.Message.Header.NoHops)1