]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use servlet context classloader when finding servlet class for websockets (#20024)
authorArtur Signell <artur@vaadin.com>
Tue, 30 Aug 2016 11:23:43 +0000 (14:23 +0300)
committerArtur Signell <artur@vaadin.com>
Tue, 30 Aug 2016 15:47:29 +0000 (18:47 +0300)
Change-Id: Ia885ecebe854c0aeda47be2bbc9a9d8a47a03d5c

server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java

index fc4dc53714f5abe070989ec0a342916a56ce1234..be74c47106e01fb085a6cb927f60340a021bba1b 100644 (file)
@@ -113,7 +113,7 @@ public class JSR356WebsocketInitializer implements ServletContextListener {
         for (String servletName : regs.keySet()) {
             ServletRegistration servletRegistration = regs.get(servletName);
 
-            if (isVaadinServlet(servletRegistration)) {
+            if (isVaadinServlet(servletRegistration, servletContext)) {
                 try {
                     initAtmosphereForVaadinServlet(servletRegistration,
                             servletContext);
@@ -193,7 +193,8 @@ public class JSR356WebsocketInitializer implements ServletContextListener {
      * @return false if the servlet is definitely not a Vaadin servlet, true
      *         otherwise
      */
-    protected boolean isVaadinServlet(ServletRegistration servletRegistration) {
+    protected boolean isVaadinServlet(ServletRegistration servletRegistration,
+            ServletContext servletContext) {
         try {
             String servletClassName = servletRegistration.getClassName();
             if (servletClassName.equals("com.ibm.ws.wsoc.WsocServlet")) {
@@ -201,7 +202,10 @@ public class JSR356WebsocketInitializer implements ServletContextListener {
                 // dynamically added
                 return false;
             }
-            Class<?> servletClass = Class.forName(servletClassName);
+            // Must use servletContext class loader to load servlet class to
+            // work correctly in an OSGi environment (#20024)
+            Class<?> servletClass = servletContext.getClassLoader()
+                    .loadClass(servletClassName);
             return VaadinServlet.class.isAssignableFrom(servletClass);
         } catch (Exception e) {
             // This will fail in OSGi environments, assume everything is a