Here ya go ...

http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/examples/embedded/src/main/java/org/eclipse/jetty/embedded/WebSocketJsrServer.java?h=jetty-9.1

Note, you will need to use Jetty 9.1 (which is currently under development
in the jetty-9.1 branch)
Expect milestone or RC releases before the week is out.

package example;

import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
import org.eclipse.jetty.websocket.jsr356.server.WebSocketConfiguration;

/**
 * Example of setting up a javax.websocket server with Jetty embedded
 */
public class WebSocketJsrServer
{
    /**
     * A server socket endpoint
     */
    @ServerEndpoint(value = "/echo")
    public static class EchoJsrSocket
    {
        @OnMessage
        public void onMessage(Session session, String message)
        {
            session.getAsyncRemote().sendText(message);
        }
    }

    public static void main(String[] args) throws Exception
    {
        Server server = new Server(8080);

        ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        server.setHandler(context);

        // Add a servlet to your context.
        // It is required that you provide at least 1 servlet.
        // Recommended that this servlet merely provide a
        // "This is a websocket only server" style response to GET requests
        context.addServlet(new ServletHolder(new DumpServlet()),"/*");

        // Enable javax.websocket configuration for the context
        ServerContainer wsContainer =
WebSocketConfiguration.configureContext(context);

        // Add your websockets to the container
        wsContainer.addEndpoint(EchoJsrSocket.class);

        server.start();
        context.dumpStdErr(); // show the context details
        server.join();
    }
}


--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/> - intalio.com/jetty
Expert advice, services and support from from the Jetty & CometD experts
eclipse.org/jetty - cometd.org


On Wed, Sep 11, 2013 at 4:21 AM, Kasper Nielsen <[email protected]> wrote:

> Hi,
>
> I'm looking for some simple sample code that sets up a simple server and
> deploys a Jsr 356 annotated endpoint.
>
> On the client side I would do something like this:
>
> WebSocketContainer container = ContainerProvider.*getWebSocketContainer*
> ();
>
>         Jsr356AnnotatedClient c = *new* Jsr356AnnotatedClient();
>
>         Session session = container.connectToServer(c, *new* URI(
> "ws://localhost:1234"));
>
>         session.getBasicRemote().sendText("Echo");
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to