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);
}
}
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;
}
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);
}
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();
}
}
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();
}
Aggregations