|
|
|
@ -35,7 +35,6 @@ import org.springframework.beans.factory.config.BeanPostProcessor; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.context.ApplicationContextAware; |
|
|
|
import org.springframework.context.ApplicationContextAware; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.ClassUtils; |
|
|
|
|
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -58,9 +57,6 @@ import org.springframework.util.ReflectionUtils; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ServerEndpointExporter implements InitializingBean, BeanPostProcessor, ApplicationContextAware { |
|
|
|
public class ServerEndpointExporter implements InitializingBean, BeanPostProcessor, ApplicationContextAware { |
|
|
|
|
|
|
|
|
|
|
|
private static final boolean isServletApiPresent = |
|
|
|
|
|
|
|
ClassUtils.isPresent("javax.servlet.ServletContext", ServerEndpointExporter.class.getClassLoader()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Log logger = LogFactory.getLog(ServerEndpointExporter.class); |
|
|
|
private static Log logger = LogFactory.getLog(ServerEndpointExporter.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -103,20 +99,25 @@ public class ServerEndpointExporter implements InitializingBean, BeanPostProcess |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected ServerContainer getServerContainer() { |
|
|
|
protected ServerContainer getServerContainer() { |
|
|
|
if (isServletApiPresent) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Method getter = ReflectionUtils.findMethod(this.applicationContext.getClass(), "getServletContext"); |
|
|
|
|
|
|
|
Object servletContext = getter.invoke(this.applicationContext); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Method attrMethod = ReflectionUtils.findMethod(servletContext.getClass(), "getAttribute", String.class); |
|
|
|
Class<?> servletContextClass; |
|
|
|
return (ServerContainer) attrMethod.invoke(servletContext, "javax.websocket.server.ServerContainer"); |
|
|
|
try { |
|
|
|
} |
|
|
|
servletContextClass = Class.forName("javax.servlet.ServletContext"); |
|
|
|
catch (Exception ex) { |
|
|
|
} |
|
|
|
throw new IllegalStateException( |
|
|
|
catch (Throwable e) { |
|
|
|
"Failed to get javax.websocket.server.ServerContainer via ServletContext attribute", ex); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Method getter = ReflectionUtils.findMethod(this.applicationContext.getClass(), "getServletContext"); |
|
|
|
|
|
|
|
Object servletContext = getter.invoke(this.applicationContext); |
|
|
|
|
|
|
|
Method attrMethod = ReflectionUtils.findMethod(servletContextClass, "getAttribute", String.class); |
|
|
|
|
|
|
|
return (ServerContainer) attrMethod.invoke(servletContext, "javax.websocket.server.ServerContainer"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) { |
|
|
|
|
|
|
|
throw new IllegalStateException( |
|
|
|
|
|
|
|
"Failed to get javax.websocket.server.ServerContainer via ServletContext attribute", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|