enapps-enorman opened a new pull request, #309:
URL: https://github.com/apache/felix-dev/pull/309

   I was trying to make this work with jetty 11.x before I saw there was 
similar work for the jetty12 branch.   So this is a slightly different approach 
than what was merged for #298 
   
   The changes I'm proposing here will initialize the websocket support in the 
main ServletContextHandler
   
   This was trying to follow the guidance from the jetty documentation at: 
https://eclipse.dev/jetty/documentation/jetty-11/programming-guide/index.html#pg-server-websocket
   
   
   How this changes the http.jetty bundle:
   
   1. No new jetty classes embedded in the http.jetty bundle.  The websocket 
related classes remain optional and would be expected to be supplied by 
deploying the appropriate jetty bundles.
   
   2. The following new entries are now in the Import-Package instruction to 
declare the new optional Import-Package values:
   
       
org.eclipse.jetty.websocket.server.config;version="[11.0,12)";resolution:=optional
       
org.eclipse.jetty.websocket.jakarta.server.config;version="[11.0,12)";resolution:=optional
   
   3. These two new configuration properties are available in the JettyConfig 
that specify whether to enable the two possible websocket implementations
   
       `org.apache.felix.jakarta.websocket.enable`
   
       when set to true, the JakartaWebSocketServletContainerInitializer is 
called to setup the ServerContainer for the web application context. This also 
requires that the org.eclipse.jetty.websocket:websocket-jakarta-server bundle 
is also deployed and active. If that bundle is missing a warning is logged and 
the websocket initialization is skipped.
   
       `org.apache.felix.jetty.websocket.enable`
   when set to true, the JettyWebSocketServletContainerInitializer is called to 
setup the JettyWebSocketServerContainer for this web application context. This 
also requires that the org.eclipse.jetty.websocket:websocket-jetty-server 
bundle is also deployed and active. If that bundle is missing a warning is 
logged and the websocket initialization is skipped.
   
   
   Then one way to declare a custom websocket from a servlet component in a 
bundle would be to override the servlet init method and do something like below:
   
       @Override
       public void init(ServletConfig config) throws ServletException {
           super.init(config);
   
           // The websocket container is attached to the main servlet context, 
not the per-bundle one.
           //  Lookup the ServletContext for the context path where the 
websocket server is attached.
           ServletContext servletContext = config.getServletContext();
           ServletContext rootContext = servletContext.getContext("/");
   
           // Retrieve the JettyWebSocketServerContainer.
           JettyWebSocketServerContainer container = 
JettyWebSocketServerContainer.getContainer(rootContext);
   
           // register the mapping to our custom websocket
           container.addMapping("/mywebsocketpath1", (upgradeRequest, 
upgradeResponse) -> new MyWebSocket1());
       }
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@felix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to