HTTPS for HTTP Client
valodzka
valodzka at gmail.com
Tue Sep 8 15:01:43 EDT 2009
I'm trying to add https support to this example
http://jboss.org/file-access/default/members/netty/freezone/xref/3.1/org/jboss/netty/example/http/snoop/HttpClient.html.
As it states:
// We can actually support HTTPS fairly easily by inserting
// an SslHandler to the pipeline - left as an exercise.
So I've added this to HttpClientPipelineFactory
(http://jboss.org/file-access/default/members/netty/freezone/xref/3.1/org/jboss/netty/example/http/snoop/HttpClientPipelineFactory.html):
SSLContext sslContext = SSLContext.getDefault();
SSLEngine sslEngine = sslContext.createSSLEngine();
sslEngine.setUseClientMode(true);
pipeline.addFirst("ssl", new SslHandler(sslEngine));
And this this to client:
ChannelFuture hf;
try {
hf =
channel.getPipeline().get(SslHandler.class).handshake(channel);
hf.awaitUninterruptibly();
if (!hf.isSuccess()) {
System.out.println("Handshake fail: " + hf.getCause());
}
else {
System.out.println("Handshake success!");
}
} catch (SSLException ex) {
ex.printStackTrace();
}
But for all https sites I've tried it fails:
Handshake fail: java.nio.channels.ClosedChannelException
Any ideas?
--
View this message in context: http://n2.nabble.com/HTTPS-for-HTTP-Client-tp3605410p3605410.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list