javax.websocket.server.PathParam Java Examples
The following examples show how to use
javax.websocket.server.PathParam.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContainerExecEndpoint.java From apollo with Apache License 2.0 | 7 votes |
@OnOpen public void onOpen(Session session, @PathParam("podName") String podName, @PathParam("containerName") String containerName) { int environmentId = StringParser.getIntFromQueryString(session.getQueryString(), QUERY_STRING_ENVIRONMENT_KEY); int serviceId = StringParser.getIntFromQueryString(session.getQueryString(), QUERY_STRING_SERVICE_KEY); Environment environment = environmentDao.getEnvironment(environmentId); Service service = serviceDao.getService(serviceId); // Get default shell String defaultShell = Optional.ofNullable(service.getDefaultShell()).orElse("/bin/bash"); KubernetesHandler kubernetesHandler = kubernetesHandlerStore.getOrCreateKubernetesHandler(environment); logger.info("Opening ExecWatch to container {} in pod {} in environment {} related to service {}", containerName, podName, environment.getName(), service.getName()); ExecWatch execWatch = kubernetesHandler.getExecWatch(podName, containerName,defaultShell); ExecutorService executor = Executors.newFixedThreadPool(2); SessionExecModel sessionExecModel = new SessionExecModel(execWatch, executor); openReaderThreads(session, sessionExecModel); // Initialize the ExecWatch against kubernetes handler execWebSocketSessionStore.addSession(session, sessionExecModel); }
Example #2
Source File: EndpointValidator.java From msf4j with Apache License 2.0 | 7 votes |
private boolean validateOnOpenMethod(Object webSocketEndpoint) throws WebSocketMethodParameterException, WebSocketEndpointMethodReturnTypeException { EndpointDispatcher dispatcher = new EndpointDispatcher(); Method method; if (dispatcher.getOnOpenMethod(webSocketEndpoint).isPresent()) { method = dispatcher.getOnOpenMethod(webSocketEndpoint).get(); } else { return true; } validateReturnType(method); for (Parameter parameter: method.getParameters()) { Class<?> paraType = parameter.getType(); if (paraType == String.class) { if (parameter.getAnnotation(PathParam.class) == null) { throw new WebSocketMethodParameterException("Invalid parameter found on open message method: " + "string parameter without " + "@PathParam annotation."); } } else if (paraType != WebSocketConnection.class) { throw new WebSocketMethodParameterException("Invalid parameter found on open message method: " + paraType); } } return true; }
Example #3
Source File: GameRoundWebsocket.java From liberty-bikes with Eclipse Public License 1.0 | 7 votes |
@OnClose public void onClose(@PathParam("roundId") String roundId, Session session) { log(roundId, "Closed a session"); if (timerContext != null) timerContext.close(); try { GameRound round = gameSvc.getRound(roundId); if (round != null) if (round.removeClient(session) == 0) gameSvc.deleteRound(round); } catch (Exception e) { e.printStackTrace(); } }
Example #4
Source File: ChartController.java From JavaWeb with Apache License 2.0 | 7 votes |
@OnOpen public void onOpen(Session session,@PathParam("username") String username) { try{ client.add(session); user.put(URLEncoder.encode(username, "UTF-8"),URLEncoder.encode(username, "UTF-8")); JSONObject jo = new JSONObject(); JSONArray ja = new JSONArray(); //获得在线用户列表 Set<String> key = user.keySet(); for (String u : key) { ja.add(u); } jo.put("onlineUser", ja); session.getBasicRemote().sendText(jo.toString()); }catch(Exception e){ //do nothing } }
Example #5
Source File: WebSocketServer.java From springboot-learn with MIT License | 7 votes |
/** * 群发自定义消息 */ public static void sendInfo(String message, @PathParam("sid") String sid) throws IOException { log.info("推送消息到窗口" + sid + ",推送内容:" + message); for (WebSocketServer item : webSocketMap.values()) { try { //这里可以设定只推送给这个sid的,为null则全部推送 if (sid == null) { item.sendMessage(message); } else if (item.sid.equals(sid)) { item.sendMessage(message); } } catch (IOException e) { continue; } } }
Example #6
Source File: CinemaSocket.java From dbys with GNU General Public License v3.0 | 7 votes |
/** * 连接建立成功调用的方法 */ @OnOpen public void onOpen(Session session, @PathParam("username") String username) { this.session = session; this.username=username; if(DELETE_P00L.containsKey(username)){ this.roomId=DELETE_P00L.get(username); DELETE_P00L.remove(username); } //加入POOL中 POOL.put(session.getId(),this); //断线重连加房间 if(roomId!=0){ CinemaRoom room= ROOM_POOL.get(roomId); if(room!=null){ ROOM_POOL.get(roomId).getSockets().add(session.getId()); } } //在线数加1 log.info("有新连接加入!当前在线人数为" + POOL.size()); CinemaSocketManagement.info(session.getId()); }
Example #7
Source File: AndroidScrcpySocketServer.java From agent with MIT License | 7 votes |
@OnOpen public void onOpen(@PathParam("mobileId") String mobileId, @PathParam("username") String username, @PathParam("projectId") Integer projectId, Session session) throws Exception { onWebsocketOpenStart(mobileId, username, session); scrcpy = ((AndroidDevice) device).getScrcpy(); sender.sendText("启动scrcpy..."); scrcpy.start(imgData -> { try { sender.sendBinary(imgData); } catch (IOException e) { log.error("[{}]发送scrcpy数据异常", mobileId, e); } }); freshDriver(projectId); onWebsocketOpenFinish(); }
Example #8
Source File: TestCaseExecutionEndPoint.java From cerberus-source with GNU General Public License v3.0 | 7 votes |
/** * Callback when receiving closed connection from client side * * @param session the client {@link Session} * @param executionId the execution identifier from the * {@link ServerEndpoint} path */ @OnClose public void closedConnection(Session session, @PathParam("execution-id") long executionId) { if (LOG.isDebugEnabled()) { LOG.debug("Session " + session.getId() + " closed connection to execution " + executionId); } mainLock.lock(); try { sessions.remove(session.getId()); Set<String> registeredSessions = executions.get(executionId); if (registeredSessions != null) { registeredSessions.remove(session.getId()); } } finally { mainLock.unlock(); } }
Example #9
Source File: WebSocketService.java From microservice-recruit with Apache License 2.0 | 7 votes |
@OnOpen public void onOpen( Session session, @PathParam("userId") Long userId) { log.info("userId: " + userId + " webSocket开始连接"); this.userId = userId; this.session = session; WebSocketService present = sessionCache.getIfPresent(userId); if (present != null && StringUtils.isNotEmpty(present.getMessage())) { present.setSession(this.session); this.message = present.getMessage(); messageBroadcast(this.userId, this.message); } else { sessionCache.put(userId, this); } log.info("sessionCache: " + sessionCache.asMap().keySet()); }
Example #10
Source File: WebSocketServer.java From paas with Apache License 2.0 | 7 votes |
/** * 连接关闭调用的方法 */ @OnClose public void onClose(@PathParam("userId") String userId) { webSocketSet.remove(this.session.getId()); String field = ID_PREFIX + userId; try { String res = jedisClient.hget(key, field); if (StringUtils.isNotBlank(res)) { //如果有,则删除原来的sessionId jedisClient.hdel(key, field); } // log.info("WebSocket连接关闭,用户ID:{}", userId); } catch (Exception e) { log.error("缓存读取异常,错误位置:{}", "WebSocketServer.OnClose()"); } }
Example #11
Source File: WebSocketServer.java From java-tutorial with Creative Commons Attribution Share Alike 4.0 International | 7 votes |
@OnOpen public void onOpen(Session session, EndpointConfig config, @PathParam("id") String id) { logger.info("Session {} connected.", session.getId()); // 如果是新 Session,记录进 Map boolean isNewUser = true; Iterator i = userSessionMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String key = (String) entry.getKey(); if (key.equals(id)) { userSessionMap.get(key).add(session); isNewUser = false; break; } } if (isNewUser) { Set<Session> sessions = new HashSet<>(); sessions.add(session); userSessionMap.put(id, sessions); } logger.info("当前在线用户数: {}", userSessionMap.values().size()); }
Example #12
Source File: AgentSubscriptionEndpoint.java From testgrid with Apache License 2.0 | 7 votes |
/** * Web socket onMessage use when agent sends a string message. * * @param session - Registered session. * @param message - String message which needs to send to peer. * @param agentId - agent Identifier. */ @OnMessage public void onMessage(Session session, String message, @PathParam("agentId") String agentId) { super.onMessage(session, message, agentId); OperationSegment operationSegment = new Gson().fromJson(message, OperationSegment.class); logger.info("Message receive from agent: " + agentId + " with operation id " + operationSegment.getOperationId() + " code " + operationSegment.getCode() + " exitValue " + operationSegment.getExitValue() + " completed " + operationSegment.getCompleted()); OperationMessage operationMessage = SessionManager.getOperationQueueMap(). get(operationSegment.getOperationId()); if (operationMessage != null) { operationMessage.addMessage(operationSegment); logger.debug("Message with size " + operationSegment.getResponse().length() + " added to the message queue with operation id " + operationSegment.getOperationId()); } SessionManager.getAgentObservable().notifyObservable(operationSegment.getOperationId()); }
Example #13
Source File: WebSocket.java From jeecg-boot-with-activiti with MIT License | 6 votes |
@OnOpen public void onOpen(Session session, @PathParam(value="userId")String userId) { try { this.session = session; webSockets.add(this); sessionPool.put(userId, session); log.info("【websocket消息】有新的连接,总数为:"+webSockets.size()); } catch (Exception e) { } }
Example #14
Source File: WebSocket.java From jeecg-cloud with Apache License 2.0 | 6 votes |
@OnOpen public void onOpen(Session session, @PathParam(value="userId")String userId) { try { this.session = session; webSockets.add(this); sessionPool.put(userId, session); log.info("【websocket消息】有新的连接,总数为:"+webSockets.size()); } catch (Exception e) { } }
Example #15
Source File: TestEndpoinWithOnTextError.java From msf4j with Apache License 2.0 | 6 votes |
@OnMessage public void onTextMessage(@PathParam("name") String name, String text, WebSocketConnection webSocketConnection, ByteBuffer buffer) throws IOException { String msg = name + ":" + text + buffer; LOGGER.info("Received Text: " + text + " from " + name + webSocketConnection.getChannelId()); sendMessageToAll(msg); }
Example #16
Source File: WebSocketServer.java From molicode with Apache License 2.0 | 6 votes |
/** * 连接建立成功调用的方法 */ @OnOpen public void onOpen(Session session, @PathParam("sid") String sid) { this.session = session; webSocketSet.add(this); //加入set中 this.sid = sid; addOnlineCount(); //在线数加1 LOGGER.info("有新窗口开始监听:" + sid + ",当前在线人数为" + getOnlineCount()); try { sendMessage("日志链接连接成功"); } catch (IOException e) { LOGGER.error("websocket IO异常", e); } }
Example #17
Source File: MissionControlStatusEndpoint.java From launchpad-missioncontrol with Apache License 2.0 | 6 votes |
@OnOpen public void onOpen(Session session, @PathParam("uuid") String uuid) { UUID key = UUID.fromString(uuid); peers.put(key, session); JsonArrayBuilder builder = Json.createArrayBuilder(); for (StatusMessage statusMessage : StatusMessage.values()) { JsonObjectBuilder object = Json.createObjectBuilder(); builder.add(object.add(statusMessage.name(), statusMessage.getMessage()).build()); } RemoteEndpoint.Async asyncRemote = session.getAsyncRemote(); asyncRemote.sendText(builder.build().toString()); // Send pending messages List<String> messages = messageBuffer.remove(key); if (messages != null) { messages.forEach(asyncRemote::sendText); } }
Example #18
Source File: TestEndpointWithOnOpenError.java From msf4j with Apache License 2.0 | 6 votes |
@OnMessage public void onTextMessage(@PathParam("name") String name, String text, WebSocketConnection webSocketConnection) throws IOException { String msg = name + ":" + text; LOGGER.info("Received Text: " + text + " from " + name + webSocketConnection.getChannelId()); sendMessageToAll(msg); }
Example #19
Source File: TestEndpointWithOnError.java From msf4j with Apache License 2.0 | 6 votes |
@OnClose public void onClose(@PathParam("name") String name, CloseReason closeReason, WebSocketConnection webSocketConnection) { LOGGER.info("Connection is closed with status code: " + closeReason.getCloseCode().getCode() + " On reason " + closeReason.getReasonPhrase()); webSocketConnections.remove(webSocketConnection); String msg = name + " left the chat"; sendMessageToAll(msg); }
Example #20
Source File: SuperTenantSubscriptionEndpoint.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
/** * Web socket onMessage - When client sens a message * * @param session - Users registered session. * @param message - Status code for web-socket close. * @param streamName - StreamName extracted from the ws url. */ @OnMessage public void onMessage(Session session, String message, @PathParam("streamname") String streamName) { if (log.isDebugEnabled()) { log.debug("Received message from client. Message: " + message + ", " + "for Session id: " + session.getId() + ", for the Stream:" + streamName); } super.onMessage(session, message); }
Example #21
Source File: AnnotatedEndpointFactory.java From quarkus-http with Apache License 2.0 | 6 votes |
private static PathParam getPathParam(final Method method, final int parameter) { for (final Annotation annotation : method.getParameterAnnotations()[parameter]) { if (annotation.annotationType().equals(PathParam.class)) { return (PathParam) annotation; } } return null; }
Example #22
Source File: AnnotatedEndpointFactory.java From quarkus-http with Apache License 2.0 | 6 votes |
private static String[] pathParams(final Method method) { String[] params = new String[method.getParameterCount()]; for (int i = 0; i < method.getParameterCount(); ++i) { PathParam param = getPathParam(method, i); if (param != null) { params[i] = param.value(); } } return params; }
Example #23
Source File: TestEndpointWithOnError.java From msf4j with Apache License 2.0 | 6 votes |
@OnOpen public void onOpen(@PathParam("name") String name, WebSocketConnection webSocketConnection) { webSocketConnections.add(webSocketConnection); String msg = name + " connected to chat"; LOGGER.info(msg); sendMessageToAll(msg); }
Example #24
Source File: TestEndpointWithOnBinaryError.java From msf4j with Apache License 2.0 | 6 votes |
@OnOpen public void onOpen(@PathParam("name") String name, WebSocketConnection webSocketConnection) { webSocketConnections.add(webSocketConnection); String msg = name + " connected to chat"; LOGGER.info(msg); sendMessageToAll(msg); }
Example #25
Source File: AndroidStfSocketServer.java From agent with MIT License | 6 votes |
@OnOpen public void onOpen(@PathParam("mobileId") String mobileId, @PathParam("username") String username, @PathParam("projectId") Integer projectId, Session session) throws Exception { onWebsocketOpenStart(mobileId, username, session); androidDevice = (AndroidDevice) device; int width = androidDevice.getMobile().getScreenWidth(); int height = androidDevice.getMobile().getScreenHeight(); String realResolution = width + "x" + height; String virtualResolution = width / 2 + "x" + height / 2; // android5以下的Mobile不多,暂不处理横竖屏切换 sender.sendText("启动minicap..."); androidDevice.getMinicap().start(Integer.parseInt(App.getProperty("minicap-quality")), realResolution, virtualResolution, 0, minicapImgData -> { try { sender.sendBinary(minicapImgData); } catch (IOException e) { log.error("[{}]发送minicap数据异常", mobileId, e); } }); sender.sendText("启动minitouch..."); androidDevice.getMinitouch().start(); freshDriver(projectId); onWebsocketOpenFinish(); }
Example #26
Source File: TestEndpointWithOnBinaryError.java From msf4j with Apache License 2.0 | 6 votes |
@OnClose public void onClose(@PathParam("name") String name, CloseReason closeReason, WebSocketConnection webSocketConnection) { LOGGER.info("Connection is closed with status code: " + closeReason.getCloseCode().getCode() + " On reason " + closeReason.getReasonPhrase()); webSocketConnections.remove(webSocketConnection); String msg = name + " left the chat"; sendMessageToAll(msg); }
Example #27
Source File: ChatAppEndpoint.java From msf4j with Apache License 2.0 | 6 votes |
@OnClose public void onClose(@PathParam("name") String name, CloseReason closeReason, WebSocketConnection webSocketConnection) { LOGGER.info("Connection is closed with status code : " + closeReason.getCloseCode().getCode() + " On reason " + closeReason.getReasonPhrase()); webSocketConnections.remove(webSocketConnection); String msg = name + " left the chat"; sendMessageToAll(msg); }
Example #28
Source File: SnoopStatusEndpoint.java From snoop with MIT License | 6 votes |
/** * Heartbeat endpoint. * Registers that the client is still there and updates configuration * if changed. * * @param clientId The client id * @param applicationConfig The updated configuration */ @OnMessage public void onMessage(@PathParam("clientId") String clientId, String applicationConfig) { LOGGER.config(() -> "Client: " + clientId + ", status: " + applicationConfig); if (applicationConfig != null && !applicationConfig.isEmpty()) { clients.register(fromJSON(applicationConfig)); } else { clients.deRegister(clientId); } }
Example #29
Source File: ChatAppEndpoint.java From msf4j with Apache License 2.0 | 6 votes |
@OnClose public void onClose(@PathParam("name") String name, CloseReason closeReason, WebSocketConnection webSocketConnection) { LOGGER.info("Connection is closed with status code : " + closeReason.getCloseCode().getCode() + " On reason " + closeReason.getReasonPhrase()); webSocketConnections.remove(webSocketConnection); String msg = name + " left the chat"; sendMessageToAll(msg); }
Example #30
Source File: AnnotatedEndpointFactory.java From quarkus-http with Apache License 2.0 | 6 votes |
BoundSingleParameter(final Method method, final Class<?> type, final boolean optional) { this.type = type; int pos = -1; for (int i = 0; i < method.getParameterCount(); ++i) { boolean pathParam = false; for (Annotation annotation : method.getParameterAnnotations()[i]) { if (annotation.annotationType().equals(PathParam.class)) { pathParam = true; break; } } if (pathParam) { continue; } if (method.getParameterTypes()[i].equals(type)) { if (pos != -1) { throw JsrWebSocketMessages.MESSAGES.moreThanOneParameterOfType(type, method); } pos = i; } } if (pos != -1) { position = pos; } else if (optional) { position = -1; } else { throw JsrWebSocketMessages.MESSAGES.parameterNotFound(type, method); } }