Search in sources :

Example 1 with BeginString

use of quickfix.field.BeginString in project wso2-synapse by wso2.

the class FIXMessageBuilder method processDocument.

public OMElement processDocument(InputStream inputStream, String contentType, MessageContext messageContext) throws AxisFault {
    Reader reader = null;
    StringBuilder messageString = new StringBuilder();
    quickfix.Message message = null;
    try {
        String charSetEncoding = (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
        if (charSetEncoding == null) {
            charSetEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
        }
        reader = new InputStreamReader(inputStream, charSetEncoding);
        try {
            int data = reader.read();
            while (data != -1) {
                char dataChar = (char) data;
                data = reader.read();
                messageString.append(dataChar);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            log.error("Error In creating FIX SOAP envelope ...", e);
            throw new AxisFault(e.getMessage());
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        log.error("Error In creating FIX SOAP envelope ...", e);
        throw new AxisFault(e.getMessage());
    }
    try {
        DefaultDataDictionaryProvider dataDictionary = new DefaultDataDictionaryProvider();
        String beginString = MessageUtils.getStringField(messageString.toString(), BeginString.FIELD);
        DataDictionary dataDic = dataDictionary.getSessionDataDictionary(beginString);
        message = new quickfix.Message(messageString.toString(), null, false);
    } catch (InvalidMessage e) {
        // TODO Auto-generated catch block
        log.error("Error In creating FIX SOAP envelope ...", e);
        throw new AxisFault(e.getMessage());
    }
    if (log.isDebugEnabled()) {
        log.debug("Creating SOAP envelope for FIX message...");
    }
    SOAPFactory soapFactory = new SOAP11Factory();
    OMElement msg = soapFactory.createOMElement(FIXConstants.FIX_MESSAGE, null);
    msg.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_MESSAGE_INCOMING_SESSION, null, ""));
    msg.addAttribute(soapFactory.createOMAttribute(FIXConstants.FIX_MESSAGE_COUNTER, null, String.valueOf("-1")));
    OMElement header = soapFactory.createOMElement(FIXConstants.FIX_HEADER, null);
    OMElement body = soapFactory.createOMElement(FIXConstants.FIX_BODY, null);
    OMElement trailer = soapFactory.createOMElement(FIXConstants.FIX_TRAILER, null);
    // process FIX header
    Iterator<quickfix.Field<?>> iter = message.getHeader().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 = messageContext.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);
            }
            header.addChild(msgField);
        }
    }
    // process FIX body
    convertFIXBodyToXML(message, body, soapFactory, messageContext);
    // process FIX trailer
    iter = message.getTrailer().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 = messageContext.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);
            }
            trailer.addChild(msgField);
        }
    }
    msg.addChild(header);
    msg.addChild(body);
    msg.addChild(trailer);
    SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
    envelope.getBody().addChild(msg);
    messageContext.setEnvelope(envelope);
    return msg;
}
Also used : AxisFault(org.apache.axis2.AxisFault) InputStreamReader(java.io.InputStreamReader) DefaultDataDictionaryProvider(quickfix.DefaultDataDictionaryProvider) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) OMElement(org.apache.axiom.om.OMElement) BeginString(quickfix.field.BeginString) InvalidMessage(quickfix.InvalidMessage) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) DataDictionary(quickfix.DataDictionary) SOAPFactory(org.apache.axiom.soap.SOAPFactory) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource) DataSource(javax.activation.DataSource) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource)

Example 2 with BeginString

use of quickfix.field.BeginString 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));
}
Also used : NewOrderSingle(quickfix.fix41.NewOrderSingle) BeginString(quickfix.field.BeginString) SenderCompID(quickfix.field.SenderCompID) Message(quickfix.Message) TargetCompID(quickfix.field.TargetCompID) BeginString(quickfix.field.BeginString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MessageContext(org.apache.axis2.context.MessageContext) SessionID(quickfix.SessionID) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with BeginString

use of quickfix.field.BeginString in project wso2-synapse by wso2.

the class FIXTransportSenderTest method testIsTargetValid.

@Test
public void testIsTargetValid() throws Exception {
    Map<String, String> fieldValues = new HashMap<>();
    fieldValues.put(FIXConstants.BEGIN_STRING, "FIX.4.1");
    fieldValues.put(FIXConstants.DELIVER_TO_COMP_ID, "SYNAPSE");
    fieldValues.put(FIXConstants.DELIVER_TO_SUB_ID, "sy");
    fieldValues.put(FIXConstants.DELIVER_TO_LOCATION_ID, "randomLoc");
    SessionID id = new SessionID(new BeginString("FIX.4.1"), new SenderCompID("BANZAI"), new SenderSubID("ba"), new SenderLocationID("senderLoc"), new TargetCompID("SYNAPSE"), new TargetSubID("sy"), new TargetLocationID("randomLoc"), "FIX.4.1:SYNAPSE->BANZAI");
    FIXTransportSender sender = new FIXTransportSender();
    Class senderClass = sender.getClass();
    Method isTargetvalid = senderClass.getDeclaredMethod("isTargetValid", Map.class, SessionID.class, boolean.class);
    isTargetvalid.setAccessible(true);
    Object result = isTargetvalid.invoke(senderClass.newInstance(), fieldValues, id, true);
    Assert.assertEquals("Invalid target!", "true", result.toString());
}
Also used : BeginString(quickfix.field.BeginString) SenderCompID(quickfix.field.SenderCompID) SenderSubID(quickfix.field.SenderSubID) HashMap(java.util.HashMap) TargetCompID(quickfix.field.TargetCompID) TargetSubID(quickfix.field.TargetSubID) TargetLocationID(quickfix.field.TargetLocationID) BeginString(quickfix.field.BeginString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Method(java.lang.reflect.Method) SenderLocationID(quickfix.field.SenderLocationID) SessionID(quickfix.SessionID) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with BeginString

use of quickfix.field.BeginString in project wso2-synapse by wso2.

the class FIXTransportSenderTest method testFIXTransportSenderSendMessage.

@Test()
public void testFIXTransportSenderSendMessage() throws Exception {
    String BEGIN_STRING = "FIX.4.1";
    String SENDER_ID = "BANZAI";
    String TARGET_ID = "SYNAPSE";
    int SEQ_NUM = 5;
    String SYMBOL = "APACHE";
    String CLORD_ID = "12345";
    String CHECKSUM = "67890";
    String TX_DATE = new Date().toString();
    String SESSION_ID = "FIX.4.1:BANZAI->SYNAPSE";
    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));
    message.getTrailer().setField(new CheckSum(CHECKSUM));
    MessageContext msgCtx = new MessageContext();
    msgCtx.setProperty(FIXConstants.FIX_SERVICE_NAME, "sampleService");
    Map trpHeaders = new HashMap();
    trpHeaders.put(FIXConstants.FIX_MESSAGE_APPLICATION, "sampleApplication");
    msgCtx.setProperty(MessageContext.TRANSPORT_HEADERS, trpHeaders);
    FIXUtils.getInstance().setSOAPEnvelope(message, SEQ_NUM, SESSION_ID, msgCtx);
    OutTransportInfo info = new FIXOutTransportInfo("fix://dummyEPR");
    FIXTransportSender spy = PowerMockito.spy(new FIXTransportSender());
    PowerMockito.doReturn(true).when(spy, "sendUsingEPR", anyString(), anyString(), any(), anyString(), anyInt(), any());
    spy.sendMessage(msgCtx, "fix://dummyEPR", info);
    PowerMockito.verifyPrivate(spy, times(1)).invoke("sendUsingEPR", anyString(), anyString(), any(), anyString(), anyInt(), any());
}
Also used : NewOrderSingle(quickfix.fix41.NewOrderSingle) BeginString(quickfix.field.BeginString) SenderCompID(quickfix.field.SenderCompID) Message(quickfix.Message) HashMap(java.util.HashMap) Symbol(quickfix.field.Symbol) TargetCompID(quickfix.field.TargetCompID) ClOrdID(quickfix.field.ClOrdID) TradeOriginationDate(quickfix.field.TradeOriginationDate) BeginString(quickfix.field.BeginString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MsgSeqNum(quickfix.field.MsgSeqNum) Date(java.util.Date) TradeOriginationDate(quickfix.field.TradeOriginationDate) OutTransportInfo(org.apache.axis2.transport.OutTransportInfo) CheckSum(quickfix.field.CheckSum) MessageContext(org.apache.axis2.context.MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with BeginString

use of quickfix.field.BeginString in project wso2-synapse by wso2.

the class FIXIncomingMessageHandlerTest method testToApp.

@Test
public void testToApp() throws Exception {
    SessionID id = new SessionID(new BeginString("FIX.4.1"), new SenderCompID("SYNAPSE"), new TargetCompID("BANZAI"), "FIX.4.1:SYNAPSE->BANZAI");
    Message message = new NewOrderSingle();
    message.getHeader().setField(new BeginString("FIX.4.1"));
    message.getHeader().setField(new SenderCompID("SYNAPSE"));
    message.getHeader().setField(new TargetCompID("BANZAI"));
    message.getHeader().setField(new MsgSeqNum(1));
    message.getHeader().setField(new MsgType("A"));
    ConfigurationContext cfgCtx = new ConfigurationContext(new AxisConfiguration());
    WorkerPool pool = new NativeWorkerPool(3, 4, 10, 10, "name", "id");
    FIXIncomingMessageHandler handler = new FIXIncomingMessageHandler(cfgCtx, pool, service, true);
    handler.toApp(message, id);
}
Also used : NewOrderSingle(quickfix.fix41.NewOrderSingle) BeginString(quickfix.field.BeginString) SenderCompID(quickfix.field.SenderCompID) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Message(quickfix.Message) TargetCompID(quickfix.field.TargetCompID) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) MsgType(quickfix.field.MsgType) MsgSeqNum(quickfix.field.MsgSeqNum) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) SessionID(quickfix.SessionID) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BeginString (quickfix.field.BeginString)7 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 SenderCompID (quickfix.field.SenderCompID)6 TargetCompID (quickfix.field.TargetCompID)6 Message (quickfix.Message)5 SessionID (quickfix.SessionID)5 NewOrderSingle (quickfix.fix41.NewOrderSingle)5 MsgSeqNum (quickfix.field.MsgSeqNum)4 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 NativeWorkerPool (org.apache.axis2.transport.base.threads.NativeWorkerPool)3 WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 MsgType (quickfix.field.MsgType)3 HashMap (java.util.HashMap)2 MessageContext (org.apache.axis2.context.MessageContext)2 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Method (java.lang.reflect.Method)1