Combine Jersey with Tyr

I have a JAX-RS Jersey application that runs on a Grizzly instance:

public class Application { public static final String BASE_URI = "http://127.0.0.1:8080/rest"; public static void main(String[] args) throws IOException { ResourceConfig rc = new ResourceConfig().packages("my.package.rest"); HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); System.out.println("Server started, press any key to stop."); System.in.read(); server.shutdownNow(); } } 

inside my.package.rest there are annotated JAX-RS resources. I would like to add websocket annotated ( @ServerEndpoint , @OnOpen , @OnMessage , etc.) Resources using Tyrus on a single server instance (for example, at http://127.0.0.1:8080/websocket "), but all the documentation which I could find shows how to start a standalone websocket server using a Tyrus + Grizzly container not related to Jersey. I am looking for something like:

 server.getServerConfiguration().addHttpHandler(new SomeTyrusHttpHandler("/websocket")); 

but I can not find anything like SomeTyrusHttpHandler . How can I combine Jersey and Tyrus on the same Grizzly server?

+5
source share
1 answer

Good question, but there is currently no good answer for this. You can still do it, but it will require a deep dive into the inside of the grizzly; Tyrus is registered as an addon (see WebSocketAddOn ), and it can be combined with Jersey by registering in this container.

Please keep in mind that integrating these two frameworks together is not a trivial task - launching them in one container is the first step, but there are other things that you need to take care of, for example, the "instance provider", setting up the life cycle, etc. d. I believe this topic is beyond the scope of one SO answer - you can expect from me or some other Tyrus / Jersey team member from the blog. (I will post it here as soon as this is done).

In any case, I would recommend taking a more conservative approach and using a small container that supports Servlet 3.1; this should require a lot less work on your side and you will have a standard runtime / servlet life cycle.

+1
source

All Articles