Here it goes.
That's how I start it:
//...
//keystore, etc.
SSLConfig.DEFAULT_CONFIG = _sslConfig;
_started = new CountDownLatch(1);
_connectorHandler = new SSLConnectorHandler();
SSLEngine _engine = _sslConfig.createSSLContext().createSSLEngine();
_engine.setUseClientMode(true);
_connectorHandler.configure(_sslConfig);
_connectorHandler.setSSLEngine(_engine);
_connectorHandler.setController(_controller);
final SSLReadFilter readFilter = new SSLReadFilter();
readFilter.setSSLContext(SSLConfig.DEFAULT_CONFIG.createSSLContext());
_controller.addSelectorHandler(_selectorHandler);
_controller.setProtocolChainInstanceHandler(new
DefaultProtocolChainInstanceHandler()
{
@Override
public ProtocolChain poll()
{
ProtocolChain protocolChain = protocolChains.poll();
if (protocolChain == null)
{
protocolChain = new DefaultProtocolChain();
protocolChain.addFilter(readFilter);
protocolChain.addFilter(new ClientDispatchFilter());
}
return protocolChain;
}
});
_controller.addStateListener(new ClientControllerState());
_controllerThread = new Thread(_controller);
_controllerThread.start();
try
{
_started.await();
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
_connectorHandler.connect(new
InetSocketAddress(InetAddress.getByName(ClientParams.getServerIP()),
ClientParams.getServerPort()), new
ClientCallbackHandlerToProtocolChain(_connectorHandler));
// wait for a successfull handshake
//...
// send data to server via _connectorHandler.write(myByteBuffer, false);
-----------------------------------------------------
The callback hadler is:
public class ClientCallbackHandlerToProtocolChain implements
SSLCallbackHandler<Context>
{
private SSLConnectorHandler _connectorHandler;
private ByteBuffer readBB;
public ClientCallbackHandlerToProtocolChain(SSLConnectorHandler connH)
{
_connectorHandler = connH;
readBB.wrap(new byte[_connectorHandler.getApplicationBufferSize()]);
}
public void onConnect(IOEvent<Context> ioEvent)
{
readBB = ((WorkerThread) Thread.currentThread()).getByteBuffer();
readBB.flip();
SelectionKey _key = ioEvent.attachment().getSelectionKey();
try
{
_connectorHandler.finishConnect(_key);
if (_connectorHandler.handshake(readBB, false))
{
onHandshake(ioEvent);
}
//...
}
public void onRead(IOEvent<Context> ioEvent)
{
try
{
Context ctx = ioEvent.attachment();
ctx.getProtocolChain().execute(ctx);
}
catch(Exception e)
{
//...
}
public void onHandshake(IOEvent<Context> context)
{
context.attachment().getSelectorHandler().register(context.attachment().getSelectionKey(),
SelectionKey.OP_READ );
// deal with CountDownLatch
//...
}
-----------------------------------------
The message, that i send after connect and handshake successfully reaches
the server, but the echoed messages produces exception from the post above.
--
View this message in context: http://www.nabble.com/Problem-with-SSL-tp19709902p19757913.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.