use of quickfix.SessionID in project camel by apache.
the class QuickfixjEngine method isConnectorRole.
private boolean isConnectorRole(SessionSettings settings, String connectorRole) throws ConfigError {
boolean hasRole = false;
Iterator<SessionID> sessionIdItr = settings.sectionIterator();
while (sessionIdItr.hasNext()) {
try {
if (connectorRole.equals(settings.getString(sessionIdItr.next(), SessionFactory.SETTING_CONNECTION_TYPE))) {
hasRole = true;
break;
}
} catch (FieldConvertError e) {
throw new ConfigError(e);
}
}
return hasRole;
}
use of quickfix.SessionID in project camel by apache.
the class QuickfixjProducer method sendMessage.
void sendMessage(Exchange exchange, org.apache.camel.Message camelMessage) throws Exception {
Message message = camelMessage.getBody(Message.class);
log.debug("Sending FIX message: {}", message);
SessionID messageSessionID = getEndpoint().getSessionID();
if (messageSessionID == null) {
messageSessionID = MessageUtils.getSessionID(message);
}
Session session = getSession(messageSessionID);
if (session == null) {
throw new IllegalStateException("Unknown session: " + messageSessionID);
}
Callable<Message> callable = null;
if (exchange.getPattern().isOutCapable()) {
MessageCorrelator messageCorrelator = getEndpoint().getEngine().getMessageCorrelator();
callable = messageCorrelator.getReply(getEndpoint().getSessionID(), exchange);
}
if (!session.send(message)) {
throw new CannotSendException("Cannot send FIX message: " + message.toString());
}
if (callable != null) {
Message reply = callable.call();
exchange.getOut().getHeaders().putAll(camelMessage.getHeaders());
exchange.getOut().setBody(reply);
}
}
use of quickfix.SessionID 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);
}
use of quickfix.SessionID in project camel by apache.
the class QuickfixjEngineTest method setUp.
@Before
public void setUp() throws Exception {
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);
sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "FOO", "BAR");
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);
settings.setBool(QuickfixjEngine.SETTING_USE_JMX, false);
TestSupport.setSessionID(settings, sessionID);
}
use of quickfix.SessionID in project camel by apache.
the class QuickfixjEngineTest method doLogonEventsTest.
private void doLogonEventsTest(SessionID acceptorSessionID, SessionID initiatorSessionID, QuickfixjEngine quickfixjEngine) throws Exception {
final List<EventRecord> events = new ArrayList<EventRecord>();
final CountDownLatch logonLatch = new CountDownLatch(2);
QuickfixjEventListener logonListener = new QuickfixjEventListener() {
@Override
public synchronized void onEvent(QuickfixjEventCategory eventCategory, SessionID sessionID, Message message) {
events.add(new EventRecord(eventCategory, sessionID, message));
if (eventCategory == QuickfixjEventCategory.SessionLogon) {
logonLatch.countDown();
}
}
};
quickfixjEngine.addEventListener(logonListener);
quickfixjEngine.start();
assertTrue("Logons not completed", logonLatch.await(5000, TimeUnit.MILLISECONDS));
quickfixjEngine.removeEventListener(logonListener);
assertThat(events.size(), is(8));
// The session events will arrive out of order as the event callbacks happen in the context of different threads so that the asserts
// below must cater for that, that's do not assert on the order of the arrived events but just do assert on their existence. for this
// to work we have've defined a relaxed comparison about the messages being sent, see the EventRecord.equals() method
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionCreated, acceptorSessionID, null)));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionCreated, initiatorSessionID, null)));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.AdminMessageSent, initiatorSessionID, new Message())));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.AdminMessageReceived, acceptorSessionID, new Message())));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.AdminMessageSent, acceptorSessionID, new Message())));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.AdminMessageReceived, initiatorSessionID, new Message())));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionLogon, initiatorSessionID, null)));
assertTrue(events.contains(new EventRecord(QuickfixjEventCategory.SessionLogon, acceptorSessionID, null)));
}
Aggregations