Skip to content
Branch: master
Find file History
skitt Remove redundant type specifiers
Signed-off-by: Stephen Kitt <skitt@redhat.com>
Latest commit 5b7e8cf May 14, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src/main/java/org/apache/karaf/examples/websocket Remove redundant type specifiers May 14, 2019
README.md Use LATEST for version in the examples README.md Dec 15, 2018
pom.xml Updating plexus May 1, 2019

README.md

Apache Karaf Websocket example

Abstract

This example show how to register a websocket in the Karaf HTTP Service.

Artifacts

  • karaf-websocket-example is the main bundle using @WebSocket annotation.

Build

The build uses Apache Maven. Simply use:

mvn clean install

Deployment

On a running Karaf instance, first, you have to install the http, jetty and scr features:

karaf@root()> feature:install http
karaf@root()> feature:inistal jetty
karaf@root()> feature:install scr

Then, you can install the websocket example bundle:

karaf@root()> bundle:install -s mvn:org.apache.karaf.examples/karaf-websocket-example/LATEST

You can see the websocket registered in the HTTP service:

karaf@root()> http:list
ID │ Servlet                 │ Servlet-Name   │ State       │ Alias              │ Url
───┼─────────────────────────┼────────────────┼─────────────┼────────────────────┼───────────────────────
92 │ WebsocketExampleServlet │ ServletModel-2 │ Deployed    │ /example-websocket │ [/example-websocket/*]

Usage

The websocket is available on http://localhost:8181/example-websocket.

You can now register your client (like curl) on this URL:

curl --include \
     --no-buffer \
     --header "Connection: Upgrade" \
     --header "Upgrade: websocket" \
     --header "Host: localhost:8181" \
     --header "Origin: http://localhost:8181/example-websocket" \
     --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
     --header "Sec-WebSocket-Version: 13" \
     http://localhost:8181/example-websocket

Your client will have a Hello World message on your client every second.

You can’t perform that action at this time.