@Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { int uid = -1; if(request.getSession(false) != null){ uid = (int) request.getSession(false).getAttribute("uid"); } System.out.println("请求登录==>uid:"+uid); ChatMessageInbound cmi = new ChatMessageInbound(uid); return cmi; }
@Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { try{ final URI uri = new URI(request.getRequestURI()); return new MessageInbound() { @Override protected void onBinaryMessage(ByteBuffer arg0) throws IOException { } @Override protected void onTextMessage(CharBuffer message) throws IOException { l.onTextMessage(message); } @Override protected void onOpen(final WsOutbound outbound) { l.onOpen(new Connection() { @Override public URI getRequestUri() { return uri; } @Override public void send(CharSequence text) throws IOException { outbound.writeTextMessage(CharBuffer.wrap(text)); } }); } @Override protected void onClose(int status) { l.onClose(status); } private ConnectionListener l = handler.createConnectionListener(); }; } catch(URISyntaxException e){ throw new RuntimeException(e); } }
@Override protected StreamInbound createWebSocketInbound(final String subProtocol, final HttpServletRequest request) { // TODO validate sub protocol and find out how to refuse connections that send an unsupported sub protocol. final String channelName = getChannelName(request); synchronized (channels) { return new SynchronizeFXTomcatConnection(channels.get(channelName)); } }
@Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { HandshakeRequest handshakeRequest = new HttpServletHandshakeRequest(request); String url = configUtil.getMaping(); if (endpointConfig.isDynamicAddressing()) { url = request.getRequestURI().substring(request.getContextPath().length()); } ClientChannel clientChannel = endpointConfig.getClientChannelFor(url); String username = null; try { username = clientChannel.authenticate(endpointConfig.getAuthenticationProvider(), handshakeRequest); } catch (AuthenticationException e) { LOG.error("Unauthorized access for " + request.getRemoteHost(), e); throw e; } WebSocketClientConfig clientConfiguration = endpointConfig.getClientBuilder(clientChannel).get(handshakeRequest) .url(url) .username(username) .protocol(subProtocol, endpointConfig.getProtocolRepository()) .build(); Tomcat7WebSocketClient client = new Tomcat7WebSocketClient(clientConfiguration); if (outboundByteBufferSize != 0) { client.setOutboundByteBufferSize(outboundByteBufferSize); } if (outboundCharBufferSize != 0) { client.setOutboundCharBufferSize(outboundCharBufferSize); } LOG.info("Client connecion created for " + request.getRemoteHost() + " with username " + username + " and ID " + clientConfiguration.getClientId() + " on " + url); return client; }
@Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { return new EchoMessageInbound(byteBufSize,charBufSize); }
@Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { return new EchoStreamInbound(); }
@Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { return new ChatMessageInbound(connectionIds.incrementAndGet()); }
@Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { return new SnakeMessageInbound(connectionIds.incrementAndGet()); }
@Override protected StreamInbound createWebSocketInbound(String arg0) { String trapPath = this.reqPath.get(); return WSServletAdaptor.getSocket(this.ctxPath, trapPath); }
@Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { return new EntranceMessageInbound(); }