From 4ff9bdc54dfbf83c401c29848153b570eca4ba32 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 15 Nov 2012 21:23:43 +1100 Subject: [PATCH] jetty-9 alternative websocket discovery --- .../jetty/websocket/servlet/WebSocketServlet.java | 13 +++++++++++-- test-jetty-webapp/pom.xml | 6 ++++++ .../src/test/java/org/eclipse/jetty/TestServer.java | 9 ++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java index 767181c161b..766e70cd706 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketServlet.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.websocket.servlet; import java.io.IOException; +import java.util.Iterator; import java.util.ServiceLoader; import javax.servlet.ServletException; @@ -128,8 +129,16 @@ public abstract class WebSocketServlet extends HttpServlet policy.setMaxBinaryMessageSize(Integer.parseInt(max)); } - ServiceLoader loader = ServiceLoader.load(WebSocketServletFactory.class); - WebSocketServletFactory baseFactory = loader.iterator().next(); + WebSocketServletFactory baseFactory ; + Iterator factories = ServiceLoader.load(WebSocketServletFactory.class).iterator(); + + if (factories.hasNext()) + baseFactory=factories.next(); + else + { + Class wssf= (Class)getServletContext().getClass().getClassLoader().loadClass("org.eclipse.jetty.websocket.server.WebSocketServerFactory"); + baseFactory=wssf.newInstance(); + } factory = baseFactory.createFactory(policy); diff --git a/test-jetty-webapp/pom.xml b/test-jetty-webapp/pom.xml index ddf8f35b51a..dcfa90c9b09 100644 --- a/test-jetty-webapp/pom.xml +++ b/test-jetty-webapp/pom.xml @@ -172,6 +172,12 @@ ${project.version} provided + + org.eclipse.jetty.websocket + websocket-server + ${project.version} + test + org.eclipse.jetty jetty-webapp diff --git a/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index f138697b3b3..75f1580c663 100644 --- a/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -149,7 +149,7 @@ public class TestServer server.setHandler(restart); - // Setup deployers + // Setup context HashLoginService login = new HashLoginService(); login.setName("Test Realm"); @@ -165,7 +165,8 @@ public class TestServer server.setSendServerVersion(true); WebAppContext webapp = new WebAppContext(); - //webapp.setParentLoaderPriority(true); + webapp.setParentLoaderPriority(true); + webapp.prependServerClass("-org.eclipse.jetty.websocket.server."); webapp.setResourceBase("./src/main/webapp"); webapp.setAttribute("testAttribute","testValue"); File sessiondir=File.createTempFile("sessions",null); @@ -190,7 +191,6 @@ public class TestServer private static class RestartHandler extends HandlerWrapper { - /* ------------------------------------------------------------ */ /** * @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) @@ -205,6 +205,7 @@ public class TestServer new Thread() { + @Override public void run() { try @@ -222,7 +223,5 @@ public class TestServer }.start(); } } - } - }