try {
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
Server server = factory.create();
server.getEndpoint().put("WS", CONTEXT_ROOT);
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
ServerLifeCycleListener stopHook = new ServerLifeCycleListener() {
@Override
public void stopServer(Server s) {
Object contextProperty = s.getEndpoint().get("WS");
if (contextProperty != null && contextProperty.equals(CONTEXT_ROOT)) {
httpService.unregister(CONTEXT_ROOT);