@Override public void onSchema(final Schema schema) { try { session.getBasicRemote().sendText( mapper.writeValueAsString(EntityUtil.buildSourceSchemaEntity(schema)) ); } catch (final IOException e) { log.error("Error sending schema", e); SessionUtil.closeSilently(session, CloseCodes.PROTOCOL_ERROR, "Unable to send schema"); } }
@OnOpen public void onOpenSession(Session session) { String designId = session.getPathParameters().get("designId"); logger.debug("WebSocket opened: {}", session.getId()); logger.debug("\tdesignId: {}", designId); String queryString = session.getQueryString(); Map<String, String> queryParams = parseQueryString(queryString); String uuid = queryParams.get("uuid"); session.getBasicRemote().sendText(builder.toString());
@Override public void send(JsonNode request) { synchronized (this) { if (websocketSession.isOpen()) { try { websocketSession.getBasicRemote().sendText(request.toString()); } catch (Exception e) { // Skip } } else { streamer.onClose(); } } }
@OnOpen public void open(Session session){ log.info("Session created: "+session.getId()); clients.add(session); try { session.getBasicRemote().sendText("welcome "+session.getUserPrincipal()); } catch (IOException e) { log.log(Level.WARNING,"Unable to send welcome message", e); } // TODO check privileges and close connection if invalid } @OnClose
@OnOpen public void open(Session session) { try { session.getBasicRemote().sendObject(new Message("Welcome")); } catch (IOException e) { logger.error(e.toString()); } catch (EncodeException e) { logger.error(e.toString()); } logger.info("Connection opened.login time {}", new Date()); }
/** * A callback when created a new websocket connection. */ @OnOpen public void onOpen(Session session) { logger.info("Connected ... " + session.getId()); try { session.getBasicRemote().sendText("start"); } catch (IOException e) { throw new RuntimeException(e); } }
@OnMessage public void onMessage(final KieServerControllerDescriptorCommand command, final Session session) { LOGGER.debug("Message received on session: {}", session.getId()); final KieServerControllerServiceResponse response = commandService.executeCommand(command); try { session.getBasicRemote().sendObject(response); } catch (IOException | EncodeException ex) { LOGGER.error("Error trying to send Web Socket response: {}", ex.getMessage(), ex); throw new RuntimeException(ex); } }
@Override public void onOpen(Session session, EndpointConfig config) { try { session.addMessageHandler(new MessageHandler.Whole<String>() { session.getBasicRemote().sendText(""); } catch (IOException e) {
@Test public void testOnSchema() throws Exception { replayOnSubscribe(); session.getBasicRemote(); EasyMock.expectLastCall().andReturn(basic).once(); final Capture<String> schema = EasyMock.newCapture(); basic.sendText(EasyMock.capture(schema)); EasyMock.expectLastCall().andThrow(new IOException("bad bad io")).once(); final Capture<CloseReason> reason = EasyMock.newCapture(); session.close(EasyMock.capture(reason)); subscription.cancel(); EasyMock.replay(subscription, session, basic); subscriber.onSchema(SchemaBuilder .struct() .field("currency", Schema.STRING_SCHEMA) .field("amount", Schema.OPTIONAL_FLOAT32_SCHEMA) .build()); subscriber.close(); assertEquals( "[" + "{\"name\":\"currency\"," + "\"schema\":{\"type\":\"STRING\",\"fields\":null,\"memberSchema\":null}}," + "{\"name\":\"amount\"," + "\"schema\":{\"type\":\"DOUBLE\",\"fields\":null,\"memberSchema\":null}}]" , schema.getValue()); assertEquals("Unable to send schema", reason.getValue().getReasonPhrase()); assertEquals(CloseCodes.PROTOCOL_ERROR, reason.getValue().getCloseCode()); EasyMock.verify(subscription, session, basic); }
@OnOpen public void open(Session session, EndpointConfig conf, @PathParam("cid") String cid) { // HandshakeRequest req = (HandshakeRequest) conf.getUserProperties() // .get("handshakereq"); try { session.setMaxIdleTimeout(timeout); session.getBasicRemote().sendObject(new Message("Welcome")); } catch (IOException e) { logger.error(e.toString()); } catch (EncodeException e) { logger.error(e.toString()); } /* Register this connection in the queue */ users.put(cid, session); logger.info("Connection opened.login user id {},login time {}", cid, new Date()); }
remote.sendText(instruction);
@Test public void testServerTemplateUpdated() throws Exception { final ServerTemplateUpdated event = new ServerTemplateUpdated(new ServerTemplate()); notificationService.notify(event); verify(endpoint, timeout(TIMEOUT)).sendObject(new KieServerControllerNotification(event)); }
public void execute(Object command) throws BuildAgentClientException { log.info("Executing remote command [{}]...", command); javax.websocket.RemoteEndpoint.Basic remoteEndpoint = commandExecutingEndpoint.getRemoteEndpoint(); ByteBuffer byteBuffer = prepareRemoteCommand(command); try { log.debug("Sending remote command..."); remoteEndpoint.sendBinary(byteBuffer); log.debug("Command sent."); } catch (IOException e) { log.error("Cannot execute remote command.", e); } }
public static void executeRemoteCommand(Client client, String command) { log.info("Executing remote command ..."); RemoteEndpoint.Basic remoteEndpoint = client.getRemoteEndpoint(); String data = "{\"action\":\"read\",\"data\":\"" + command + "\\r\\n\"}"; try { remoteEndpoint.sendBinary(ByteBuffer.wrap(data.getBytes())); } catch (IOException e) { e.printStackTrace(); } } }
@Test public void testServerInstanceConnected() throws Exception { final ServerInstanceConnected event = new ServerInstanceConnected(new ServerInstance()); notificationService.notify(event); verify(endpoint, timeout(TIMEOUT)).sendObject(new KieServerControllerNotification(event)); }
@Test public void testServerInstanceUpdated() throws Exception { final ServerInstanceUpdated event = new ServerInstanceUpdated(new ServerInstance()); notificationService.notify(event); verify(endpoint, timeout(TIMEOUT)).sendObject(new KieServerControllerNotification(event)); }
public static void executeRemoteCommand(Client client, String command) { log.info("Executing remote command ..."); RemoteEndpoint.Basic remoteEndpoint = client.getRemoteEndpoint(); String data = "{\"action\":\"read\",\"data\":\"" + command + "\\r\\n\"}"; try { remoteEndpoint.sendBinary(ByteBuffer.wrap(data.getBytes())); } catch (IOException e) { e.printStackTrace(); } } }
public static void executeRemoteCommand(Client client, String command) { log.info("Executing remote command ..."); RemoteEndpoint.Basic remoteEndpoint = client.getRemoteEndpoint(); String data = "{\"action\":\"read\",\"data\":\"" + command + "\\r\\n\"}"; try { remoteEndpoint.sendBinary(ByteBuffer.wrap(data.getBytes())); } catch (IOException e) { e.printStackTrace(); } } }
@Test public void testServerInstanceDisconnected() throws Exception { final ServerInstanceDisconnected event = new ServerInstanceDisconnected("serverId"); notificationService.notify(event); verify(endpoint, timeout(TIMEOUT)).sendObject(new KieServerControllerNotification(event)); }
@Test public void testServerInstanceDeleted() throws Exception { final ServerInstanceDeleted event = new ServerInstanceDeleted("serverId"); notificationService.notify(event); verify(endpoint, timeout(TIMEOUT)).sendObject(new KieServerControllerNotification(event)); }