private void executeMethod(Method method, Object webSocketEndpoint, List<Object> parameterList, Session session) { try { if (method.getReturnType() == String.class) { String returnStr = (String) method.invoke(webSocketEndpoint, parameterList.toArray()); session.getBasicRemote().sendText(returnStr); } else if (method.getReturnType() == ByteBuffer.class) { ByteBuffer buffer = (ByteBuffer) method.invoke(webSocketEndpoint, parameterList.toArray()); session.getBasicRemote().sendBinary(buffer); } else if (method.getReturnType() == byte[].class) { byte[] bytes = (byte[]) method.invoke(webSocketEndpoint, parameterList.toArray()); session.getBasicRemote().sendBinary(ByteBuffer.wrap(bytes)); } else if (method.getReturnType() == void.class) { method.invoke(webSocketEndpoint, parameterList.toArray()); } else if (method.getReturnType() == PongMessage.class) { PongMessage pongMessage = (PongMessage) method.invoke(webSocketEndpoint, parameterList.toArray()); session.getBasicRemote().sendPong(pongMessage.getApplicationData()); } else { throw new WebSocketEndpointMethodReturnTypeException("Unknown return type."); } } catch (IllegalAccessException e) { log.error("Illegal access exception occurred: " + e.toString()); } catch (InvocationTargetException e) { log.error("Method invocation failed: " + e.toString()); } catch (IOException e) { log.error("IOException occurred: " + e.toString()); } catch (WebSocketEndpointMethodReturnTypeException e) { log.error("WebSocket method return type exception occurred: " + e.toString()); } } }
private void executeMethod(Method method, Object webSocketEndpoint, List<Object> parameterList, Session session) { try { if (method.getReturnType() == String.class) { String returnStr = (String) method.invoke(webSocketEndpoint, parameterList.toArray()); session.getBasicRemote().sendText(returnStr); } else if (method.getReturnType() == ByteBuffer.class) { ByteBuffer buffer = (ByteBuffer) method.invoke(webSocketEndpoint, parameterList.toArray()); session.getBasicRemote().sendBinary(buffer); } else if (method.getReturnType() == byte[].class) { byte[] bytes = (byte[]) method.invoke(webSocketEndpoint, parameterList.toArray()); session.getBasicRemote().sendBinary(ByteBuffer.wrap(bytes)); } else if (method.getReturnType() == void.class) { method.invoke(webSocketEndpoint, parameterList.toArray()); } else if (method.getReturnType() == PongMessage.class) { PongMessage pongMessage = (PongMessage) method.invoke(webSocketEndpoint, parameterList.toArray()); session.getBasicRemote().sendPong(pongMessage.getApplicationData()); } else { throw new WebSocketEndpointMethodReturnTypeException("Unknown return type."); } } catch (IllegalAccessException e) { log.error("Illegal access exception occurred: " + e.toString()); } catch (InvocationTargetException e) { log.error("Method invocation failed: " + e.toString()); } catch (IOException e) { log.error("IOException occurred: " + e.toString()); } catch (WebSocketEndpointMethodReturnTypeException e) { log.error("WebSocket method return type exception occurred: " + e.toString()); } } }
/** * Sends a pong back to the client; normally in response to a ping. * * @param buf * @throws IOException * @throws IllegalArgumentException */ public void sendPong(byte[] buf) throws IllegalArgumentException, IOException { if (log.isTraceEnabled()) { log.trace("send pong: {}", buf); } if (wsSession != null && isConnected()) { // send the bytes wsSession.getBasicRemote().sendPong(ByteBuffer.wrap(buf)); // update counter writtenBytes += buf.length; } }
} else if (opCode == Constants.OPCODE_PING) { if (wsSession.isOpen()) { wsSession.getBasicRemote().sendPong(controlBufferBinary);
} else if (opCode == Constants.OPCODE_PING) { if (wsSession.isOpen()) { wsSession.getBasicRemote().sendPong(controlBufferBinary);
} else if (opCode == Constants.OPCODE_PING) { if (wsSession.isOpen()) { wsSession.getBasicRemote().sendPong(controlBufferBinary);
} else if (opCode == Constants.OPCODE_PING) { if (wsSession.isOpen()) { wsSession.getBasicRemote().sendPong(controlBufferBinary);
} else if (opCode == Constants.OPCODE_PING) { if (wsSession.isOpen()) { wsSession.getBasicRemote().sendPong(controlBufferBinary);
/** * Called by the provider when the web socket connection * has an incoming ping message from the given remote endpoint. * <p> * The endpoint needs to respond as soon as possible (see the websocket RFC). * No involvement from application layer, there is no ping listener. * * @param socket {@link TyrusWebSocket} who sent the message. * @param bytes the message. */ void onPing(TyrusWebSocket socket, ByteBuffer bytes) { TyrusSession session = getSession(socket); if (session == null) { LOGGER.log(Level.FINE, "Ping received on already closed connection."); return; } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received ping message"); session.restartIdleTimeoutExecutor(); try { session.getBasicRemote().sendPong(bytes); } catch (IOException e) { // do nothing. // we might consider calling onError, but there should be better defined exception. } }
/** * Called by the provider when the web socket connection * has an incoming ping message from the given remote endpoint. * <p> * The endpoint needs to respond as soon as possible (see the websocket RFC). * No involvement from application layer, there is no ping listener. * * @param socket {@link TyrusWebSocket} who sent the message. * @param bytes the message. */ void onPing(TyrusWebSocket socket, ByteBuffer bytes) { TyrusSession session = getSession(socket); if (session == null) { LOGGER.log(Level.FINE, "Ping received on already closed connection."); return; } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received ping message"); session.restartIdleTimeoutExecutor(); try { session.getBasicRemote().sendPong(bytes); } catch (IOException e) { // do nothing. // we might consider calling onError, but there should be better defined exception. } }
Disposable startKeepAlives() { if (keepAliveSeconds > 0) { return Flux.interval(Duration.ofSeconds(keepAliveSeconds)).handle((x, sink) -> { if (!session.isOpen()) { sink.complete(); } else { synchronized (session) { try { log.debug("Sending Unsolicited Pong"); session.getBasicRemote().sendPong(EMPTY); } catch (Exception e) { log.error("Failed to send Unsolicited Pong", e); sink.complete(); } } } }).subscribe(); } return Disposables.single(); }
@Override public void run() { TyrusSession session = TyrusSession.this; if (session.isOpen() && session.getHeartbeatInterval() > 0) { try { session.getBasicRemote().sendPong(null); } catch (IOException e) { LOGGER.log(Level.FINE, "Pong could not have been sent " + e.getMessage()); } } else { cancelHeartBeatTask(); } } }
@Override public void run() { TyrusSession session = TyrusSession.this; if (session.isOpen() && session.getHeartbeatInterval() > 0) { try { session.getBasicRemote().sendPong(null); } catch (IOException e) { LOGGER.log(Level.FINE, "Pong could not have been sent " + e.getMessage()); } } else { cancelHeartBeatTask(); } } }
@Override protected void sendPongMessage(PongMessage message) throws IOException { getNativeSession().getBasicRemote().sendPong(message.getPayload()); }
@Override protected void sendPongMessage(PongMessage message) throws IOException { getNativeSession().getBasicRemote().sendPong(message.getPayload()); }
/** * Invoked on send pong frame event. * * @param payload pong frame payload. * @throws IOException if there is a problem delivering the message. */ public void onSendPong(byte[] payload) throws IOException { session.getBasicRemote().sendPong(ByteBuffer.wrap(payload)); }
/** * Invoked on send pong frame event. * * @param payload pong frame payload. * @throws IOException if there is a problem delivering the message. */ public void onSendPong(byte[] payload) throws IOException { session.getBasicRemote().sendPong(ByteBuffer.wrap(payload)); }
@Override protected void sendPongMessage(PongMessage message) throws IOException { getNativeSession().getBasicRemote().sendPong(message.getPayload()); }