Search in sources :

Example 11 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project jetty.project by eclipse.

the class RFCSocket method onText.

@OnWebSocketMessage
public void onText(String message) throws IOException {
    LOG.debug("onText({})", message);
    // trigger a WebSocket server terminated close.
    if (message.equals("CRASH")) {
        throw new RuntimeException("Something bad happened");
    }
    // echo the message back.
    RemoteEndpoint remote = session.getRemote();
    remote.sendString(message, null);
    if (remote.getBatchMode() == BatchMode.ON)
        remote.flush();
}
Also used : RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 12 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project jetty.project by eclipse.

the class ABSocket method onBinary.

@OnWebSocketMessage
public void onBinary(byte[] buf, int offset, int len) {
    LOG.debug("onBinary(byte[{}],{},{})", buf.length, offset, len);
    // echo the message back.
    ByteBuffer data = ByteBuffer.wrap(buf, offset, len);
    this.session.getRemote().sendBytes(data, null);
}
Also used : ByteBuffer(java.nio.ByteBuffer) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 13 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project jetty.project by eclipse.

the class InfoSocket method onMessage.

@OnWebSocketMessage
public void onMessage(String msg) {
    RemoteEndpoint remote = this.session.getRemote();
    remote.sendStringByFuture("session.maxTextMessageSize=" + session.getPolicy().getMaxTextMessageSize());
}
Also used : RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 14 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project Openfire by igniterealtime.

the class XmppWebSocket method onTextMethod.

@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);
        }
    }
}
Also used : XMPPPacketReader(org.dom4j.io.XMPPPacketReader) StringReader(java.io.StringReader) Document(org.dom4j.Document) IOException(java.io.IOException) UnknownStanzaException(org.jivesoftware.openfire.multiplex.UnknownStanzaException) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 15 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project pulsar by yahoo.

the class SimpleConsumerSocket method onMessage.

@OnWebSocketMessage
public synchronized void onMessage(String msg) throws JsonParseException, IOException {
    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());
    receivedMessages.incrementAndGet();
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Aggregations

OnWebSocketMessage (org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)16 RemoteEndpoint (org.eclipse.jetty.websocket.api.RemoteEndpoint)9 ByteBuffer (java.nio.ByteBuffer)4 Gson (com.google.gson.Gson)3 JsonObject (com.google.gson.JsonObject)3 IOException (java.io.IOException)2 WebSocketMessage (org.springframework.web.reactive.socket.WebSocketMessage)2 JsonPrimitive (com.google.gson.JsonPrimitive)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 List (java.util.List)1 Document (org.dom4j.Document)1 XMPPPacketReader (org.dom4j.io.XMPPPacketReader)1 UnknownStanzaException (org.jivesoftware.openfire.multiplex.UnknownStanzaException)1