QuickFixSessionConfigurer { public void configure(InputStream in, OutputStream out) throws Exception { final SessionSettings quickFixSettings = new SessionSettings(); final Interfaces interfaces = unmarshal(in); final List<InterfaceType> interfaceList = interfaces.getInterface(); for (final InterfaceType interfaceType : interfaceList) { boolean isFixSession = false; String interfaceVersion = null; List<SessionProtocolType> sessionProtocols = interfaceType.getSessionProtocol(); for (final SessionProtocolType sessionProtocolType : sessionProtocols) { final String protocolName = sessionProtocolType.getName(); if (protocolName.contains("FIX4") || protocolName.contains("FIXT")) { interfaceVersion = sessionProtocolType.getVersion(); isFixSession = true; break; } } final Sessions sessions = interfaceType.getSessions(); final List<SessionType> sessionList = sessions.getSession(); for (final SessionType sessionType : sessionList) { String version = null; sessionProtocols = sessionType.getSessionProtocol(); for (final SessionProtocolType sessionProtocolType : sessionProtocols) { final String protocolName = sessionProtocolType.getName(); if (protocolName.contains("FIX4") || protocolName.contains("FIXT")) { version = sessionProtocolType.getVersion(); isFixSession = true; break; } } if (!isFixSession) { continue; } if (version == null) { version = interfaceVersion; } if (version == null) { System.err.println("FIX version unknown; skipping session"); break; } final XMLGregorianCalendar activationTimeXml = sessionType.getActivationTime(); if (activationTimeXml != null) { final ZonedDateTime activationTime = activationTimeXml.toGregorianCalendar().toZonedDateTime(); if (activationTime.isAfter(effectiveTime)) { continue; } } final XMLGregorianCalendar deactivationTimeXml = sessionType.getDeactivationTime(); if (deactivationTimeXml != null) { final ZonedDateTime deativationTime = deactivationTimeXml.toGregorianCalendar().toZonedDateTime(); if (deativationTime.isBefore(effectiveTime)) { continue; } } String beginString = null; String applVersion = null; switch (version) { case FixVersions.BEGINSTRING_FIX42: beginString = FixVersions.BEGINSTRING_FIX42; break; case FixVersions.BEGINSTRING_FIX44: beginString = FixVersions.BEGINSTRING_FIX44; break; case FixVersions.BEGINSTRING_FIXT11: case FixVersions.FIX50SP2: beginString = FixVersions.BEGINSTRING_FIXT11; applVersion = FixVersions.FIX50SP2; break; } final Map<String, String> identifierMap = new HashMap<>(); final List<IdentifierType> identifierList = sessionType.getIdentifier(); for (final IdentifierType identifierType : identifierList) { final String name = identifierType.getName(); final String value = identifierType.getContent(); identifierMap.put(name, value); } final Dictionary dictionary = new Dictionary(); dictionary.setString(SessionSettings.BEGINSTRING, beginString); dictionary.setString(SessionSettings.SENDERCOMPID, identifierMap.getOrDefault(SessionSettings.SENDERCOMPID, SessionID.NOT_SET)); dictionary.setString(SessionSettings.SENDERSUBID, identifierMap.getOrDefault(SessionSettings.SENDERSUBID, SessionID.NOT_SET)); dictionary.setString(SessionSettings.SENDERLOCID, identifierMap.getOrDefault(SessionSettings.SENDERLOCID, SessionID.NOT_SET)); dictionary.setString(SessionSettings.TARGETCOMPID, identifierMap.getOrDefault(SessionSettings.TARGETCOMPID, SessionID.NOT_SET)); dictionary.setString(SessionSettings.TARGETSUBID, identifierMap.getOrDefault(SessionSettings.TARGETSUBID, SessionID.NOT_SET)); dictionary.setString(SessionSettings.TARGETLOCID, identifierMap.getOrDefault(SessionSettings.TARGETLOCID, SessionID.NOT_SET)); if (FixVersions.FIX50SP2.equals(version)) { dictionary.setString(quickfix.Session.SETTING_DEFAULT_APPL_VER_ID, applVersion); } final RoleT role = sessionType.getRole(); final List<TransportProtocolType> transportList = sessionType.getTransport(); TransportProtocolType transport = null; final int transportCount = transportList.size(); if (transportCount == 1) { transport = transportList.get(0); } else { for (final TransportProtocolType aTransport : transportList) { if (aTransport.getUse().equalsIgnoreCase(TransportUseEnum.PRIMARY.toString())) { transport = aTransport; } } if (transport == null) { System.err.println("Transport not configured; skipping session"); continue; } final String address = transport.getAddress(); final String[] addressParts = address.split(":"); switch (role) { case INITIATOR: dictionary.setString(SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE); dictionary.setString(Initiator.SETTING_SOCKET_CONNECT_HOST, addressParts[0]); dictionary.setString(Initiator.SETTING_SOCKET_CONNECT_PORT, addressParts[1]); break; case ACCEPTOR: dictionary.setString(SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE); dictionary.setString(Acceptor.SETTING_SOCKET_ACCEPT_ADDRESS, addressParts[0]); dictionary.setString(Acceptor.SETTING_SOCKET_ACCEPT_PORT, addressParts[1]); break; } final SessionID sessionId = new SessionID(beginString, identifierMap.get(SessionSettings.SENDERCOMPID), identifierMap.get(SessionSettings.SENDERSUBID), identifierMap.get(SessionSettings.SENDERLOCID), identifierMap.get(SessionSettings.TARGETCOMPID), identifierMap.get(SessionSettings.TARGETSUBID), identifierMap.get(SessionSettings.TARGETLOCID), SessionID.NOT_SET); quickFixSettings.set(sessionId, dictionary); } quickFixSettings.toStream(out); } } }  static void main(String[] args); static void useage(); void configure(InputStream in, OutputStream out); ZonedDateTime getEffectiveTime(); void setEffectiveTime(ZonedDateTime effectiveTime);  }
@Test public void testCreateFixSession() throws Exception { final String outfile = "target/test/QuickFixConfiguration.ini"; tool.configure( Thread.currentThread().getContextClassLoader().getResourceAsStream("SampleInterfaces.xml"), new FileOutputStream(outfile)); Assertions.assertTrue(new File(outfile).exists()); }