當前位置: 首頁>>代碼示例>>Java>>正文


Java SslContext.newClientContext方法代碼示例

本文整理匯總了Java中io.netty.handler.ssl.SslContext.newClientContext方法的典型用法代碼示例。如果您正苦於以下問題:Java SslContext.newClientContext方法的具體用法?Java SslContext.newClientContext怎麽用?Java SslContext.newClientContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.ssl.SslContext的用法示例。


在下文中一共展示了SslContext.newClientContext方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initChannel

import io.netty.handler.ssl.SslContext; //導入方法依賴的package包/類
@Override
protected void initChannel(SocketChannel channel) throws SSLException {
    URI uri = config.getConnectionWebsocketUri();

    DefaultHttpHeaders headers = new DefaultHttpHeaders();
    headers.add(USER_ID_HEADER, config.getConnectionUserId().toString());
    headers.add(USER_PASSWORD_HEADER, config.getConnectionUserPassword());
    headers.add(SUPPLIER_ID_HEADER, config.getConnectionServerId());

    WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WS_VERSION, null, false, headers);

    ChannelPipeline pipeline = channel.pipeline();
    if (config.isConnectionSecure()) {
        try {
            SslContext sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
            pipeline.addLast(sslContext.newHandler(channel.alloc()));
        } catch (SSLException e) {
            logger.log(Level.SEVERE, "Shutting down client due to unexpected failure to create SSL context", e);
            throw e;
        }
    }
    pipeline.addLast(new HttpClientCodec());
    pipeline.addLast(new HttpObjectAggregator(8192));
    pipeline.addLast(new AudioConnectClientHandler(handshaker));
}
 
開發者ID:DeadmanDungeons,項目名稱:AudioConnect,代碼行數:26,代碼來源:AudioConnectClient.java

示例2: connect

import io.netty.handler.ssl.SslContext; //導入方法依賴的package包/類
@Override
protected InetSocketAddress connect(final URI uri, final int port) throws Exception {
	InetSocketAddress address = super.connect(uri, port);

	final SslContext ssl;
	if (uri.getScheme().equalsIgnoreCase("wss")) {
		ssl = SslContext.newClientContext(getTrustManager());
	} else {
		ssl = null;
	}

	HttpHeaders headers = new DefaultHttpHeaders();
	for (Map.Entry<String, String> header : this.headers.entrySet()) {
		headers.add(header.getKey(), header.getValue());
	}

	clientListener = new ClientListener(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, headers));

	Bootstrap b = new Bootstrap();
	b.group(SocketPoller.group())
		.channel(NioSocketChannel.class)
		.handler(new ChannelInitializer<SocketChannel>() {
			@Override
			protected void initChannel(SocketChannel ch) throws Exception {
				ChannelPipeline p = ch.pipeline();
				if (ssl != null) p.addLast(ssl.newHandler(ch.alloc(), uri.getHost(), port));
				p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), clientListener);
			}
		});

	channelFuture = b.connect(address);

	return address;
}
 
開發者ID:SquidDev-CC,項目名稱:CCTweaks-Lua,代碼行數:35,代碼來源:WebSocketConnection.java

示例3: get

import io.netty.handler.ssl.SslContext; //導入方法依賴的package包/類
private File get(URI uri, String url, String proxyHost, int proxyPort,
        final String target) throws Exception {
    final SslContext sslCtx;
    if (isSecured(uri)) {
        sslCtx = SslContext
                .newClientContext(InsecureTrustManagerFactory.INSTANCE);
    } else {
        sslCtx = null;
    }
    final NettyClientHandler handler = new NettyClientHandler(target);
    EventLoopGroup group = new NioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class)
                .handler(new NettyClientInitializer(sslCtx, handler));
        // .handler(new HttpSnoopClientInitializer(sslCtx));

        Channel ch = b.connect(proxyHost, proxyPort).sync().channel();

        HttpRequest request = new DefaultFullHttpRequest(
                HttpVersion.HTTP_1_1, HttpMethod.GET, url);
        request.headers().set(HttpHeaders.Names.HOST, uri.getHost());
        request.headers().set(HttpHeaders.Names.CONNECTION,
                HttpHeaders.Values.CLOSE);
        request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING,
                HttpHeaders.Values.GZIP);

        ch.writeAndFlush(request);
        ch.closeFuture().sync();

    } finally {
        group.shutdownGracefully();
    }
    return handler.getFile();
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:36,代碼來源:NettyClient_NoHttps.java

示例4: get

import io.netty.handler.ssl.SslContext; //導入方法依賴的package包/類
public File get(String url) throws Exception {
    URI uri = new URI(url);
    String scheme = uri.getScheme() == null ? "http" : uri.getScheme();
    if (!"http".equalsIgnoreCase(scheme)
            && !"https".equalsIgnoreCase(scheme)) {
        LOG.info("Only HTTP(S) is supported.");
        return null;
    }
    String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
    int port;
    if (uri.getPort() == -1) {
        if ("http".equalsIgnoreCase(scheme)) {
            port = 80;
        } else if ("https".equalsIgnoreCase(scheme)) {
            port = 443;
        } else {
            port = -1;
        }
    } else {
        port = uri.getPort();
    }
    this.uri = new URI(scheme, uri.getUserInfo(), host, port,
            uri.getPath(), uri.getQuery(), uri.getFragment());

    final boolean ssl = "https".equalsIgnoreCase(scheme);
    if (ssl) {
        sslCtx = SslContext
                .newClientContext(InsecureTrustManagerFactory.INSTANCE);
    } else {
        sslCtx = null;
    }

    connect(false, group);

    return null;
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:37,代碼來源:RetryClient.java

示例5: tryConnect

import io.netty.handler.ssl.SslContext; //導入方法依賴的package包/類
public boolean tryConnect(boolean ssl, SimpleChannelInboundHandler<Packet> default_handler, Auth auth, Runnable cancelTask)
{
    try
    {
        eventLoopGroup = NetworkUtils.eventLoopGroup(4);
        if (ssl) sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);

        Bootstrap bootstrap = new Bootstrap()
                .option(ChannelOption.SO_KEEPALIVE, true)
                .option(ChannelOption.TCP_NODELAY, true)
                .option(ChannelOption.IP_TOS, 24)
                .option(ChannelOption.AUTO_READ, true)
                .group(eventLoopGroup)
                .handler(new ChannelInitializer<Channel>() {

                    @Override
                    protected void initChannel(Channel channel) throws Exception
                    {

                        if (sslContext != null)
                            channel.pipeline().addLast(sslContext.newHandler(channel.alloc(), connectableAddress.getHostName(), connectableAddress.getPort()));

                        NetworkUtils.initChannel(channel).pipeline().addLast(default_handler);

                    }
                })
                .channel(NetworkUtils.socketChannel());
        this.channel = bootstrap.connect(connectableAddress.getHostName(), connectableAddress.getPort()).sync().channel().writeAndFlush(new PacketOutAuth(auth)).syncUninterruptibly().channel();

        return true;
    } catch (Exception ex)
    {
        connectionTrys++;
        System.out.println("Failed to connect... [" + connectionTrys + "]");
        System.out.println("Error: " + ex.getMessage());

        if(eventLoopGroup != null)
            eventLoopGroup.shutdownGracefully();

        eventLoopGroup = null;

        if (cancelTask != null)
        {
            cancelTask.run();
        }

        return false;
    }
}
 
開發者ID:Dytanic,項目名稱:CloudNet,代碼行數:50,代碼來源:NetworkConnection.java


注:本文中的io.netty.handler.ssl.SslContext.newClientContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。