Пример #1
0
  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();
    }
  }
Пример #2
0
  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();
    }
  }