Issue #3139 ContextHandler must be set on server before configureContext
If configure context is called with a context that does not yet have a server, we should just throw an ISE. This is better than having a different configuration result depending on if the context has been set been added to the handler tree or not. Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
ececab10ca
commit
a8a5e50579
|
@ -57,6 +57,8 @@ public class WebSocketJsrServer
|
||||||
ServletContextHandler.SESSIONS);
|
ServletContextHandler.SESSIONS);
|
||||||
context.setContextPath("/");
|
context.setContextPath("/");
|
||||||
handlers.addHandler(context);
|
handlers.addHandler(context);
|
||||||
|
handlers.addHandler(new DefaultHandler());
|
||||||
|
server.setHandler(handlers);
|
||||||
|
|
||||||
// Enable javax.websocket configuration for the context
|
// Enable javax.websocket configuration for the context
|
||||||
ServerContainer wsContainer = JavaxWebSocketServletContainerInitializer
|
ServerContainer wsContainer = JavaxWebSocketServletContainerInitializer
|
||||||
|
@ -65,9 +67,6 @@ public class WebSocketJsrServer
|
||||||
// Add your websockets to the container
|
// Add your websockets to the container
|
||||||
wsContainer.addEndpoint(EchoJsrSocket.class);
|
wsContainer.addEndpoint(EchoJsrSocket.class);
|
||||||
|
|
||||||
handlers.addHandler(new DefaultHandler());
|
|
||||||
|
|
||||||
server.setHandler(handlers);
|
|
||||||
server.start();
|
server.start();
|
||||||
context.dumpStdErr();
|
context.dumpStdErr();
|
||||||
server.join();
|
server.join();
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.websocket.DeploymentException;
|
import javax.websocket.DeploymentException;
|
||||||
|
@ -42,7 +41,6 @@ import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
|
||||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||||
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
|
import org.eclipse.jetty.websocket.core.WebSocketExtensionRegistry;
|
||||||
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
|
||||||
|
@ -85,26 +83,23 @@ public class JavaxWebSocketServerContainer
|
||||||
public static JavaxWebSocketServerContainer ensureContainer(ServletContext servletContext) throws ServletException
|
public static JavaxWebSocketServerContainer ensureContainer(ServletContext servletContext) throws ServletException
|
||||||
{
|
{
|
||||||
ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "Javax Websocket");
|
ContextHandler contextHandler = ServletContextHandler.getServletContextHandler(servletContext, "Javax Websocket");
|
||||||
|
if (contextHandler.getServer() == null)
|
||||||
|
throw new IllegalStateException("Server has not been set on the ServletContextHandler");
|
||||||
|
|
||||||
JavaxWebSocketServerContainer container = contextHandler.getBean(JavaxWebSocketServerContainer.class);
|
JavaxWebSocketServerContainer container = contextHandler.getBean(JavaxWebSocketServerContainer.class);
|
||||||
if (container==null)
|
if (container==null)
|
||||||
{
|
{
|
||||||
// Find Pre-Existing (Shared?) HttpClient and/or executor
|
// Find Pre-Existing (Shared?) HttpClient and/or executor
|
||||||
HttpClient httpClient = (HttpClient)servletContext.getAttribute(JavaxWebSocketServletContainerInitializer.HTTPCLIENT_ATTRIBUTE);
|
HttpClient httpClient = (HttpClient)servletContext.getAttribute(JavaxWebSocketServletContainerInitializer.HTTPCLIENT_ATTRIBUTE);
|
||||||
if ((httpClient == null) && (contextHandler.getServer() != null))
|
if (httpClient == null)
|
||||||
httpClient = (HttpClient)contextHandler.getServer()
|
httpClient = (HttpClient)contextHandler.getServer()
|
||||||
.getAttribute(JavaxWebSocketServletContainerInitializer.HTTPCLIENT_ATTRIBUTE);
|
.getAttribute(JavaxWebSocketServletContainerInitializer.HTTPCLIENT_ATTRIBUTE);
|
||||||
|
|
||||||
Executor executor = httpClient == null?null:httpClient.getExecutor();
|
Executor executor = httpClient == null?null:httpClient.getExecutor();
|
||||||
if (executor == null)
|
if (executor == null)
|
||||||
executor = (Executor)servletContext.getAttribute("org.eclipse.jetty.server.Executor");
|
executor = (Executor)servletContext.getAttribute("org.eclipse.jetty.server.Executor");
|
||||||
if ((executor == null) && (contextHandler.getServer() != null))
|
|
||||||
executor = contextHandler.getServer().getThreadPool();
|
|
||||||
if (executor == null)
|
if (executor == null)
|
||||||
{
|
executor = contextHandler.getServer().getThreadPool();
|
||||||
executor = new QueuedThreadPool();
|
|
||||||
contextHandler.setAttribute("org.eclipse.jetty.server.Executor", executor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (httpClient != null && httpClient.getExecutor() == null)
|
if (httpClient != null && httpClient.getExecutor() == null)
|
||||||
httpClient.setExecutor(executor);
|
httpClient.setExecutor(executor);
|
||||||
|
|
Loading…
Reference in New Issue