turcsanyip commented on a change in pull request #4918:
URL: https://github.com/apache/nifi/pull/4918#discussion_r600926356



##########
File path: 
nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/main/java/org/apache/nifi/websocket/jetty/JettyWebSocketServer.java
##########
@@ -213,6 +214,14 @@ public void configure(WebSocketServletFactory 
webSocketServletFactory) {
             webSocketServletFactory.setCreator(this);
         }
 
+        @Override
+        public void init() throws ServletException {
+            // Set Component ClassLoader as Thread Context ClassLoader so that 
jetty-server classes are available to WebSocketServletFactory.Loader
+            final ClassLoader componentClassLoader = 
getClass().getClassLoader();
+            Thread.currentThread().setContextClassLoader(componentClassLoader);
+            super.init();
+        }

Review comment:
       The class loader for the servlet worker threads can be set on 
`ServletContextHandler` when you build up the Jetty server / servlets.
   ```
   final ServletContextHandler contextHandler = new ServletContextHandler();
   
contextHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
   ```
   (I used the instance class loader here because it was originally in 1.12 but 
the component class loader can also be used).
   
   I'm not sure which one is the right way to set the class loader but using 
the `ServletContextHandler` API seems to me less "hack".




-- 
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.

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


Reply via email to