Search in sources :

Example 1 with Group

use of quickfix.Group in project wso2-synapse by wso2.

the class FIXMessageBuilder method convertFIXBodyToXML.

/**
 * Constructs the XML infoset for the FIX message body
 *
 * @param message
 *            the FIX message
 * @param body
 *            the body element of the XML infoset
 * @param soapFactory
 *            the SOAP factory to create XML elements
 * @param msgCtx
 *            the Axis2 Message context
 * @throws AxisFault
 *             on error
 */
private void convertFIXBodyToXML(FieldMap message, OMElement body, SOAPFactory soapFactory, MessageContext msgCtx) throws AxisFault {
    if (log.isDebugEnabled()) {
        log.debug("Generating FIX message body (Message ID: " + msgCtx.getMessageID() + ")");
    }
    Iterator<quickfix.Field<?>> iter = message.iterator();
    if (iter != null) {
        while (iter.hasNext()) {
            quickfix.Field<?> field = iter.next();
            OMElement msgField = soapFactory.createOMElement(FIXConstants.FIX_FIELD, null);
            msgField.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_FIELD_ID, null, String.valueOf(field.getTag())));
            Object value = field.getObject();
            if (value instanceof byte[]) {
                DataSource dataSource = new ByteArrayDataSource((byte[]) value);
                DataHandler dataHandler = new DataHandler(dataSource);
                String contentID = msgCtx.addAttachment(dataHandler);
                OMElement binaryData = soapFactory.createOMElement(FIXConstants.FIX_BINARY_FIELD, null);
                String binaryCID = "cid:" + contentID;
                binaryData.addAttribute(FIXConstants.FIX_MESSAGE_REFERENCE, binaryCID, null);
                msgField.addChild(binaryData);
            } else {
                soapFactory.createOMText(msgField, value.toString(), OMElement.CDATA_SECTION_NODE);
            }
            body.addChild(msgField);
        }
    }
    // process FIX repeating groups
    Iterator<Integer> groupKeyItr = message.groupKeyIterator();
    if (groupKeyItr != null) {
        while (groupKeyItr.hasNext()) {
            int groupKey = groupKeyItr.next();
            OMElement groupsField = soapFactory.createOMElement(FIXConstants.FIX_GROUPS, null);
            groupsField.addAttribute(FIXConstants.FIX_FIELD_ID, String.valueOf(groupKey), null);
            List<Group> groupList = message.getGroups(groupKey);
            Iterator<Group> groupIterator = groupList.iterator();
            while (groupIterator.hasNext()) {
                Group msgGroup = groupIterator.next();
                OMElement groupField = soapFactory.createOMElement(FIXConstants.FIX_GROUP, null);
                // rec. call the method to process the repeating groups
                convertFIXBodyToXML(msgGroup, groupField, soapFactory, msgCtx);
                groupsField.addChild(groupField);
            }
            body.addChild(groupsField);
        }
    }
}
Also used : Group(quickfix.Group) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) BeginString(quickfix.field.BeginString) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource) DataSource(javax.activation.DataSource) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource)

Example 2 with Group

use of quickfix.Group in project camel by apache.

the class QuickfixjMessageJsonTransformer method transform.

private void transform(String name, FieldMap fieldMap, StringBuilder sb, String indent, DataDictionary dd) {
    sb.append(indent).append("\"").append(name).append("\": {\n");
    int fieldCount = 0;
    Iterator<Field<?>> fieldIterator = fieldMap.iterator();
    while (fieldIterator.hasNext()) {
        if (fieldCount > 0) {
            sb.append(",\n");
        }
        Field<?> field = fieldIterator.next();
        sb.append(indent).append("  \"").append(dd.getFieldName(field.getField())).append("\": ");
        if (dd.hasFieldValue(field.getField())) {
            int tag = field.getField();
            sb.append("[ \"").append(field.getObject().toString()).append("\", \"").append(dd.getValueName(tag, field.getObject().toString())).append("\" ]");
        } else {
            FieldType fieldType = dd.getFieldType(field.getField());
            if (Number.class.isAssignableFrom(fieldType.getJavaType())) {
                sb.append(field.getObject());
            } else {
                sb.append("\"").append(field.getObject().toString()).append("\"");
            }
        }
        fieldCount++;
    }
    sb.append("\n");
    Iterator<Integer> groupKeys = fieldMap.groupKeyIterator();
    while (groupKeys.hasNext()) {
        int groupTag = groupKeys.next();
        for (Group group : fieldMap.getGroups(groupTag)) {
            String groupName = dd.getFieldName(groupTag);
            transform(groupName, group, sb, indent + "  ", dd);
        }
    }
    sb.append(indent).append("}").append("\n");
}
Also used : Field(quickfix.Field) Group(quickfix.Group) FieldType(quickfix.FieldType)

Example 3 with Group

use of quickfix.Group in project wso2-synapse by wso2.

the class FieldOrderingTest method testRepeatingGroupOrdering.

public void testRepeatingGroupOrdering() throws IOException {
    int[] order = new int[] { Symbol.FIELD, SecurityID.FIELD, SecurityIDSource.FIELD, Product.FIELD, QuoteType.FIELD, OrderQty.FIELD, SettlDate.FIELD, QuotePriceType.FIELD, ValidUntilTime.FIELD, ExpireTime.FIELD };
    Message message = new QuoteRequest(new QuoteReqID("20101110-2"));
    Group group = new Group(NoRelatedSym.FIELD, Symbol.FIELD, order);
    group.setField(new Symbol("TestSymbol"));
    group.setField(new SecurityID("SecurityID"));
    group.setField(new SecurityIDSource("SecurityIDSource"));
    group.setField(new Product(11));
    group.setField(new QuoteType(1));
    group.setField(new OrderQty(500));
    group.setField(new SettlDate("20151116"));
    group.setField(new QuotePriceType(1));
    group.setField(new ValidUntilTime(new Date()));
    group.setField(new ExpireTime(new Date()));
    message.addGroup(group);
    System.out.println("Original Message: " + message);
    MessageContext msgCtx = new MessageContext();
    FIXUtils.getInstance().setSOAPEnvelope(message, 1, "TestSession", msgCtx);
    OMElement msgElt = msgCtx.getEnvelope().getBody().getFirstElement();
    OMElement groupsElt = msgElt.getFirstChildWithName(new QName(FIXConstants.FIX_BODY)).getFirstChildWithName(new QName(FIXConstants.FIX_GROUPS));
    int groupId = Integer.parseInt(groupsElt.getAttributeValue(new QName(FIXConstants.FIX_FIELD_ID)));
    assertEquals(groupId, group.getFieldTag());
    // Test whether the fileds in the SOAP infoset are in the correct order
    Iterator fields = groupsElt.getFirstElement().getChildrenWithName(new QName(FIXConstants.FIX_FIELD));
    List<Integer> fieldList = new ArrayList<Integer>();
    while (fields.hasNext()) {
        OMElement fieldElt = (OMElement) fields.next();
        fieldList.add(Integer.parseInt(fieldElt.getAttributeValue(new QName(FIXConstants.FIX_FIELD_ID))));
    }
    assertEquals(order.length, fieldList.size());
    for (int i = 0; i < order.length; i++) {
        assertEquals(order[i], (int) fieldList.get(i));
    }
    // Test whether the reconstructed message preserves the group field order
    Message copy = FIXUtils.getInstance().createFIXMessage(msgCtx);
    System.out.println("Reconstructed Message: " + copy);
    List<Group> groups = copy.getGroups(NoRelatedSym.FIELD);
    assertEquals(1, groups.size());
    int[] copyOrder = groups.get(0).getFieldOrder();
    assertEquals(order.length, copyOrder.length);
    for (int i = 0; i < order.length; i++) {
        assertEquals(order[i], copyOrder[i]);
    }
    assertEquals(message.toString(), copy.toString());
}
Also used : Group(quickfix.Group) Message(quickfix.Message) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement) Iterator(java.util.Iterator) MessageContext(org.apache.axis2.context.MessageContext) QuoteRequest(quickfix.fix44.QuoteRequest) QName(javax.xml.namespace.QName) Date(java.util.Date)

Example 4 with Group

use of quickfix.Group in project wso2-synapse by wso2.

the class MessageTest method testAdvancedFIXMessage.

public void testAdvancedFIXMessage() throws Exception {
    Message message = new NewOrderSingle();
    message.getHeader().setField(new BeginString(BEGIN_STRING));
    message.getHeader().setField(new SenderCompID(SENDER_ID));
    message.getHeader().setField(new TargetCompID(TARGET_ID));
    message.getHeader().setField(new MsgSeqNum(SEQ_NUM));
    message.setField(new Symbol(SYMBOL));
    message.setField(new ClOrdID(CLORD_ID));
    message.setField(new TradeOriginationDate(TX_DATE));
    Group g1 = new Group(NoAllocs.FIELD, AllocAccount.FIELD);
    g1.setField(new AllocAccount("ABC"));
    g1.setField(new IndividualAllocID("PQR"));
    message.addGroup(g1);
    Group g2 = new Group(NoAllocs.FIELD, AllocAccount.FIELD);
    g2.setField(new AllocAccount("MNO"));
    g2.setField(new IndividualAllocID("XYZ"));
    message.addGroup(g2);
    message.getTrailer().setField(new CheckSum(CHECKSUM));
    MessageContext msgCtx = new MessageContext();
    FIXUtils.getInstance().setSOAPEnvelope(message, SEQ_NUM, SESSION_ID, msgCtx);
    String result = msgCtx.getEnvelope().getBody().getFirstElement().toString();
    String expected = "<message inSession=\"" + SESSION_ID + "\" counter=\"" + SEQ_NUM + "\">" + "<header>" + "<field id=\"" + BeginString.FIELD + "\">" + BEGIN_STRING + "</field>" + "<field id=\"" + MsgSeqNum.FIELD + "\">" + SEQ_NUM + "</field>" + "<field id=\"" + MsgType.FIELD + "\">" + NewOrderSingle.MSGTYPE + "</field>" + "<field id=\"" + SenderCompID.FIELD + "\">" + SENDER_ID + "</field>" + "<field id=\"" + TargetCompID.FIELD + "\">" + TARGET_ID + "</field>" + "</header>" + "<body>" + "<field id=\"" + ClOrdID.FIELD + "\">" + CLORD_ID + "</field>" + "<field id=\"" + Symbol.FIELD + "\">" + SYMBOL + "</field>" + "<field id=\"" + NoAllocs.FIELD + "\">2</field>" + "<field id=\"" + TradeOriginationDate.FIELD + "\">" + TX_DATE + "</field>" + "<groups id=\"" + NoAllocs.FIELD + "\">" + "<group>" + "<field id=\"" + AllocAccount.FIELD + "\">ABC</field>" + "<field id=\"" + IndividualAllocID.FIELD + "\">PQR</field>" + "</group>" + "<group>" + "<field id=\"" + AllocAccount.FIELD + "\">MNO</field>" + "<field id=\"" + IndividualAllocID.FIELD + "\">XYZ</field>" + "</group>" + "</groups>" + "</body>" + "<trailer>" + "<field id=\"" + CheckSum.FIELD + "\">" + CHECKSUM + "</field>" + "</trailer>" + "</message>";
    assertXMLEqual(expected, AXIOMUtil.stringToOM(result).toString());
}
Also used : NewOrderSingle(quickfix.fix41.NewOrderSingle) Group(quickfix.Group) Message(quickfix.Message) MessageContext(org.apache.axis2.context.MessageContext)

Example 5 with Group

use of quickfix.Group in project wildfly-camel by wildfly-extras.

the class QuickfixjMessageJsonTransformer method transform.

private void transform(String name, FieldMap fieldMap, StringBuilder sb, String indent, DataDictionary dd) {
    sb.append(indent).append("\"").append(name).append("\": {\n");
    int fieldCount = 0;
    Iterator<Field<?>> fieldIterator = fieldMap.iterator();
    while (fieldIterator.hasNext()) {
        if (fieldCount > 0) {
            sb.append(",\n");
        }
        Field<?> field = fieldIterator.next();
        sb.append(indent).append("  \"").append(dd.getFieldName(field.getField())).append("\": ");
        if (dd.hasFieldValue(field.getField())) {
            int tag = field.getField();
            sb.append("[ \"").append(field.getObject().toString()).append("\", \"").append(dd.getValueName(tag, field.getObject().toString())).append("\" ]");
        } else {
            FieldType fieldType = dd.getFieldType(field.getField());
            if (Number.class.isAssignableFrom(fieldType.getJavaType())) {
                sb.append(field.getObject());
            } else {
                sb.append("\"").append(field.getObject().toString()).append("\"");
            }
        }
        fieldCount++;
    }
    sb.append("\n");
    Iterator<Integer> groupKeys = fieldMap.groupKeyIterator();
    while (groupKeys.hasNext()) {
        int groupTag = groupKeys.next();
        for (Group group : fieldMap.getGroups(groupTag)) {
            String groupName = dd.getFieldName(groupTag);
            transform(groupName, group, sb, indent + "  ", dd);
        }
    }
    sb.append(indent).append("}").append("\n");
}
Also used : Field(quickfix.Field) Group(quickfix.Group) FieldType(quickfix.FieldType)

Aggregations

Group (quickfix.Group)5 OMElement (org.apache.axiom.om.OMElement)2 MessageContext (org.apache.axis2.context.MessageContext)2 Field (quickfix.Field)2 FieldType (quickfix.FieldType)2 Message (quickfix.Message)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 DataHandler (javax.activation.DataHandler)1 DataSource (javax.activation.DataSource)1 QName (javax.xml.namespace.QName)1 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)1 BeginString (quickfix.field.BeginString)1 NewOrderSingle (quickfix.fix41.NewOrderSingle)1 QuoteRequest (quickfix.fix44.QuoteRequest)1