当前位置: 首页>>代码示例>>Java>>正文


Java SslContext.newEngine方法代码示例

本文整理汇总了Java中io.netty.handler.ssl.SslContext.newEngine方法的典型用法代码示例。如果您正苦于以下问题:Java SslContext.newEngine方法的具体用法?Java SslContext.newEngine怎么用?Java SslContext.newEngine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.handler.ssl.SslContext的用法示例。


在下文中一共展示了SslContext.newEngine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: clientSslEngineFor

import io.netty.handler.ssl.SslContext; //导入方法依赖的package包/类
@Override
public SSLEngine clientSslEngineFor(HttpRequest httpRequest, SSLSession sslSession) {
    String requestedHostname = HttpUtil.getHostFromRequest(httpRequest);

    try {
        SslContext ctx = getHostnameImpersonatingSslContext(requestedHostname, sslSession);

        return ctx.newEngine(ByteBufAllocator.DEFAULT);
    } catch (RuntimeException e) {
        throw new MitmException("Error creating SSLEngine for connection to client to impersonate upstream host: " + requestedHostname, e);
    }
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:13,代码来源:ImpersonatingMitmManager.java

示例2: initChannel

import io.netty.handler.ssl.SslContext; //导入方法依赖的package包/类
/**
 * 业务线程池
 * 用以单独处理业务handler,避免造成IO线程的阻塞
 * TODO 是否需要使用业务线程池,线程池的数量该怎么确定
 * private static final EventExecutorGroup EVENT_EXECUTOR = new DefaultEventExecutorGroup(50);
 */

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();

    if(CommonConstants.USE_SSL){
        SslContext context = SslContextHelper.getSslContext(CommonConstants.KEY_STORE_PATH,CommonConstants.KEY_STORE_PASSWORD);
        if(context!=null) {
            SSLEngine engine = context.newEngine(ch.alloc());
            engine.setUseClientMode(false);
            p.addLast(new SslHandler(engine));
        }else{
            logger.warn("SslContext is null with keyPath={}",CommonConstants.KEY_STORE_PATH);
        }
    }

    // HttpServerCodec is a combination of HttpRequestDecoder and HttpResponseEncoder
    // 使用HttpServerCodec将ByteBuf编解码为httpRequest/httpResponse
    p.addLast(new HttpServerCodec());

    // add gizp compressor for http response content
    p.addLast(new HttpContentCompressor());

    // 将多个HttpRequest组合成一个FullHttpRequest
    p.addLast(new HttpObjectAggregator(CommonConstants.MAX_CONTENT_LENGTH));

    p.addLast(new ChunkedWriteHandler());

    // 前置拦截器
    ChannelHandler[] preInterceptors = InterceptorUtil.getPreInterceptors();
    if(preInterceptors.length>0) {
        p.addLast(preInterceptors);
    }

    // 临时保存请求数据
    p.addLast(new DataStorer());

    // 路由分发器
    p.addLast(new ControllerDispatcher());

    // 后置拦截器
    ChannelHandler[] afterInterceptors = InterceptorUtil.getAfterInterceptors();
    if(afterInterceptors.length>0) {
        p.addLast(afterInterceptors);
    }

    // 请求结果响应
    p.addLast(new ResponseWriter());

}
 
开发者ID:all4you,项目名称:redant,代码行数:57,代码来源:NettyServer.java

示例3: initChannel

import io.netty.handler.ssl.SslContext; //导入方法依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {

	IConfig cfg = Config.getInstance();
	
	//if we need to check for ByteBuf leaks.
	if(cfg.isLeakDetector()){
		ResourceLeakDetector.setLevel(Level.ADVANCED);
	}
	
	//so we get enough data to build our pipeline
	ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(1024));

	ChannelPipeline pipeline = ch.pipeline();

	int incomingPort = ch.localAddress().getPort();
	
	
	//if users are coming in on a different port than the proxy port we need to redirect them.
	if(cfg.isProxy() && cfg.getPort() != incomingPort){
		redirectBuilder.apply(pipeline);
        return;
	}
	
	
	if (cfg.isEncrypted()) {
		SslContext sslContext = factory.createSslContext(Config.getInstance());
		SSLEngine engine = sslContext.newEngine(ch.alloc());
		engine.setUseClientMode(false);
		engine.setNeedClientAuth(cfg.isCertAuth());
		ch.pipeline().addFirst("ssl",new SslHandler(engine));
	}

	if(cfg.isProxy()){
		pipeline.channel().config().setAutoRead(false);
		pipeline.addLast(guicer.inject(new ProxyFrontendHandler(cfg.getProxyBackendHost(),cfg.getProxyBackendPort())));
		
	}else{
		websocketBuilder.apply(pipeline);
	}

}
 
开发者ID:mwambler,项目名称:xockets.io,代码行数:43,代码来源:WebSocketServerInitializer.java


注:本文中的io.netty.handler.ssl.SslContext.newEngine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。