org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage Java Examples
The following examples show how to use
org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage.
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: WebSocketConnection.java From jmeter-bzm-plugins with Apache License 2.0 | 6 votes |
@OnWebSocketMessage public void onMessage(String msg) { messages.add("[RECIVED at "+ System.currentTimeMillis() + "] " + msg); if (!closeConnectionPattern.isEmpty()){ if (closeConnectionExpression.matcher(msg).find()) { closeLatch.countDown(); close(); } } if (this.waitMessage){ if (!waitResponsePatter.isEmpty()){ if (waitResponseExpresion.matcher(msg).find()) { messageLatch.countDown(); this.waitMessage = false; } } } }
Example #2
Source File: ServiceSocket.java From JMeter-WebSocketSampler with Apache License 2.0 | 6 votes |
@OnWebSocketMessage public void onMessage(String msg) { synchronized (parent) { log.debug("Received message: " + msg); String length = " (" + msg.length() + " bytes)"; logMessage.append(" - Received message #").append(messageCounter).append(length); addResponseMessage("[Message " + (messageCounter++) + "]\n" + msg + "\n\n"); if (responseExpression == null || responseExpression.matcher(msg).find()) { logMessage.append("; matched response pattern").append("\n"); closeLatch.countDown(); } else if (!disconnectPattern.isEmpty() && disconnectExpression.matcher(msg).find()) { logMessage.append("; matched connection close pattern").append("\n"); closeLatch.countDown(); close(StatusCode.NORMAL, "JMeter closed session."); } else { logMessage.append("; didn't match any pattern").append("\n"); } } }
Example #3
Source File: XmppWebSocket.java From Openfire with Apache License 2.0 | 6 votes |
@OnWebSocketMessage public void onTextMethod(String stanza) { XMPPPacketReader reader = null; try { reader = readerPool.borrowObject(); Document doc = reader.read(new StringReader(stanza)); if (xmppSession == null) { initiateSession(doc.getRootElement()); } else { processStanza(doc.getRootElement()); } } catch (Exception ex) { Log.error("Failed to process XMPP stanza", ex); } finally { if (reader != null) { readerPool.returnObject(reader); } } }
Example #4
Source File: SocketImplementation.java From hapi-fhir-jpaserver-starter with Apache License 2.0 | 6 votes |
/** * This is the message handler for the client * * @param theMsg */ @OnWebSocketMessage public void onMessage(String theMsg) { ourLog.info("Got msg: " + theMsg); myMessages.add(theMsg); if (theMsg.startsWith("bound ")) { myGotBound = true; mySubsId = (theMsg.substring("bound ".length())); } else if (myGotBound && theMsg.startsWith("add " + mySubsId + "\n")) { String text = theMsg.substring(("add " + mySubsId + "\n").length()); ourLog.info("text: " + text); } else if (theMsg.startsWith("ping ")) { myPingCount++; } else { myError = "Unexpected message: " + theMsg; } }
Example #5
Source File: WSMainSocket.java From Web-API with MIT License | 6 votes |
@OnWebSocketMessage public void onMessage(String message) { try { ObjectMapper mapper = new ObjectMapper(); BaseMessage msg = mapper.readValue(message, BaseMessage.class); switch (msg.getType()) { case CONNECT: ConnectMessage connMsg = (ConnectMessage)msg; this.privateKey = connMsg.getKey(); link.addServer(connMsg.getKey(), this); break; case DISCONNECT: link.removeServer(privateKey); break; case RESPONSE: link.respond((ResponseMessage) msg); break; } } catch (IOException e) { e.printStackTrace(); } }
Example #6
Source File: WebSocketRunnerMock.java From codenjoy with GNU General Public License v3.0 | 6 votes |
@OnWebSocketMessage public void onMessage(String data) { System.out.println("client got message: " + data); messages.add(data); if (answer == null) { throw new IllegalArgumentException("Answer is null!"); } if (!answered) { for (int index = 0; index < times; index++) { send(); } if (onlyOnce) { answered = true; } } request = data; }
Example #7
Source File: WebSocketChannelImpl.java From swellrt with Apache License 2.0 | 6 votes |
@OnWebSocketMessage public void onMessage(String data) { if (data.startsWith(HEARTBEAT_DATA_PREFIX)) { handleHeartbeatMessage(data); return; } if (data.startsWith(RECONNECTION_DATA_PREFIX)) { handleReconnectionMessage(data); return; } recvCount++; handleMessageString(data); }
Example #8
Source File: SimpleWebSocket.java From java-11-examples with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onMessage(InputStream inputStream) { try { MessageWrapper messageWrapper = MessageWrapper.parseFrom(inputStream.readAllBytes()); this.sessionListener.onMessageWrapper(messageWrapper); } catch (IOException e) { LOG.error("Error: ", e); } }
Example #9
Source File: WSClientSocket.java From Web-API with MIT License | 5 votes |
@OnWebSocketMessage public void onMessage(String msg) { BaseMessage req = parseRequest(msg, BaseMessage.class); if (req == null) { return; } if (req instanceof RequestMessage) { ResponseMessage res = WebAPI.emulateRequest((RequestMessage) req); send(res); } else { WebAPI.getLogger().warn("Unknown message from WebSocket: " + msg); } }
Example #10
Source File: JettyWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onWebSocketBinary(byte[] payload, int offset, int length) { BinaryMessage message = new BinaryMessage(payload, offset, length, true); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #11
Source File: JettyWebSocketHandlerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onWebSocketText(String payload) { TextMessage message = new TextMessage(payload); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #12
Source File: JettyWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@OnWebSocketMessage public void onWebSocketText(String payload) { TextMessage message = new TextMessage(payload); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #13
Source File: JettyWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@OnWebSocketMessage public void onWebSocketBinary(byte[] payload, int offset, int length) { BinaryMessage message = new BinaryMessage(payload, offset, length, true); try { this.webSocketHandler.handleMessage(this.wsSession, message); } catch (Throwable ex) { ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger); } }
Example #14
Source File: CmdConsume.java From pulsar with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public synchronized void onMessage(String msg) throws Exception { JsonObject message = new Gson().fromJson(msg, JsonObject.class); JsonObject ack = new JsonObject(); String messageId = message.get(X_PULSAR_MESSAGE_ID).getAsString(); ack.add("messageId", new JsonPrimitive(messageId)); // Acking the proxy this.getRemote().sendString(ack.toString()); this.incomingMessages.put(msg); }
Example #15
Source File: TextExchangeSocket.java From conga with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onMessage(Session session, String text) { byte[] bytes = text.getBytes(); BufferSupply supply = ringBuffer.get(); if (null != supply.acquireAndCopy(bytes, 0, bytes.length)) { supply.setSource(principal); supply.release(); } else { // todo log error } }
Example #16
Source File: BinaryExchangeSocket.java From conga with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onMessage(Session session, byte src[], int offset, int length) { BufferSupply supply = ringBuffer.get(); if (null != supply.acquireAndCopy(src, offset, length)) { supply.setSource(principal); supply.release(); } else { // todo log error } }
Example #17
Source File: SocketServer.java From Much-Assembly-Required with GNU General Public License v3.0 | 5 votes |
@OnWebSocketMessage public void onMessage(Session session, String message) { OnlineUser onlineUser = onlineUserManager.getUser(session); //Shouldn't happen if (onlineUser == null) { LogManager.LOGGER.severe("(WS) FIXME: SocketServer:onMessage"); return; } //Authenticated user if (onlineUser.isAuthenticated()) { messageDispatcher.dispatch(onlineUser, message); return; } //Handle auth request if (message.length() == AUTH_TOKEN_LEN) { LogManager.LOGGER.info("(WS) Received message from unauthenticated user " + session.getRemoteAddress().getAddress()); User user = GameServer.INSTANCE.getUserManager().validateAuthToken(message); if (user != null) { doPostAuthUser(session, onlineUser, user); } else if (this.guestPolicy != GuestPolicy.BLOCK) { doPostAuthGuest(session, onlineUser); } else { LogManager.LOGGER.info("(WS) Blocked guest user " + session.getRemoteAddress().getAddress()); kickOnlineUser(session); } } //Ignore other cases }
Example #18
Source File: JettyWebSocketHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
@OnWebSocketMessage public void onWebSocketBinary(byte[] message, int offset, int length) { if (this.delegateSession != null) { ByteBuffer buffer = ByteBuffer.wrap(message, offset, length); WebSocketMessage webSocketMessage = toMessage(Type.BINARY, buffer); this.delegateSession.handleMessage(webSocketMessage.getType(), webSocketMessage); } }
Example #19
Source File: SimpleConsumerSocket.java From pulsar with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public synchronized void onMessage(String msg) throws JsonParseException, IOException { receivedMessages.incrementAndGet(); JsonObject message = new Gson().fromJson(msg, JsonObject.class); JsonObject ack = new JsonObject(); String messageId = message.get(X_PULSAR_MESSAGE_ID).getAsString(); consumerBuffer.add(messageId); ack.add("messageId", new JsonPrimitive(messageId)); // Acking the proxy this.getRemote().sendString(ack.toString()); }
Example #20
Source File: JettyWebSocketHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@OnWebSocketMessage public void onWebSocketBinary(byte[] message, int offset, int length) { if (this.delegateSession != null) { ByteBuffer buffer = ByteBuffer.wrap(message, offset, length); WebSocketMessage webSocketMessage = toMessage(Type.BINARY, buffer); this.delegateSession.handleMessage(webSocketMessage.getType(), webSocketMessage); } }
Example #21
Source File: CmdProduce.java From pulsar with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public synchronized void onMessage(String msg) throws JsonParseException { LOG.info("ack= {}",msg); if(this.result!=null) { this.result.complete(null); } }
Example #22
Source File: SimpleTestProducerSocket.java From pulsar with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onMessage(String msg) throws JsonParseException { JsonObject json = new Gson().fromJson(msg, JsonObject.class); long endTimeNs = System.nanoTime(); long startTime = endTimeNs; if (startTimeMap.get(json.get(CONTEXT).getAsString()) != null) { startTime = startTimeMap.get(json.get(CONTEXT).getAsString()); } long latencyNs = endTimeNs - startTime; recorder.recordValue(NANOSECONDS.toMicros(latencyNs)); }
Example #23
Source File: ServerSocket.java From java-docs-samples with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onWebSocketText(String message) { logger.fine("Received message: " + message); try { // echo message back to client this.session.getRemote().sendString(message); } catch (IOException e) { logger.severe("Error echoing message: " + e.getMessage()); } }
Example #24
Source File: WebSocketClientSource.java From datacollector with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onMessage(String message) { String requestId = System.currentTimeMillis() + "." + counter.getAndIncrement(); try (DataParser parser = dataParserFactory.getParser(requestId, message)) { process(parser); } catch (Exception ex) { errorQueue.offer(ex); LOG.warn("Error while processing request payload from: {}", ex.toString(), ex); } }
Example #25
Source File: WebSocketClientSource.java From datacollector with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void onMessage(byte[] payload, int offset, int len) { String requestId = System.currentTimeMillis() + "." + counter.getAndIncrement(); try (DataParser parser = dataParserFactory.getParser(requestId, payload, offset, len)) { process(parser); } catch (Exception ex) { errorQueue.offer(ex); LOG.warn("Error while processing request payload from: {}", ex.toString(), ex); } }
Example #26
Source File: ChatWebSocket.java From tp_java_2015_02 with MIT License | 5 votes |
@OnWebSocketMessage public void onMessage(String data) { for (ChatWebSocket user : users) { try { user.getSession().getRemote().sendString(data); } catch (Exception e) { System.out.print(e); } } logger.info("onMessage: " + data); }
Example #27
Source File: RosBridge.java From java_rosbridge with GNU Lesser General Public License v3.0 | 5 votes |
@OnWebSocketMessage public void onMessage(String msg) { if(this.printMessagesAsReceived){ System.out.println(msg); } ObjectMapper mapper = new ObjectMapper(); JsonNode node = null; try { node = mapper.readTree(msg); if(node.has("op")){ String op = node.get("op").asText(); if(op.equals("publish")){ String topic = node.get("topic").asText(); RosBridgeSubscriber subscriber = this.listeners.get(topic); if(subscriber != null){ subscriber.receive(node, msg); } } else if(op.equals("fragment")){ this.processFragment(node); } } } catch(IOException e) { System.out.println("Could not parse ROSBridge web socket message into JSON data"); e.printStackTrace(); } }
Example #28
Source File: Peer.java From nextrtc-signaling-server with MIT License | 5 votes |
@OnWebSocketMessage public void onMessage(String msg) { Message message = gson.fromJson(msg, Message.class); if (!"ping".equalsIgnoreCase(message.getSignal())) { log.add(message); } service.submit(() -> { String key = message.getSignal().toLowerCase(); if (actions.containsKey(key)) { actions.get(key).execute(session, message); } }); }
Example #29
Source File: VisWebSocket.java From opensim-gui with Apache License 2.0 | 5 votes |
@OnWebSocketMessage public void visMessage(String stringToParse) { try { //System.out.println("visMessage: " + stringToParse); JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(stringToParse); setChanged(); notifyObservers(jsonObj); } catch (ParseException ex) { Logger.getLogger(VisWebSocket.class.getName()).log(Level.SEVERE, null, ex); } }
Example #30
Source File: WebSocketImpl.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
@OnWebSocketMessage public void onBinary(byte[] bytes, int start, int length) { if (length == 0) { return; } ByteBuffer buffer = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN); long topicId = buffer.getLong(); BinaryMessageListener binaryMessageListener = binaryMessageListeners.get(topicId); if (binaryMessageListener != null) { binaryMessageListener.newData(bytes, start, length); } }