forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 2d55d09)
- Loading branch information
Showing
13 changed files
with
246 additions
and
248 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
.../src/main/resources/codestarts/quarkus/examples/undertow-websockets-example/codestart.yml
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
...bsockets-example/java/src/main/java/org/acme/undertowwebsockets/SupersonicChatSocket.java
This file was deleted.
Oops, something went wrong.
115 changes: 0 additions & 115 deletions
115
...dertow-websockets-example/java/src/main/resources/META-INF/resources/supersonic-chat.html
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
...kets-example/java/src/test/java/org/acme/undertowwebsockets/SupersonicChatSocketTest.java
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
...main/resources/codestarts/quarkus/extension-codestarts/websockets-codestart/codestart.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: websockets-codestart | ||
ref: websockets | ||
type: code | ||
tags: extension-codestart | ||
metadata: | ||
title: WebSockets | ||
description: WebSocket communication channel starter code | ||
related-guide-section: https://quarkus.io/guides/websockets | ||
language: | ||
base: | ||
dependencies: | ||
- io.quarkus:quarkus-websockets |
55 changes: 55 additions & 0 deletions
55
...extension-codestarts/websockets-codestart/java/src/main/java/org/acme/StartWebSocket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ilove.quark.us; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.websocket.EncodeException; | ||
import javax.websocket.OnClose; | ||
import javax.websocket.OnError; | ||
import javax.websocket.OnMessage; | ||
import javax.websocket.OnOpen; | ||
import javax.websocket.Session; | ||
import javax.websocket.server.PathParam; | ||
import javax.websocket.server.ServerEndpoint; | ||
import java.io.IOException; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
@ServerEndpoint("/start-websocket/{name}") | ||
@ApplicationScoped | ||
public class StartWebSocket { | ||
|
||
@OnOpen | ||
public void onOpen(Session session, @PathParam("name") String name) { | ||
System.out.println("onOpen> " + name); | ||
} | ||
|
||
@OnClose | ||
public void onClose(Session session, @PathParam("name") String name) { | ||
System.out.println("onClose> " + name); | ||
} | ||
|
||
@OnError | ||
public void onError(Session session, @PathParam("name") String name, Throwable throwable) { | ||
System.out.println("onError> " + name + ": " + throwable); | ||
} | ||
|
||
@OnMessage | ||
public void onMessage(String message, @PathParam("username") String name) { | ||
System.out.println("onMessage> " + name + ": " + message); | ||
} | ||
|
||
/** | ||
* Send a message to a remote websocket session | ||
* | ||
* @param session the websocket session | ||
* @param message the message to send | ||
* @throws IOException if there is a communication error sending the message object. | ||
* @throws EncodeException if there was a problem encoding the message. | ||
* @throws IllegalArgumentException if the message parameter is {@code null} | ||
*/ | ||
public void sendMessage(Session session, String message) throws EncodeException, IOException { | ||
requireNonNull(session, "session is required"); | ||
|
||
session.getBasicRemote().sendObject(message); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...tension-codestarts/websockets-codestart/kotlin/src/main/kotlin/org/acme/StartWebSocket.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ilove.quark.us | ||
|
||
import java.io.IOException | ||
import javax.enterprise.context.ApplicationScoped | ||
import javax.websocket.* | ||
import javax.websocket.server.PathParam | ||
import javax.websocket.server.ServerEndpoint | ||
|
||
@ServerEndpoint("/start-websocket/{name}") | ||
@ApplicationScoped | ||
class StartWebSocket { | ||
|
||
@OnOpen | ||
fun onOpen(session: Session?, @PathParam("name") name: String) { | ||
println("onOpen> $name") | ||
} | ||
|
||
@OnClose | ||
fun onClose(session: Session?, @PathParam("name") name: String) { | ||
println("onClose> $name") | ||
} | ||
|
||
@OnError | ||
fun onError(session: Session?, @PathParam("name") name: String, throwable: Throwable) { | ||
println("onError> $name: $throwable") | ||
} | ||
|
||
@OnMessage | ||
fun onMessage(message: String, @PathParam("username") name: String) { | ||
println("onMessage> $name: $message") | ||
} | ||
|
||
/** | ||
* Send a message to a remote websocket session | ||
* | ||
* @param session the websocket session | ||
* @param message the message to send | ||
* @throws IOException if there is a communication error sending the message object. | ||
* @throws EncodeException if there was a problem encoding the message. | ||
*/ | ||
@Throws(EncodeException::class, IOException::class) | ||
fun sendMessage(session: Session, message: String) { | ||
session.basicRemote.sendObject(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.