io.undertow.websockets.core.BufferedTextMessage Java Examples

The following examples show how to use io.undertow.websockets.core.BufferedTextMessage. 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: WebSocketMessageListener.java    From core-ng-project with Apache License 2.0 6 votes vote down vote up
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage textMessage) {
    var wrapper = (ChannelImpl) channel.getAttribute(WebSocketHandler.CHANNEL_KEY);
    ActionLog actionLog = logManager.begin("=== ws message handling begin ===");
    try {
        actionLog.action(wrapper.action);
        linkContext(channel, wrapper, actionLog);

        String data = textMessage.getData();
        logger.debug("[channel] message={}", data);     // not mask, assume ws message not containing sensitive info, the data can be json or plain text
        actionLog.track("ws", 0, 1, 0);

        validateRate(wrapper);

        Object message = wrapper.handler.fromClientMessage(data);
        wrapper.handler.listener.onMessage(wrapper, message);
    } catch (Throwable e) {
        logManager.logError(e);
        WebSockets.sendClose(closeCode(e), e.getMessage(), channel, ChannelCallback.INSTANCE);
    } finally {
        logManager.end("=== ws message handling end ===");
    }
}
 
Example #2
Source File: WebSocketUndertowServletRequest.java    From cxf with Apache License 2.0 6 votes vote down vote up
public WebSocketUndertowServletRequest(WebSocketChannel channel, Object message, HttpServerExchange exchange)
    throws IOException {
    this.channel = channel;
    if (message instanceof BufferedBinaryMessage) {
        in = new ByteBufferInputStream(((BufferedBinaryMessage)message).getData().getResource()[0]);
    } else if (message instanceof BufferedTextMessage) {
        in = new ByteArrayInputStream(((BufferedTextMessage)message).getData().getBytes());
    }
    this.requestHeaders = WebSocketUtils.readHeaders(in);
    /*String path = requestHeaders.get(WebSocketUtils.URI_KEY);
    String origin = channel.getUrl();
    path = path.substring(0,  path.length() - 10);
    if (!path.startsWith(origin)) {
        throw new InvalidPathException();
    }*/
    this.attributes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    Object v = channel.getAttribute("org.apache.cxf.transport.endpoint.address");
    if (v != null) {
        attributes.put("org.apache.cxf.transport.endpoint.address", v);
    }
}
 
Example #3
Source File: SocketServer.java    From tutorials with MIT License 5 votes vote down vote up
private static AbstractReceiveListener getListener() {
    return new AbstractReceiveListener() {
        @Override
        protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) {
            final String messageData = message.getData();
            for (WebSocketChannel session : channel.getPeerConnections()) {
                WebSockets.sendText(messageData, session, null);
            }
        }
    };
}
 
Example #4
Source File: UndertowWebSocketHandlerAdapter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) {
	this.session.handleMessage(Type.TEXT, toMessage(Type.TEXT, message.getData()));
}
 
Example #5
Source File: UndertowWebSocketHandlerAdapter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) {
	this.session.handleMessage(Type.TEXT, toMessage(Type.TEXT, message.getData()));
}
 
Example #6
Source File: MangooWebSocket.java    From mangooio with Apache License 2.0 4 votes vote down vote up
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) {}
 
Example #7
Source File: WebSocketController.java    From mangooio with Apache License 2.0 4 votes vote down vote up
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) {
    LOG.info(message.toString());
}
 
Example #8
Source File: UndertowWebSocketAdapter.java    From pippo with Apache License 2.0 4 votes vote down vote up
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) throws IOException {
    handler.onMessage(context, message.getData());
}