Java Code Examples for javax.websocket.RemoteEndpoint#Basic

The following examples show how to use javax.websocket.RemoteEndpoint#Basic . 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: PojoMessageHandlerBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
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 2
Source File: Client.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
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 3
Source File: WebSocketTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: WebSocketTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: Client.java    From termd with Apache License 2.0 5 votes vote down vote up
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 6
Source File: UndertowSession.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: EchoEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
    RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
    session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic));
    session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic));
}
 
Example 8
Source File: EchoEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
    RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
    session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic));
    session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic));
}
 
Example 9
Source File: EchoEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic) {
    this.remoteEndpointBasic = remoteEndpointBasic;
}
 
Example 10
Source File: MockSession.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public RemoteEndpoint.Basic getBasicRemote() {
	return basicRemote;
}
 
Example 11
Source File: WsSession.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public RemoteEndpoint.Basic getBasicRemote() {
    checkState();
    return remoteEndpointBasic;
}
 
Example 12
Source File: Client.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
public RemoteEndpoint.Basic getRemoteEndpoint() {
    return endpoint.session.getBasicRemote();
}
 
Example 13
Source File: EchoEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic) {
    this.remoteEndpointBasic = remoteEndpointBasic;
}
 
Example 14
Source File: BinaryOutputStream.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public BinaryOutputStream(RemoteEndpoint.Basic basic) {
    this.basic = basic;
}
 
Example 15
Source File: EchoEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
    RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
    session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic));
    session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic));
}
 
Example 16
Source File: EchoEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic) {
    this.remoteEndpointBasic = remoteEndpointBasic;
}
 
Example 17
Source File: EchoEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
    RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
    session.addMessageHandler(new EchoMessageHandlerText(remoteEndpointBasic));
    session.addMessageHandler(new EchoMessageHandlerBinary(remoteEndpointBasic));
}
 
Example 18
Source File: WsSession.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public RemoteEndpoint.Basic getBasicRemote() {
    checkState();
    return remoteEndpointBasic;
}
 
Example 19
Source File: EchoEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private EchoMessageHandlerBinary(RemoteEndpoint.Basic remoteEndpointBasic) {
    this.remoteEndpointBasic = remoteEndpointBasic;
}
 
Example 20
Source File: EchoEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private EchoMessageHandlerText(RemoteEndpoint.Basic remoteEndpointBasic) {
    this.remoteEndpointBasic = remoteEndpointBasic;
}