當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。