use of quickfix.field.TargetCompID in project wso2-synapse by wso2.
the class FIXOutgoingMessageHandlerTest method testSendMessage.
@Test
public void testSendMessage() throws Exception {
int SEQ_NUM = 1;
String SESSION_ID = "FIX.4.1:BANZAI->SYNAPSE";
Message message = new NewOrderSingle();
MessageContext msgCtx = new MessageContext();
PowerMockito.when(sessionFactory.getApplication(anyString())).thenReturn(app);
PowerMockito.mockStatic(Session.class);
PowerMockito.when(Session.sendToTarget(any(Message.class), any(SessionID.class))).thenReturn(true);
SessionID id = new SessionID(new BeginString("FIX.4.1"), new SenderCompID("SYNAPSE"), new TargetCompID("BANZAI"), "FIX.4.1:SYNAPSE->BANZAI");
spy.sendMessage(message, id, SESSION_ID, SEQ_NUM, msgCtx, "fix://sample");
PowerMockito.verifyStatic(times(1));
}
use of quickfix.field.TargetCompID in project wso2-synapse by wso2.
the class FIXIncomingMessageHandler method toApp.
/**
* This is a callback for application messages that are being sent to a
* counter party.
*
* @param message QuickFIX message
* @param sessionID QuickFIX session ID
* @throws DoNotSend This exception aborts message transmission
*/
public void toApp(Message message, SessionID sessionID) throws DoNotSend {
if (log.isDebugEnabled()) {
StringBuffer sb = new StringBuffer();
try {
sb.append("Sending application level FIX message to ").append(message.getHeader().getField(new TargetCompID()).getValue());
sb.append("\nMessage Type: ").append(message.getHeader().getField(new MsgType()).getValue());
sb.append("\nMessage Sequence Number: ").append(message.getHeader().getField(new MsgSeqNum()).getValue());
sb.append("\nSender ID: ").append(message.getHeader().getField(new SenderCompID()).getValue());
} catch (FieldNotFound e) {
sb.append("Sending application level FIX message...");
log.warn("One or more required fields are not found in the response message", e);
}
log.debug(sb.toString());
if (log.isTraceEnabled()) {
log.trace("Message: " + message.toString());
}
}
if (eventHandler != null) {
eventHandler.toApp(this, message, sessionID);
}
}
use of quickfix.field.TargetCompID in project wso2-synapse by wso2.
the class FIXIncomingMessageHandler method fromApp.
/**
* This callback receives messages for the application. This is one of the
* core entry points for the FIX application. Every application level
* request will come through here. A new thread will be spawned from the
* thread pool for each incoming message.
*
* @param message QuickFIX message
* @param sessionID QuickFIX session ID
* @throws FieldNotFound
* @throws IncorrectDataFormat
* @throws IncorrectTagValue
* @throws UnsupportedMessageType
*/
public void fromApp(Message message, SessionID sessionID) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
if (log.isDebugEnabled()) {
StringBuffer sb = new StringBuffer();
sb.append("Received FIX message from ").append(message.getHeader().getField(new SenderCompID()).getValue());
sb.append("\nMessage Sequence Number: ").append(message.getHeader().getField(new MsgSeqNum()).getValue());
sb.append("\nReceiver ID: ").append(message.getHeader().getField(new TargetCompID()).getValue());
log.debug(sb.toString());
if (log.isTraceEnabled()) {
log.trace("Message: " + message.toString());
}
}
AtomicInteger atomicCounter = countersMap.get(sessionID);
int counter = atomicCounter.incrementAndGet();
boolean rolled = atomicCounter.compareAndSet(FIXConstants.DEFAULT_COUNTER_UPPER_LIMIT, 0);
if (rolled && log.isDebugEnabled()) {
log.debug("Incoming request counter rolled over for the session: " + sessionID);
}
workerPool.execute(new FIXWorkerThread(message, sessionID, counter));
}
use of quickfix.field.TargetCompID in project wso2-synapse by wso2.
the class FIXIncomingMessageHandler method fromAdmin.
/**
* This callback notifies when an administrative message is sent from a
* counterparty to the FIX engine.
*
* @param message QuickFIX message
* @param sessionID QuickFIX session ID
* @throws FieldNotFound
* @throws IncorrectDataFormat
* @throws IncorrectTagValue
* @throws RejectLogon causes a logon reject
*/
public void fromAdmin(Message message, SessionID sessionID) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon {
if (log.isDebugEnabled()) {
StringBuffer sb = new StringBuffer();
sb.append("Received admin level FIX message from ").append(message.getHeader().getField(new SenderCompID()).getValue());
sb.append("\nMessage Type: ").append(message.getHeader().getField(new MsgType()).getValue());
sb.append("\nMessage Sequence Number: ").append(message.getHeader().getField(new MsgSeqNum()).getValue());
sb.append("\nReceiver ID: ").append(message.getHeader().getField(new TargetCompID()).getValue());
log.debug(sb.toString());
if (log.isTraceEnabled()) {
log.trace("Message: " + message.toString());
}
}
if (eventHandler != null) {
eventHandler.fromAdmin(this, message, sessionID);
}
}
use of quickfix.field.TargetCompID in project wso2-synapse by wso2.
the class FIXIncomingMessageHandler method toAdmin.
/**
* This callback provides Synapse with a peek at the administrative messages
* that are being sent from your FIX engine to the counter party. This is
* normally not useful for an application however it is provided for any
* logging one may wish to do.
*
* @param message QuickFIX message
* @param sessionID QuickFIX session ID
*/
public void toAdmin(Message message, SessionID sessionID) {
if (log.isDebugEnabled()) {
StringBuffer sb = new StringBuffer();
try {
sb.append("Sending admin level FIX message to ").append(message.getHeader().getField(new TargetCompID()).getValue());
sb.append("\nMessage Type: ").append(message.getHeader().getField(new MsgType()).getValue());
sb.append("\nMessage Sequence Number: ").append(message.getHeader().getField(new MsgSeqNum()).getValue());
sb.append("\nSender ID: ").append(message.getHeader().getField(new SenderCompID()).getValue());
} catch (FieldNotFound e) {
sb.append("Sending admin level FIX message...");
log.warn("One or more required fields are not found in the response message", e);
}
log.debug(sb.toString());
if (log.isTraceEnabled()) {
log.trace("Message: " + message.toString());
}
}
try {
// Before FIX server sends (35=A) admin login message get username/password values from proxy configuration
if (message.getHeader().getField(new StringField(FIXConstants.FIX_MESSAGE_TYPE)).getValue().equals(FIXConstants.LOGON)) {
Parameter userName = service.getParameter(FIXConstants.FIX_USERNAME);
Parameter passWord = service.getParameter(FIXConstants.FIX_PASSWORD);
if (userName != null && passWord != null) {
message.setString(FIXConstants.USERNAME_TAG, userName.getValue().toString());
message.setString(FIXConstants.PASSWORD_TAG, passWord.getValue().toString());
}
if (log.isDebugEnabled()) {
log.debug("Username:" + userName + " or password:" + passWord + "from proxy configuration..");
}
}
} catch (FieldNotFound e) {
log.error("One or more required fields are not found in the response message", e);
}
if (eventHandler != null) {
eventHandler.toAdmin(this, message, sessionID);
}
}
Aggregations