@Test public void testCloseServer() throws Throwable { CountDownLatch latch = new CountDownLatch(1); SslEchoServer server = new SslEchoServer(); try { server.start(); String message = "Hello world\n"; ByteBuffer readBuffer = ByteBuffer.allocate(message.length()); Filter<ByteBuffer, ByteBuffer, ByteBuffer, ByteBuffer> clientSocket = openClientSocket("localhost", readBuffer, latch, null); clientSocket.write(stringToBuffer(message), new CompletionHandler<ByteBuffer>() { @Override public void failed(Throwable t) { t.printStackTrace(); } }); assertTrue(latch.await(5, TimeUnit.SECONDS)); server.stop(); readBuffer.flip(); String received = bufferToString(readBuffer); assertEquals(message, received); } finally { server.stop(); } }
@Override synchronized void write(final ByteBuffer applicationData, final CompletionHandler<ByteBuffer> completionHandler) { switch (state) { case NOT_STARTED: { writeQueue.write(applicationData, completionHandler); return; } case HANDSHAKING: { completionHandler.failed(new IllegalStateException("Cannot write until SSL handshake has been completed")); break; } case REHANDSHAKING: { storePendingApplicationWrite(applicationData, completionHandler); break; } case DATA: { handleWrite(applicationData, completionHandler); break; } case CLOSED: { completionHandler.failed(new IllegalStateException(LocalizationMessages.SSL_SESSION_CLOSED())); break; } } }
SslFilter extends Filter<ByteBuffer, ByteBuffer, ByteBuffer, ByteBuffer> { @Override synchronized void write(final ByteBuffer applicationData, final CompletionHandler<ByteBuffer> completionHandler) { switch (state) { case NOT_STARTED: { writeQueue.write(applicationData, completionHandler); return; } case HANDSHAKING: { completionHandler.failed(new IllegalStateException("Cannot write until SSL handshake has been completed")); break; } case REHANDSHAKING: { storePendingApplicationWrite(applicationData, completionHandler); break; } case DATA: { handleWrite(applicationData, completionHandler); break; } case CLOSED: { completionHandler.failed(new IllegalStateException(LocalizationMessages.SSL_SESSION_CLOSED())); break; } } } }
SslFilter extends Filter<ByteBuffer, ByteBuffer, ByteBuffer, ByteBuffer> { @Override synchronized void write(final ByteBuffer applicationData, final CompletionHandler<ByteBuffer> completionHandler) { switch (state) { case NOT_STARTED: { writeQueue.write(applicationData, completionHandler); return; } case HANDSHAKING: { completionHandler.failed(new IllegalStateException("Cannot write until SSL handshake has been completed")); break; } case REHANDSHAKING: { storePendingApplicationWrite(applicationData, completionHandler); break; } case DATA: { handleWrite(applicationData, completionHandler); break; } case CLOSED: { completionHandler.failed(new IllegalStateException(LocalizationMessages.SSL_SESSION_CLOSED())); break; } } } SslFilter(Filter<ByteBuffer, ByteBuffer, ?, ?> downstreamFilter,
              SSLContext sslContext,
              String serverHost,
              HostnameVerifier customHostnameVerifier); }
SslFilter extends Filter<ByteBuffer, ByteBuffer, ByteBuffer, ByteBuffer> { @Override synchronized void write(final ByteBuffer applicationData, final CompletionHandler<ByteBuffer> completionHandler) { switch (state) { case NOT_STARTED: { writeQueue.write(applicationData, completionHandler); return; } case HANDSHAKING: { completionHandler.failed(new IllegalStateException("Cannot write until SSL handshake has been completed")); break; } case REHANDSHAKING: { storePendingApplicationWrite(applicationData, completionHandler); break; } case DATA: { handleWrite(applicationData, completionHandler); break; } case CLOSED: { completionHandler.failed(new IllegalStateException(LocalizationMessages.SSL_SESSION_CLOSED())); break; } } } SslFilter(Filter<ByteBuffer, ByteBuffer, ?, ?> downstreamFilter,
              SSLContext sslContext,
              String serverHost,
              HostnameVerifier customHostnameVerifier);  }
SslFilter extends Filter<ByteBuffer, ByteBuffer, ByteBuffer, ByteBuffer> { @Override synchronized void write(final ByteBuffer applicationData, final CompletionHandler<ByteBuffer> completionHandler) { switch (state) { case NOT_STARTED: { writeQueue.write(applicationData, completionHandler); return; } case HANDSHAKING: { completionHandler.failed(new IllegalStateException("Cannot write until SSL handshake has been completed")); break; } case REHANDSHAKING: { storePendingApplicationWrite(applicationData, completionHandler); break; } case DATA: { handleWrite(applicationData, completionHandler); break; } case CLOSED: { completionHandler.failed(new IllegalStateException(LocalizationMessages.SSL_SESSION_CLOSED())); break; } } } SslFilter(Filter<ByteBuffer, ByteBuffer, ?, ?> downstreamFilter,
              SSLContext sslContext,
              String serverHost,
              HostnameVerifier customHostnameVerifier);   }