javax.websocket.RemoteEndpoint Java Examples
The following examples show how to use
javax.websocket.RemoteEndpoint.
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: ClassLoaderEndpointTest.java From websocket-classloader with Apache License 2.0 | 6 votes |
@SuppressWarnings("ResultOfMethodCallIgnored") @Before public void setup() throws Exception{ //setup mocks cle = new ClassLoaderEndpoint(); session = mock(Session.class); RemoteEndpoint remoteEndpoint = mock(RemoteEndpoint.Async.class); doReturn(remoteEndpoint).when(session).getAsyncRemote(); ((RemoteEndpoint.Async) doReturn(null).when(remoteEndpoint)).sendBinary(any(ByteBuffer.class)); resourceRequest = mock(ResourceRequest.class); doReturn(UUID.randomUUID()).when(resourceRequest).getClassLoaderId(); doReturn("resource1").when(resourceRequest).getResourceName(); FressianWriter fressianWriter = mock(FressianWriter.class); doReturn(mock(Writer.class)).when(fressianWriter).writeObject(any(ResourceRequest.class)); PowerMockito.whenNew(FressianWriter.class).withAnyArguments().thenReturn(fressianWriter); }
Example #2
Source File: PojoMessageHandlerBase.java From tomcatsrc with Apache License 2.0 | 6 votes |
protected final void processResult(Object result) { if (result == null) { return; } RemoteEndpoint.Basic remoteEndpoint = session.getBasicRemote(); try { if (result instanceof String) { remoteEndpoint.sendText((String) result); } else if (result instanceof ByteBuffer) { remoteEndpoint.sendBinary((ByteBuffer) result); } else if (result instanceof byte[]) { remoteEndpoint.sendBinary(ByteBuffer.wrap((byte[]) result)); } else { remoteEndpoint.sendObject(result); } } catch (IOException ioe) { throw new IllegalStateException(ioe); } catch (EncodeException ee) { throw new IllegalStateException(ee); } }
Example #3
Source File: PojoMessageHandlerBase.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
protected final void processResult(Object result) { if (result == null) { return; } RemoteEndpoint.Basic remoteEndpoint = session.getBasicRemote(); try { if (result instanceof String) { remoteEndpoint.sendText((String) result); } else if (result instanceof ByteBuffer) { remoteEndpoint.sendBinary((ByteBuffer) result); } else if (result instanceof byte[]) { remoteEndpoint.sendBinary(ByteBuffer.wrap((byte[]) result)); } else { remoteEndpoint.sendObject(result); } } catch (IOException ioe) { throw new IllegalStateException(ioe); } catch (EncodeException ee) { throw new IllegalStateException(ee); } }
Example #4
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 #5
Source File: PojoMessageHandlerBase.java From Tomcat8-Source-Read with MIT License | 6 votes |
protected final void processResult(Object result) { if (result == null) { return; } RemoteEndpoint.Basic remoteEndpoint = session.getBasicRemote(); try { if (result instanceof String) { remoteEndpoint.sendText((String) result); } else if (result instanceof ByteBuffer) { remoteEndpoint.sendBinary((ByteBuffer) result); } else if (result instanceof byte[]) { remoteEndpoint.sendBinary(ByteBuffer.wrap((byte[]) result)); } else { remoteEndpoint.sendObject(result); } } catch (IOException | EncodeException ioe) { throw new IllegalStateException(ioe); } }
Example #6
Source File: Client.java From aesh-readline with Apache License 2.0 | 5 votes |
public static void executeRemoteCommand(Client client, String command) { LOGGER.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(); } }
Example #7
Source File: WebSocketTest.java From data-highway with Apache License 2.0 | 5 votes |
@Test public void send() throws Exception { underTest.connect(); RemoteEndpoint.Basic basicRemote = mock(RemoteEndpoint.Basic.class); doReturn(basicRemote).when(session).getBasicRemote(); underTest.send(new Cancel()); verify(basicRemote).sendBinary(ByteBuffer.wrap("{\"type\":\"CANCEL\"}".getBytes())); }
Example #8
Source File: WebSocketTest.java From data-highway with Apache License 2.0 | 5 votes |
@Test(expected = UncheckedIOException.class) public void sendException() throws Exception { underTest.connect(); RemoteEndpoint.Basic basicRemote = mock(RemoteEndpoint.Basic.class); doReturn(basicRemote).when(session).getBasicRemote(); doThrow(IOException.class).when(basicRemote).sendBinary(any(ByteBuffer.class)); underTest.send(new Cancel()); }
Example #9
Source File: WebSocketTest.java From data-highway with Apache License 2.0 | 5 votes |
@Test public void keepAlives() throws Exception { underTest.connect(); RemoteEndpoint.Basic basicRemote = mock(RemoteEndpoint.Basic.class); doReturn(basicRemote).when(session).getBasicRemote(); doReturn(true).when(session).isOpen(); Awaitility.await().atMost(2, SECONDS).pollInterval(200, MILLISECONDS).until(() -> { try { verify(basicRemote).sendPong(any()); } catch (Exception e) { fail(); } }); }
Example #10
Source File: WsUpdatesClient.java From pnc with Apache License 2.0 | 5 votes |
public void subscribeBlocking(String topic, String filter, Consumer<String> onMessage) throws IOException, DeploymentException { ProgressUpdatesRequest progressUpdatesRequest = ProgressUpdatesRequest.subscribe(topic, filter); UpdatesMessageHandler updatesMessageHandler = new UpdatesMessageHandler(onMessage); WebSocketContainer container = ContainerProvider.getWebSocketContainer(); String uri = "ws://localhost:8080/pnc-rest-new/" + NotificationsEndpoint.ENDPOINT_PATH; Session session = container.connectToServer(updatesMessageHandler, URI.create(uri)); RemoteEndpoint.Basic asyncRemote = session.getBasicRemote(); asyncRemote.sendText(toJson(progressUpdatesRequest)); }
Example #11
Source File: UndertowSession.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public RemoteEndpoint.Basic getBasicRemote() { if (channel.eventLoop().inEventLoop()) { throw new IllegalStateException("Cannot use the basic remote from an IO thread"); } return remote.getBasic(); }
Example #12
Source File: Client.java From termd with Apache License 2.0 | 5 votes |
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(); } }
Example #13
Source File: Client.java From termd with Apache License 2.0 | 5 votes |
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(); } }
Example #14
Source File: Util.java From PeonyFramwork with Apache License 2.0 | 5 votes |
public static String getIp(javax.websocket.Session session){ RemoteEndpoint.Async async = session.getAsyncRemote(); InetSocketAddress addr = (InetSocketAddress) getFieldInstance(async, "base#sos#socketWrapper#socket#sc#remoteAddress"); if(addr == null){ return "127.0.0.1"; } return addr.getAddress().getHostAddress(); }
Example #15
Source File: EchoEndpoint.java From tomcatsrc with Apache License 2.0 | 4 votes |
private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic) { this.remoteEndpointBasic = remoteEndpointBasic; }
Example #16
Source File: WsSession.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public RemoteEndpoint.Async getAsyncRemote() { checkState(); return remoteEndpointAsync; }
Example #17
Source File: WsSession.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public RemoteEndpoint.Basic getBasicRemote() { checkState(); return remoteEndpointBasic; }
Example #18
Source File: MCRWebCLIResourceSockets.java From mycore with GNU General Public License v3.0 | 4 votes |
@Override public RemoteEndpoint.Async getAsyncRemote() { return delegate.getAsyncRemote(); }
Example #19
Source File: EchoEndpoint.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void onOpen(Session session, EndpointConfig endpointConfig) { RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote(); session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic)); session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic)); }
Example #20
Source File: EchoEndpoint.java From tomcatsrc with Apache License 2.0 | 4 votes |
private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic) { this.remoteEndpointBasic = remoteEndpointBasic; }
Example #21
Source File: BinaryFrameOutputStream.java From websocket-classloader with Apache License 2.0 | 4 votes |
public BinaryFrameOutputStream(RemoteEndpoint.Async remote) { this.buffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE); this.remote = remote; }
Example #22
Source File: EchoEndpoint.java From tomcatsrc with Apache License 2.0 | 4 votes |
private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic) { this.remoteEndpointBasic = remoteEndpointBasic; }
Example #23
Source File: EchoEndpoint.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void onOpen(Session session, EndpointConfig endpointConfig) { RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote(); session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic)); session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic)); }
Example #24
Source File: EchoEndpoint.java From tomcatsrc with Apache License 2.0 | 4 votes |
private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic) { this.remoteEndpointBasic = remoteEndpointBasic; }
Example #25
Source File: MockSession.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
@Override public RemoteEndpoint.Async getAsyncRemote() { return asyncRemote; }
Example #26
Source File: MockSession.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
@Override public RemoteEndpoint.Basic getBasicRemote() { return basicRemote; }
Example #27
Source File: Client.java From aesh-readline with Apache License 2.0 | 4 votes |
public RemoteEndpoint.Basic getRemoteEndpoint() { return endpoint.session.getBasicRemote(); }
Example #28
Source File: Client.java From termd with Apache License 2.0 | 4 votes |
public RemoteEndpoint.Basic getRemoteEndpoint() { return endpoint.session.getBasicRemote(); }
Example #29
Source File: UndertowSession.java From quarkus-http with Apache License 2.0 | 4 votes |
@Override public RemoteEndpoint.Async getAsyncRemote() { return remote.getAsync(); }
Example #30
Source File: EchoEndpoint.java From Tomcat8-Source-Read with MIT License | 4 votes |
private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic) { this.remoteEndpointBasic = remoteEndpointBasic; }