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

项目:AudioConnect    文件:AudioConnectClient.java   
@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));
}
项目:qonduit    文件:WebSocketIT.java   
@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");
    }
}
项目:timely    文件:WebSocketIT.java   
@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");
    }
}
项目:carbon-transports    文件:WebSocketTargetHandler.java   
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;
}
项目:SynchronizeFX    文件:WebsocketChannelInitializer.java   
@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());
}
项目:wecard-server    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(long uid, WebSocketClientHandshaker handshaker) {
    this.uid = uid;
    this.handshaker = handshaker;
}
项目:qonduit    文件:WebSocketIT.java   
public ClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:AudioConnect    文件:AudioConnectClient.java   
private AudioConnectClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:timely    文件:WebSocketIT.java   
public ClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:StreamingData-Book-Examples    文件:MeetupWebSocketClientHandler.java   
MeetupWebSocketClientHandler(WebSocketClientHandshaker handshaker, RSVPProducer rsvpProducer) {
    this.handshaker = handshaker;
    this.rsvpProducer = rsvpProducer;
}
项目:LiteGraph    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:product-ei    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker, CountDownLatch latch) {
    this.handshaker = handshaker;
    this.latch = latch;
    this.isOpen = true;
}
项目:xockets.io    文件:NettyTestClient.java   
@Override
public void onOpen(WebSocketClientHandshaker handShaker) {
    // TODO Auto-generated method stub

}
项目:xockets.io    文件:AbstractClient.java   
@Override
public void onOpen(WebSocketClientHandshaker handShaker) {
    logger.log(Level.INFO, "onOpen");
}
项目:xockets.io    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:JavaAyo    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:iofabric    文件:MessageReceiverWebSocketClientHandler.java   
public MessageReceiverWebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:iofabric    文件:MessageSenderWebSocketClientHandler.java   
public MessageSenderWebSocketClientHandler(WebSocketClientHandshaker handshaker, String id) {
    this.handshaker = handshaker;
    publisherId = id;
}
项目:iofabric    文件:WebSocketClientHandlerControl.java   
public WebSocketClientHandlerControl(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:snotel    文件:NettyFirehoseOnSubscribe.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:netty4.0.27Learn    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:bitso-java    文件:BitsoWebSocket.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    mHandshaker = handshaker;
}
项目:msf4j    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:dslink-java-android    文件:AndroidWsProvider.java   
@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();
}
项目:dslink-java-android    文件:AndroidWsProvider.java   
public WebSocketHandler(WebSocketClientHandshaker handshake,
                        WsClient client) {
    this.handshake = handshake;
    this.client = client;
}
项目:idea-websocket-client    文件:WebSocketClient.java   
@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);
  }
}
项目:idea-websocket-client    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
  this.handshaker = handshaker;
  this.eventBus = EventBusService.getInstance();
}
项目:carbon-transports    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker, CountDownLatch latch) {
    this.handshaker = handshaker;
    this.latch = latch;
    this.isOpen = true;
}
项目:blynk-server    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:tinkerpop    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:netty4study    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}
项目:kurento-java    文件:AbstractJsonRpcWebSocketClientHandler.java   
public AbstractJsonRpcWebSocketClientHandler(WebSocketClientHandshaker handshaker) {
  this.handshaker = handshaker;
}
项目:kurento-java    文件:JsonRpcClientNettyWebSocket.java   
public JsonRpcWebSocketClientHandler(WebSocketClientHandshaker handshaker) {
  super(handshaker);
}
项目:c5    文件:WebsocketProtostuffEncoder.java   
public WebsocketProtostuffEncoder(WebSocketClientHandshaker handShaker) {
  this.handShaker = handShaker;
}
项目:c5    文件:WebsocketProtostuffEncoder.java   
public WebSocketClientHandshaker getHandShaker() {
  return handShaker;
}
项目:c5    文件:WebsocketProtostuffDecoder.java   
public WebsocketProtostuffDecoder(WebSocketClientHandshaker handShaker) {
  super(handShaker);
  this.handShaker = handShaker;
}
项目:c5    文件:C5ConnectionInitializer.java   
public C5ConnectionInitializer(WebSocketClientHandshaker handShaker) {
  super();
  this.handShaker = handShaker;
}
项目:dslink-java-android    文件:AndroidWsProvider.java   
@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();
}
项目:dslink-java-android    文件:AndroidWsProvider.java   
public WebSocketHandler(WebSocketClientHandshaker handshake,
                        WsClient client) {
    this.handshake = handshake;
    this.client = client;
}
项目:netty-netty-5.0.0.Alpha1    文件:WebSocketClientHandler.java   
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
    this.handshaker = handshaker;
}