Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Example of REST API along with WebSocket endpoint using Undertow, Weld, Jersey and JSR 356.

License

NotificationsYou must be signed in to change notification settings

cassiomolin/jersey-websockets-undertow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusMIT Licensed

Example of application using:

  • Undertow: Servlet container that also provides WebSockets support (JSR 356 implementation).
  • Weld: CDI reference implementation.
  • Jersey: JAX-RS reference implementation for creating RESTful web services in Java.
  • WebSockets: Using the JSR 356 implementation provided by Undertow.

In this example, a message created from the REST API is broadcasted to all WebSocket clients.CDI events are used to send data from the REST API to the WebSocket endpoint.

Building and running this application

Follow these steps to build and run this application:

  1. Open a command line window or terminal.
  2. Navigate to the root directory of the project, where thepom.xml resides.
  3. Compile the project:mvn clean compile.
  4. Package the application:mvn package.
  5. Change into thetarget directory:cd target
  6. You should see a file with the following or a similar name:jersey-websockets-undertow-1.0.jar.
  7. Execute the JAR:java -jar jersey-websockets-undertow-1.0.jar.
  8. A page to test the application will be available athttp://localhost:8080/index.html. The following endpoints will be available:
    1. http://localhost:8080/api/messages: REST endpoint over HTTP to broadcast a message to the WebSocket clients
    2. ws://localhost:8080/push: WebSocket endpoint to get messages pushed by the server

Quick words on Undertow and uber-jars

This application is packed as anuber-jar, making it easy to run, so you don't need to be bothered by installing a servlet container such as Tomcat and then deploy the application on it. Just executejava -jar <jar-file> and the application will be up and running.

This application usesUndertow, a lighweight Servlet container designed to be fully embeddable. It's used as the default web server in theWildFly Application Server.

The uber-jar is created with theApache Maven Shade Plugin, that provides the capability to create an executable jar including its dependencies.

Using the application

Browse tohttp://localhost:8080/index.html, type a message in the text field and clickBroadcast message to send the message to all WebSocket clients. A new WebSocket connection will be created for each tab you open and the message will be broadcasted to them as well.

Alternatively to the test page, you can broadcast a message withcurl:

curl -X POST \'http://localhost:8080/api/messages' \  -H'Content-Type: application/json' \  -d'{  "message": "Hello from curl!"}'

AndPostman also can be used to target the REST API. Refer to thesrc/main/postman directory for the collection files.

About

Example of REST API along with WebSocket endpoint using Undertow, Weld, Jersey and JSR 356.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp