java类io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker的实例源码

AudioConnectClient.java 文件源码 项目:AudioConnect 阅读 20 收藏 0 点赞 0 评论 0
@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));
}
WebSocketIT.java 文件源码 项目:qonduit 阅读 22 收藏 0 点赞 0 评论 0
@Before
public void setup() throws Exception {
    s = new Server(conf);
    s.run();

    Connector con = mac.getConnector("root", "secret");
    con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));

    this.sessionId = UUID.randomUUID().toString();
    AuthCache.getCache().put(sessionId, token);
    group = new NioEventLoopGroup();
    SslContext ssl = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();

    String cookieVal = ClientCookieEncoder.STRICT.encode(Constants.COOKIE_NAME, sessionId);
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(Names.COOKIE, cookieVal);

    WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(LOCATION,
            WebSocketVersion.V13, (String) null, false, headers);
    handler = new ClientHandler(handshaker);
    Bootstrap boot = new Bootstrap();
    boot.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", ssl.newHandler(ch.alloc(), "127.0.0.1", WS_PORT));
            ch.pipeline().addLast(new HttpClientCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(8192));
            ch.pipeline().addLast(handler);
        }
    });
    ch = boot.connect("127.0.0.1", WS_PORT).sync().channel();
    // Wait until handshake is complete
    while (!handshaker.isHandshakeComplete()) {
        sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
        LOG.debug("Waiting for Handshake to complete");
    }
}
WebSocketIT.java 文件源码 项目:timely 阅读 26 收藏 0 点赞 0 评论 0
@Before
public void setup() throws Exception {
    s = new Server(conf);
    s.run();

    Connector con = mac.getConnector("root", "secret");
    con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));

    this.sessionId = UUID.randomUUID().toString();
    AuthCache.getCache().put(sessionId, token);
    group = new NioEventLoopGroup();
    SslContext ssl = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();

    String cookieVal = ClientCookieEncoder.STRICT.encode(Constants.COOKIE_NAME, sessionId);
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(Names.COOKIE, cookieVal);

    WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(LOCATION,
            WebSocketVersion.V13, (String) null, false, headers);
    handler = new ClientHandler(handshaker);
    Bootstrap boot = new Bootstrap();
    boot.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", ssl.newHandler(ch.alloc(), "127.0.0.1", WS_PORT));
            ch.pipeline().addLast(new HttpClientCodec());
            ch.pipeline().addLast(new HttpObjectAggregator(8192));
            ch.pipeline().addLast(handler);
        }
    });
    ch = boot.connect("127.0.0.1", WS_PORT).sync().channel();
    // Wait until handshake is complete
    while (!handshaker.isHandshakeComplete()) {
        sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
        LOG.debug("Waiting for Handshake to complete");
    }
}
WebSocketTargetHandler.java 文件源码 项目:carbon-transports 阅读 22 收藏 0 点赞 0 评论 0
public WebSocketTargetHandler(WebSocketClientHandshaker handshaker, boolean isSecure, String requestedUri,
                              String target, WebSocketConnectorListener webSocketConnectorListener) {
    this.handshaker = handshaker;
    this.isSecure = isSecure;
    this.requestedUri = requestedUri;
    this.target = target;
    this.connectorListener = webSocketConnectorListener;
    handshakeFuture = null;
}
WebsocketChannelInitializer.java 文件源码 项目:SynchronizeFX 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void addToPipeline(final ChannelPipeline pipeline) {
    pipeline.addLast("http-codec", new HttpClientCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(8192));

    final WebSocketClientHandshaker handShaker = new WhiteSpaceInPathWebSocketClientHandshaker13(serverUri,
            WebSocketVersion.V13, PROTOCOL, false, createHttpHeaders(httpHeaders), Integer.MAX_VALUE);
    pipeline.addLast("websocket-protocol-handler", new WebSocketClientProtocolHandler(handShaker));

    pipeline.addLast("websocket-frame-codec", new ByteBufToWebSocketFrameCodec());
}
WebSocketClientHandler.java 文件源码 项目:wecard-server 阅读 20 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(long uid, WebSocketClientHandshaker handshaker) {
    this.uid = uid;
    this.handshaker = handshaker;
}
WebSocketIT.java 文件源码 项目:qonduit 阅读 26 收藏 0 点赞 0 评论 0
public ClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
AudioConnectClient.java 文件源码 项目:AudioConnect 阅读 26 收藏 0 点赞 0 评论 0
private AudioConnectClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
WebSocketIT.java 文件源码 项目:timely 阅读 28 收藏 0 点赞 0 评论 0
public ClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
MeetupWebSocketClientHandler.java 文件源码 项目:StreamingData-Book-Examples 阅读 22 收藏 0 点赞 0 评论 0
MeetupWebSocketClientHandler(WebSocketClientHandshaker handshaker, RSVPProducer rsvpProducer) {
    this.handshaker = handshaker;
    this.rsvpProducer = rsvpProducer;
}
WebSocketClientHandler.java 文件源码 项目:LiteGraph 阅读 24 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
WebSocketClientHandler.java 文件源码 项目:product-ei 阅读 29 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker, CountDownLatch latch) {
    this.handshaker = handshaker;
    this.latch = latch;
    this.isOpen = true;
}
NettyTestClient.java 文件源码 项目:xockets.io 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void onOpen(WebSocketClientHandshaker handShaker) {
    // TODO Auto-generated method stub

}
AbstractClient.java 文件源码 项目:xockets.io 阅读 24 收藏 0 点赞 0 评论 0
@Override
public void onOpen(WebSocketClientHandshaker handShaker) {
    logger.log(Level.INFO, "onOpen");
}
WebSocketClientHandler.java 文件源码 项目:xockets.io 阅读 27 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
WebSocketClientHandler.java 文件源码 项目:JavaAyo 阅读 29 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
MessageReceiverWebSocketClientHandler.java 文件源码 项目:iofabric 阅读 25 收藏 0 点赞 0 评论 0
public MessageReceiverWebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
MessageSenderWebSocketClientHandler.java 文件源码 项目:iofabric 阅读 24 收藏 0 点赞 0 评论 0
public MessageSenderWebSocketClientHandler(WebSocketClientHandshaker handshaker, String id) {
    this.handshaker = handshaker;
    publisherId = id;
}
WebSocketClientHandlerControl.java 文件源码 项目:iofabric 阅读 19 收藏 0 点赞 0 评论 0
public WebSocketClientHandlerControl(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
NettyFirehoseOnSubscribe.java 文件源码 项目:snotel 阅读 22 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
WebSocketClientHandler.java 文件源码 项目:netty4.0.27Learn 阅读 19 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
BitsoWebSocket.java 文件源码 项目:bitso-java 阅读 24 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    mHandshaker = handshaker;
}
WebSocketClientHandler.java 文件源码 项目:msf4j 阅读 38 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
AndroidWsProvider.java 文件源码 项目:dslink-java-android 阅读 22 收藏 0 点赞 0 评论 0
@Override
public void connect(WsClient client) {
    if (client == null) {
        throw new NullPointerException("client");
    }
    final URLInfo url = client.getUrl();
    String full = url.protocol + "://" + url.host
            + ":" + url.port + url.path;
    URI uri;
    try {
        uri = new URI(full);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    WebSocketVersion v = WebSocketVersion.V13;
    HttpHeaders h = new DefaultHttpHeaders();
    final WebSocketClientHandshaker wsch = WebSocketClientHandshakerFactory
            .newHandshaker(uri, v, null, true, h, Integer.MAX_VALUE);
    final WebSocketHandler handler = new WebSocketHandler(wsch, client);

    Bootstrap b = new Bootstrap();
    b.group(SharedObjects.getLoop());
    b.channel(NioSocketChannel.class);
    b.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            if (url.secure) {
                TrustManagerFactory man = InsecureTrustManagerFactory.INSTANCE;
                SslContext con = SslContext.newClientContext(man);
                p.addLast(con.newHandler(ch.alloc()));
            }

            p.addLast(new HttpClientCodec());
            p.addLast(new HttpObjectAggregator(8192));
            p.addLast(handler);
        }
    });

    ChannelFuture fut = b.connect(url.host, url.port);
    fut.syncUninterruptibly();
    handler.handshakeFuture().syncUninterruptibly();
}
AndroidWsProvider.java 文件源码 项目:dslink-java-android 阅读 26 收藏 0 点赞 0 评论 0
public WebSocketHandler(WebSocketClientHandshaker handshake,
                        WsClient client) {
    this.handshake = handshake;
    this.client = client;
}
WebSocketClient.java 文件源码 项目:idea-websocket-client 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void connect(String url) throws Exception {
  URI uri = new URI(url);
  setConnected(false);

  String scheme = uri.getScheme() == null ? "http" : uri.getScheme();
  final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
  final 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();
  }

  if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme)) {
    Notifications.Bus.notify(
        new Notification(
            "Websocket Client",
            "Unable to connect",
            "Only WS(S) is supported.",
            NotificationType.ERROR)
    );
    return;
  }

  EventLoopGroup group = new NioEventLoopGroup();
  try {
    WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(
        uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders());
    WebSocketClientHandler webSocketClientHandler = new WebSocketClientHandler(handshaker);

    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(group)
        .channel(NioSocketChannel.class)
        .handler(new ChannelInitializer<SocketChannel>() {
          @Override
          protected void initChannel(SocketChannel ch) {
            ChannelPipeline p = ch.pipeline();

            p.addLast(
                new HttpClientCodec(),
                new HttpObjectAggregator(8192),
                webSocketClientHandler);
          }
        });

    channel = bootstrap.connect(uri.getHost(), port).sync().channel();
    webSocketClientHandler.handshakeFuture().sync();
    setConnected(true);

    for (; ; );
  } finally {
    group.shutdownGracefully();
    setConnected(false);
  }
}
WebSocketClientHandler.java 文件源码 项目:idea-websocket-client 阅读 24 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
  this.handshaker = handshaker;
  this.eventBus = EventBusService.getInstance();
}
WebSocketClientHandler.java 文件源码 项目:carbon-transports 阅读 26 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker, CountDownLatch latch) {
    this.handshaker = handshaker;
    this.latch = latch;
    this.isOpen = true;
}
WebSocketClientHandler.java 文件源码 项目:blynk-server 阅读 23 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
WebSocketClientHandler.java 文件源码 项目:tinkerpop 阅读 22 收藏 0 点赞 0 评论 0
public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}


问题


面经


文章

微信
公众号

扫码关注公众号