Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] WebSockets JSR 356, war files and Embedded Jetty

Hi Joakim,

Thanks for your reply. Sorry, I did not provide enough information, the only item in my lib directory is: WEB-INF/lib/javax.websocket-api-1.1.jar, nothing else. Also I am not using WebSocket annotations, just the programmatic classes listed below, therefore adding annotations may not be appropriate. I appreciate that Embedded Jetty needs heavy configuration, but I am at a loss even after trying to looking into your suggestions. Most of the examples I have seen assume I have access to my endpoint from within OneWebApp (or similar), but I do not since it is in the war file. The configuration for Embedded Jetty with a websocket war has me beat. For interest, code for the simple webapp is below.

I am hoping for an easy answer :)


package jwsp.chapter1;

import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.MessageHandler;
import javax.websocket.Session;

public class ProgrammaticEchoServer extends Endpoint {

    public void onOpen(Session session, EndpointConfig endpointConfig) {
        final Session mySession = session;
        mySession.addMessageHandler(new MessageHandler.Whole<String>() {
            public void onMessage(String text) {
                try {
mySession.getBasicRemote().sendText("I got this (" + text + ") so I am sending it back !");
                } catch (IOException ioe) {
System.out.println("oh dear, something went wrong trying to send the message back: " + ioe.getMessage());


package jwsp.chapter1;

import java.util.HashSet;
import java.util.Set;
import javax.websocket.Endpoint;
import javax.websocket.server.*;

public class ProgrammaticEchoServerAppConfig implements ServerApplicationConfig {

public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> endpointClasses) {
        Set configs = new HashSet<ServerEndpointConfig>();
        ServerEndpointConfig sec = ServerEndpointConfig.Builder
.create(ProgrammaticEchoServer.class, "/programmaticecho")
        return configs;

    public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
        return scanned;

Quoting Joakim Erdfelt <joakim@xxxxxxxxxxx>:

First, Tyrus is for containers that don't have their own WebSocket

Jetty (and Tomcat) both implement JSR356 natively, use those, not Tyrus.

Jetty, unlike Tomcat, is a modular container, everything is optional (even
the Server!).
When you go standalone, the modules are glued together to fit the various
specs most people are comfortable with.
When you go embedded, all of that glue is now on you to piece together to
suit your needs specifically.
What is likely happening, is that you are including Tyrus (don't), and have
not enabled the Annotation scanning.

To enable annotations ...

  org.eclipse.jetty.webapp.Configuration.ClassList classlist =

Try that first.

Otherwise you can look at the embedded-jetty examples below ...

Joakim Erdfelt / joakim@xxxxxxxxxxx

On Sun, Apr 2, 2017 at 6:47 PM, <goffredo@xxxxxxxxxxx> wrote:


I have been trying to load (into Jetty Embedded) the simple Echo example
as presented by Danny Coward in the first chapter of his book Java
WebSocket Programming (Oracle Press). His program is a variant of the
standard echo example presented on the Tyrus site also. I use Eclipse Neon.
I am not using Jetty WebSockets, rather I am using the Java JSR 356
WebSockets implementation. Also, I have no trouble with the embedded Jetty
WebSockets examples, but I am trying to load a war file.

The program Danny presents works fine on current Tomcat, and as a war
file, it also works fine on a standalone current Jetty. My problem is I am
unable to take the exact same WebSockets war file that works OK on
standalone Jetty and load it successfully into the Embedded Jetty. I do not
know where to look, or what to do. Is it a setting problem? Or a Thread
problem? Or ... If someone can point me in the right direction I would be


jetty-users mailing list
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit

Back to the top