use of quickfix.Session 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.Session 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());
}
}
use of quickfix.Session 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.Session in project camel by apache.
the class QuickfixjProducerTest method processInOutExchangeSendUnsuccessful.
@Test
public void processInOutExchangeSendUnsuccessful() throws Exception {
Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_CRITERIA_KEY)).thenReturn(new MessagePredicate(sessionID, MsgType.EMAIL));
Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_TIMEOUT_KEY, 1000L, Long.class)).thenReturn(5000L);
org.apache.camel.Message mockOutboundCamelMessage = Mockito.mock(org.apache.camel.Message.class);
Mockito.when(mockExchange.getOut()).thenReturn(mockOutboundCamelMessage);
final Message outboundFixMessage = new Email();
outboundFixMessage.getHeader().setString(SenderCompID.FIELD, "TARGET");
outboundFixMessage.getHeader().setString(TargetCompID.FIELD, "SENDER");
Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
Mockito.doReturn(mockSession).when(producer).getSession(MessageUtils.getSessionID(inboundFixMessage));
Mockito.doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
try {
quickfixjEngine.getMessageCorrelator().onEvent(QuickfixjEventCategory.AppMessageReceived, sessionID, outboundFixMessage);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, 10);
return false;
}
}).when(mockSession).send(Matchers.isA(Message.class));
producer.process(mockExchange);
Mockito.verify(mockOutboundCamelMessage, Mockito.never()).setBody(Matchers.isA(Message.class));
Mockito.verify(mockSession).send(inboundFixMessage);
Mockito.verify(mockExchange).setException(Matchers.isA(CannotSendException.class));
}
use of quickfix.Session in project camel by apache.
the class QuickfixjProducerTest method setExceptionOnExchange.
@Test
public void setExceptionOnExchange() throws Exception {
Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
Mockito.doReturn(mockSession).when(producer).getSession(MessageUtils.getSessionID(inboundFixMessage));
Mockito.doThrow(new TestException()).when(mockSession).send(Matchers.isA(Message.class));
producer.process(mockExchange);
Mockito.verify(mockExchange).setException(Matchers.isA(TestException.class));
}
Aggregations