@Override @Nullable public URI getUri() { return this.delegate.getUri(); }
@Override @Nullable public URI getUri() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getUri(); }
@Test public void doHandshake() throws Exception { WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); headers.setSecWebSocketProtocol(Arrays.asList("echo")); this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get(); assertEquals(this.wsUrl, this.wsSession.getUri().toString()); assertEquals("echo", this.wsSession.getAcceptedProtocol()); }
@Test public void doHandshakeWithTaskExecutor() throws Exception { WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); headers.setSecWebSocketProtocol(Arrays.asList("echo")); this.client.setTaskExecutor(new SimpleAsyncTaskExecutor()); this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get(); assertEquals(this.wsUrl, this.wsSession.getUri().toString()); assertEquals("echo", this.wsSession.getAcceptedProtocol()); }
@Override @Nullable public URI getUri() { return this.delegate.getUri(); }
@Override @Nullable public URI getUri() { return this.delegate.getUri(); }
@Override @Nullable public URI getUri() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getUri(); }
@Override @Nullable public URI getUri() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getUri(); }
private Session upgradeSession(WebSocketSession webSocketSession){ Session session = new Session(webSocketSession); session.setType(pathHelper.getSessionType(webSocketSession.getUri().getPath())); return session; }
@Override public void afterConnectionEstablished(WebSocketSession session) { URI uri = session.getUri(); try { UriComponents uc = UriComponentsBuilder.fromUri(uri).build(); MultiValueMap<String, String> params = uc.getQueryParams(); String containerId = params.getFirst("container"); try(TempAuth ta = withAuth(session)) { connectToContainer(session, containerId); } } catch (Exception e) { log.error("Can not establish connection for '{}' due to error:", uri, e); } }
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { try { incNumConnectionsIfAllowed(); } catch (MaxNumberWsConnectionsReachedException e) { log.warn("Closed a WS connection because MAX_WS_CONNECTIONS={} limit reached", MAX_WS_CONNECTIONS); session.close(); } try { // We send this notification to the JsonRpcHandler when the JsonRpc // session is established, not when websocket session is established log.debug( "{} Client connection established from session={} uri={} headers={} acceptedProtocol={} attributes={}", label, session.getRemoteAddress(), session.getUri(), session.getHandshakeHeaders(), session.getAcceptedProtocol(), session.getAttributes()); } catch (Throwable t) { log.error("{} Exception processing afterConnectionEstablished in session={}", label, session.getId(), t); } }
private void connectToProxiedTarget(WebSocketSession session) { URI sessionUri = session.getUri(); ZuulWebSocketProperties.WsBrokerage wsBrokerage = getWebSocketBrokarage( sessionUri); Assert.notNull(wsBrokerage, "wsBrokerage must not be null"); String path = getWebSocketServerPath(wsBrokerage, sessionUri); Assert.notNull(path, "Web socket uri path must be null"); URI routeTarget = proxyTargetResolver.resolveTarget(wsBrokerage); Assert.notNull(routeTarget, "routeTarget must not be null"); String uri = ServletUriComponentsBuilder .fromUri(routeTarget) .path(path) .replaceQuery(sessionUri.getQuery()) .toUriString(); ProxyWebSocketConnectionManager connectionManager = new ProxyWebSocketConnectionManager( messagingTemplate, stompClient, session, headersCallback, uri); connectionManager.errorHandler(this.errorHandler); managers.put(session, connectionManager); connectionManager.start(); }
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { try { incNumConnectionsIfAllowed(); } catch (MaxNumberWsConnectionsReachedException e) { log.warn("Closed a WS connection because MAX_WS_CONNECTIONS={} limit reached", MAX_WS_CONNECTIONS); session.close(); } try { // We send this notification to the JsonRpcHandler when the JsonRpc // session is established, not when websocket session is established log.debug( "{} Client connection established from session={} uri={} headers={} acceptedProtocol={} attributes={}", label, session.getRemoteAddress(), session.getUri(), session.getHandshakeHeaders(), session.getAcceptedProtocol(), session.getAttributes()); } catch (Throwable t) { log.error("{} Exception processing afterConnectionEstablished in session={}", label, session.getId(), t); } }
Msg msg = new Msg(); switch (pathHelper.getSessionType(session.getUri().getPath())){ case Session.EXEC: msg.setMsgType(Msg.PIPE_EXEC);
@Override public void onConnected(Session session) { super.onConnected(session); //agent 与 devops 服务建立的 log 连接 if(session.getWebSocketSession().getUri().getPath().contains("/agent")){ return; } PipeRequest pipeRequest = extractLogRequest(session.getWebSocketSession().getAttributes()); if (pipeRequest == null){ logger.error("received web log connect but not enable log request , close connection"); try { session.getWebSocketSession().close(); return; } catch (IOException e) { logger.info("error when close socket"); } } Msg msg = null; if (session.getType() == Session.LOG) { msg = MsgFactory.logMsg(session.getUuid(),session.getRegisterKey(), pipeRequest); } else if (session.getType() == Session.EXEC ) { msg = MsgFactory.execMsg(session.getUuid(),session.getRegisterKey(), pipeRequest); } agentCommandListener.onMsg(msg); }
@Override protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { String sessionId = getSessionId(session); int sessionType = pathHelper.getSessionType(session.getUri().getPath()); int msgType; switch (sessionType){