Netty: How to Initiate SSL Handshake From Client

Apr 23, 2013 1 minutes read

I have had spent some time recently making netty 3.6 sending some message when connection has been established.

What documentation suggests to do is to extend SimpleChannelUpstreamHandler and override method channelConnected(...). It works fine unless SslHandler is used in the pipeline. If handler is present, channelConnected() was never called on my handler.

The problem was caused by client, which did not initialized SSL handshake on connection. Until handshake completed, no other ChannelHandlers are notified. Hopefully, there is a convenient way to initiate handshake on the client. Netty documentation states:


If isIssueHandshake() is false (default) you will need to take care of calling handshake() by your own. In most situations were SslHandler is used in ‘client mode’ you want to issue a handshake once the connection was established. if setIssueHandshake(boolean) is set to true you don’t need to worry about this as the SslHandler will take care of it.

So, you should set isIssueHandshake on SslHandler before establishing the connection:

SslHandler sslHandler = new SslHandler(engine);
pipeline.addLast("ssl", sslHandler);

After that, server got hadshaked and SslHandler fired connected ChannelStateEvent to other UpstreamHandlers.

See Also

Using Expected Exceptions in UnitTests

Sometimes, reviewing code, I see misunderstanding of using Expected Exception concept in unit tests.

Configuring Protobuf to Java compiler in maven

Here are few steps to configure protobuf-to-java compilation in your maven project:

Install google protobuf compiler on your computer.

Java-protobuf-format: Easy Protobuf-to-JSON Serialization in Java

If you need Google Protobuf-to-JSON serialization (and vice versa) there is quick solution. Protobuf-java-format library provides serialization of protobuf-generated java classes to number of formats: JSON, XML, HTML, Java property file format, Smile, CoachDB.

Here is a step-by-step instruction.

logo   Never miss a story, subscribe to our newsletter