private void doLogonTest(String keyStoreName, String keyStorePassword) throws InterruptedException, ConfigError { ServerThread serverThread = new ServerThread(keyStoreName, keyStorePassword); try { serverThread.setDaemon(true); serverThread.start(); serverThread.waitForInitialization(); SessionID clientSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "TW", "ISLD"); SessionSettings settings = getClientSessionSettings(clientSessionID); ClientApplication clientApplication = new ClientApplication(); ThreadedSocketInitiator initiator = new ThreadedSocketInitiator( clientApplication, new MemoryStoreFactory(), settings, new DefaultMessageFactory()); try { log.info("Do login"); clientApplication.setUpLogonExpectation(); initiator.start(); Session clientSession = Session.lookupSession(clientSessionID); assertLoggedOn(clientApplication, clientSession); } finally { initiator.stop(); } } finally { serverThread.interrupt(); serverThread.join(); } }
/** * Listen for incoming and outgoing requests. If the <code>serverEnabled</code> member is <code> * false</code> the server for incoming requests is not started. This starts the internal server * thread that processes messages. * * @throws SocketException when the transport is already listening for incoming/outgoing messages. * @throws IOException */ public synchronized void listen() throws java.io.IOException { if (server != null) { throw new SocketException("Port already listening"); } server = new ServerThread(); if (connectionTimeout > 0) { socketCleaner = new Timer(true); // run as daemon } server.setDaemon(true); server.start(); }
public void testLogonWithBadCertificate() throws Exception { ServerThread serverThread = new ServerThread("nonexistent", "pwd"); try { serverThread.setDaemon(true); serverThread.start(); serverThread.waitForInitialization(); SessionID clientSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "TW", "ISLD"); SessionSettings settings = getClientSessionSettings(clientSessionID); ClientApplication clientApplication = new ClientApplication(); ThreadedSocketInitiator initiator = new ThreadedSocketInitiator( clientApplication, new MemoryStoreFactory(), settings, new DefaultMessageFactory()); final CountDownLatch exceptionCaught = new CountDownLatch(1); initiator.setIoFilterChainBuilder( new IoFilterChainBuilder() { public void buildFilterChain(IoFilterChain chain) throws Exception { chain.addLast( "ExceptionCatcher", new IoFilterAdapter() { public void exceptionCaught( NextFilter nextFilter, IoSession session, Throwable cause) throws Exception { log.info("MINA exception: " + cause.getMessage()); exceptionCaught.countDown(); } }); } }); try { log.info("Do login"); initiator.start(); assertTrue("no exception thrown", exceptionCaught.await(5, TimeUnit.SECONDS)); } finally { initiator.stop(); } } finally { serverThread.interrupt(); serverThread.join(); } }