Created
July 14, 2014 08:54
-
-
Save benoitx/e7da15dba9da133ac7b9 to your computer and use it in GitHub Desktop.
Fix Validation fails when using XML (ClassCastException)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fixfun; | |
import quickfix.DataDictionary; | |
import quickfix.DefaultDataDictionaryProvider; | |
import quickfix.FieldNotFound; | |
import quickfix.IncorrectDataFormat; | |
import quickfix.IncorrectTagValue; | |
import quickfix.field.ApplVerID; | |
import quickfix.field.Currency; | |
import quickfix.field.IOIQty; | |
import quickfix.field.IOITransType; | |
import quickfix.field.IOIid; | |
import quickfix.field.SecurityID; | |
import quickfix.field.SecurityIDSource; | |
import quickfix.field.SenderCompID; | |
import quickfix.field.Side; | |
import quickfix.field.Symbol; | |
import quickfix.field.TargetCompID; | |
import quickfix.field.XmlData; | |
import quickfix.field.XmlDataLen; | |
import quickfix.fix50.IOI; | |
public class IOIValidation { | |
private void validateIoiWithoutXml() { | |
final IOI ioi = createAValidIoi(); | |
validateIoi(ioi); | |
} | |
private void validateIoiWithXml() { | |
final IOI ioi = createAValidIoi(); | |
final String xml = "<a>Hello</a>"; | |
ioi.getHeader().setField(XmlData.FIELD, new XmlData(xml)); | |
ioi.getHeader().setField(XmlDataLen.FIELD, new XmlDataLen(xml.length())); | |
validateIoi(ioi); | |
} | |
private void validateIoi(final IOI ioi) { | |
System.out.println(ioi.toString()); | |
final DefaultDataDictionaryProvider d = new DefaultDataDictionaryProvider(); | |
final DataDictionary dict = d.getApplicationDataDictionary(new ApplVerID(ApplVerID.FIX50)); | |
try { | |
dict.validate(ioi); | |
} catch (final IncorrectTagValue e) { | |
e.printStackTrace(); | |
} catch (final FieldNotFound e) { | |
e.printStackTrace(); | |
} catch (final IncorrectDataFormat e) { | |
e.printStackTrace(); | |
} | |
} | |
private IOI createAValidIoi() { | |
final IOI ioi = new IOI(); | |
ioi.getHeader().setField(SenderCompID.FIELD, new SenderCompID("Sender")); | |
ioi.getHeader().setField(TargetCompID.FIELD, new TargetCompID("Target")); | |
ioi.set(new IOIid("IOD-1")); | |
ioi.set(new IOITransType(IOITransType.NEW)); | |
ioi.set(new Side(Side.SELL)); | |
ioi.set(new IOIQty(IOIQty.MEDIUM)); | |
ioi.set(new Currency("USD")); | |
ioi.set(new Symbol("IBM.N")); | |
ioi.set(new SecurityIDSource(SecurityIDSource.RIC_CODE)); | |
ioi.set(new SecurityID("IBM.N")); | |
return ioi; | |
} | |
public static void main(final String[] args) { | |
final IOIValidation test = new IOIValidation(); | |
System.out.println("Testing WITHOUT XML"); | |
test.validateIoiWithoutXml(); | |
System.out.println("Testing WITH XML ===> FAILS"); | |
test.validateIoiWithXml(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment