From 408253bc3f8bd3975f0525ce6832be214a3552e9 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 30 Aug 2016 14:23:43 +0300 Subject: [PATCH] Use servlet context classloader when finding servlet class for websockets (#20024) Change-Id: Ia885ecebe854c0aeda47be2bbc9a9d8a47a03d5c --- .../communication/JSR356WebsocketInitializer.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java b/server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java index fc4dc53714..be74c47106 100644 --- a/server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java +++ b/server/src/main/java/com/vaadin/server/communication/JSR356WebsocketInitializer.java @@ -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 -- 2.39.5