@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)); }
@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"); } }
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; }
@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()); }
public WebSocketClientHandler(long uid, WebSocketClientHandshaker handshaker) { this.uid = uid; this.handshaker = handshaker; }
public ClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
private AudioConnectClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
MeetupWebSocketClientHandler(WebSocketClientHandshaker handshaker, RSVPProducer rsvpProducer) { this.handshaker = handshaker; this.rsvpProducer = rsvpProducer; }
public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker, CountDownLatch latch) { this.handshaker = handshaker; this.latch = latch; this.isOpen = true; }
@Override public void onOpen(WebSocketClientHandshaker handShaker) { // TODO Auto-generated method stub }
@Override public void onOpen(WebSocketClientHandshaker handShaker) { logger.log(Level.INFO, "onOpen"); }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public MessageReceiverWebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public MessageSenderWebSocketClientHandler(WebSocketClientHandshaker handshaker, String id) { this.handshaker = handshaker; publisherId = id; }
public WebSocketClientHandlerControl(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { mHandshaker = handshaker; }
@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(); }
public WebSocketHandler(WebSocketClientHandshaker handshake, WsClient client) { this.handshake = handshake; this.client = client; }
@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); } }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; this.eventBus = EventBusService.getInstance(); }
public AbstractJsonRpcWebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public JsonRpcWebSocketClientHandler(WebSocketClientHandshaker handshaker) { super(handshaker); }
public WebsocketProtostuffEncoder(WebSocketClientHandshaker handShaker) { this.handShaker = handShaker; }
public WebSocketClientHandshaker getHandShaker() { return handShaker; }
public WebsocketProtostuffDecoder(WebSocketClientHandshaker handShaker) { super(handShaker); this.handShaker = handShaker; }
public C5ConnectionInitializer(WebSocketClientHandshaker handShaker) { super(); this.handShaker = handShaker; }