quickfix.field.MsgType Java Examples

The following examples show how to use quickfix.field.MsgType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QFJIMessageConverter.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public Message convert(IMessage message, boolean fixt, Class<? extends Message> messageClass) throws MessageConvertException {
if(message == null) {
    return null;
}

      try {
          Message resultMessage = createInstance(message.getName(), messageClass, message.getMetaData());

          traverseIMessage(resultMessage, message);

          if(fixt) {
              Header header = resultMessage.getHeader();
              IMessage iheader = message.getField(FixMessageHelper.HEADER);
              String messageType = iheader.getField("MsgType");

              header.setString(BeginString.FIELD, FixVersions.BEGINSTRING_FIXT11);
              header.setString(MsgType.FIELD, messageType);
          }

          return resultMessage;
      } catch(InstantiationException | IllegalAccessException e) {
          throw new MessageConvertException("Failed to create result message", e);
      }
  }
 
Example #2
Source File: DemoServerApplication.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
@Override
public void fromApp(Message message, SessionID sessionId) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
    ISession iSession = getSession(sessionId);
    if (message.getHeader().getString(MsgType.FIELD).equals("D")) {
        Message executionReport = new Message();
        executionReport.getHeader().setString(MsgType.FIELD, "8");
        executionReport.setString(OrderID.FIELD, String.valueOf(orderIdGenerator.incrementAndGet()));
        executionReport.setString(ExecID.FIELD, String.valueOf(execIdGenerator.incrementAndGet()));
        executionReport.setString(ExecType.FIELD, "2");
        executionReport.setString(OrdStatus.FIELD, "0");
        executionReport.setString(Side.FIELD, message.getString(Side.FIELD));
        executionReport.setString(LeavesQty.FIELD, message.getString(OrderQty.FIELD));
        executionReport.setString(CumQty.FIELD, "0");
        executionReport.setString(ClOrdID.FIELD, message.getString(ClOrdID.FIELD));
        executionReport.setString(SecurityID.FIELD, message.getString(SecurityID.FIELD));
        executionReport.setString(SecurityIDSource.FIELD, message.getString(SecurityIDSource.FIELD));
        executionReport.setString(OrdType.FIELD, message.getString(OrdType.FIELD));
        executionReport.setString(OrderQty.FIELD, message.getString(OrderQty.FIELD));
        executionReport.setUtcTimeStamp(TransactTime.FIELD, Timestamp.valueOf(LocalDateTime.now()));

        Session session = Session.lookupSession(sessionId);
        session.send(executionReport);
    }

    storeMessage(iSession, message, sessionId.getTargetCompID(), sessionId.getSenderCompID(), FROM_APP);
}
 
Example #3
Source File: QFixMessengerApplication.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void fromAdmin(Message message, SessionID sessionId)
		throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue,
		RejectLogon
{
	// Listen for Session Reject messages
	MsgType msgType = (MsgType) message.getHeader().getField(new MsgType());
	if (msgType.getValue().equals("3"))
	{
		for (QFixMessageListener messageListener : messageListeners)
		{
			messageListener.onMessage(QFixMessageListener.RECV, message,
					sessionId);
		}
	}
}
 
Example #4
Source File: MessagesTableModel.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onMessage(String direction, Message message, SessionID sessionId)
{
	try
	{
		MsgType msgType = (MsgType) message.getHeader().getField(
				new MsgType());
		MessagesTableModelData data = new MessagesTableModelData(
				new Date(), direction, QFixUtil.getSessionName(sessionId),
				message.toString(), msgType.getValue());
		addRow(data);
	} catch (FieldNotFound ex)
	{
		logger.error("An exception occured!", ex);
	}
}
 
Example #5
Source File: FIXApplication.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
@Override
public void toApp(Message message, SessionID sessionID) throws DoNotSend {
    logger.debug("toApp: {}", message);
	//logger.info("toApp: getExpectedTargetNum "+Session.lookupSession(sessionID).getExpectedTargetNum());

	String type = getMessageType(message);

       if(sendAppReject == false) {
		if (MsgType.REJECT.equals(type)) {
			logger.info("Block appliction sending Reject message : {}", message);

			// DG: QFJ lock sender MsgSeqNum from changing before call this callback
			//setNextSenderMsgSeqNum(message, sessionID);
			throw new DoNotSend();
		}
	}
}
 
Example #6
Source File: FIXCodec.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
protected IMessage convertToIMessageByIDictionaryStructure(String fixMessage) throws Exception {
    Message fixMessageSrc = new Message();
    fixMessageSrc.fromString(fixMessage, dataDict, true);

    IMessage iMessage = settings.isDepersonalizationIncomingMessages() ?
                            convertMessageToIMessage(fixMessageSrc, dictionary.getNamespace()) :
                            qfjConverter.convert(fixMessageSrc, false, false);

    parseXmlFields(iMessage, new MessageFieldExtractor(fixMessageSrc),
            fixMessageSrc.getHeader().getString(MsgType.FIELD));

    if (fixMessageSrc.getException() != null) {
        iMessage.getMetaData().setRejectReason(fixMessageSrc.getException().getMessage());
    }

    if (settings.isDepersonalizationIncomingMessages()) {
        MsgMetaData metaData = iMessage.getMetaData();

        String unexpectedMessages = settings.getUnexpectedMessages();
        metaData.setAdmin(unexpectedMessages != null && !unexpectedMessages.trim().isEmpty() && isUnexpectedMessage(fixMessage, unexpectedMessages));
    }

    return iMessage;
}
 
Example #7
Source File: CommonMessageFactory.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public Message create(String beginString, String msgType) {
	Message msg = new Message();
	Header hdr = msg.getHeader();
	hdr.setField(new BeginString(beginString));
	hdr.setField(new MsgType(msgType));
	return msg;
}
 
Example #8
Source File: QFixMessengerApplication.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isMessageOfType(Message message, String type)
{
	try
	{
		return type.equals(message.getHeader().getField(new MsgType())
				.getValue());
	} catch (FieldNotFound ex)
	{
		logger.error("Unable to find MsgType from Message!", ex);
		return false;
	}
}
 
Example #9
Source File: ServerApplication.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private String getMessageType(Message message) {
    try {
        return message.getHeader().getString(MsgType.FIELD);
    } catch (FieldNotFound e) {
        logger.error(e.getMessage());
    }
    return null;
}
 
Example #10
Source File: FIXCodec.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private IMessage convertMessageToIMessage(Message message, String namespace) throws Exception {
    String msgType = message.getHeader().getString(MsgType.FIELD);
    String messageName = msgStructures.get(msgType).getName();
    IMessage iMessage = msgFactory.createMessage(messageName, namespace);

    // create header / trailer if not exist
    IMessage header = (IMessage) iMessage.getField(FixMessageHelper.HEADER);
    if (header == null) {
        header = msgFactory.createMessage(FixMessageHelper.HEADER, namespace);
        iMessage.addField(FixMessageHelper.HEADER, header);
    }
    IMessage trailer = (IMessage) iMessage.getField(FixMessageHelper.TRAILER);
    if (trailer == null) {
        trailer = msgFactory.createMessage(FixMessageHelper.TRAILER, namespace);
        iMessage.addField(FixMessageHelper.TRAILER, trailer);
    }

    IMessageStructure messageStructure =
            getMessageStructure(message.getHeader().getString(MsgType.FIELD));
    IMessageStructure headerStructure = dictionary.getMessages().get(FixMessageHelper.HEADER);
    IMessageStructure trailerStructure = dictionary.getMessages().get(FixMessageHelper.TRAILER);

    copyFields(message, iMessage, messageStructure);
    copyFields(message.getHeader(), header, headerStructure);
    copyFields(message.getTrailer(), trailer, trailerStructure);

    iMessage.getMetaData().setAdmin(message.isAdmin());
    iMessage.getMetaData().setRawMessage(FixUtil.getRawMessage(message));

    return iMessage;
}
 
Example #11
Source File: FIXApplication.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private String getMessageType(Message message)
{
	try {
		return message.getHeader().getString(MsgType.FIELD);
	} catch (FieldNotFound e) {
		logger.error(e.getMessage(), e);
	}
	return null;
}
 
Example #12
Source File: QFJDictionaryAdapter.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public String getValueName(int tag, String value) {
       if(tag == MsgType.FIELD) {
           return getMessageName(value);
       }
       IFieldStructure fieldType = iMsgDict.getFields().get(fields.get(tag).getName());
       if (fieldType != null && fieldType.isEnum()) {
           for (String el : fieldType.getValues().keySet()) {
               if (fieldType.getValues().get(el).getValue().equals(value)) {
                   return el;
               }
           }
       }
       return null;
}
 
Example #13
Source File: DemoServerApplication.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private String getMessageType(Message message) {
    try {
        return message.getHeader().getString(MsgType.FIELD);
    } catch (FieldNotFound e) {
        logger.error(e.getMessage());
    }
    return null;
}
 
Example #14
Source File: QFJIMessageConverter.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public IMessage convert(Message message, Boolean verifyTagsOverride, Boolean skipTagsOverride,
        boolean ignoreFieldType) throws MessageConvertException {

    if(message == null) {
        return null;
    }

    String messageType = null;

    try {
        messageType = message.getHeader().getString(MsgType.FIELD);
    } catch (FieldNotFound e) {
        throw new MessageConvertException(message, "Failed to get message type", e);
    }

    IMessageStructure messageStructure = typeToStructure.get(messageType);

    if(messageStructure == null) {
        throw new MessageConvertException(message, "Unknown message type: " + messageType);
    }

    IMessage resultMessage = message instanceof SailfishQuickfixMessage
            ? factory.createMessage(((SailfishQuickfixMessage)message).getMetadata())
            : factory.createMessage(messageStructure.getName(), messageStructure.getNamespace());

    IMessage messageHeader = factory.createMessage(FixMessageHelper.HEADER, messageStructure.getNamespace());
    IMessage messageTrailer = factory.createMessage(FixMessageHelper.TRAILER, messageStructure.getNamespace());

    resultMessage.addField(FixMessageHelper.HEADER, messageHeader);
    resultMessage.addField(FixMessageHelper.TRAILER, messageTrailer);

    boolean verifyTags = ObjectUtils.defaultIfNull(verifyTagsOverride, this.verifyTags);
    boolean skipTags = ObjectUtils.defaultIfNull(skipTagsOverride, this.skipTags);

    traverseMessage(resultMessage, message, factory, resultMessage, verifyTags, skipTags, ignoreFieldType);
    traverseMessage(resultMessage, message.getHeader(), factory, resultMessage, verifyTags, skipTags, ignoreFieldType);
    traverseMessage(resultMessage, message.getTrailer(), factory, resultMessage, verifyTags, skipTags, ignoreFieldType);


    // dictionaryName, environment, fromService, toService - will be filled in FixToImessageConvertingHandler
    resultMessage.getMetaData().setAdmin(message.isAdmin());
    resultMessage.getMetaData().setRawMessage(FixUtil.getRawMessage(message));

    if (message.getException() != null) {
        resultMessage.getMetaData().setRejectReason(message.getException().getMessage());
    }

    return resultMessage;
}
 
Example #15
Source File: ConverterTest.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
private boolean compareMessages(Message message, RawMessage raw, int tag, boolean checkTrailer, boolean checkHeader) {
    Map<Integer, List<String>> messageMap = getMapFromMessage(message.toString());
    Map<Integer, List<String>> rawMap = getMapFromMessage(raw.toString());
    for (int key : messageMap.keySet()) {
        if (messageMap.get(key) == null) {
            return false;
        }
        if (rawMap.get(key) == null) {
            return false;
        }

        // tag=10 is checksum
        if (key == tag || key == 10) {
            continue;
        }

        if (!checkHeader
                && (key == MsgSeqNum.FIELD || key == MsgType.FIELD || key == BeginString.FIELD || key == BodyLength.FIELD
                        || key == SenderCompID.FIELD
                        || key == SendingTime.FIELD || key == TargetCompID.FIELD)) {
            /*
             * if body contains header's field, then try to compare this
             * field with original message's field
             */
            if (messageMap.get(key).size() + 1 == rawMap.get(key).size()) {
                if (!messageMap.get(key).get(0).equals(rawMap.get(key).get(1))) {
                    return false;
                }
            }
            continue;
        }

        if (!checkTrailer && key == 10) {
            /*
             * if body contains trailer's field, then try to compare this
             * field with original message
             */
            if (messageMap.get(key).size() + 1 == rawMap.get(key).size()) {
                if (!messageMap.get(key).get(0).equals(rawMap.get(key).get(0))) {
                    return false;
                }
            }
            continue;
        }

        if (messageMap.get(key).size() != rawMap.get(key).size()) {
            return false;
        }

        for (int i = 0; i < messageMap.get(key).size(); i++) {
            if (!messageMap.get(key).get(i).equals(rawMap.get(key).get(i))) {
                return false;
            }
        }
    }
    return true;
}
 
Example #16
Source File: ServerSideIoHandler.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public void messageReceived(IoSession session, Object message)
throws Exception
{
	logger.debug("messageReceived: {}", getClass().getSimpleName());

	if(message instanceof IMessage){
		byte[] rawMessage = ((IMessage)message).getMetaData().getRawMessage();
		message = new String(rawMessage);
	}

	// TODO Create message through factory
	Message mess = new Message((String)message);
	String fixVers = mess.getHeader().getString(BeginString.FIELD);
	String msgType = mess.getHeader().getString(MsgType.FIELD);
	Message msg = factory.create(fixVers, msgType);
	msg.fromString((String)message, appDictionary, true);

	// TODO Store message to IMessage storage
	IMessage convertedMessage = converter.convert(msg);
	MsgMetaData metaData = convertedMessage.getMetaData();
	metaData.setFromService(mess.getHeader().getString(SenderCompID.FIELD));
	metaData.setToService(mess.getHeader().getString(TargetCompID.FIELD));
	metaData.setServiceInfo(serviceInfo);

	// TODO invoke IServiceHandler
	if (msg.isAdmin())
	{
		metaData.setAdmin(true);
		handler.putMessage(proxyService.getSession(), ServiceHandlerRoute.FROM_ADMIN, convertedMessage);
	}
	if (msg.isApp())
	{
		metaData.setAdmin(false);
		handler.putMessage(proxyService.getSession(), ServiceHandlerRoute.FROM_APP, convertedMessage);
	}

       storage.storeMessage(convertedMessage);

	boolean notSend = isNotSendAndRulesProcess(mess, msgType, proxyService);

	if (!notSend) {
		//Default handler
		super.messageReceived(session, mess.toString());
	} else {
		logger.debug("Message is not sent, because rules have NotSend");
	}
}
 
Example #17
Source File: ClientSideIoHandler.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
public void messageReceived(IoSession session, Object message) throws Exception
{
	logger.debug("messageReceived: {}", message.getClass().getSimpleName());
	logger.debug("messageReceived: {}", message);
	if(message instanceof IMessage){
		byte[] rawMessage = ((IMessage)message).getMetaData().getRawMessage();
		message = new String(rawMessage);
	}

	// Create message through factory
	Message mess = FixUtil.fromString((String)message);
	logger.debug("mess: {}", mess);
	String fixVers = mess.getHeader().getString(BeginString.FIELD);
	String msgType = mess.getHeader().getString(MsgType.FIELD);
	Message msg = factory.create(fixVers, msgType);
	msg.fromString((String)message, appDictionary, true);
	logger.debug("msg: {}", msg);
	logger.debug("appDictionary: {}", appDictionary.getBeginString());

	// Store message to IMessage storage
	IMessage convertedMessage = converter.convert(msg);
	MsgMetaData metaData = convertedMessage.getMetaData();
	metaData.setFromService(mess.getHeader().getString(SenderCompID.FIELD));
	metaData.setToService(mess.getHeader().getString(TargetCompID.FIELD));
	metaData.setServiceInfo(serviceInfo);

	// invoke IServiceHandler
	if (msg.isAdmin())
	{
		metaData.setAdmin(true);
		handler.putMessage(proxyService.getSession(session), ServiceHandlerRoute.FROM_ADMIN, convertedMessage);
	}
	if (msg.isApp())
	{
		metaData.setAdmin(false);
		handler.putMessage(proxyService.getSession(session), ServiceHandlerRoute.FROM_APP, convertedMessage);
	}

	storage.storeMessage(convertedMessage);

	boolean notSend = isNotSendAndRulesProcess(mess, msgType, proxyService);

	if (!notSend) {
		//Default handler
		super.messageReceived(session, mess.toString());
	} else {
		logger.debug("Message is not sent, because rules have NotSend");
	}
}
 
Example #18
Source File: QuickfixIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Test
 public void sendMessage() throws Exception {

     final CountDownLatch logonLatch = new CountDownLatch(2);
     final CountDownLatch receivedMessageLatch = new CountDownLatch(1);

     CamelContext camelctx = new DefaultCamelContext();
     camelctx.addRoutes(new RouteBuilder() {
         @Override
         public void configure() throws Exception {
             // Release latch when session logon events are received
             // We expect two events, one for the trader session and one for the market session
             from("quickfix:quickfix/inprocess.cfg").
                 filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
                 bean(new CountDownLatchDecrementer("logon", logonLatch));

             // For all received messages, print the JSON-formatted message to stdout
             from("quickfix:quickfix/inprocess.cfg").
                 filter(PredicateBuilder.or(
                         header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived),
                         header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived))).
                 bean(new QuickfixjMessageJsonPrinter());

             // If the market session receives an email then release the latch
             from("quickfix:quickfix/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
                 filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL)).
                 bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
         }
     });

     camelctx.start();
     try {
         Assert.assertTrue("Logon succeed", logonLatch.await(5L, TimeUnit.SECONDS));

         String marketUri = "quickfix:quickfix/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
         Endpoint endpoint = camelctx.getEndpoint(marketUri);
Producer producer = endpoint.createProducer();

         Email email = createEmailMessage("Example");
         Exchange exchange = endpoint.createExchange(ExchangePattern.InOnly);
         exchange.getIn().setBody(email);
         producer.process(exchange);

         Assert.assertTrue("Message reached market", receivedMessageLatch.await(5L, TimeUnit.SECONDS));
     } finally {
         camelctx.close();
     }
 }