本文整理匯總了Java中org.jboss.netty.handler.ssl.SslHandler類的典型用法代碼示例。如果您正苦於以下問題:Java SslHandler類的具體用法?Java SslHandler怎麽用?Java SslHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SslHandler類屬於org.jboss.netty.handler.ssl包,在下文中一共展示了SslHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newChannel
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{new PermissiveTrustManager()},
null);
SSLEngine sslEngine = sslContext.createSSLEngine();
sslEngine.setUseClientMode(true);
// addFirst() will make SSL handling the first stage of decoding
// and the last stage of encoding
pipeline.addFirst("ssl", new SslHandler(sslEngine));
return super.newChannel(pipeline);
} catch (Exception ex) {
throw new RuntimeException("Cannot create SSL channel", ex);
}
}
示例2: channelConnected
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
@Override
public void channelConnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception
{
if (LOG.isTraceEnabled()) {
LOG.trace("Channel connected " + e);
}
NettyServerCnxn cnxn = new NettyServerCnxn(ctx.getChannel(),
zkServer, NettyServerCnxnFactory.this);
ctx.setAttachment(cnxn);
if (secure) {
SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
ChannelFuture handshakeFuture = sslHandler.handshake();
handshakeFuture.addListener(new CertificateVerifier(sslHandler, cnxn));
} else {
allChannels.add(ctx.getChannel());
addCnxn(cnxn);
}
}
示例3: getPipeline
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (sslFactory != null) {
pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
}
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunking", new ChunkedWriteHandler());
pipeline.addLast("shuffle", SHUFFLE);
return pipeline;
// TODO factor security manager into pipeline
// TODO factor out encode/decode to permit binary shuffle
// TODO factor out decode of index to permit alt. models
}
示例4: channelConnected
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
@Override
public void channelConnected(ChannelHandlerContext ctx,
ChannelStateEvent e) throws Exception
{
if (LOG.isTraceEnabled()) {
LOG.trace("Channel connected " + e);
}
NettyServerCnxn cnxn = new NettyServerCnxn(ctx.getChannel(),
zkServer, NettyServerCnxnFactory.this);
ctx.setAttachment(cnxn);
//SECUREKEEPER: Enable ssl only if specified
//if (secure) {
if(encryption.equals("ssl")){
SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
ChannelFuture handshakeFuture = sslHandler.handshake();
handshakeFuture.addListener(new CertificateVerifier(sslHandler, cnxn));
} else {
allChannels.add(ctx.getChannel());
addCnxn(cnxn);
}
}
示例5: getPipeline
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
@Override
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = Channels.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
if (configuration.isChunked()) {
pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
}
pipeline.addLast("encoder", new HttpResponseEncoder());
if (configuration.isCompression()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
pipeline.addLast("handler", channelFactory.getChannelHandler());
return pipeline;
}
示例6: configureServerSSLOnDemand
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
private SslHandler configureServerSSLOnDemand() throws Exception {
if (!configuration.isSsl()) {
return null;
}
if (configuration.getSslHandler() != null) {
return configuration.getSslHandler();
} else if (sslContext != null) {
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(false);
engine.setNeedClientAuth(configuration.isNeedClientAuth());
if (configuration.getSslContextParameters() == null) {
// just set the enabledProtocols if the SslContextParameter doesn't set
engine.setEnabledProtocols(configuration.getEnabledProtocols().split(","));
}
return new SslHandler(engine);
}
return null;
}
示例7: configureServerSSLOnDemand
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
private SslHandler configureServerSSLOnDemand() throws Exception {
if (!consumer.getConfiguration().isSsl()) {
return null;
}
if (consumer.getConfiguration().getSslHandler() != null) {
return consumer.getConfiguration().getSslHandler();
} else if (sslContext != null) {
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(false);
engine.setNeedClientAuth(consumer.getConfiguration().isNeedClientAuth());
if (consumer.getConfiguration().getSslContextParameters() == null) {
// just set the enabledProtocols if the SslContextParameter doesn't set
engine.setEnabledProtocols(consumer.getConfiguration().getEnabledProtocols().split(","));
}
return new SslHandler(engine);
}
return null;
}
示例8: configureClientSSLOnDemand
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
private SslHandler configureClientSSLOnDemand() throws Exception {
if (!producer.getConfiguration().isSsl()) {
return null;
}
if (producer.getConfiguration().getSslHandler() != null) {
return producer.getConfiguration().getSslHandler();
} else if (sslContext != null) {
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(true);
if (producer.getConfiguration().getSslContextParameters() == null) {
// just set the enabledProtocols if the SslContextParameter doesn't set
engine.setEnabledProtocols(producer.getConfiguration().getEnabledProtocols().split(","));
}
return new SslHandler(engine);
}
return null;
}
示例9: configureClientSSLOnDemand
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
private SslHandler configureClientSSLOnDemand() throws Exception {
if (!producer.getConfiguration().isSsl()) {
return null;
}
if (producer.getConfiguration().getSslHandler() != null) {
return producer.getConfiguration().getSslHandler();
} else if (sslContext != null) {
SSLEngine engine = sslContext.createSSLEngine();
if (producer.getConfiguration().getSslContextParameters() == null) {
// just set the enabledProtocols if the SslContextParameter doesn't set
engine.setEnabledProtocols(producer.getConfiguration().getEnabledProtocols().split(","));
}
engine.setUseClientMode(true);
return new SslHandler(engine);
}
return null;
}
示例10: configureServerSSLOnDemand
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
private SslHandler configureServerSSLOnDemand() throws Exception {
if (!consumer.getConfiguration().isSsl()) {
return null;
}
if (consumer.getConfiguration().getSslHandler() != null) {
return consumer.getConfiguration().getSslHandler();
} else if (sslContext != null) {
SSLEngine engine = sslContext.createSSLEngine();
engine.setUseClientMode(false);
engine.setNeedClientAuth(consumer.getConfiguration().isNeedClientAuth());
if (consumer.getConfiguration().getSslContextParameters() == null) {
// just set the enabledProtocols if the SslContextParameter doesn't set
engine.setEnabledProtocols(consumer.getConfiguration().getEnabledProtocols().split(","));
}
return new SslHandler(engine);
}
return null;
}
示例11: start
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
public void start() {
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newFixedThreadPool(1),
Executors.newCachedThreadPool()
));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = new DefaultChannelPipeline();
pipeline.addLast("ssl", new SslHandler(getSSLEngine()));
pipeline.addLast("decoder", new LumberjackDecoder());
pipeline.addLast("logHandler", new LogEventHandler(eventListener));
return pipeline;
}
});
bootstrap.bind(new InetSocketAddress(configuration.getIpAddress(), configuration.getPort()));
}
示例12: messageReceived
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
@Override
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e) throws Exception {
final Object o = e.getMessage();
if (o instanceof DefaultHttpRequest) {
final SslHandler sslhandler = (SslHandler) e.getChannel().getPipeline().get("ssl_http");
final Principal principal = sslhandler.getEngine().getSession().getPeerCertificateChain()[0].getSubjectDN();
final DefaultHttpRequest request = (DefaultHttpRequest) o;
final DefaultHttpsRequest httpsRequest = new DefaultHttpsRequest(request, principal);
final MessageEventFacade facade = new MessageEventFacade(e, httpsRequest);
super.messageReceived(ctx, facade);
} else {
super.messageReceived(ctx, e);
}
}
示例13: channelConnected
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
@Override
public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) {
//prevent javax.net.ssl.SSLException: Received close_notify during handshake
final SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
if (sslHandler == null) {
return;
}
final ChannelFuture handshakeFuture = sslHandler.handshake();
handshakeFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
if (logger.isTraceEnabled()) {
logger.trace("Node to Node encryption cipher is {}/{}", sslHandler.getEngine().getSession().getProtocol(), sslHandler
.getEngine().getSession().getCipherSuite());
}
ctx.sendUpstream(e);
}
});
}
示例14: start
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
public void start() {
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newFixedThreadPool(1),
Executors.newCachedThreadPool()
));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = new DefaultChannelPipeline();
if(configuration.isSslEnabled()) {
pipeline.addLast("ssl", new SslHandler(getSSLEngine()));
}
pipeline.addLast("decoder", new LumberjackDecoder());
pipeline.addLast("logHandler", new EventHandler(eventListener));
return pipeline;
}
});
bootstrap.bind(new InetSocketAddress(configuration.getIpAddress(), configuration.getPort()));
}
示例15: channelConnected
import org.jboss.netty.handler.ssl.SslHandler; //導入依賴的package包/類
@Override
public void channelConnected(ChannelHandlerContext ctx,
final ChannelStateEvent e) throws Exception {
ChannelListener listener = this.listenerFactory.createChannelListener(new ObjectChannelImpl(e.getChannel()));
this.listeners.put(e.getChannel(), listener);
maxChannels = Math.max(maxChannels, this.listeners.size());
SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
if (sslHandler != null) {
sslHandler.handshake().addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture arg0)
throws Exception {
onConnection(e.getChannel());
}
});
} else {
onConnection(e.getChannel());
}
}