+ * The {@link ServletContainerInitializer} will have its {@link ServletContainerInitializer#onStartup(Set, ServletContext)}
+ * method called with the manually configured list of {@code Set> c} set.
+ * In other words, this usage does not perform bytecode or annotation scanning against the classes in
+ * your {@code ServletContextHandler} or {@code WebAppContext}.
+ *
+ *
+ * @param sci the {@link ServletContainerInitializer} to call
+ * @return the {@link ServletContextListener} wrapping the SCI
+ * @see SCIAsContextListener#addClasses(Class[])
+ * @see SCIAsContextListener#addClasses(String...)
+ */
+ public static SCIAsContextListener asContextListener(ServletContainerInitializer sci)
+ {
+ return new SCIAsContextListener(sci);
+ }
+
+ public static class SCIAsContextListener implements ServletContextListener
+ {
+ private final ServletContainerInitializer sci;
+ private Set classNames;
+ private Set> classes = new HashSet<>();
+ private Consumer postOnStartupConsumer;
+
+ public SCIAsContextListener(ServletContainerInitializer sci)
+ {
+ this.sci = sci;
+ }
+
+ /**
+ * Add classes to be passed to the {@link ServletContainerInitializer#onStartup(Set, ServletContext)} call.
+ *
+ * Note that these classes will be loaded using the context classloader for the ServletContext
+ * initialization phase.
+ *
+ *
+ * @param classNames the class names to load and pass into the {@link ServletContainerInitializer#onStartup(Set, ServletContext)} call
+ * @return this configured {@link SCIAsContextListener} instance.
+ */
+ public SCIAsContextListener addClasses(String... classNames)
+ {
+ if (this.classNames == null)
+ {
+ this.classNames = new HashSet<>();
+ }
+ this.classNames.addAll(Arrays.asList(classNames));
+ return this;
+ }
+
+ /**
+ * Add classes to be passed to the {@link ServletContainerInitializer#onStartup(Set, ServletContext)} call.
+ *
+ * Note that these classes will exist on the classloader that was used to call this method.
+ * If you want the classes to be loaded using the context classloader for the ServletContext
+ * then use the String form of the classes via the {@link #addClasses(String...)} method.
+ *
+ *
+ * @param classes the classes to pass into the {@link ServletContainerInitializer#onStartup(Set, ServletContext)} call
+ * @return this configured {@link SCIAsContextListener} instance.
+ */
+ public SCIAsContextListener addClasses(Class>... classes)
+ {
+ this.classes.addAll(Arrays.asList(classes));
+ return this;
+ }
+
+ /**
+ * Add a optional consumer to execute once the {@link ServletContainerInitializer#onStartup(Set, ServletContext)} has
+ * been called successfully.
+ *
+ * This would be for actions to perform on a ServletContext once this specific SCI has completed
+ * its execution. Actions that would require specific configurations that the SCI provides to be present on the
+ * ServletContext to function properly.
+ *
+ *
+ * This consumer is typically used for Embedded Jetty users to configure Jetty for their specific needs.
+ *
+ *
+ *
+ * @param consumer the consumer to execute after the SCI has executed
+ * @return this configured {@link SCIAsContextListener} instance.
+ */
+ public SCIAsContextListener setPostOnStartupConsumer(Consumer consumer)
+ {
+ this.postOnStartupConsumer = consumer;
+ return this;
+ }
+
+ @Override
+ public void contextInitialized(ServletContextEvent sce)
+ {
+ ServletContext servletContext = sce.getServletContext();
+ try
+ {
+ sci.onStartup(getClasses(), servletContext);
+ if (postOnStartupConsumer != null)
+ {
+ postOnStartupConsumer.accept(servletContext);
+ }
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Throwable cause)
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
+ public Set> getClasses()
+ {
+ if (classNames != null && !classNames.isEmpty())
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+ for (String className : classNames)
+ {
+ try
+ {
+ Class> clazz = cl.loadClass(className);
+ classes.add(clazz);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Unable to find class: " + className, e);
+ }
+ }
+ }
+
+ return classes;
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce)
+ {
+ // ignore
+ }
+ }
+}
diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
index fabb5b82cbc..02bcc59b607 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
@@ -20,7 +20,6 @@ package org.eclipse.jetty.websocket.jsr356.server.deploy;
import java.util.HashSet;
import java.util.Set;
-
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
@@ -34,8 +33,10 @@ import javax.websocket.server.ServerEndpoint;
import javax.websocket.server.ServerEndpointConfig;
import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.listener.ContainerInitializer;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -53,7 +54,8 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
public static final String ADD_DYNAMIC_FILTER_KEY = "org.eclipse.jetty.websocket.jsr356.addDynamicFilter";
private static final Logger LOG = Log.getLogger(WebSocketServerContainerInitializer.class);
public static final String HTTPCLIENT_ATTRIBUTE = "org.eclipse.jetty.websocket.jsr356.HttpClient";
-
+ public static final String ATTR_JAVAX_SERVER_CONTAINER = javax.websocket.server.ServerContainer.class.getName();
+
/**
* DestroyListener
*/
@@ -129,61 +131,145 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
return defValue;
}
-
+
+ public interface Configurator
+ {
+ void accept(ServletContext servletContext, ServerContainer serverContainer) throws DeploymentException;
+ }
+
/**
- * Embedded Jetty approach for non-bytecode scanning.
* @param context the {@link ServletContextHandler} to use
* @return a configured {@link ServerContainer} instance
* @throws ServletException if the {@link WebSocketUpgradeFilter} cannot be configured
+ * @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
+ * @see #configure(ServletContextHandler, Configurator)
*/
+ @Deprecated
public static ServerContainer configureContext(ServletContextHandler context) throws ServletException
{
- // Create Basic components
- NativeWebSocketConfiguration nativeWebSocketConfiguration = NativeWebSocketServletContainerInitializer.getDefaultFrom(context.getServletContext());
-
- // Build HttpClient
- HttpClient httpClient = (HttpClient) context.getServletContext().getAttribute(HTTPCLIENT_ATTRIBUTE);
- if ((httpClient == null) && (context.getServer() != null))
- {
- httpClient = (HttpClient) context.getServer().getAttribute(HTTPCLIENT_ATTRIBUTE);
- }
-
- // Create the Jetty ServerContainer implementation
- ServerContainer jettyContainer = new ServerContainer(nativeWebSocketConfiguration, httpClient);
- context.addBean(jettyContainer);
-
- // Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
- context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
-
- // Create Filter
- if(isEnabledViaContext(context.getServletContext(), ADD_DYNAMIC_FILTER_KEY, true))
- {
- String instanceKey = WebSocketUpgradeFilter.class.getName() + ".SCI";
- if(context.getAttribute(instanceKey) == null)
- {
- if (LOG.isDebugEnabled())
- LOG.debug("Dynamic filter add to support JSR356/javax.websocket.server: {}", WebSocketUpgradeFilter.class.getName());
- WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(context);
- context.setAttribute(instanceKey, wsuf);
- }
- }
-
- return jettyContainer;
+ ServletContext servletContext = context.getServletContext();
+ initialize(servletContext);
+ return (ServerContainer)servletContext.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
}
-
+
/**
- * @deprecated use {@link #configureContext(ServletContextHandler)} instead
* @param context not used
* @param jettyContext the {@link ServletContextHandler} to use
* @return a configured {@link ServerContainer} instance
* @throws ServletException if the {@link WebSocketUpgradeFilter} cannot be configured
+ * @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
+ * @see #configure(ServletContextHandler, Configurator)
*/
@Deprecated
public static ServerContainer configureContext(ServletContext context, ServletContextHandler jettyContext) throws ServletException
{
- return configureContext(jettyContext);
+ initialize(context);
+ return (ServerContainer)context.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
}
+ /**
+ * Initialize the {@link ServletContext} with the default (and empty) {@link ServerContainer}.
+ *
+ *
+ * This performs a subset of the behaviors that {@link #onStartup(Set, ServletContext)} does.
+ * There is no enablement check here, and no automatic deployment of endpoints at this point
+ * in time. It merely sets up the {@link ServletContext} so with the basics needed to start
+ * configuring for `javax.websocket.server` based endpoints.
+ *
+ *
+ * @param context the context to work with
+ */
+ public static void initialize(ServletContext context) throws ServletException
+ {
+ // Create Basic components
+ NativeWebSocketServletContainerInitializer.initialize(context);
+ NativeWebSocketConfiguration nativeWebSocketConfiguration = (NativeWebSocketConfiguration)context.getAttribute(NativeWebSocketServletContainerInitializer.ATTR_KEY);
+
+ ContextHandler contextHandler = null;
+ // Attach default configuration to context lifecycle
+ if (context instanceof ContextHandler.Context)
+ {
+ contextHandler = ((ContextHandler.Context)context).getContextHandler();
+ }
+
+ // Obtain HttpClient
+ HttpClient httpClient = (HttpClient)context.getAttribute(HTTPCLIENT_ATTRIBUTE);
+ if ((httpClient == null) && (contextHandler != null))
+ {
+ Server server = contextHandler.getServer();
+ if (server != null)
+ {
+ httpClient = (HttpClient)server.getAttribute(HTTPCLIENT_ATTRIBUTE);
+ }
+ }
+
+ // Create the Jetty ServerContainer implementation
+ ServerContainer jettyContainer = new ServerContainer(nativeWebSocketConfiguration, httpClient);
+ contextHandler.addBean(jettyContainer);
+
+ // Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
+ context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
+
+ if(contextHandler instanceof ServletContextHandler)
+ {
+ ServletContextHandler servletContextHandler = (ServletContextHandler)contextHandler;
+ // Create Filter
+ if(isEnabledViaContext(context, ADD_DYNAMIC_FILTER_KEY, true))
+ {
+ String instanceKey = WebSocketUpgradeFilter.class.getName() + ".SCI";
+ if(context.getAttribute(instanceKey) == null)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Dynamic filter add to support JSR356/javax.websocket.server: {}", WebSocketUpgradeFilter.class.getName());
+ WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(servletContextHandler);
+ context.setAttribute(instanceKey, wsuf);
+ }
+ }
+ }
+ }
+
+ /**
+ * Configure the {@link ServletContextHandler} to call {@link WebSocketServerContainerInitializer#onStartup(Set, ServletContext)}
+ * during the {@link ServletContext} initialization phase.
+ *
+ * @param context the context to add listener to
+ */
+ public static void configure(ServletContextHandler context)
+ {
+ context.addEventListener(ContainerInitializer.asContextListener(new WebSocketServerContainerInitializer()));
+ }
+
+ /**
+ * Configure the {@link ServletContextHandler} to call {@link WebSocketServerContainerInitializer#onStartup(Set, ServletContext)}
+ * during the {@link ServletContext} initialization phase.
+ *
+ * @param context the context to add listener to
+ * @param configurator the lambda that is called to allow the {@link ServerContainer} to
+ * be configured during the {@link ServletContext} initialization phase
+ */
+ public static void configure(ServletContextHandler context, Configurator configurator)
+ {
+ // In this embedded-jetty usage, allow ServletContext.addListener() to
+ // add other ServletContextListeners (such as the ContextDestroyListener) after
+ // the initialization phase is over. (important for this SCI to function)
+ context.getServletContext().setExtendedListenerTypes(true);
+
+ context.addEventListener(
+ ContainerInitializer.asContextListener(new WebSocketServerContainerInitializer())
+ .setPostOnStartupConsumer((servletContext) ->
+ {
+ ServerContainer serverContainer = (ServerContainer)servletContext.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
+ try
+ {
+ configurator.accept(servletContext, serverContainer);
+ }
+ catch (DeploymentException e)
+ {
+ throw new RuntimeException("Failed to deploy WebSocket Endpoint", e);
+ }
+ }));
+ }
+
@Override
public void onStartup(Set> c, ServletContext context) throws ServletException
{
@@ -205,12 +291,11 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
throw new ServletException("Not running in Jetty ServletContextHandler, JSR-356 support unavailable");
}
- ServletContextHandler jettyContext = (ServletContextHandler)handler;
-
try(ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader()))
{
// Create the Jetty ServerContainer implementation
- ServerContainer jettyContainer = configureContext(jettyContext);
+ initialize(context);
+ ServerContainer jettyContainer = (ServerContainer)context.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
context.addListener(new ContextDestroyListener()); // make sure context is cleaned up when the context stops
diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/BinaryStreamTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/BinaryStreamTest.java
index 0018d9ec0eb..bd2075f90e7 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/BinaryStreamTest.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/BinaryStreamTest.java
@@ -18,9 +18,6 @@
package org.eclipse.jetty.websocket.jsr356.server;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -29,7 +26,6 @@ import java.net.URI;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.OnMessage;
@@ -43,10 +39,12 @@ import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
import org.junit.jupiter.api.AfterEach;
-
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class BinaryStreamTest
{
private static final String PATH = "/echo";
@@ -63,9 +61,11 @@ public class BinaryStreamTest
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(server, "/", true, false);
- ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
- ServerEndpointConfig config = ServerEndpointConfig.Builder.create(ServerBinaryStreamer.class, PATH).build();
- container.addEndpoint(config);
+ WebSocketServerContainerInitializer.configure(context, (servletContext, container) ->
+ {
+ ServerEndpointConfig config = ServerEndpointConfig.Builder.create(ServerBinaryStreamer.class, PATH).build();
+ container.addEndpoint(config);
+ });
server.start();
diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/browser/JsrBrowserDebugTool.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/browser/JsrBrowserDebugTool.java
index ea45a3d2fda..21c8e52115c 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/browser/JsrBrowserDebugTool.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/browser/JsrBrowserDebugTool.java
@@ -19,14 +19,10 @@
package org.eclipse.jetty.websocket.jsr356.server.browser;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;
-import javax.servlet.ServletException;
-import javax.websocket.DeploymentException;
-
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
@@ -37,7 +33,6 @@ import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
/**
@@ -68,7 +63,6 @@ public class JsrBrowserDebugTool
JsrBrowserDebugTool tool = new JsrBrowserDebugTool();
tool.setupServer(port);
tool.server.start();
- tool.server.dumpStdErr();
LOG.info("Server available at {}", tool.server.getURI());
tool.server.join();
}
@@ -80,12 +74,10 @@ public class JsrBrowserDebugTool
private Server server;
- private ServerContainer setupServer(int port) throws DeploymentException, ServletException, URISyntaxException, MalformedURLException, IOException
+ private void setupServer(int port) throws URISyntaxException, IOException
{
server = new Server();
- server.setDumpAfterStart(true);
-
HttpConfiguration httpConf = new HttpConfiguration();
httpConf.setSendServerVersion(true);
@@ -106,10 +98,9 @@ public class JsrBrowserDebugTool
holder.setInitParameter("dirAllowed","true");
server.setHandler(context);
- ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
- container.addEndpoint(JsrBrowserSocket.class);
+ WebSocketServerContainerInitializer.configure(context,
+ (servletContext, container) -> container.addEndpoint(JsrBrowserSocket.class));
LOG.info("{} setup on port {}",this.getClass().getName(),port);
- return container;
}
}
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/AnnoMaxMessageEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/AnnoMaxMessageEndpoint.java
new file mode 100644
index 00000000000..ad6d06b37d3
--- /dev/null
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/AnnoMaxMessageEndpoint.java
@@ -0,0 +1,36 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests;
+
+import java.io.IOException;
+
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+
+@SuppressWarnings("unused")
+@WebSocket(maxTextMessageSize = 100*1024)
+public class AnnoMaxMessageEndpoint
+{
+ @OnWebSocketMessage
+ public void onMessage(Session session, String msg) throws IOException
+ {
+ session.getRemote().sendString(msg);
+ }
+}
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConnectMessageEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConnectMessageEndpoint.java
new file mode 100644
index 00000000000..d9ff09a4645
--- /dev/null
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConnectMessageEndpoint.java
@@ -0,0 +1,36 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests;
+
+import java.io.IOException;
+
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+
+@SuppressWarnings("unused")
+@WebSocket
+public class ConnectMessageEndpoint
+{
+ @OnWebSocketConnect
+ public void onConnect(Session session) throws IOException
+ {
+ session.getRemote().sendString("Greeting from onConnect");
+ }
+}
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoSocket.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoSocket.java
index 4908c6cb29c..ce2d9f651af 100644
--- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoSocket.java
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoSocket.java
@@ -24,6 +24,7 @@ import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+@SuppressWarnings("unused")
@WebSocket
public class EchoSocket
{
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/GetAuthHeaderEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/GetAuthHeaderEndpoint.java
new file mode 100644
index 00000000000..8e6130841cf
--- /dev/null
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/GetAuthHeaderEndpoint.java
@@ -0,0 +1,38 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests;
+
+import java.io.IOException;
+
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+
+@SuppressWarnings("unused")
+@WebSocket
+public class GetAuthHeaderEndpoint
+{
+ @OnWebSocketConnect
+ public void onConnect(Session session) throws IOException
+ {
+ String authHeaderName = "Authorization";
+ String authHeaderValue = session.getUpgradeRequest().getHeader(authHeaderName);
+ session.getRemote().sendString("Header[" + authHeaderName + "]=" + authHeaderValue);
+ }
+}
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/InvalidUpgradeServlet.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/InvalidUpgradeServlet.java
new file mode 100644
index 00000000000..44b49eeef3f
--- /dev/null
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/InvalidUpgradeServlet.java
@@ -0,0 +1,68 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.http.HttpHeader;
+import org.eclipse.jetty.websocket.common.AcceptHash;
+
+public class InvalidUpgradeServlet extends HttpServlet
+{
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ {
+ String pathInfo = req.getPathInfo();
+ if (pathInfo.contains("only-accept"))
+ {
+ // Force 200 response, no response body content, incomplete websocket response headers, no actual upgrade for this test
+ resp.setStatus(HttpServletResponse.SC_OK);
+ String key = req.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.toString());
+ resp.setHeader(HttpHeader.SEC_WEBSOCKET_ACCEPT.toString(), AcceptHash.hashKey(key));
+ }
+ else if (pathInfo.contains("close-connection"))
+ {
+ // Force 101 response, with invalid Connection header, invalid handshake
+ resp.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
+ String key = req.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.toString());
+ resp.setHeader(HttpHeader.CONNECTION.toString(), "close");
+ resp.setHeader(HttpHeader.SEC_WEBSOCKET_ACCEPT.toString(), AcceptHash.hashKey(key));
+ }
+ else if (pathInfo.contains("missing-connection"))
+ {
+ // Force 101 response, with no Connection header, invalid handshake
+ resp.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
+ String key = req.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.toString());
+ // Intentionally leave out Connection header
+ resp.setHeader(HttpHeader.SEC_WEBSOCKET_ACCEPT.toString(), AcceptHash.hashKey(key));
+ }
+ else if (pathInfo.contains("rubbish-accept"))
+ {
+ // Force 101 response, with no Connection header, invalid handshake
+ resp.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
+ resp.setHeader(HttpHeader.SEC_WEBSOCKET_ACCEPT.toString(), "rubbish");
+ }
+ else
+ {
+ resp.setStatus(500);
+ }
+ }
+}
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ParamsEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ParamsEndpoint.java
new file mode 100644
index 00000000000..bd4470465f1
--- /dev/null
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ParamsEndpoint.java
@@ -0,0 +1,49 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+
+@SuppressWarnings("unused")
+@WebSocket
+public class ParamsEndpoint
+{
+ @OnWebSocketConnect
+ public void onConnect(Session session) throws IOException
+ {
+ Map> params = session.getUpgradeRequest().getParameterMap();
+ StringBuilder msg = new StringBuilder();
+
+ for (String key : params.keySet())
+ {
+ msg.append("Params[").append(key).append("]=");
+ msg.append(params.get(key).stream().collect(Collectors.joining(", ", "[", "]")));
+ msg.append("\n");
+ }
+
+ session.getRemote().sendString(msg.toString());
+ }
+}
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/SimpleStatusServlet.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/SimpleStatusServlet.java
new file mode 100644
index 00000000000..300439a10d4
--- /dev/null
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/SimpleStatusServlet.java
@@ -0,0 +1,41 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class SimpleStatusServlet extends HttpServlet
+{
+ private final int statusCode;
+
+ public SimpleStatusServlet(int statusCode)
+ {
+ this.statusCode = statusCode;
+ }
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ resp.setStatus(this.statusCode);
+ }
+}
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConnectTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConnectTest.java
new file mode 100644
index 00000000000..343ec19e095
--- /dev/null
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConnectTest.java
@@ -0,0 +1,436 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests.client;
+
+import java.net.ConnectException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.SocketTimeoutException;
+import java.net.URI;
+import java.util.EnumSet;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import javax.servlet.DispatcherType;
+
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.io.ByteBufferPool;
+import org.eclipse.jetty.io.MappedByteBufferPool;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.UpgradeException;
+import org.eclipse.jetty.websocket.api.util.WSURI;
+import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
+import org.eclipse.jetty.websocket.client.WebSocketClient;
+import org.eclipse.jetty.websocket.client.WebSocketUpgradeRequest;
+import org.eclipse.jetty.websocket.server.NativeWebSocketServletContainerInitializer;
+import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
+import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint;
+import org.eclipse.jetty.websocket.tests.EchoSocket;
+import org.eclipse.jetty.websocket.tests.GetAuthHeaderEndpoint;
+import org.eclipse.jetty.websocket.tests.InvalidUpgradeServlet;
+import org.eclipse.jetty.websocket.tests.SimpleStatusServlet;
+import org.hamcrest.Matcher;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.anyOf;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * Various connect condition testing
+ */
+@SuppressWarnings("Duplicates")
+public class ClientConnectTest
+{
+ public ByteBufferPool bufferPool = new MappedByteBufferPool();
+
+ private Server server;
+ private WebSocketClient client;
+
+ @SuppressWarnings("unchecked")
+ private E assertExpectedError(ExecutionException e, CloseTrackingEndpoint wsocket, Matcher errorMatcher)
+ {
+ // Validate thrown cause
+ Throwable cause = e.getCause();
+
+ assertThat("ExecutionException.cause", cause, errorMatcher);
+
+ // Validate websocket captured cause
+ Throwable capcause = wsocket.error.get();
+ assertThat("Error", capcause, notNullValue());
+ assertThat("Error", capcause, errorMatcher);
+
+ // Validate that websocket didn't see an open event
+ assertThat("Open Latch", wsocket.openLatch.getCount(), is(1L));
+
+ // Return the captured cause
+ return (E)capcause;
+ }
+
+ @BeforeEach
+ public void startClient() throws Exception
+ {
+ client = new WebSocketClient();
+ client.setBufferPool(bufferPool);
+ client.setConnectTimeout(TimeUnit.SECONDS.toMillis(3));
+ client.setMaxIdleTimeout(TimeUnit.SECONDS.toMillis(3));
+ client.getPolicy().setIdleTimeout(TimeUnit.SECONDS.toMillis(10));
+ client.start();
+ }
+
+ @BeforeEach
+ public void startServer() throws Exception
+ {
+ server = new Server();
+
+ ServerConnector connector = new ServerConnector(server);
+ connector.setPort(0);
+ server.addConnector(connector);
+
+ ServletContextHandler context = new ServletContextHandler();
+ context.setContextPath("/");
+
+ NativeWebSocketServletContainerInitializer.configure(context,
+ (servletContext, configuration) ->
+ {
+ configuration.getPolicy().setIdleTimeout(10000);
+ configuration.addMapping("/echo", (req, resp) ->
+ {
+ if (req.hasSubProtocol("echo"))
+ resp.setAcceptedSubProtocol("echo");
+ return new EchoSocket();
+ });
+ configuration.addMapping("/get-auth-header", (req, resp) -> new GetAuthHeaderEndpoint());
+ });
+
+ context.addFilter(WebSocketUpgradeFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
+
+ context.addServlet(new ServletHolder(new SimpleStatusServlet(404)), "/bogus");
+ context.addServlet(new ServletHolder(new SimpleStatusServlet(200)), "/a-okay");
+ context.addServlet(new ServletHolder(new InvalidUpgradeServlet()), "/invalid-upgrade/*");
+
+ server.setHandler(context);
+
+ server.start();
+ }
+
+ @AfterEach
+ public void stopClient() throws Exception
+ {
+ client.stop();
+ }
+
+ @AfterEach
+ public void stopServer() throws Exception
+ {
+ server.stop();
+ }
+
+ @Test
+ public void testUpgradeRequest() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+ client.getPolicy().setIdleTimeout(10000);
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ request.setSubProtocols("echo");
+ Future future = client.connect(cliSock, wsUri);
+
+ try (Session sess = future.get(30, TimeUnit.SECONDS))
+ {
+ assertThat("Connect.UpgradeRequest", sess.getUpgradeRequest(), notNullValue());
+ assertThat("Connect.UpgradeResponse", sess.getUpgradeResponse(), notNullValue());
+ }
+ }
+
+ @Test
+ public void testAltConnect() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));
+ HttpClient httpClient = new HttpClient();
+ try
+ {
+ httpClient.start();
+
+ WebSocketUpgradeRequest req = new WebSocketUpgradeRequest(new WebSocketClient(), httpClient, wsUri, cliSock);
+ req.header("X-Foo", "Req");
+ CompletableFuture sess = req.sendAsync();
+
+ sess.thenAccept((s) ->
+ {
+ System.out.printf("Session: %s%n", s);
+ s.close();
+ assertThat("Connect.UpgradeRequest", s.getUpgradeRequest(), notNullValue());
+ assertThat("Connect.UpgradeResponse", s.getUpgradeResponse(), notNullValue());
+ });
+ }
+ finally
+ {
+ httpClient.stop();
+ }
+ }
+
+ @Test
+ public void testUpgradeWithAuthorizationHeader() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/get-auth-header"));
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ // actual value for this test is irrelevant, its important that this
+ // header actually be sent with a value (the value specified)
+ String authHeaderValue = "Basic YWxhZGRpbjpvcGVuc2VzYW1l";
+ request.setHeader("Authorization", authHeaderValue);
+ Future future = client.connect(cliSock, wsUri, request);
+
+ try (Session sess = future.get(5, TimeUnit.SECONDS))
+ {
+ // Test client side
+ String cliAuthValue = sess.getUpgradeRequest().getHeader("Authorization");
+ assertThat("Client Request Authorization Value", cliAuthValue, is(authHeaderValue));
+
+ // wait for response from server
+ String received = cliSock.messageQueue.poll(5, TimeUnit.SECONDS);
+ assertThat("Message", received, containsString("Header[Authorization]=" + authHeaderValue));
+ }
+ }
+
+ @Test
+ public void testBadHandshake() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/bogus"));
+ Future future = client.connect(cliSock, wsUri);
+
+ // The attempt to get upgrade response future should throw error
+ ExecutionException e = assertThrows(ExecutionException.class,
+ () -> future.get(5, TimeUnit.SECONDS));
+
+ UpgradeException ue = assertExpectedError(e, cliSock, instanceOf(UpgradeException.class));
+ assertThat("UpgradeException.requestURI", ue.getRequestURI(), notNullValue());
+ assertThat("UpgradeException.requestURI", ue.getRequestURI().toASCIIString(), is(wsUri.toASCIIString()));
+ assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(404));
+ }
+
+ @Test
+ public void testBadHandshake_GetOK() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/a-okay"));
+ Future future = client.connect(cliSock, wsUri);
+
+ // The attempt to get upgrade response future should throw error
+ ExecutionException e = assertThrows(ExecutionException.class,
+ () -> future.get(5, TimeUnit.SECONDS));
+
+ UpgradeException ue = assertExpectedError(e, cliSock, instanceOf(UpgradeException.class));
+ assertThat("UpgradeException.requestURI", ue.getRequestURI(), notNullValue());
+ assertThat("UpgradeException.requestURI", ue.getRequestURI().toASCIIString(), is(wsUri.toASCIIString()));
+ assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(200));
+ }
+
+ @Test
+ public void testBadHandshake_GetOK_WithSecWebSocketAccept() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/invalid-upgrade/only-accept"));
+ Future future = client.connect(cliSock, wsUri);
+
+ // The attempt to get upgrade response future should throw error
+ ExecutionException e = assertThrows(ExecutionException.class,
+ () -> future.get(5, TimeUnit.SECONDS));
+
+ UpgradeException ue = assertExpectedError(e, cliSock, instanceOf(UpgradeException.class));
+ assertThat("UpgradeException.requestURI", ue.getRequestURI(), notNullValue());
+ assertThat("UpgradeException.requestURI", ue.getRequestURI().toASCIIString(), is(wsUri.toASCIIString()));
+ assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(200));
+ }
+
+ @Test
+ public void testBadHandshake_SwitchingProtocols_InvalidConnectionHeader() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/invalid-upgrade/close-connection"));
+ Future future = client.connect(cliSock, wsUri);
+
+ // The attempt to get upgrade response future should throw error
+ ExecutionException e = assertThrows(ExecutionException.class,
+ () -> future.get(5, TimeUnit.SECONDS));
+
+ UpgradeException ue = assertExpectedError(e, cliSock, instanceOf(UpgradeException.class));
+ assertThat("UpgradeException.requestURI", ue.getRequestURI(), notNullValue());
+ assertThat("UpgradeException.requestURI", ue.getRequestURI().toASCIIString(), is(wsUri.toASCIIString()));
+ assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(101));
+ }
+
+ @Test
+ public void testBadHandshake_SwitchingProtocols_NoConnectionHeader() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/invalid-upgrade/missing-connection"));
+ Future future = client.connect(cliSock, wsUri);
+
+ // The attempt to get upgrade response future should throw error
+ ExecutionException e = assertThrows(ExecutionException.class,
+ () -> future.get(5, TimeUnit.SECONDS));
+
+ UpgradeException ue = assertExpectedError(e, cliSock, instanceOf(UpgradeException.class));
+ assertThat("UpgradeException.requestURI", ue.getRequestURI(), notNullValue());
+ assertThat("UpgradeException.requestURI", ue.getRequestURI().toASCIIString(), is(wsUri.toASCIIString()));
+ assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(101));
+ }
+
+ @Test
+ public void testBadUpgrade() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/invalid-upgrade/rubbish-accept"));
+ Future future = client.connect(cliSock, wsUri);
+
+ // The attempt to get upgrade response future should throw error
+ ExecutionException e = assertThrows(ExecutionException.class,
+ () -> future.get(5, TimeUnit.SECONDS));
+
+ UpgradeException ue = assertExpectedError(e, cliSock, instanceOf(UpgradeException.class));
+ assertThat("UpgradeException.responseStatusCode", ue.getResponseStatusCode(), is(101));
+ }
+
+ @Test
+ public void testConnectionNotAccepted() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ try (ServerSocket serverSocket = new ServerSocket())
+ {
+ InetAddress addr = InetAddress.getByName("localhost");
+ InetSocketAddress endpoint = new InetSocketAddress(addr, 0);
+ serverSocket.bind(endpoint, 1);
+ int port = serverSocket.getLocalPort();
+
+ URI wsUri = URI.create(String.format("ws://%s:%d/", addr.getHostAddress(), port));
+ Future future = client.connect(cliSock, wsUri);
+
+ // Intentionally not accept incoming socket.
+ // serverSocket.accept();
+
+ try
+ {
+ future.get(8, TimeUnit.SECONDS);
+ fail("Should have Timed Out");
+ }
+ catch (ExecutionException e)
+ {
+ // Passing Path (active session wait timeout)
+ assertExpectedError(e, cliSock, instanceOf(UpgradeException.class));
+ }
+ catch (TimeoutException e)
+ {
+ // Passing Path
+ }
+ }
+ }
+
+ @Test
+ public void testConnectionRefused() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ // Intentionally bad port with nothing listening on it
+ URI wsUri = new URI("ws://127.0.0.1:1");
+
+ try
+ {
+ Future future = client.connect(cliSock, wsUri);
+
+ // The attempt to get upgrade response future should throw error
+ future.get(5, TimeUnit.SECONDS);
+ fail("Expected ExecutionException -> ConnectException");
+ }
+ catch (ConnectException e)
+ {
+ Throwable t = cliSock.error.get();
+ assertThat("Error Queue[0]", t, instanceOf(ConnectException.class));
+ }
+ catch (ExecutionException e)
+ {
+ assertExpectedError(e, cliSock,
+ anyOf(
+ instanceOf(UpgradeException.class),
+ instanceOf(SocketTimeoutException.class),
+ instanceOf(ConnectException.class)));
+ }
+ }
+
+ @Test
+ public void testConnectionTimeout_Concurrent() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ try (ServerSocket serverSocket = new ServerSocket())
+ {
+ InetAddress addr = InetAddress.getByName("localhost");
+ InetSocketAddress endpoint = new InetSocketAddress(addr, 0);
+ serverSocket.bind(endpoint, 1);
+ int port = serverSocket.getLocalPort();
+ URI wsUri = URI.create(String.format("ws://%s:%d/", addr.getHostAddress(), port));
+ Future future = client.connect(cliSock, wsUri);
+
+ // Accept the connection, but do nothing on it (no response, no upgrade, etc)
+ serverSocket.accept();
+
+ // The attempt to get upgrade response future should throw error
+ Exception e = assertThrows(Exception.class,
+ () -> future.get(5, TimeUnit.SECONDS));
+
+ if (e instanceof ExecutionException)
+ {
+ assertExpectedError((ExecutionException)e, cliSock, anyOf(
+ instanceOf(ConnectException.class),
+ instanceOf(UpgradeException.class)
+ ));
+ }
+ else
+ {
+ assertThat("Should have been a TimeoutException", e, instanceOf(TimeoutException.class));
+ }
+ }
+ }
+}
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/WebSocketClientTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/WebSocketClientTest.java
new file mode 100644
index 00000000000..fd8ecddf230
--- /dev/null
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/WebSocketClientTest.java
@@ -0,0 +1,333 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests.client;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import javax.servlet.DispatcherType;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.util.StringUtil;
+import org.eclipse.jetty.websocket.api.RemoteEndpoint;
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.UpgradeRequest;
+import org.eclipse.jetty.websocket.api.util.WSURI;
+import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
+import org.eclipse.jetty.websocket.client.WebSocketClient;
+import org.eclipse.jetty.websocket.common.WebSocketSession;
+import org.eclipse.jetty.websocket.common.io.FutureWriteCallback;
+import org.eclipse.jetty.websocket.server.NativeWebSocketServletContainerInitializer;
+import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
+import org.eclipse.jetty.websocket.tests.AnnoMaxMessageEndpoint;
+import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint;
+import org.eclipse.jetty.websocket.tests.ConnectMessageEndpoint;
+import org.eclipse.jetty.websocket.tests.EchoSocket;
+import org.eclipse.jetty.websocket.tests.ParamsEndpoint;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class WebSocketClientTest
+{
+ private Server server;
+ private WebSocketClient client;
+
+ @BeforeEach
+ public void startClient() throws Exception
+ {
+ client = new WebSocketClient();
+ client.start();
+ }
+
+ @BeforeEach
+ public void startServer() throws Exception
+ {
+ server = new Server();
+
+ ServerConnector connector = new ServerConnector(server);
+ connector.setPort(0);
+ server.addConnector(connector);
+
+ ServletContextHandler context = new ServletContextHandler();
+ context.setContextPath("/");
+
+ NativeWebSocketServletContainerInitializer.configure(context,
+ (servletContext, configuration) ->
+ {
+ configuration.getPolicy().setIdleTimeout(10000);
+ configuration.addMapping("/echo", (req, resp) ->
+ {
+ if (req.hasSubProtocol("echo"))
+ resp.setAcceptedSubProtocol("echo");
+ return new EchoSocket();
+ });
+ configuration.addMapping("/anno-max-message", (req, resp) -> new AnnoMaxMessageEndpoint());
+ configuration.addMapping("/connect-msg", (req, resp) -> new ConnectMessageEndpoint());
+ configuration.addMapping("/get-params", (req, resp) -> new ParamsEndpoint());
+ });
+
+ context.addFilter(WebSocketUpgradeFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
+
+ server.setHandler(context);
+
+ server.start();
+ }
+
+ @AfterEach
+ public void stopClient() throws Exception
+ {
+ client.stop();
+ }
+
+ @AfterEach
+ public void stopServer() throws Exception
+ {
+ server.stop();
+ }
+
+ @Test
+ public void testAddExtension_NotInstalled() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ client.getPolicy().setIdleTimeout(10000);
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ request.setSubProtocols("echo");
+ request.addExtensions("x-bad");
+
+ assertThrows(IllegalArgumentException.class, () ->
+ {
+ // Should trigger failure on bad extension
+ client.connect(cliSock, wsUri, request);
+ });
+ }
+
+ @Test
+ public void testBasicEcho_FromClient() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ client.getPolicy().setIdleTimeout(10000);
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ request.setSubProtocols("echo");
+ Future future = client.connect(cliSock, wsUri, request);
+
+ try (Session sess = future.get(30, TimeUnit.SECONDS))
+ {
+ assertThat("Session", sess, notNullValue());
+ assertThat("Session.open", sess.isOpen(), is(true));
+ assertThat("Session.upgradeRequest", sess.getUpgradeRequest(), notNullValue());
+ assertThat("Session.upgradeResponse", sess.getUpgradeResponse(), notNullValue());
+
+ Collection sessions = client.getOpenSessions();
+ assertThat("client.sessions.size", sessions.size(), is(1));
+
+ RemoteEndpoint remote = cliSock.getSession().getRemote();
+ remote.sendString("Hello World!");
+
+ // wait for response from server
+ String received = cliSock.messageQueue.poll(5, TimeUnit.SECONDS);
+ assertThat("Message", received, containsString("Hello World"));
+ }
+ }
+
+ @Test
+ public void testBasicEcho_UsingCallback() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ client.getPolicy().setIdleTimeout(10000);
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ request.setSubProtocols("echo");
+ Future future = client.connect(cliSock, wsUri, request);
+
+ try (Session sess = future.get(5, TimeUnit.SECONDS))
+ {
+ assertThat("Session", sess, notNullValue());
+ assertThat("Session.open", sess.isOpen(), is(true));
+ assertThat("Session.upgradeRequest", sess.getUpgradeRequest(), notNullValue());
+ assertThat("Session.upgradeResponse", sess.getUpgradeResponse(), notNullValue());
+
+ Collection sessions = client.getOpenSessions();
+ assertThat("client.sessions.size", sessions.size(), is(1));
+
+ FutureWriteCallback callback = new FutureWriteCallback();
+
+ cliSock.getSession().getRemote().sendString("Hello World!", callback);
+ callback.get(5, TimeUnit.SECONDS);
+
+ // wait for response from server
+ String received = cliSock.messageQueue.poll(5, TimeUnit.SECONDS);
+ assertThat("Message", received, containsString("Hello World"));
+ }
+ }
+
+ @Test
+ public void testBasicEcho_FromServer() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ client.getPolicy().setIdleTimeout(10000);
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/connect-msg"));
+ Future future = client.connect(cliSock, wsUri);
+
+ try (Session sess = future.get(5, TimeUnit.SECONDS))
+ {
+ // Validate connect
+ assertThat("Session", sess, notNullValue());
+ assertThat("Session.open", sess.isOpen(), is(true));
+ assertThat("Session.upgradeRequest", sess.getUpgradeRequest(), notNullValue());
+ assertThat("Session.upgradeResponse", sess.getUpgradeResponse(), notNullValue());
+
+ // wait for message from server
+ String received = cliSock.messageQueue.poll(5, TimeUnit.SECONDS);
+ assertThat("Message", received, containsString("Greeting from onConnect"));
+ }
+ }
+
+ @Test
+ public void testLocalRemoteAddress() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ client.getPolicy().setIdleTimeout(10000);
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/echo"));
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ request.setSubProtocols("echo");
+ Future future = client.connect(cliSock, wsUri, request);
+
+ try (Session sess = future.get(5, TimeUnit.SECONDS))
+ {
+ Assertions.assertTrue(cliSock.openLatch.await(1, TimeUnit.SECONDS));
+
+ InetSocketAddress local = cliSock.getSession().getLocalAddress();
+ InetSocketAddress remote = cliSock.getSession().getRemoteAddress();
+
+ assertThat("Local Socket Address", local, notNullValue());
+ assertThat("Remote Socket Address", remote, notNullValue());
+
+ // Hard to validate (in a portable unit test) the local address that was used/bound in the low level Jetty Endpoint
+ assertThat("Local Socket Address / Host", local.getAddress().getHostAddress(), notNullValue());
+ assertThat("Local Socket Address / Port", local.getPort(), greaterThan(0));
+
+ String uriHostAddress = InetAddress.getByName(wsUri.getHost()).getHostAddress();
+ assertThat("Remote Socket Address / Host", remote.getAddress().getHostAddress(), is(uriHostAddress));
+ assertThat("Remote Socket Address / Port", remote.getPort(), greaterThan(0));
+ }
+ }
+
+ /**
+ * Ensure that @WebSocket(maxTextMessageSize = 100*1024) behaves as expected.
+ *
+ * @throws Exception on test failure
+ */
+ @Test
+ public void testMaxMessageSize() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ client.getPolicy().setMaxTextMessageSize(100 * 1024);
+ client.getPolicy().setIdleTimeout(10000);
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/anno-max-message"));
+ Future future = client.connect(cliSock, wsUri);
+
+ try (Session sess = future.get(5, TimeUnit.SECONDS))
+ {
+ assertThat("Session", sess, notNullValue());
+ assertThat("Session.open", sess.isOpen(), is(true));
+
+ // Create string that is larger than default size of 64k
+ // but smaller than maxMessageSize of 100k
+ int size = 80 * 1024;
+ byte buf[] = new byte[size];
+ Arrays.fill(buf,(byte)'x');
+ String msg = StringUtil.toUTF8String(buf,0,buf.length);
+
+ sess.getRemote().sendString(msg);
+
+ // wait for message from server
+ String received = cliSock.messageQueue.poll(5, TimeUnit.SECONDS);
+ assertThat("Message", received.length(), is(size));
+ }
+ }
+
+ @Test
+ public void testParameterMap() throws Exception
+ {
+ CloseTrackingEndpoint cliSock = new CloseTrackingEndpoint();
+
+ client.getPolicy().setMaxTextMessageSize(100 * 1024);
+ client.getPolicy().setIdleTimeout(10000);
+
+ URI wsUri = WSURI.toWebsocket(server.getURI().resolve("/get-params?snack=cashews&amount=handful&brand=off"));
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ Future future = client.connect(cliSock, wsUri, request);
+
+ try (Session sess = future.get(5, TimeUnit.SECONDS))
+ {
+ UpgradeRequest req = sess.getUpgradeRequest();
+ assertThat("Upgrade Request", req, notNullValue());
+
+ Map> parameterMap = req.getParameterMap();
+ assertThat("Parameter Map", parameterMap, notNullValue());
+
+ assertThat("Parameter[snack]", parameterMap.get("snack"), is(Arrays.asList(new String[]{"cashews"})));
+ assertThat("Parameter[amount]", parameterMap.get("amount"), is(Arrays.asList(new String[]{"handful"})));
+ assertThat("Parameter[brand]", parameterMap.get("brand"), is(Arrays.asList(new String[]{"off"})));
+
+ assertThat("Parameter[cost]", parameterMap.get("cost"), nullValue());
+
+ // wait for message from server indicating what it sees
+ String received = cliSock.messageQueue.poll(5, TimeUnit.SECONDS);
+ assertThat("Parameter[snack]", received, containsString("Params[snack]=[cashews]"));
+ assertThat("Parameter[amount]", received, containsString("Params[amount]=[handful]"));
+ assertThat("Parameter[brand]", received, containsString("Params[brand]=[off]"));
+ assertThat("Parameter[cost]", received, not(containsString("Params[cost]=")));
+ }
+ }
+}
diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java
deleted file mode 100644
index 811718de27d..00000000000
--- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/ClientConnectTest.java
+++ /dev/null
@@ -1,463 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.websocket.client;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.net.ConnectException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.SocketTimeoutException;
-import java.net.URI;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.http.HttpField;
-import org.eclipse.jetty.http.HttpFields;
-import org.eclipse.jetty.http.HttpHeader;
-import org.eclipse.jetty.io.ByteBufferPool;
-import org.eclipse.jetty.io.MappedByteBufferPool;
-import org.eclipse.jetty.websocket.api.Session;
-import org.eclipse.jetty.websocket.api.UpgradeException;
-import org.eclipse.jetty.websocket.common.AcceptHash;
-import org.eclipse.jetty.websocket.common.test.BlockheadConnection;
-import org.eclipse.jetty.websocket.common.test.BlockheadServer;
-import org.eclipse.jetty.websocket.common.test.Timeouts;
-import org.hamcrest.Matcher;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-/**
- * Various connect condition testing
- */
-@SuppressWarnings("Duplicates")
-public class ClientConnectTest
-{
- public ByteBufferPool bufferPool = new MappedByteBufferPool();
-
- private static BlockheadServer server;
- private WebSocketClient client;
-
- @SuppressWarnings("unchecked")
- private E assertExpectedError(ExecutionException e, JettyTrackingSocket wsocket, Matcher errorMatcher)
- {
- // Validate thrown cause
- Throwable cause = e.getCause();
-
- assertThat("ExecutionException.cause",cause,errorMatcher);
-
- // Validate websocket captured cause
- assertThat("Error Queue Length",wsocket.errorQueue.size(),greaterThanOrEqualTo(1));
- Throwable capcause = wsocket.errorQueue.poll();
- assertThat("Error Queue[0]",capcause,notNullValue());
- assertThat("Error Queue[0]",capcause,errorMatcher);
-
- // Validate that websocket didn't see an open event
- wsocket.assertNotOpened();
-
- // Return the captured cause
- return (E)capcause;
- }
-
- @BeforeEach
- public void startClient() throws Exception
- {
- client = new WebSocketClient();
- client.setBufferPool(bufferPool);
- client.setConnectTimeout(Timeouts.CONNECT_UNIT.toMillis(Timeouts.CONNECT));
- client.start();
- }
-
- @BeforeAll
- public static void startServer() throws Exception
- {
- server = new BlockheadServer();
- server.start();
- }
-
- @BeforeEach
- public void resetServerHandler()
- {
- // for each test, reset the server request handling to default
- server.resetRequestHandling();
- }
-
- @AfterEach
- public void stopClient() throws Exception
- {
- client.stop();
- }
-
- @AfterAll
- public static void stopServer() throws Exception
- {
- server.stop();
- }
-
- @Test
- public void testUpgradeRequest() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- Session sess = future.get(30,TimeUnit.SECONDS);
-
- wsocket.waitForConnected();
-
- assertThat("Connect.UpgradeRequest", wsocket.connectUpgradeRequest, notNullValue());
- assertThat("Connect.UpgradeResponse", wsocket.connectUpgradeResponse, notNullValue());
-
- sess.close();
- }
-
- @Test
- public void testAltConnect() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
- URI wsUri = server.getWsUri();
-
- HttpClient httpClient = new HttpClient();
- try
- {
- httpClient.start();
-
- WebSocketUpgradeRequest req = new WebSocketUpgradeRequest(new WebSocketClient(), httpClient, wsUri, wsocket);
- req.header("X-Foo", "Req");
- CompletableFuture sess = req.sendAsync();
-
- sess.thenAccept((s) -> {
- System.out.printf("Session: %s%n", s);
- s.close();
- assertThat("Connect.UpgradeRequest", wsocket.connectUpgradeRequest, notNullValue());
- assertThat("Connect.UpgradeResponse", wsocket.connectUpgradeResponse, notNullValue());
- });
- }
- finally
- {
- httpClient.stop();
- }
- }
-
- @Test
- public void testUpgradeWithAuthorizationHeader() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- // Hook into server connection creation
- CompletableFuture serverConnFut = new CompletableFuture<>();
- server.addConnectFuture(serverConnFut);
-
- URI wsUri = server.getWsUri();
- ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
- // actual value for this test is irrelevant, its important that this
- // header actually be sent with a value (the value specified)
- upgradeRequest.setHeader("Authorization", "Basic YWxhZGRpbjpvcGVuc2VzYW1l");
- Future future = client.connect(wsocket,wsUri,upgradeRequest);
-
- try (BlockheadConnection serverConn = serverConnFut.get(Timeouts.CONNECT, Timeouts.CONNECT_UNIT))
- {
- HttpFields upgradeRequestHeaders = serverConn.getUpgradeRequestHeaders();
-
- Session sess = future.get(30, TimeUnit.SECONDS);
-
- HttpField authHeader = upgradeRequestHeaders.getField(HttpHeader.AUTHORIZATION);
- assertThat("Server Request Authorization Header", authHeader, is(notNullValue()));
- assertThat("Server Request Authorization Value", authHeader.getValue(), is("Basic YWxhZGRpbjpvcGVuc2VzYW1l"));
- assertThat("Connect.UpgradeRequest", wsocket.connectUpgradeRequest, notNullValue());
- assertThat("Connect.UpgradeResponse", wsocket.connectUpgradeResponse, notNullValue());
-
- sess.close();
- }
- }
-
- @Test
- public void testBadHandshake() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- // Force 404 response, no upgrade for this test
- server.setRequestHandling((req, resp) -> {
- resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
- return true;
- });
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- // The attempt to get upgrade response future should throw error
- ExecutionException e = assertThrows(ExecutionException.class,
- ()-> future.get(30,TimeUnit.SECONDS));
-
- UpgradeException ue = assertExpectedError(e,wsocket,instanceOf(UpgradeException.class));
- assertThat("UpgradeException.requestURI",ue.getRequestURI(),notNullValue());
- assertThat("UpgradeException.requestURI",ue.getRequestURI().toASCIIString(),is(wsUri.toASCIIString()));
- assertThat("UpgradeException.responseStatusCode",ue.getResponseStatusCode(),is(404));
- }
-
- @Test
- public void testBadHandshake_GetOK() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- // Force 200 response, no response body content, no upgrade for this test
- server.setRequestHandling((req, resp) -> {
- resp.setStatus(HttpServletResponse.SC_OK);
- return true;
- });
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- // The attempt to get upgrade response future should throw error
- ExecutionException e = assertThrows(ExecutionException.class,
- ()-> future.get(30,TimeUnit.SECONDS));
-
- UpgradeException ue = assertExpectedError(e,wsocket,instanceOf(UpgradeException.class));
- assertThat("UpgradeException.requestURI",ue.getRequestURI(),notNullValue());
- assertThat("UpgradeException.requestURI",ue.getRequestURI().toASCIIString(),is(wsUri.toASCIIString()));
- assertThat("UpgradeException.responseStatusCode",ue.getResponseStatusCode(),is(200));
- }
-
- @Test
- public void testBadHandshake_GetOK_WithSecWebSocketAccept() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- // Force 200 response, no response body content, incomplete websocket response headers, no actual upgrade for this test
- server.setRequestHandling((req, resp) -> {
- String key = req.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.toString());
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setHeader(HttpHeader.SEC_WEBSOCKET_ACCEPT.toString(), AcceptHash.hashKey(key));
- return true;
- });
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- // The attempt to get upgrade response future should throw error
- ExecutionException e = assertThrows(ExecutionException.class,
- ()-> future.get(30,TimeUnit.SECONDS));
-
- UpgradeException ue = assertExpectedError(e,wsocket,instanceOf(UpgradeException.class));
- assertThat("UpgradeException.requestURI",ue.getRequestURI(),notNullValue());
- assertThat("UpgradeException.requestURI",ue.getRequestURI().toASCIIString(),is(wsUri.toASCIIString()));
- assertThat("UpgradeException.responseStatusCode",ue.getResponseStatusCode(),is(200));
- }
-
- @Test
- public void testBadHandshake_SwitchingProtocols_InvalidConnectionHeader() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- // Force 101 response, with invalid Connection header, invalid handshake
- server.setRequestHandling((req, resp) -> {
- String key = req.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.toString());
- resp.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
- resp.setHeader(HttpHeader.CONNECTION.toString(), "close");
- resp.setHeader(HttpHeader.SEC_WEBSOCKET_ACCEPT.toString(), AcceptHash.hashKey(key));
- return true;
- });
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- // The attempt to get upgrade response future should throw error
- ExecutionException e = assertThrows(ExecutionException.class,
- ()-> future.get(30,TimeUnit.SECONDS));
-
- UpgradeException ue = assertExpectedError(e,wsocket,instanceOf(UpgradeException.class));
- assertThat("UpgradeException.requestURI",ue.getRequestURI(),notNullValue());
- assertThat("UpgradeException.requestURI",ue.getRequestURI().toASCIIString(),is(wsUri.toASCIIString()));
- assertThat("UpgradeException.responseStatusCode",ue.getResponseStatusCode(),is(101));
- }
-
- @Test
- public void testBadHandshake_SwitchingProtocols_NoConnectionHeader() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- // Force 101 response, with no Connection header, invalid handshake
- server.setRequestHandling((req, resp) -> {
- String key = req.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.toString());
- resp.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
- // Intentionally leave out Connection header
- resp.setHeader(HttpHeader.SEC_WEBSOCKET_ACCEPT.toString(), AcceptHash.hashKey(key));
- return true;
- });
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- // The attempt to get upgrade response future should throw error
- ExecutionException e = assertThrows(ExecutionException.class,
- ()-> future.get(30,TimeUnit.SECONDS));
-
- UpgradeException ue = assertExpectedError(e,wsocket,instanceOf(UpgradeException.class));
- assertThat("UpgradeException.requestURI",ue.getRequestURI(),notNullValue());
- assertThat("UpgradeException.requestURI",ue.getRequestURI().toASCIIString(),is(wsUri.toASCIIString()));
- assertThat("UpgradeException.responseStatusCode",ue.getResponseStatusCode(),is(101));
- }
-
- @Test
- public void testBadUpgrade() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- // Force 101 response, with invalid response accept header
- server.setRequestHandling((req, resp) -> {
- resp.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
- resp.setHeader(HttpHeader.SEC_WEBSOCKET_ACCEPT.toString(), "rubbish");
- return true;
- });
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- // The attempt to get upgrade response future should throw error
- ExecutionException e = assertThrows(ExecutionException.class,
- ()-> future.get(30,TimeUnit.SECONDS));
-
- UpgradeException ue = assertExpectedError(e,wsocket,instanceOf(UpgradeException.class));
- assertThat("UpgradeException.requestURI",ue.getRequestURI(),notNullValue());
- assertThat("UpgradeException.requestURI",ue.getRequestURI().toASCIIString(),is(wsUri.toASCIIString()));
- assertThat("UpgradeException.responseStatusCode",ue.getResponseStatusCode(),is(101));
- }
-
- @Test
- public void testConnectionNotAccepted() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- try(ServerSocket serverSocket = new ServerSocket())
- {
- InetAddress addr = InetAddress.getByName("localhost");
- InetSocketAddress endpoint = new InetSocketAddress(addr, 0);
- serverSocket.bind(endpoint, 1);
- int port = serverSocket.getLocalPort();
- URI wsUri = URI.create(String.format("ws://%s:%d/", addr.getHostAddress(), port));
- Future future = client.connect(wsocket, wsUri);
-
- // Intentionally not accept incoming socket.
- // serverSocket.accept();
-
- try
- {
- future.get(3, TimeUnit.SECONDS);
- fail("Should have Timed Out");
- }
- catch (ExecutionException e)
- {
- assertExpectedError(e, wsocket, instanceOf(UpgradeException.class));
- // Possible Passing Path (active session wait timeout)
- wsocket.assertNotOpened();
- }
- catch (TimeoutException e)
- {
- // Possible Passing Path (concurrency timeout)
- wsocket.assertNotOpened();
- }
- }
- }
-
- @Test
- public void testConnectionRefused() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- // Intentionally bad port with nothing listening on it
- URI wsUri = new URI("ws://127.0.0.1:1");
-
- try
- {
- Future future = client.connect(wsocket,wsUri);
-
- // The attempt to get upgrade response future should throw error
- future.get(3,TimeUnit.SECONDS);
- fail("Expected ExecutionException -> ConnectException");
- }
- catch (ConnectException e)
- {
- Throwable t = wsocket.errorQueue.remove();
- assertThat("Error Queue[0]",t,instanceOf(ConnectException.class));
- wsocket.assertNotOpened();
- }
- catch (ExecutionException e)
- {
- assertExpectedError(e, wsocket,
- anyOf(
- instanceOf(UpgradeException.class),
- instanceOf(SocketTimeoutException.class),
- instanceOf(ConnectException.class)));
- }
- }
-
- @Test
- public void testConnectionTimeout_Concurrent() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- try(ServerSocket serverSocket = new ServerSocket())
- {
- InetAddress addr = InetAddress.getByName("localhost");
- InetSocketAddress endpoint = new InetSocketAddress(addr, 0);
- serverSocket.bind(endpoint, 1);
- int port = serverSocket.getLocalPort();
- URI wsUri = URI.create(String.format("ws://%s:%d/", addr.getHostAddress(), port));
- Future future = client.connect(wsocket, wsUri);
-
- // Accept the connection, but do nothing on it (no response, no upgrade, etc)
- serverSocket.accept();
-
- // The attempt to get upgrade response future should throw error
- Exception e = assertThrows(Exception.class,
- ()-> future.get(3, TimeUnit.SECONDS));
-
- if (e instanceof ExecutionException)
- {
- assertExpectedError((ExecutionException) e, wsocket, anyOf(
- instanceOf(ConnectException.class),
- instanceOf(UpgradeException.class)
- ));
- }
- else
- {
- assertThat("Should have been a TimeoutException", e, instanceOf(TimeoutException.class));
- }
- }
- }
-}
diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java
deleted file mode 100644
index adee6b543d4..00000000000
--- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java
+++ /dev/null
@@ -1,328 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.websocket.client;
-
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-import org.eclipse.jetty.util.StringUtil;
-import org.eclipse.jetty.websocket.api.BatchMode;
-import org.eclipse.jetty.websocket.api.RemoteEndpoint;
-import org.eclipse.jetty.websocket.api.Session;
-import org.eclipse.jetty.websocket.api.UpgradeRequest;
-import org.eclipse.jetty.websocket.common.WebSocketFrame;
-import org.eclipse.jetty.websocket.common.WebSocketSession;
-import org.eclipse.jetty.websocket.common.frames.TextFrame;
-import org.eclipse.jetty.websocket.common.io.FutureWriteCallback;
-import org.eclipse.jetty.websocket.common.test.BlockheadConnection;
-import org.eclipse.jetty.websocket.common.test.BlockheadServer;
-import org.eclipse.jetty.websocket.common.test.Timeouts;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class WebSocketClientTest
-{
- private static BlockheadServer server;
- private WebSocketClient client;
-
- @BeforeEach
- public void startClient() throws Exception
- {
- client = new WebSocketClient();
- client.start();
- }
-
- @BeforeAll
- public static void startServer() throws Exception
- {
- server = new BlockheadServer();
- server.getPolicy().setMaxTextMessageSize(200 * 1024);
- server.getPolicy().setMaxBinaryMessageSize(200 * 1024);
- server.start();
- }
-
- @AfterEach
- public void stopClient() throws Exception
- {
- client.stop();
- }
-
- @AfterAll
- public static void stopServer() throws Exception
- {
- server.stop();
- }
-
- @Test
- public void testAddExtension_NotInstalled() throws Exception
- {
- JettyTrackingSocket cliSock = new JettyTrackingSocket();
-
- client.getPolicy().setIdleTimeout(10000);
-
- URI wsUri = server.getWsUri();
- ClientUpgradeRequest request = new ClientUpgradeRequest();
- request.setSubProtocols("echo");
- request.addExtensions("x-bad");
-
- assertThrows(IllegalArgumentException.class, ()-> {
- // Should trigger failure on bad extension
- client.connect(cliSock, wsUri, request);
- });
- }
-
- @Test
- public void testBasicEcho_FromClient() throws Exception
- {
- JettyTrackingSocket cliSock = new JettyTrackingSocket();
-
- client.getPolicy().setIdleTimeout(10000);
-
- // Hook into server connection creation
- CompletableFuture serverConnFut = new CompletableFuture<>();
- server.addConnectFuture(serverConnFut);
-
- URI wsUri = server.getWsUri();
- ClientUpgradeRequest request = new ClientUpgradeRequest();
- request.setSubProtocols("echo");
- Future future = client.connect(cliSock,wsUri,request);
-
- try (BlockheadConnection serverConn = serverConnFut.get(Timeouts.CONNECT, Timeouts.CONNECT_UNIT))
- {
- // Setup echo of frames on server side
- serverConn.setIncomingFrameConsumer((frame)->{
- WebSocketFrame copy = WebSocketFrame.copy(frame);
- copy.setMask(null); // strip client mask (if present)
- serverConn.write(copy);
- });
-
- Session sess = future.get(30,TimeUnit.SECONDS);
- assertThat("Session",sess,notNullValue());
- assertThat("Session.open",sess.isOpen(),is(true));
- assertThat("Session.upgradeRequest",sess.getUpgradeRequest(),notNullValue());
- assertThat("Session.upgradeResponse",sess.getUpgradeResponse(),notNullValue());
-
- cliSock.assertWasOpened();
- cliSock.assertNotClosed();
-
- Collection sessions = client.getOpenSessions();
- assertThat("client.connectionManager.sessions.size",sessions.size(),is(1));
-
- RemoteEndpoint remote = cliSock.getSession().getRemote();
- remote.sendStringByFuture("Hello World!");
- if (remote.getBatchMode() == BatchMode.ON)
- remote.flush();
-
- // wait for response from server
- String received = cliSock.messageQueue.poll(Timeouts.POLL_EVENT, Timeouts.POLL_EVENT_UNIT);
- assertThat("Message", received, containsString("Hello World"));
- }
- }
-
- @Test
- public void testBasicEcho_UsingCallback() throws Exception
- {
- client.setMaxIdleTimeout(160000);
- JettyTrackingSocket cliSock = new JettyTrackingSocket();
-
- // Hook into server connection creation
- CompletableFuture serverConnFut = new CompletableFuture<>();
- server.addConnectFuture(serverConnFut);
-
- URI wsUri = server.getWsUri();
- ClientUpgradeRequest request = new ClientUpgradeRequest();
- request.setSubProtocols("echo");
- Future future = client.connect(cliSock,wsUri,request);
-
- try (BlockheadConnection serverConn = serverConnFut.get(Timeouts.CONNECT, Timeouts.CONNECT_UNIT))
- {
- Session sess = future.get(30, TimeUnit.SECONDS);
- assertThat("Session", sess, notNullValue());
- assertThat("Session.open", sess.isOpen(), is(true));
- assertThat("Session.upgradeRequest", sess.getUpgradeRequest(), notNullValue());
- assertThat("Session.upgradeResponse", sess.getUpgradeResponse(), notNullValue());
-
- cliSock.assertWasOpened();
- cliSock.assertNotClosed();
-
- Collection sessions = client.getBeans(WebSocketSession.class);
- assertThat("client.connectionManager.sessions.size", sessions.size(), is(1));
-
- FutureWriteCallback callback = new FutureWriteCallback();
-
- cliSock.getSession().getRemote().sendString("Hello World!", callback);
- callback.get(1, TimeUnit.SECONDS);
- }
- }
-
- @Test
- public void testBasicEcho_FromServer() throws Exception
- {
- // Hook into server connection creation
- CompletableFuture serverConnFut = new CompletableFuture<>();
- server.addConnectFuture(serverConnFut);
-
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
- Future future = client.connect(wsocket,server.getWsUri());
-
- try (BlockheadConnection serverConn = serverConnFut.get(Timeouts.CONNECT, Timeouts.CONNECT_UNIT))
- {
- // Validate connect
- Session sess = future.get(30, TimeUnit.SECONDS);
- assertThat("Session", sess, notNullValue());
- assertThat("Session.open", sess.isOpen(), is(true));
- assertThat("Session.upgradeRequest", sess.getUpgradeRequest(), notNullValue());
- assertThat("Session.upgradeResponse", sess.getUpgradeResponse(), notNullValue());
-
- // Have server send initial message
- serverConn.write(new TextFrame().setPayload("Hello World"));
-
- // Verify connect
- future.get(30, TimeUnit.SECONDS);
- wsocket.assertWasOpened();
-
- String received = wsocket.messageQueue.poll(Timeouts.POLL_EVENT, Timeouts.POLL_EVENT_UNIT);
- assertThat("Message", received, containsString("Hello World"));
- }
- }
-
- @Test
- public void testLocalRemoteAddress() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- future.get(30,TimeUnit.SECONDS);
-
- assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS));
-
- InetSocketAddress local = wsocket.getSession().getLocalAddress();
- InetSocketAddress remote = wsocket.getSession().getRemoteAddress();
-
- assertThat("Local Socket Address",local,notNullValue());
- assertThat("Remote Socket Address",remote,notNullValue());
-
- // Hard to validate (in a portable unit test) the local address that was used/bound in the low level Jetty Endpoint
- assertThat("Local Socket Address / Host",local.getAddress().getHostAddress(),notNullValue());
- assertThat("Local Socket Address / Port",local.getPort(),greaterThan(0));
-
- String uriHostAddress = InetAddress.getByName(wsUri.getHost()).getHostAddress();
- assertThat("Remote Socket Address / Host",remote.getAddress().getHostAddress(),is(uriHostAddress));
- assertThat("Remote Socket Address / Port",remote.getPort(),greaterThan(0));
- }
-
- /**
- * Ensure that @WebSocket(maxTextMessageSize = 100*1024) behaves as expected.
- *
- * @throws Exception
- * on test failure
- */
- @Test
- public void testMaxMessageSize() throws Exception
- {
- MaxMessageSocket wsocket = new MaxMessageSocket();
-
- // Hook into server connection creation
- CompletableFuture serverConnFut = new CompletableFuture<>();
- server.addConnectFuture(serverConnFut);
-
- URI wsUri = server.getWsUri();
- Future future = client.connect(wsocket,wsUri);
-
- try (BlockheadConnection serverConn = serverConnFut.get(Timeouts.CONNECT, Timeouts.CONNECT_UNIT))
- {
- // Setup echo of frames on server side
- serverConn.setIncomingFrameConsumer((frame)->{
- WebSocketFrame copy = WebSocketFrame.copy(frame);
- copy.setMask(null); // strip client mask (if present)
- serverConn.write(copy);
- });
-
- wsocket.awaitConnect(1,TimeUnit.SECONDS);
-
- Session sess = future.get(30,TimeUnit.SECONDS);
- assertThat("Session",sess,notNullValue());
- assertThat("Session.open",sess.isOpen(),is(true));
-
- // Create string that is larger than default size of 64k
- // but smaller than maxMessageSize of 100k
- byte buf[] = new byte[80 * 1024];
- Arrays.fill(buf,(byte)'x');
- String msg = StringUtil.toUTF8String(buf,0,buf.length);
-
- wsocket.getSession().getRemote().sendStringByFuture(msg);
-
- // wait for response from server
- wsocket.waitForMessage(1, TimeUnit.SECONDS);
-
- wsocket.assertMessage(msg);
-
- assertTrue(wsocket.dataLatch.await(2, TimeUnit.SECONDS));
- }
- }
-
- @Test
- public void testParameterMap() throws Exception
- {
- JettyTrackingSocket wsocket = new JettyTrackingSocket();
-
- URI wsUri = server.getWsUri().resolve("/test?snack=cashews&amount=handful&brand=off");
- Future future = client.connect(wsocket,wsUri);
-
- future.get(30,TimeUnit.SECONDS);
-
- assertTrue(wsocket.openLatch.await(1,TimeUnit.SECONDS));
-
- Session session = wsocket.getSession();
- UpgradeRequest req = session.getUpgradeRequest();
- assertThat("Upgrade Request",req,notNullValue());
-
- Map> parameterMap = req.getParameterMap();
- assertThat("Parameter Map",parameterMap,notNullValue());
-
- assertThat("Parameter[snack]",parameterMap.get("snack"),is(Arrays.asList(new String[] { "cashews" })));
- assertThat("Parameter[amount]",parameterMap.get("amount"),is(Arrays.asList(new String[] { "handful" })));
- assertThat("Parameter[brand]",parameterMap.get("brand"),is(Arrays.asList(new String[] { "off" })));
-
- assertThat("Parameter[cost]",parameterMap.get("cost"),nullValue());
- }
-}
diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
index 4559ae1fdb7..7853b548fc3 100644
--- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
+++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
@@ -19,40 +19,98 @@
package org.eclipse.jetty.websocket.server;
import java.util.Set;
-
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.listener.ContainerInitializer;
public class NativeWebSocketServletContainerInitializer implements ServletContainerInitializer
{
+ public static final String ATTR_KEY = NativeWebSocketConfiguration.class.getName();
+
+ public interface Configurator
+ {
+ void accept(ServletContext servletContext, NativeWebSocketConfiguration nativeWebSocketConfiguration);
+ }
+
+ /**
+ * Initialize the ServletContext with the default (and empty) {@link NativeWebSocketConfiguration}
+ *
+ * @param context the context to work with
+ */
+ public static void initialize(ServletContext context)
+ {
+ NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration)context.getAttribute(ATTR_KEY);
+ if (configuration != null)
+ return; // it exists.
+
+ // Not provided to us, create a new default one.
+ configuration = new NativeWebSocketConfiguration(context);
+ context.setAttribute(ATTR_KEY, configuration);
+
+ // Attach default configuration to context lifecycle
+ if (context instanceof ContextHandler.Context)
+ {
+ ContextHandler handler = ((ContextHandler.Context)context).getContextHandler();
+ // Let ContextHandler handle configuration lifecycle
+ handler.addManaged(configuration);
+ }
+ }
+
+ /**
+ * Configure the {@link ServletContextHandler} to call the {@link NativeWebSocketServletContainerInitializer}
+ * during the {@link ServletContext} initialization phase.
+ *
+ * @param context the context to add listener to.
+ */
+ public static void configure(ServletContextHandler context)
+ {
+ context.addEventListener(ContainerInitializer.asContextListener(new NativeWebSocketServletContainerInitializer()));
+ }
+
+ /**
+ * Configure the {@link ServletContextHandler} to call the {@link NativeWebSocketServletContainerInitializer}
+ * during the {@link ServletContext} initialization phase.
+ *
+ * @param context the context to add listener to.
+ * @param configurator a lambda that is called to allow the {@link NativeWebSocketConfiguration} to
+ * be configured during {@link ServletContext} initialization phase
+ */
+ public static void configure(ServletContextHandler context, Configurator configurator)
+ {
+ context.addEventListener(
+ ContainerInitializer
+ .asContextListener(new NativeWebSocketServletContainerInitializer())
+ .setPostOnStartupConsumer((servletContext) ->
+ {
+ NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration)servletContext.getAttribute(ATTR_KEY);
+ configurator.accept(servletContext, configuration);
+ }));
+ }
+
+ /**
+ * Obtain the default {@link NativeWebSocketConfiguration} from the {@link ServletContext}
+ *
+ * @param context the context to work with
+ * @return the default {@link NativeWebSocketConfiguration}
+ * @see #initialize(ServletContext)
+ * @see #configure(ServletContextHandler)
+ * @see #configure(ServletContextHandler, Configurator)
+ * @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
+ */
+ @Deprecated
public static NativeWebSocketConfiguration getDefaultFrom(ServletContext context)
{
- final String KEY = NativeWebSocketConfiguration.class.getName();
-
- NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getAttribute(KEY);
- if (configuration == null)
- {
- // Not provided to us, create a new default one.
- configuration = new NativeWebSocketConfiguration(context);
- context.setAttribute(KEY, configuration);
-
- // Attach default configuration to context lifecycle
- if (context instanceof ContextHandler.Context)
- {
- ContextHandler handler = ((ContextHandler.Context)context).getContextHandler();
- // Let ContextHandler handle configuration lifecycle
- handler.addManaged(configuration);
- }
- }
- return configuration;
+ initialize(context);
+ return (NativeWebSocketConfiguration)context.getAttribute(ATTR_KEY);
}
-
+
@Override
public void onStartup(Set> c, ServletContext ctx)
{
// initialize
- getDefaultFrom(ctx);
+ initialize(ctx);
}
}
From a6b2bd86efdfc20fd8073716d9ab865b626156ea Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Mon, 3 Jun 2019 15:52:41 -0500
Subject: [PATCH 12/45] Issue #3698 - Changes based on review from @sbordet
Signed-off-by: Joakim Erdfelt
---
.../listener/ContainerInitializer.java | 37 +++++++++----------
.../WebSocketServerContainerInitializer.java | 13 +++----
...eWebSocketServletContainerInitializer.java | 2 +-
3 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/listener/ContainerInitializer.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/listener/ContainerInitializer.java
index b1eb8fe9124..648248f4401 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/listener/ContainerInitializer.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/listener/ContainerInitializer.java
@@ -37,11 +37,11 @@ public final class ContainerInitializer
* Utility Method to allow for manual execution of {@link javax.servlet.ServletContainerInitializer} when
* using Embedded Jetty.
*
- *
+ *
* ServletContextHandler context = new ServletContextHandler();
* ServletContainerInitializer corpSci = new MyCorporateSCI();
* context.addEventListener(ContainerInitializer.asContextListener(corpSci));
- *
+ *
*
*
* The {@link ServletContainerInitializer} will have its {@link ServletContainerInitializer#onStartup(Set, ServletContext)}
@@ -52,22 +52,22 @@ public final class ContainerInitializer
*
* @param sci the {@link ServletContainerInitializer} to call
* @return the {@link ServletContextListener} wrapping the SCI
- * @see SCIAsContextListener#addClasses(Class[])
- * @see SCIAsContextListener#addClasses(String...)
+ * @see ServletContainerInitializerServletContextListener#addClasses(Class[])
+ * @see ServletContainerInitializerServletContextListener#addClasses(String...)
*/
- public static SCIAsContextListener asContextListener(ServletContainerInitializer sci)
+ public static ServletContainerInitializerServletContextListener asContextListener(ServletContainerInitializer sci)
{
- return new SCIAsContextListener(sci);
+ return new ServletContainerInitializerServletContextListener(sci);
}
- public static class SCIAsContextListener implements ServletContextListener
+ public static class ServletContainerInitializerServletContextListener implements ServletContextListener
{
private final ServletContainerInitializer sci;
private Set classNames;
private Set> classes = new HashSet<>();
- private Consumer postOnStartupConsumer;
+ private Consumer afterStartupConsumer;
- public SCIAsContextListener(ServletContainerInitializer sci)
+ public ServletContainerInitializerServletContextListener(ServletContainerInitializer sci)
{
this.sci = sci;
}
@@ -80,9 +80,9 @@ public final class ContainerInitializer
*
*
* @param classNames the class names to load and pass into the {@link ServletContainerInitializer#onStartup(Set, ServletContext)} call
- * @return this configured {@link SCIAsContextListener} instance.
+ * @return this configured {@link ServletContainerInitializerServletContextListener} instance.
*/
- public SCIAsContextListener addClasses(String... classNames)
+ public ServletContainerInitializerServletContextListener addClasses(String... classNames)
{
if (this.classNames == null)
{
@@ -101,9 +101,9 @@ public final class ContainerInitializer
*
*
* @param classes the classes to pass into the {@link ServletContainerInitializer#onStartup(Set, ServletContext)} call
- * @return this configured {@link SCIAsContextListener} instance.
+ * @return this configured {@link ServletContainerInitializerServletContextListener} instance.
*/
- public SCIAsContextListener addClasses(Class>... classes)
+ public ServletContainerInitializerServletContextListener addClasses(Class>... classes)
{
this.classes.addAll(Arrays.asList(classes));
return this;
@@ -121,13 +121,12 @@ public final class ContainerInitializer
* This consumer is typically used for Embedded Jetty users to configure Jetty for their specific needs.
*
*
- *
* @param consumer the consumer to execute after the SCI has executed
- * @return this configured {@link SCIAsContextListener} instance.
+ * @return this configured {@link ServletContainerInitializerServletContextListener} instance.
*/
- public SCIAsContextListener setPostOnStartupConsumer(Consumer consumer)
+ public ServletContainerInitializerServletContextListener afterStartup(Consumer consumer)
{
- this.postOnStartupConsumer = consumer;
+ this.afterStartupConsumer = consumer;
return this;
}
@@ -138,9 +137,9 @@ public final class ContainerInitializer
try
{
sci.onStartup(getClasses(), servletContext);
- if (postOnStartupConsumer != null)
+ if (afterStartupConsumer != null)
{
- postOnStartupConsumer.accept(servletContext);
+ afterStartupConsumer.accept(servletContext);
}
}
catch (RuntimeException rte)
diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
index 02bcc59b607..b06741960a3 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
@@ -142,7 +142,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
* @return a configured {@link ServerContainer} instance
* @throws ServletException if the {@link WebSocketUpgradeFilter} cannot be configured
* @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
- * @see #configure(ServletContextHandler, Configurator)
+ * @see #initialize(ServletContext)
*/
@Deprecated
public static ServerContainer configureContext(ServletContextHandler context) throws ServletException
@@ -153,12 +153,12 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
}
/**
- * @param context not used
- * @param jettyContext the {@link ServletContextHandler} to use
+ * @param context the {@link ServletContext} to use
+ * @param jettyContext not used
* @return a configured {@link ServerContainer} instance
* @throws ServletException if the {@link WebSocketUpgradeFilter} cannot be configured
* @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
- * @see #configure(ServletContextHandler, Configurator)
+ * @see #initialize(ServletContext)
*/
@Deprecated
public static ServerContainer configureContext(ServletContext context, ServletContextHandler jettyContext) throws ServletException
@@ -254,9 +254,8 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
// the initialization phase is over. (important for this SCI to function)
context.getServletContext().setExtendedListenerTypes(true);
- context.addEventListener(
- ContainerInitializer.asContextListener(new WebSocketServerContainerInitializer())
- .setPostOnStartupConsumer((servletContext) ->
+ context.addEventListener(ContainerInitializer.asContextListener(new WebSocketServerContainerInitializer())
+ .afterStartup((servletContext) ->
{
ServerContainer serverContainer = (ServerContainer)servletContext.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
try
diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
index 7853b548fc3..d0943fbcb8d 100644
--- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
+++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
@@ -83,7 +83,7 @@ public class NativeWebSocketServletContainerInitializer implements ServletContai
context.addEventListener(
ContainerInitializer
.asContextListener(new NativeWebSocketServletContainerInitializer())
- .setPostOnStartupConsumer((servletContext) ->
+ .afterStartup((servletContext) ->
{
NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration)servletContext.getAttribute(ATTR_KEY);
configurator.accept(servletContext, configuration);
From 631f0cd9f61904af92d2e95321a34a1c31270668 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Thu, 6 Jun 2019 11:39:55 -0500
Subject: [PATCH 13/45] Issue #3648 - SSL based on WebSocket behavior (CLIENT
vs SERVER)
Signed-off-by: Joakim Erdfelt
---
.../jetty/websocket/common/scopes/SimpleContainerScope.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java
index 8b00a84601b..11dcbefeaad 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java
@@ -84,7 +84,10 @@ public class SimpleContainerScope extends ContainerLifeCycle implements WebSocke
if (ssl == null)
{
- this.sslContextFactory = new SslContextFactory.Server();
+ if (policy.getBehavior() == WebSocketBehavior.CLIENT)
+ this.sslContextFactory = new SslContextFactory.Client();
+ else if (policy.getBehavior() == WebSocketBehavior.SERVER)
+ this.sslContextFactory = new SslContextFactory.Server();
}
else
{
From 986dd77e609b42934766683cdd34bfd229bcd926 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Thu, 6 Jun 2019 16:44:35 -0500
Subject: [PATCH 14/45] Issue #3698 - Applying changes from PR feedback.
Signed-off-by: Joakim Erdfelt
---
.../jetty/servlet/ServletContextHandler.java | 12 +-
.../WebSocketServerContainerInitializer.java | 133 +++++------
.../jsr356/server/RestartContextTest.java | 212 ++++++++++++++++++
...eWebSocketServletContainerInitializer.java | 70 +++---
.../server/WebSocketUpgradeFilter.java | 86 +++----
5 files changed, 356 insertions(+), 157 deletions(-)
create mode 100644 jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/RestartContextTest.java
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java
index 11bd7254d89..7764959b8f0 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java
@@ -29,7 +29,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
@@ -61,7 +60,6 @@ import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
-import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.server.session.SessionHandler;
@@ -780,6 +778,16 @@ public class ServletContextHandler extends ContextHandler
_objFactory.destroy(filter);
}
+ public static ServletContextHandler getServletContextHandler(ServletContext context)
+ {
+ ContextHandler handler = getContextHandler(context);
+ if (handler == null)
+ return null;
+ if (handler instanceof ServletContextHandler)
+ return (ServletContextHandler) handler;
+ return null;
+ }
+
/* ------------------------------------------------------------ */
public static class JspPropertyGroup implements JspPropertyGroupDescriptor
{
diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
index b06741960a3..ef025338ba3 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
@@ -34,7 +34,6 @@ import javax.websocket.server.ServerEndpointConfig;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.listener.ContainerInitializer;
import org.eclipse.jetty.util.TypeUtil;
@@ -50,11 +49,16 @@ import org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter;
{ ServerApplicationConfig.class, ServerEndpoint.class, Endpoint.class })
public class WebSocketServerContainerInitializer implements ServletContainerInitializer
{
+ /**
+ * The ServletContext attribute key name for the
+ * ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
+ */
+ public static final String ATTR_JAVAX_SERVER_CONTAINER = javax.websocket.server.ServerContainer.class.getName();
+
public static final String ENABLE_KEY = "org.eclipse.jetty.websocket.jsr356";
public static final String ADD_DYNAMIC_FILTER_KEY = "org.eclipse.jetty.websocket.jsr356.addDynamicFilter";
private static final Logger LOG = Log.getLogger(WebSocketServerContainerInitializer.class);
public static final String HTTPCLIENT_ATTRIBUTE = "org.eclipse.jetty.websocket.jsr356.HttpClient";
- public static final String ATTR_JAVAX_SERVER_CONTAINER = javax.websocket.server.ServerContainer.class.getName();
/**
* DestroyListener
@@ -70,10 +74,10 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
@Override
public void contextDestroyed(ServletContextEvent sce)
{
- //remove any ServerContainer beans
- if (sce.getServletContext() instanceof ContextHandler.Context)
+ // remove any ServerContainer beans
+ ServletContextHandler handler = ServletContextHandler.getServletContextHandler(sce.getServletContext());
+ if (handler != null)
{
- ContextHandler handler = ((ContextHandler.Context)sce.getServletContext()).getContextHandler();
ServerContainer bean = handler.getBean(ServerContainer.class);
if (bean != null)
handler.removeBean(bean);
@@ -142,33 +146,28 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
* @return a configured {@link ServerContainer} instance
* @throws ServletException if the {@link WebSocketUpgradeFilter} cannot be configured
* @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
- * @see #initialize(ServletContext)
*/
@Deprecated
public static ServerContainer configureContext(ServletContextHandler context) throws ServletException
{
- ServletContext servletContext = context.getServletContext();
- initialize(servletContext);
- return (ServerContainer)servletContext.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
+ return initialize(context);
}
/**
- * @param context the {@link ServletContext} to use
- * @param jettyContext not used
+ * @param context not used
+ * @param jettyContext the {@link ServletContextHandler} to use
* @return a configured {@link ServerContainer} instance
* @throws ServletException if the {@link WebSocketUpgradeFilter} cannot be configured
* @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
- * @see #initialize(ServletContext)
*/
@Deprecated
public static ServerContainer configureContext(ServletContext context, ServletContextHandler jettyContext) throws ServletException
{
- initialize(context);
- return (ServerContainer)context.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
+ return initialize(jettyContext);
}
/**
- * Initialize the {@link ServletContext} with the default (and empty) {@link ServerContainer}.
+ * Immediately initialize the {@link ServletContext} with the default (and empty) {@link ServerContainer}.
*
*
* This performs a subset of the behaviors that {@link #onStartup(Set, ServletContext)} does.
@@ -178,65 +177,41 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
*
*
* @param context the context to work with
+ * @return the default {@link ServerContainer} for this context
*/
- public static void initialize(ServletContext context) throws ServletException
+ public static ServerContainer initialize(ServletContextHandler context) throws ServletException
{
- // Create Basic components
- NativeWebSocketServletContainerInitializer.initialize(context);
- NativeWebSocketConfiguration nativeWebSocketConfiguration = (NativeWebSocketConfiguration)context.getAttribute(NativeWebSocketServletContainerInitializer.ATTR_KEY);
-
- ContextHandler contextHandler = null;
- // Attach default configuration to context lifecycle
- if (context instanceof ContextHandler.Context)
+ ServerContainer serverContainer = (ServerContainer) context.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
+ if(serverContainer == null)
{
- contextHandler = ((ContextHandler.Context)context).getContextHandler();
- }
+ // Create Basic components
+ NativeWebSocketConfiguration nativeWebSocketConfiguration = NativeWebSocketServletContainerInitializer.initialize(context);
- // Obtain HttpClient
- HttpClient httpClient = (HttpClient)context.getAttribute(HTTPCLIENT_ATTRIBUTE);
- if ((httpClient == null) && (contextHandler != null))
- {
- Server server = contextHandler.getServer();
- if (server != null)
+ // Obtain HttpClient
+ HttpClient httpClient = (HttpClient) context.getAttribute(HTTPCLIENT_ATTRIBUTE);
+ if (httpClient == null)
{
- httpClient = (HttpClient)server.getAttribute(HTTPCLIENT_ATTRIBUTE);
- }
- }
-
- // Create the Jetty ServerContainer implementation
- ServerContainer jettyContainer = new ServerContainer(nativeWebSocketConfiguration, httpClient);
- contextHandler.addBean(jettyContainer);
-
- // Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
- context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
-
- if(contextHandler instanceof ServletContextHandler)
- {
- ServletContextHandler servletContextHandler = (ServletContextHandler)contextHandler;
- // Create Filter
- if(isEnabledViaContext(context, ADD_DYNAMIC_FILTER_KEY, true))
- {
- String instanceKey = WebSocketUpgradeFilter.class.getName() + ".SCI";
- if(context.getAttribute(instanceKey) == null)
+ Server server = context.getServer();
+ if (server != null)
{
- if (LOG.isDebugEnabled())
- LOG.debug("Dynamic filter add to support JSR356/javax.websocket.server: {}", WebSocketUpgradeFilter.class.getName());
- WebSocketUpgradeFilter wsuf = WebSocketUpgradeFilter.configureContext(servletContextHandler);
- context.setAttribute(instanceKey, wsuf);
+ httpClient = (HttpClient) server.getAttribute(HTTPCLIENT_ATTRIBUTE);
}
}
- }
- }
- /**
- * Configure the {@link ServletContextHandler} to call {@link WebSocketServerContainerInitializer#onStartup(Set, ServletContext)}
- * during the {@link ServletContext} initialization phase.
- *
- * @param context the context to add listener to
- */
- public static void configure(ServletContextHandler context)
- {
- context.addEventListener(ContainerInitializer.asContextListener(new WebSocketServerContainerInitializer()));
+ // Create the Jetty ServerContainer implementation
+ serverContainer = new ServerContainer(nativeWebSocketConfiguration, httpClient);
+ context.addBean(serverContainer);
+
+ // Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
+ context.setAttribute(ATTR_JAVAX_SERVER_CONTAINER, serverContainer);
+
+ // Create Filter
+ if (isEnabledViaContext(context.getServletContext(), ADD_DYNAMIC_FILTER_KEY, true))
+ {
+ WebSocketUpgradeFilter.initialize(context);
+ }
+ }
+ return serverContainer;
}
/**
@@ -258,13 +233,16 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
.afterStartup((servletContext) ->
{
ServerContainer serverContainer = (ServerContainer)servletContext.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
- try
+ if (configurator != null)
{
- configurator.accept(servletContext, serverContainer);
- }
- catch (DeploymentException e)
- {
- throw new RuntimeException("Failed to deploy WebSocket Endpoint", e);
+ try
+ {
+ configurator.accept(servletContext, serverContainer);
+ }
+ catch (DeploymentException e)
+ {
+ throw new RuntimeException("Failed to deploy WebSocket Endpoint", e);
+ }
}
}));
}
@@ -278,24 +256,17 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
return;
}
- ContextHandler handler = ContextHandler.getContextHandler(context);
+ ServletContextHandler handler = ServletContextHandler.getServletContextHandler(context);
if (handler == null)
{
throw new ServletException("Not running on Jetty, JSR-356 support unavailable");
}
- if (!(handler instanceof ServletContextHandler))
- {
- throw new ServletException("Not running in Jetty ServletContextHandler, JSR-356 support unavailable");
- }
-
try(ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader()))
{
- // Create the Jetty ServerContainer implementation
- initialize(context);
- ServerContainer jettyContainer = (ServerContainer)context.getAttribute(ATTR_JAVAX_SERVER_CONTAINER);
-
+ // Initialize the Jetty ServerContainer implementation
+ ServerContainer jettyContainer = initialize(handler);
context.addListener(new ContextDestroyListener()); // make sure context is cleaned up when the context stops
if (c.isEmpty())
diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/RestartContextTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/RestartContextTest.java
new file mode 100644
index 00000000000..fd390547208
--- /dev/null
+++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/RestartContextTest.java
@@ -0,0 +1,212 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.jsr356.server;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.websocket.DeploymentException;
+import javax.websocket.OnMessage;
+import javax.websocket.server.ServerEndpoint;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+import org.eclipse.jetty.websocket.api.util.WSURI;
+import org.eclipse.jetty.websocket.client.WebSocketClient;
+import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+public class RestartContextTest
+{
+ private Server server;
+ private WebSocketClient client;
+
+ @BeforeEach
+ public void startClient() throws Exception
+ {
+ client = new WebSocketClient();
+ client.start();
+ }
+
+ @AfterEach
+ public void stopClient() throws Exception
+ {
+ client.stop();
+ }
+
+ @AfterEach
+ public void startServer() throws Exception
+ {
+ server.stop();
+ }
+
+ @Test
+ public void testStartStopStart_ServletContextListener() throws Exception
+ {
+ server = new Server();
+
+ ServerConnector connector = new ServerConnector(server);
+ connector.setPort(0);
+ server.addConnector(connector);
+
+ // Setup Context
+ ServletContextHandler context = new ServletContextHandler();
+ context.setContextPath("/");
+ WebSocketServerContainerInitializer.configure(context, null);
+ // late initialization via my own ServletContextListener
+ context.addEventListener(new AddEndpointListener());
+
+ // Setup handler tree
+ HandlerList handlers = new HandlerList();
+ handlers.addHandler(context);
+ handlers.addHandler(new DefaultHandler());
+
+ // Add handler tree to server
+ server.setHandler(handlers);
+
+ // Start server
+ server.start();
+
+ // verify functionality
+ verifyWebSocketEcho(server.getURI().resolve("/echo"));
+
+ // Stop server
+ server.stop();
+
+ // Start server (again)
+ server.start();
+
+ // verify functionality (again)
+ verifyWebSocketEcho(server.getURI().resolve("/echo"));
+ }
+
+ @Test
+ public void testStartStopStart_Configurator() throws Exception
+ {
+ server = new Server();
+
+ ServerConnector connector = new ServerConnector(server);
+ connector.setPort(0);
+ server.addConnector(connector);
+
+ // Setup Context
+ ServletContextHandler context = new ServletContextHandler();
+ context.setContextPath("/");
+ WebSocketServerContainerInitializer.configure(context, (servletContext, serverContainer) -> {
+ // Add endpoint via configurator
+ serverContainer.addEndpoint(EchoEndpoint.class);
+ });
+
+ // Setup handler tree
+ HandlerList handlers = new HandlerList();
+ handlers.addHandler(context);
+ handlers.addHandler(new DefaultHandler());
+
+ // Add handler tree to server
+ server.setHandler(handlers);
+
+ // Start server
+ server.start();
+
+ // verify functionality
+ verifyWebSocketEcho(server.getURI().resolve("/echo"));
+
+ // Stop server
+ server.stop();
+
+ // Start server (again)
+ server.start();
+
+ // verify functionality (again)
+ verifyWebSocketEcho(server.getURI().resolve("/echo"));
+ }
+
+ private void verifyWebSocketEcho(URI endpointUri) throws URISyntaxException, IOException, ExecutionException, InterruptedException
+ {
+ ClientEndpoint endpoint = new ClientEndpoint();
+ Future fut = client.connect(endpoint, WSURI.toWebsocket(endpointUri));
+ try(Session session = fut.get())
+ {
+ session.getRemote().sendString("Test Echo");
+ String msg = endpoint.messages.poll(5, TimeUnit.SECONDS);
+ assertThat("msg", msg, is("Test Echo"));
+ }
+ }
+
+ public static class AddEndpointListener implements ServletContextListener
+ {
+ @Override
+ public void contextInitialized(ServletContextEvent sce)
+ {
+ ServerContainer container = (ServerContainer) sce.getServletContext().getAttribute(javax.websocket.server.ServerContainer.class.getName());
+ try
+ {
+ container.addEndpoint(EchoEndpoint.class);
+ }
+ catch (DeploymentException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce)
+ {
+ }
+ }
+
+ @ServerEndpoint("/echo")
+ public static class EchoEndpoint
+ {
+ @OnMessage
+ public String onMessage(String msg)
+ {
+ return msg;
+ }
+ }
+
+ @WebSocket
+ public static class ClientEndpoint
+ {
+ public LinkedBlockingQueue messages = new LinkedBlockingQueue<>();
+
+ @OnWebSocketMessage
+ public void onMessage(String msg)
+ {
+ this.messages.offer(msg);
+ }
+ }
+}
diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
index d0943fbcb8d..77b68a84dc1 100644
--- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
+++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
@@ -22,7 +22,6 @@ import java.util.Set;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
-import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.listener.ContainerInitializer;
@@ -36,38 +35,29 @@ public class NativeWebSocketServletContainerInitializer implements ServletContai
}
/**
- * Initialize the ServletContext with the default (and empty) {@link NativeWebSocketConfiguration}
+ * Immediately initialize the {@link ServletContextHandler} with the default {@link NativeWebSocketConfiguration}.
+ *
+ *
+ * This will return the default {@link NativeWebSocketConfiguration} if already initialized,
+ * and not create a new {@link NativeWebSocketConfiguration} each time it is called.
+ *
*
* @param context the context to work with
+ * @return the default {@link NativeWebSocketConfiguration}
*/
- public static void initialize(ServletContext context)
+ public static NativeWebSocketConfiguration initialize(ServletContextHandler context)
{
- NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration)context.getAttribute(ATTR_KEY);
- if (configuration != null)
- return; // it exists.
-
- // Not provided to us, create a new default one.
- configuration = new NativeWebSocketConfiguration(context);
- context.setAttribute(ATTR_KEY, configuration);
-
- // Attach default configuration to context lifecycle
- if (context instanceof ContextHandler.Context)
+ NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getAttribute(ATTR_KEY);
+ if (configuration == null)
{
- ContextHandler handler = ((ContextHandler.Context)context).getContextHandler();
- // Let ContextHandler handle configuration lifecycle
- handler.addManaged(configuration);
- }
- }
+ // Not provided to us, create a new default one.
+ configuration = new NativeWebSocketConfiguration(context.getServletContext());
+ context.setAttribute(ATTR_KEY, configuration);
- /**
- * Configure the {@link ServletContextHandler} to call the {@link NativeWebSocketServletContainerInitializer}
- * during the {@link ServletContext} initialization phase.
- *
- * @param context the context to add listener to.
- */
- public static void configure(ServletContextHandler context)
- {
- context.addEventListener(ContainerInitializer.asContextListener(new NativeWebSocketServletContainerInitializer()));
+ // Attach default configuration to context lifecycle
+ context.addManaged(configuration);
+ }
+ return configuration;
}
/**
@@ -85,8 +75,11 @@ public class NativeWebSocketServletContainerInitializer implements ServletContai
.asContextListener(new NativeWebSocketServletContainerInitializer())
.afterStartup((servletContext) ->
{
- NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration)servletContext.getAttribute(ATTR_KEY);
- configurator.accept(servletContext, configuration);
+ if (configurator != null)
+ {
+ NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) servletContext.getAttribute(ATTR_KEY);
+ configurator.accept(servletContext, configuration);
+ }
}));
}
@@ -95,7 +88,6 @@ public class NativeWebSocketServletContainerInitializer implements ServletContai
*
* @param context the context to work with
* @return the default {@link NativeWebSocketConfiguration}
- * @see #initialize(ServletContext)
* @see #configure(ServletContextHandler)
* @see #configure(ServletContextHandler, Configurator)
* @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
@@ -103,14 +95,22 @@ public class NativeWebSocketServletContainerInitializer implements ServletContai
@Deprecated
public static NativeWebSocketConfiguration getDefaultFrom(ServletContext context)
{
- initialize(context);
- return (NativeWebSocketConfiguration)context.getAttribute(ATTR_KEY);
+ ServletContextHandler handler = ServletContextHandler.getServletContextHandler(context);
+ if (handler == null)
+ {
+ throw new IllegalStateException("Unable to find ServletContextHandler for provided ServletContext");
+ }
+ return initialize(handler);
}
@Override
- public void onStartup(Set> c, ServletContext ctx)
+ public void onStartup(Set> c, ServletContext context)
{
- // initialize
- initialize(ctx);
+ ServletContextHandler handler = ServletContextHandler.getServletContextHandler(context);
+ if (handler == null)
+ {
+ throw new IllegalStateException("Unable to find ServletContextHandler for provided ServletContext");
+ }
+ initialize(handler);
}
}
diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java
index 0d91dc11639..7f5613c366f 100644
--- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java
+++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java
@@ -20,7 +20,6 @@ package org.eclipse.jetty.websocket.server;
import java.io.IOException;
import java.util.EnumSet;
-
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -34,7 +33,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.pathmap.MappedResource;
import org.eclipse.jetty.http.pathmap.PathSpec;
-import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
@@ -54,43 +52,60 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
private static final Logger LOG = Log.getLogger(WebSocketUpgradeFilter.class);
public static final String CONTEXT_ATTRIBUTE_KEY = "contextAttributeKey";
public static final String CONFIG_ATTRIBUTE_KEY = "configAttributeKey";
+ public static final String ATTR_KEY = WebSocketUpgradeFilter.class.getName();
+
+ /**
+ * Immediately initialize the default WebSocketUpgradeFilter.
+ *
+ *
+ * Return default {@link WebSocketUpgradeFilter} if
+ *
+ *
+ * @param context the {@link ServletContextHandler} to use
+ * @return the configured default {@link WebSocketUpgradeFilter} instance
+ * @throws ServletException if the filer cannot be configured
+ */
+ public static WebSocketUpgradeFilter initialize(ServletContextHandler context) throws ServletException
+ {
+ // Prevent double configure
+ WebSocketUpgradeFilter filter = (WebSocketUpgradeFilter) context.getAttribute(ATTR_KEY);
+ if (filter == null)
+ {
+ // Dynamically add filter
+ NativeWebSocketConfiguration configuration = NativeWebSocketServletContainerInitializer.initialize(context);
+ filter = new WebSocketUpgradeFilter(configuration);
+ filter.setToAttribute(context, ATTR_KEY);
+
+ String name = "Jetty_WebSocketUpgradeFilter";
+ String pathSpec = "/*";
+ EnumSet dispatcherTypes = EnumSet.of(DispatcherType.REQUEST);
+
+ FilterHolder fholder = new FilterHolder(filter);
+ fholder.setName(name);
+ fholder.setAsyncSupported(true);
+ fholder.setInitParameter(CONTEXT_ATTRIBUTE_KEY, WebSocketUpgradeFilter.class.getName());
+ context.addFilter(fholder, pathSpec, dispatcherTypes);
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Adding [{}] {} mapped to {} to {}", name, filter, pathSpec, context);
+ }
+ }
+
+ return filter;
+ }
/**
*
* @param context the {@link ServletContextHandler} to use
* @return a configured {@link WebSocketUpgradeFilter} instance
* @throws ServletException if the filer cannot be configured
+ * @deprecated use {@link #initialize(ServletContextHandler)} instead
*/
+ @Deprecated
public static WebSocketUpgradeFilter configureContext(ServletContextHandler context) throws ServletException
{
- // Prevent double configure
- WebSocketUpgradeFilter filter = (WebSocketUpgradeFilter) context.getAttribute(WebSocketUpgradeFilter.class.getName());
- if (filter != null)
- {
- return filter;
- }
-
- // Dynamically add filter
- NativeWebSocketConfiguration configuration = NativeWebSocketServletContainerInitializer.getDefaultFrom(context.getServletContext());
- filter = new WebSocketUpgradeFilter(configuration);
- filter.setToAttribute(context, WebSocketUpgradeFilter.class.getName());
-
- String name = "Jetty_WebSocketUpgradeFilter";
- String pathSpec = "/*";
- EnumSet dispatcherTypes = EnumSet.of(DispatcherType.REQUEST);
-
- FilterHolder fholder = new FilterHolder(filter);
- fholder.setName(name);
- fholder.setAsyncSupported(true);
- fholder.setInitParameter(CONTEXT_ATTRIBUTE_KEY, WebSocketUpgradeFilter.class.getName());
- context.addFilter(fholder, pathSpec, dispatcherTypes);
-
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Adding [{}] {} mapped to {} to {}", name, filter, pathSpec, context);
- }
-
- return filter;
+ return initialize(context);
}
/**
@@ -102,19 +117,12 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
@Deprecated
public static WebSocketUpgradeFilter configureContext(ServletContext context) throws ServletException
{
- ContextHandler handler = ContextHandler.getContextHandler(context);
-
+ ServletContextHandler handler = ServletContextHandler.getServletContextHandler(context);
if (handler == null)
{
throw new ServletException("Not running on Jetty, WebSocket support unavailable");
}
-
- if (!(handler instanceof ServletContextHandler))
- {
- throw new ServletException("Not running in Jetty ServletContextHandler, WebSocket support via " + WebSocketUpgradeFilter.class.getName() + " unavailable");
- }
-
- return configureContext((ServletContextHandler) handler);
+ return initialize(handler);
}
private NativeWebSocketConfiguration configuration;
From 550fb99e867258617288feaf315fb93b5d04f39a Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Fri, 7 Jun 2019 07:01:06 -0500
Subject: [PATCH 15/45] Issue #3698 - fixing javadoc
---
.../server/NativeWebSocketServletContainerInitializer.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
index 77b68a84dc1..51fdf9b7f3c 100644
--- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
+++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
@@ -88,7 +88,6 @@ public class NativeWebSocketServletContainerInitializer implements ServletContai
*
* @param context the context to work with
* @return the default {@link NativeWebSocketConfiguration}
- * @see #configure(ServletContextHandler)
* @see #configure(ServletContextHandler, Configurator)
* @deprecated use {@link #configure(ServletContextHandler, Configurator)} instead
*/
From 85566d03778318c3ca323b8a14eb267a3a0a2911 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Wed, 5 Jun 2019 07:49:59 -0500
Subject: [PATCH 16/45] Issue #3731 - adding cdi2 test webapp
Signed-off-by: Joakim Erdfelt
---
tests/test-webapps/pom.xml | 1 +
tests/test-webapps/test-cdi2-webapp/pom.xml | 59 +++++++++++++++++++
.../eclipse/jetty/test/FriendlyGreetings.java | 33 +++++++++++
.../org/eclipse/jetty/test/Greetings.java | 24 ++++++++
.../eclipse/jetty/test/GreetingsServlet.java | 42 +++++++++++++
.../org/eclipse/jetty/test/InfoServlet.java | 52 ++++++++++++++++
.../eclipse/jetty/test/ManifestServerID.java | 20 +++++++
.../eclipse/jetty/test/MyContextListener.java | 42 +++++++++++++
.../org/eclipse/jetty/test/OldGreetings.java | 14 +++++
.../java/org/eclipse/jetty/test/ServerID.java | 24 ++++++++
.../eclipse/jetty/test/ServerIDFilter.java | 57 ++++++++++++++++++
.../src/main/resources/META-INF/beans.xml | 8 +++
.../src/main/webapp/WEB-INF/jetty-env.xml | 18 ++++++
.../src/main/webapp/WEB-INF/web.xml | 17 ++++++
14 files changed, 411 insertions(+)
create mode 100644 tests/test-webapps/test-cdi2-webapp/pom.xml
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/FriendlyGreetings.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/Greetings.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/GreetingsServlet.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/InfoServlet.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ManifestServerID.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/MyContextListener.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/OldGreetings.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ServerID.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ServerIDFilter.java
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/resources/META-INF/beans.xml
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/webapp/WEB-INF/jetty-env.xml
create mode 100644 tests/test-webapps/test-cdi2-webapp/src/main/webapp/WEB-INF/web.xml
diff --git a/tests/test-webapps/pom.xml b/tests/test-webapps/pom.xml
index 811613302a4..0d92961c94e 100644
--- a/tests/test-webapps/pom.xml
+++ b/tests/test-webapps/pom.xml
@@ -40,5 +40,6 @@
test-jndi-webapptest-http2-webapptest-simple-webapp
+ test-cdi2-webapp
\ No newline at end of file
diff --git a/tests/test-webapps/test-cdi2-webapp/pom.xml b/tests/test-webapps/test-cdi2-webapp/pom.xml
new file mode 100644
index 00000000000..b5c53caa3c6
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/pom.xml
@@ -0,0 +1,59 @@
+
+
+
+ org.eclipse.jetty.tests
+ test-webapps-parent
+ 9.4.19-SNAPSHOT
+
+
+ 4.0.0
+ test-cdi2-webapp
+ Test :: CDI2 On Jetty :: Included in WebApp
+ war
+
+
+ ${project.groupId}.cdi2.webapp
+
+
+
+ cdi2-demo
+
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ provided
+
+
+ javax.el
+ javax.el-api
+
+
+ org.mortbay.jasper
+ apache-el
+ 9.0.19
+ provided
+
+
+
+ org.jboss.weld.servlet
+ weld-servlet
+ ${weld.version}
+
+
+
+ org.eclipse.jetty
+ jetty-annotations
+ ${project.version}
+ test
+
+
+ org.eclipse.jetty
+ jetty-client
+ ${project.version}
+ test
+
+
+
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/FriendlyGreetings.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/FriendlyGreetings.java
new file mode 100644
index 00000000000..3e4dc04fe14
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/FriendlyGreetings.java
@@ -0,0 +1,33 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.test;
+
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Named;
+
+public class FriendlyGreetings
+{
+ @Produces
+ @Named("friendly")
+ public Greetings getGreetings(InjectionPoint ip)
+ {
+ return () -> "Hello " + ip.getMember().getDeclaringClass().getSimpleName();
+ }
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/Greetings.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/Greetings.java
new file mode 100644
index 00000000000..425b65052b2
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/Greetings.java
@@ -0,0 +1,24 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.test;
+
+public interface Greetings
+{
+ String getGreeting();
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/GreetingsServlet.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/GreetingsServlet.java
new file mode 100644
index 00000000000..773ea5092d1
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/GreetingsServlet.java
@@ -0,0 +1,42 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.test;
+
+import java.io.IOException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@WebServlet("/greetings")
+public class GreetingsServlet extends HttpServlet
+{
+ @Inject
+ @Named("friendly")
+ public Greetings greetings;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
+ {
+ resp.setContentType("text/plain");
+ resp.getWriter().println("[" + greetings.getGreeting() + "]");
+ }
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/InfoServlet.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/InfoServlet.java
new file mode 100644
index 00000000000..7809857744e
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/InfoServlet.java
@@ -0,0 +1,52 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.test;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Set;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@WebServlet("/info")
+public class InfoServlet extends HttpServlet
+{
+ @Inject
+ BeanManager beanManager;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
+ {
+ resp.setContentType("text/plain");
+ resp.setCharacterEncoding("utf-8");
+
+ PrintWriter out = resp.getWriter();
+ out.println("Bean Manager: " + beanManager);
+ Set> beans = beanManager.getBeans("");
+ for (Bean> bean : beans)
+ {
+ out.println(" " + bean);
+ }
+ }
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ManifestServerID.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ManifestServerID.java
new file mode 100644
index 00000000000..421197d8a94
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ManifestServerID.java
@@ -0,0 +1,20 @@
+package org.eclipse.jetty.test;
+
+import javax.enterprise.inject.Produces;
+
+public class ManifestServerID
+{
+ @Produces
+ public ServerID getServerID()
+ {
+ return () ->
+ {
+ String implVersion = this.getClass().getPackage().getImplementationVersion();
+ if(implVersion == null)
+ implVersion = this.getClass().getPackage().getName();
+ if(implVersion == null)
+ implVersion = "unknown";
+ return "CDI-Demo-" + implVersion;
+ };
+ }
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/MyContextListener.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/MyContextListener.java
new file mode 100644
index 00000000000..ead2931610f
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/MyContextListener.java
@@ -0,0 +1,42 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.test;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.annotation.WebListener;
+
+@WebListener
+public class MyContextListener implements ServletContextListener
+{
+ @Inject
+ public ServerID serverId;
+
+ @Override
+ public void contextInitialized(ServletContextEvent sce)
+ {
+ sce.getServletContext().setAttribute("ServerID", serverId.get());
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce)
+ {
+ }
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/OldGreetings.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/OldGreetings.java
new file mode 100644
index 00000000000..e602ecb7b16
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/OldGreetings.java
@@ -0,0 +1,14 @@
+package org.eclipse.jetty.test;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+public class OldGreetings
+{
+ @Produces
+ @Named("old")
+ public Greetings getGreeting()
+ {
+ return () -> "Salutations!";
+ }
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ServerID.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ServerID.java
new file mode 100644
index 00000000000..5332a27ac46
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ServerID.java
@@ -0,0 +1,24 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.test;
+
+public interface ServerID
+{
+ String get();
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ServerIDFilter.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ServerIDFilter.java
new file mode 100644
index 00000000000..beee9d1562c
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ServerIDFilter.java
@@ -0,0 +1,57 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.test;
+
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * A Web Filter that doesn't use CDI.
+ */
+@WebFilter("/*")
+public class ServerIDFilter implements Filter
+{
+ @Override
+ public void init(FilterConfig filterConfig)
+ {
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
+ {
+ if (response instanceof HttpServletResponse)
+ {
+ String serverID = (String)request.getServletContext().getAttribute("ServerID");
+ ((HttpServletResponse)response).setHeader("Server", serverID);
+ }
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void destroy()
+ {
+ }
+}
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/resources/META-INF/beans.xml b/tests/test-webapps/test-cdi2-webapp/src/main/resources/META-INF/beans.xml
new file mode 100644
index 00000000000..7b838c91edd
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,8 @@
+
+
\ No newline at end of file
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/webapp/WEB-INF/jetty-env.xml b/tests/test-webapps/test-cdi2-webapp/src/main/webapp/WEB-INF/jetty-env.xml
new file mode 100644
index 00000000000..57bd8efa30d
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/webapp/WEB-INF/jetty-env.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+ BeanManager
+
+
+ javax.enterprise.inject.spi.BeanManager
+ org.jboss.weld.resources.ManagerObjectFactory
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/webapp/WEB-INF/web.xml b/tests/test-webapps/test-cdi2-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000000..1665f2146c7
--- /dev/null
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,17 @@
+
+
+ CDI Integration Test WebApp
+
+
+ org.jboss.weld.environment.servlet.Listener
+
+
+
+ Object factory for the CDI Bean Manager
+ BeanManager
+ javax.enterprise.inject.spi.BeanManager
+
+
From 715bbbb6a27cb88d5f8f5510a6afdbddac265fd9 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Wed, 5 Jun 2019 08:07:32 -0500
Subject: [PATCH 17/45] Issue #3731 - Adding CDI2 tests to test-distribution
Signed-off-by: Joakim Erdfelt
---
tests/test-distribution/pom.xml | 7 +
.../distribution/DistributionTester.java | 4 +-
.../jetty/tests/distribution/CDITests.java | 138 ++++++++++++++++++
.../src/test/resources/cdi/demo_context.xml | 24 +++
tests/test-webapps/test-cdi2-webapp/pom.xml | 18 +--
5 files changed, 175 insertions(+), 16 deletions(-)
create mode 100644 tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
create mode 100644 tests/test-distribution/src/test/resources/cdi/demo_context.xml
diff --git a/tests/test-distribution/pom.xml b/tests/test-distribution/pom.xml
index c26af378a94..9850dfba808 100644
--- a/tests/test-distribution/pom.xml
+++ b/tests/test-distribution/pom.xml
@@ -75,6 +75,13 @@
wartest
+
+ org.eclipse.jetty.tests
+ test-cdi2-webapp
+ ${project.version}
+ war
+ test
+ org.eclipse.jetty.toolchainjetty-test-helper
diff --git a/tests/test-distribution/src/main/java/org/eclipse/jetty/tests/distribution/DistributionTester.java b/tests/test-distribution/src/main/java/org/eclipse/jetty/tests/distribution/DistributionTester.java
index 27724f8b436..e0ee4502676 100644
--- a/tests/test-distribution/src/main/java/org/eclipse/jetty/tests/distribution/DistributionTester.java
+++ b/tests/test-distribution/src/main/java/org/eclipse/jetty/tests/distribution/DistributionTester.java
@@ -191,15 +191,17 @@ public class DistributionTester
*
* @param warFile the war file to install
* @param context the context path
+ * @return the path to the installed webapp exploded directory
* @throws IOException if the installation fails
*/
- public void installWarFile(File warFile, String context) throws IOException
+ public Path installWarFile(File warFile, String context) throws IOException
{
//webapps
Path webapps = config.jettyBase.resolve("webapps").resolve(context);
if (!Files.exists(webapps))
Files.createDirectories(webapps);
unzip(warFile, webapps.toFile());
+ return webapps;
}
/**
diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
new file mode 100644
index 00000000000..c614957b08e
--- /dev/null
+++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
@@ -0,0 +1,138 @@
+package org.eclipse.jetty.tests.distribution;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import org.eclipse.jetty.client.api.ContentResponse;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class CDITests extends AbstractDistributionTest
+{
+ /**
+ * Tests a WAR file that is CDI complete as it includes the weld
+ * library in its WEB-INF/lib directory.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCDI2_IncludedInWebapp() throws Exception
+ {
+ String jettyVersion = System.getProperty("jettyVersion");
+ DistributionTester distribution = DistributionTester.Builder.newInstance()
+ .jettyVersion(jettyVersion)
+ .mavenLocalRepository(System.getProperty("mavenRepoPath"))
+ .build();
+
+ String[] args1 = {
+ "--create-startd",
+ "--approve-all-licenses",
+ "--add-to-start=http,deploy,annotations,jsp"
+ };
+ try (DistributionTester.Run run1 = distribution.start(args1))
+ {
+ assertTrue(run1.awaitFor(5, TimeUnit.SECONDS));
+ assertEquals(0, run1.getExitValue());
+
+ File war = distribution.resolveArtifact("org.eclipse.jetty.tests:test-cdi2-webapp:war:" + jettyVersion);
+ distribution.installWarFile(war, "demo");
+
+ distribution.installBaseResource("cdi/demo_context.xml", "webapps/demo.xml");
+
+ int port = distribution.freePort();
+ try (DistributionTester.Run run2 = distribution.start("jetty.http.port=" + port))
+ {
+ assertTrue(run2.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS));
+
+ startHttpClient();
+ ContentResponse response = client.GET("http://localhost:" + port + "/demo/greetings");
+ assertEquals(HttpStatus.OK_200, response.getStatus());
+ // Confirm Servlet based CDI
+ assertThat(response.getContentAsString(), containsString("Hello GreetingsServlet"));
+ // Confirm Listener based CDI (this has been a problem in the past, keep this for regression testing!)
+ assertThat(response.getHeaders().get("Server"), containsString("CDI-Demo-org.eclipse.jetty.test"));
+
+ run2.stop();
+ assertTrue(run2.awaitFor(5, TimeUnit.SECONDS));
+ }
+ }
+ }
+
+ /**
+ * Tests a WAR file that is expects CDI to be provided by the server.
+ *
+ *
+ * This means the WAR does NOT have the weld libs in its
+ * WEB-INF/lib directory.
+ *
+ *
+ *
+ * The expectation is that CDI2 is provided by weld
+ * and the javax.el support comes from JSP
+ *
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testCDI2_ProvidedByServer() throws Exception
+ {
+ String jettyVersion = System.getProperty("jettyVersion");
+ DistributionTester distribution = DistributionTester.Builder.newInstance()
+ .jettyVersion(jettyVersion)
+ .mavenLocalRepository(System.getProperty("mavenRepoPath"))
+ .build();
+
+ String[] args1 = {
+ "--create-startd",
+ "--approve-all-licenses",
+ // standard entries
+ "--add-to-start=http,deploy,annotations",
+ // cdi2 specific entry (should transitively pull in what it needs, the user should not be expected to know the transitive entries)
+ "--add-to-start=cdi2"
+ };
+ try (DistributionTester.Run run1 = distribution.start(args1))
+ {
+ assertTrue(run1.awaitFor(5, TimeUnit.SECONDS));
+ assertEquals(0, run1.getExitValue());
+
+ File war = distribution.resolveArtifact("org.eclipse.jetty.tests:test-cdi2-webapp:war:" + jettyVersion);
+ Path demoDir = distribution.installWarFile(war, "demo");
+ // Remove weld libs
+ Path libDir = demoDir.resolve("WEB-INF/lib");
+ List weldLibs = Files.list(libDir).filter((path) -> path.getFileName().toString().contains("weld"))
+ .collect(Collectors.toList());
+ for (Path weldLib : weldLibs)
+ {
+ assertTrue(Files.deleteIfExists(weldLib));
+ }
+
+ distribution.installBaseResource("cdi/demo_context.xml", "webapps/demo.xml");
+
+ int port = distribution.freePort();
+ try (DistributionTester.Run run2 = distribution.start("jetty.http.port=" + port))
+ {
+ assertTrue(run2.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS));
+
+ startHttpClient();
+ ContentResponse response = client.GET("http://localhost:" + port + "/demo/greetings");
+ assertEquals(HttpStatus.OK_200, response.getStatus());
+ // Confirm Servlet based CDI
+ assertThat(response.getContentAsString(), containsString("Hello GreetingsServlet"));
+ // Confirm Listener based CDI (this has been a problem in the past, keep this for regression testing!)
+ assertThat(response.getHeaders().get("Server"), containsString("CDI-Demo-org.eclipse.jetty.test"));
+
+ run2.stop();
+ assertTrue(run2.awaitFor(5, TimeUnit.SECONDS));
+ }
+ }
+ }
+}
diff --git a/tests/test-distribution/src/test/resources/cdi/demo_context.xml b/tests/test-distribution/src/test/resources/cdi/demo_context.xml
new file mode 100644
index 00000000000..ed6a36f114e
--- /dev/null
+++ b/tests/test-distribution/src/test/resources/cdi/demo_context.xml
@@ -0,0 +1,24 @@
+
+
+
+
+ /demo
+ /demo/
+
+
+ -org.eclipse.jetty.util.Decorator
+
+
+ -org.eclipse.jetty.util.DecoratedObjectFactory
+
+
+ -org.eclipse.jetty.server.handler.ContextHandler.
+
+
+ -org.eclipse.jetty.server.handler.ContextHandler
+
+
+ -org.eclipse.jetty.servlet.ServletContextHandler
+
+
+
diff --git a/tests/test-webapps/test-cdi2-webapp/pom.xml b/tests/test-webapps/test-cdi2-webapp/pom.xml
index b5c53caa3c6..dec9d245562 100644
--- a/tests/test-webapps/test-cdi2-webapp/pom.xml
+++ b/tests/test-webapps/test-cdi2-webapp/pom.xml
@@ -29,31 +29,19 @@
javax.eljavax.el-api
+ 3.0.0
-
+
org.jboss.weld.servletweld-servlet${weld.version}
-
-
- org.eclipse.jetty
- jetty-annotations
- ${project.version}
- test
-
-
- org.eclipse.jetty
- jetty-client
- ${project.version}
- test
-
From c6e5371ea25bcb1380fbcc39f7304caa662ab53f Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Wed, 5 Jun 2019 08:08:56 -0500
Subject: [PATCH 18/45] Issue #3731 - Cleaning up test-cdi2-webapp to be the
minimal needed
Signed-off-by: Joakim Erdfelt
---
tests/test-webapps/test-cdi2-webapp/pom.xml | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/tests/test-webapps/test-cdi2-webapp/pom.xml b/tests/test-webapps/test-cdi2-webapp/pom.xml
index dec9d245562..7e59dafca22 100644
--- a/tests/test-webapps/test-cdi2-webapp/pom.xml
+++ b/tests/test-webapps/test-cdi2-webapp/pom.xml
@@ -26,17 +26,6 @@
javax.servlet-apiprovided
-
- javax.el
- javax.el-api
- 3.0.0
-
-
org.jboss.weld.servlet
From 4f82a23a7af384e9a22fde0fd851e57abe99b45c Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Wed, 5 Jun 2019 12:59:58 -0500
Subject: [PATCH 19/45] Issue #3731 - fixing license headers
---
.../jetty/tests/distribution/CDITests.java | 18 ++++++++++++++++++
.../eclipse/jetty/test/ManifestServerID.java | 18 ++++++++++++++++++
.../org/eclipse/jetty/test/OldGreetings.java | 18 ++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
index c614957b08e..7af2b30e4ca 100644
--- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
+++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
@@ -1,3 +1,21 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
package org.eclipse.jetty.tests.distribution;
import java.io.File;
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ManifestServerID.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ManifestServerID.java
index 421197d8a94..a0562311a92 100644
--- a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ManifestServerID.java
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/ManifestServerID.java
@@ -1,3 +1,21 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
package org.eclipse.jetty.test;
import javax.enterprise.inject.Produces;
diff --git a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/OldGreetings.java b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/OldGreetings.java
index e602ecb7b16..b9274880d9c 100644
--- a/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/OldGreetings.java
+++ b/tests/test-webapps/test-cdi2-webapp/src/main/java/org/eclipse/jetty/test/OldGreetings.java
@@ -1,3 +1,21 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
package org.eclipse.jetty.test;
import javax.enterprise.inject.Produces;
From 0d4aa4ea4945d8ab78836e99575ac5c98118eb72 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Thu, 6 Jun 2019 10:02:32 -0500
Subject: [PATCH 20/45] Issue #3731 - updating `cdi2` module expectations
Signed-off-by: Joakim Erdfelt
---
.../cdi-2/src/main/config/modules/cdi2.mod | 3 ++
.../jetty/tests/distribution/CDITests.java | 28 ++++++-------------
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/jetty-cdi/cdi-2/src/main/config/modules/cdi2.mod b/jetty-cdi/cdi-2/src/main/config/modules/cdi2.mod
index df6ee4135cd..2461212f798 100644
--- a/jetty-cdi/cdi-2/src/main/config/modules/cdi2.mod
+++ b/jetty-cdi/cdi-2/src/main/config/modules/cdi2.mod
@@ -6,6 +6,9 @@ Jetty setup to support Weld/CDI2 with WELD inside the webapp
[depend]
deploy
+[lib]
+lib/apache-jsp/org.mortbay.jasper.apache-el-*.jar
+
[xml]
etc/cdi2/jetty-cdi2.xml
diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
index 7af2b30e4ca..d4837a451de 100644
--- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
+++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java
@@ -19,11 +19,7 @@
package org.eclipse.jetty.tests.distribution;
import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.List;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpStatus;
@@ -86,22 +82,24 @@ public class CDITests extends AbstractDistributionTest
}
/**
- * Tests a WAR file that is expects CDI to be provided by the server.
+ * Tests a WAR file that is expects CDI to be configured by the server.
*
*
- * This means the WAR does NOT have the weld libs in its
+ * This means the WAR has the weld libs in its
* WEB-INF/lib directory.
*
*
*
- * The expectation is that CDI2 is provided by weld
- * and the javax.el support comes from JSP
+ * The expectation is that a context xml deployable file is not
+ * required when using this `cdi2` module, and the appropriate
+ * server side libs are made available to allow weld to function.
+ * (the required server side javax.el support comes from the cdi2 module)
*
*
* @throws Exception
*/
@Test
- public void testCDI2_ProvidedByServer() throws Exception
+ public void testCDI2_ConfiguredByServer() throws Exception
{
String jettyVersion = System.getProperty("jettyVersion");
DistributionTester distribution = DistributionTester.Builder.newInstance()
@@ -123,17 +121,7 @@ public class CDITests extends AbstractDistributionTest
assertEquals(0, run1.getExitValue());
File war = distribution.resolveArtifact("org.eclipse.jetty.tests:test-cdi2-webapp:war:" + jettyVersion);
- Path demoDir = distribution.installWarFile(war, "demo");
- // Remove weld libs
- Path libDir = demoDir.resolve("WEB-INF/lib");
- List weldLibs = Files.list(libDir).filter((path) -> path.getFileName().toString().contains("weld"))
- .collect(Collectors.toList());
- for (Path weldLib : weldLibs)
- {
- assertTrue(Files.deleteIfExists(weldLib));
- }
-
- distribution.installBaseResource("cdi/demo_context.xml", "webapps/demo.xml");
+ distribution.installWarFile(war, "demo");
int port = distribution.freePort();
try (DistributionTester.Run run2 = distribution.start("jetty.http.port=" + port))
From 5c74de8ab4c42779749742c5ca70c42adf9627f8 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Thu, 6 Jun 2019 11:33:21 -0500
Subject: [PATCH 21/45] Issue #3731 - Removing old CDI1 libs/modules
+ Moved remaining CDI2 module to top level /jetty-cdi/ (no need for
sub-modules anymore)
---
jetty-cdi/cdi-2/pom.xml | 36 ---
jetty-cdi/cdi-core/pom.xml | 71 -----
.../eclipse/jetty/cdi/core/AnyLiteral.java | 28 --
.../jetty/cdi/core/JettyLogFactory.java | 37 ---
.../eclipse/jetty/cdi/core/NamedLiteral.java | 46 ----
.../jetty/cdi/core/ScopedInstance.java | 45 ----
.../jetty/cdi/core/SimpleBeanStore.java | 95 -------
.../src/main/resources/META-INF/beans.xml | 6 -
.../jetty/cdi/core/AbstractWeldTest.java | 78 ------
.../jetty/cdi/core/NamedLiteralTest.java | 45 ----
.../cdi/core/logging/LeanConsoleHandler.java | 112 --------
.../jetty/cdi/core/logging/LogFactory.java | 33 ---
.../jetty/cdi/core/logging/Logging.java | 46 ----
.../src/test/resources/logging.properties | 2 -
jetty-cdi/cdi-full-servlet/pom.xml | 53 ----
jetty-cdi/cdi-servlet/pom.xml | 90 -------
.../src/main/config/etc/jetty-cdi.xml | 19 --
.../src/main/config/modules/cdi.mod | 7 -
.../src/main/config/modules/cdi1.mod | 39 ---
.../jetty/cdi/servlet/EmbeddedCdiHandler.java | 145 ----------
.../cdi/servlet/JettyWeldInitializer.java | 78 ------
.../cdi/servlet/WeldDeploymentBinding.java | 60 -----
.../org/eclipse/jetty/cdi/servlet/Dumper.java | 27 --
.../jetty/cdi/servlet/IsoTimeFormatter.java | 39 ---
.../cdi/servlet/LocaleTimeFormatter.java | 38 ---
.../jetty/cdi/servlet/RequestInfoServlet.java | 69 -----
.../cdi/servlet/RequestParamsDumper.java | 71 -----
.../jetty/cdi/servlet/TimeFormatter.java | 26 --
.../jetty/cdi/servlet/TimeServlet.java | 59 ----
.../cdi/servlet/WeldInitializationTest.java | 121 ---------
.../src/test/resources/META-INF/beans.xml | 6 -
.../test/resources/jetty-logging.properties | 11 -
.../src/test/resources/logging.properties | 2 -
jetty-cdi/cdi-websocket/pom.xml | 71 -----
.../websocket/AbstractContainerListener.java | 74 -----
.../JavaWebSocketSessionProducer.java | 57 ----
.../JettyWebSocketSessionProducer.java | 56 ----
.../websocket/WebSocketCdiInitializer.java | 71 -----
.../cdi/websocket/WebSocketCdiListener.java | 138 ----------
.../cdi/websocket/WebSocketScopeContext.java | 231 ----------------
.../websocket/WebSocketScopeExtension.java | 75 ------
.../websocket/annotation/WebSocketScope.java | 46 ----
.../src/main/resources/META-INF/beans.xml | 4 -
.../javax.enterprise.inject.spi.Extension | 1 -
.../javax.servlet.ServletContainerInitializer | 1 -
.../jetty/cdi/websocket/CheckSocket.java | 99 -------
.../cdi/websocket/basicapp/BasicAppTest.java | 130 ---------
.../cdi/websocket/basicapp/EchoSocket.java | 57 ----
.../jetty/cdi/websocket/basicscope/Food.java | 100 -------
.../jetty/cdi/websocket/basicscope/Meal.java | 40 ---
.../websocket/basicscope/ScopeBasicsTest.java | 97 -------
.../cdi/websocket/cdiapp/CdiAppTest.java | 185 -------------
.../jetty/cdi/websocket/cdiapp/DataMaker.java | 43 ---
.../cdi/websocket/cdiapp/EchoSocket.java | 57 ----
.../cdi/websocket/cdiapp/InfoSocket.java | 94 -------
.../cdi/websocket/wsscope/BogusSession.java | 150 -----------
.../cdi/websocket/wsscope/BogusSocket.java | 36 ---
.../jetty/cdi/websocket/wsscope/Food.java | 119 --------
.../jetty/cdi/websocket/wsscope/Meal.java | 40 ---
.../wsscope/WebSocketScopeBaselineTest.java | 131 ---------
.../wsscope/WebSocketScopeSessionTest.java | 253 ------------------
.../src/test/resources/META-INF/beans.xml | 6 -
.../test/resources/jetty-logging.properties | 15 --
.../src/test/resources/logging.properties | 2 -
jetty-cdi/pom.xml | 42 +--
.../src/main/config/etc/cdi2/jetty-cdi2.xml | 0
.../main/config/etc/cdi2/jetty-web-cdi2.xml | 0
.../src/main/config/modules/cdi2.mod | 0
jetty-cdi/test-cdi-it/pom.xml | 204 --------------
.../java/org/eclipse/jetty/tests/HelloIT.java | 41 ---
.../org/eclipse/jetty/tests/ServerInfoIT.java | 47 ----
.../eclipse/jetty/tests/ws/SessionInfoIT.java | 106 --------
.../test/resources/jetty-logging.properties | 10 -
.../src/test/scripts/setup-jetty.sh | 19 --
.../src/test/scripts/start-jetty.sh | 17 --
.../src/test/scripts/stop-jetty.sh | 11 -
jetty-cdi/test-cdi-webapp/pom.xml | 87 ------
.../src/assembly/with-weld.xml | 31 ---
.../org/eclipse/jetty/tests/HelloServlet.java | 42 ---
.../jetty/tests/ServerInfoServlet.java | 54 ----
.../eclipse/jetty/tests/logging/JULog.java | 47 ----
.../jetty/tests/logging/JULogFactory.java | 31 ---
.../jetty/tests/ws/SessionInfoSocket.java | 98 -------
.../src/main/webapp/WEB-INF/beans.xml | 0
.../src/main/webapp/WEB-INF/web.xml | 18 --
85 files changed, 27 insertions(+), 4997 deletions(-)
delete mode 100644 jetty-cdi/cdi-2/pom.xml
delete mode 100644 jetty-cdi/cdi-core/pom.xml
delete mode 100644 jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/AnyLiteral.java
delete mode 100644 jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/JettyLogFactory.java
delete mode 100644 jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/NamedLiteral.java
delete mode 100644 jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/ScopedInstance.java
delete mode 100644 jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/SimpleBeanStore.java
delete mode 100644 jetty-cdi/cdi-core/src/main/resources/META-INF/beans.xml
delete mode 100644 jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/AbstractWeldTest.java
delete mode 100644 jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/NamedLiteralTest.java
delete mode 100644 jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/LeanConsoleHandler.java
delete mode 100644 jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/LogFactory.java
delete mode 100644 jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/Logging.java
delete mode 100644 jetty-cdi/cdi-core/src/test/resources/logging.properties
delete mode 100644 jetty-cdi/cdi-full-servlet/pom.xml
delete mode 100644 jetty-cdi/cdi-servlet/pom.xml
delete mode 100644 jetty-cdi/cdi-servlet/src/main/config/etc/jetty-cdi.xml
delete mode 100644 jetty-cdi/cdi-servlet/src/main/config/modules/cdi.mod
delete mode 100644 jetty-cdi/cdi-servlet/src/main/config/modules/cdi1.mod
delete mode 100644 jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java
delete mode 100644 jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/JettyWeldInitializer.java
delete mode 100644 jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/WeldDeploymentBinding.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/Dumper.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/IsoTimeFormatter.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/LocaleTimeFormatter.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/RequestInfoServlet.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/RequestParamsDumper.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/TimeFormatter.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/TimeServlet.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java
delete mode 100644 jetty-cdi/cdi-servlet/src/test/resources/META-INF/beans.xml
delete mode 100644 jetty-cdi/cdi-servlet/src/test/resources/jetty-logging.properties
delete mode 100644 jetty-cdi/cdi-servlet/src/test/resources/logging.properties
delete mode 100644 jetty-cdi/cdi-websocket/pom.xml
delete mode 100644 jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/AbstractContainerListener.java
delete mode 100644 jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/JavaWebSocketSessionProducer.java
delete mode 100644 jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/JettyWebSocketSessionProducer.java
delete mode 100644 jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketCdiInitializer.java
delete mode 100644 jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketCdiListener.java
delete mode 100644 jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketScopeContext.java
delete mode 100644 jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketScopeExtension.java
delete mode 100644 jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/annotation/WebSocketScope.java
delete mode 100644 jetty-cdi/cdi-websocket/src/main/resources/META-INF/beans.xml
delete mode 100644 jetty-cdi/cdi-websocket/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
delete mode 100644 jetty-cdi/cdi-websocket/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/CheckSocket.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicapp/BasicAppTest.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicapp/EchoSocket.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/Food.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/Meal.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/ScopeBasicsTest.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/CdiAppTest.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/DataMaker.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/EchoSocket.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/InfoSocket.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/BogusSession.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/BogusSocket.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/Food.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/Meal.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/WebSocketScopeBaselineTest.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/WebSocketScopeSessionTest.java
delete mode 100644 jetty-cdi/cdi-websocket/src/test/resources/META-INF/beans.xml
delete mode 100644 jetty-cdi/cdi-websocket/src/test/resources/jetty-logging.properties
delete mode 100644 jetty-cdi/cdi-websocket/src/test/resources/logging.properties
rename jetty-cdi/{cdi-2 => }/src/main/config/etc/cdi2/jetty-cdi2.xml (100%)
rename jetty-cdi/{cdi-2 => }/src/main/config/etc/cdi2/jetty-web-cdi2.xml (100%)
rename jetty-cdi/{cdi-2 => }/src/main/config/modules/cdi2.mod (100%)
delete mode 100644 jetty-cdi/test-cdi-it/pom.xml
delete mode 100644 jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/HelloIT.java
delete mode 100644 jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/ServerInfoIT.java
delete mode 100644 jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/ws/SessionInfoIT.java
delete mode 100644 jetty-cdi/test-cdi-it/src/test/resources/jetty-logging.properties
delete mode 100755 jetty-cdi/test-cdi-it/src/test/scripts/setup-jetty.sh
delete mode 100755 jetty-cdi/test-cdi-it/src/test/scripts/start-jetty.sh
delete mode 100755 jetty-cdi/test-cdi-it/src/test/scripts/stop-jetty.sh
delete mode 100644 jetty-cdi/test-cdi-webapp/pom.xml
delete mode 100644 jetty-cdi/test-cdi-webapp/src/assembly/with-weld.xml
delete mode 100644 jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/HelloServlet.java
delete mode 100644 jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ServerInfoServlet.java
delete mode 100644 jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULog.java
delete mode 100644 jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULogFactory.java
delete mode 100644 jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ws/SessionInfoSocket.java
delete mode 100644 jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/beans.xml
delete mode 100644 jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/web.xml
diff --git a/jetty-cdi/cdi-2/pom.xml b/jetty-cdi/cdi-2/pom.xml
deleted file mode 100644
index 1ee75b45a06..00000000000
--- a/jetty-cdi/cdi-2/pom.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
- org.eclipse.jetty.cdi
- jetty-cdi-parent
- 9.4.20-SNAPSHOT
-
- 4.0.0
- cdi-2
- Jetty :: CDI 2
- http://www.eclipse.org/jetty
- jar
-
- ${project.groupId}.cdi2
-
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
-
-
- package
-
- single
-
-
-
- config
-
-
-
-
-
-
-
-
diff --git a/jetty-cdi/cdi-core/pom.xml b/jetty-cdi/cdi-core/pom.xml
deleted file mode 100644
index eed27ed07fa..00000000000
--- a/jetty-cdi/cdi-core/pom.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
- org.eclipse.jetty.cdi
- jetty-cdi-parent
- 9.4.20-SNAPSHOT
-
- 4.0.0
- cdi-core
- Jetty :: CDI :: Core
-
- Core CDI routines for Jetty (Also useful for CDI/SE applications that dont need a server)
-
- http://www.eclipse.org/jetty
- jar
-
- ${project.groupId}.core
-
-
-
-
- org.eclipse.jetty
- jetty-util
- ${project.version}
-
-
- javax.enterprise
- cdi-api
- 1.2
-
-
- javax.el
- javax.el-api
-
-
-
-
- org.jboss.weld
- weld-core
- ${weld.version}
- test
-
-
- org.jboss.weld.se
- weld-se-core
- ${weld.version}
- test
-
-
- org.eclipse.jetty.toolchain
- jetty-test-helper
- test
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
-
-
- tests-jar
-
- test-jar
-
-
-
-
-
-
-
diff --git a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/AnyLiteral.java b/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/AnyLiteral.java
deleted file mode 100644
index 54d4f10eb57..00000000000
--- a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/AnyLiteral.java
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core;
-
-import javax.enterprise.inject.Any;
-import javax.enterprise.util.AnnotationLiteral;
-
-@SuppressWarnings("serial")
-public class AnyLiteral extends AnnotationLiteral
-{
- public static final AnyLiteral INSTANCE = new AnyLiteral();
-}
diff --git a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/JettyLogFactory.java b/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/JettyLogFactory.java
deleted file mode 100644
index aaeddb98446..00000000000
--- a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/JettyLogFactory.java
+++ /dev/null
@@ -1,37 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core;
-
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-
-/**
- * CDI Producer of Jetty Logging instances.
- */
-public class JettyLogFactory
-{
- @Produces
- public Logger createLogger(InjectionPoint injectionPoint)
- {
- return Log.getLogger(injectionPoint.getMember().getDeclaringClass());
- }
-}
diff --git a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/NamedLiteral.java b/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/NamedLiteral.java
deleted file mode 100644
index 9b1584c62db..00000000000
--- a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/NamedLiteral.java
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core;
-
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Named;
-
-@SuppressWarnings("serial")
-public class NamedLiteral extends AnnotationLiteral implements Named
-{
- private final String value;
-
- @Override
- public String value()
- {
- return value;
- }
-
- public NamedLiteral(String name)
- {
- if (name == null)
- {
- this.value = "";
- }
- else
- {
- this.value = name;
- }
- }
-}
diff --git a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/ScopedInstance.java b/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/ScopedInstance.java
deleted file mode 100644
index 1b51d8823f9..00000000000
--- a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/ScopedInstance.java
+++ /dev/null
@@ -1,45 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-
-public class ScopedInstance
-{
- public Bean bean;
- public CreationalContext creationalContext;
- public T instance;
-
- public void destroy()
- {
- bean.destroy(instance,creationalContext);
- }
-
- @Override
- public String toString()
- {
- StringBuilder s = new StringBuilder();
- s.append("ScopedInstance[");
- s.append(bean);
- s.append(',').append(creationalContext);
- s.append(']');
- return s.toString();
- }
-}
diff --git a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/SimpleBeanStore.java b/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/SimpleBeanStore.java
deleted file mode 100644
index 2b3616022fe..00000000000
--- a/jetty-cdi/cdi-core/src/main/java/org/eclipse/jetty/cdi/core/SimpleBeanStore.java
+++ /dev/null
@@ -1,95 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.enterprise.context.spi.Contextual;
-
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-
-@Deprecated
-public class SimpleBeanStore
-{
- private static final Logger LOG = Log.getLogger(SimpleBeanStore.class);
-
- public Map, List>> beans = new HashMap<>();
-
- public void addBean(ScopedInstance> instance)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("addBean({})",instance);
- }
- List> instances = getBeans(instance.bean);
- if (instances == null)
- {
- instances = new ArrayList<>();
- beans.put(instance.bean,instances);
- }
- instances.add(instance);
- }
-
- public void clear()
- {
- beans.clear();
- }
-
- public void destroy()
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("destroy() - {} beans",beans.size());
- }
- for (List> instances : beans.values())
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("destroying - {} instance(s)",instances.size());
- }
- for (ScopedInstance> instance : instances)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("destroying instance {}",instance);
- }
- instance.destroy();
- }
- }
- }
-
- public List> getBeans(Contextual> contextual)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("getBeans({})",contextual);
- }
- return beans.get(contextual);
- }
-
- @Override
- public String toString()
- {
- return String.format("%s@%X[size=%d]",this.getClass().getSimpleName(),hashCode(),beans.size());
- }
-}
diff --git a/jetty-cdi/cdi-core/src/main/resources/META-INF/beans.xml b/jetty-cdi/cdi-core/src/main/resources/META-INF/beans.xml
deleted file mode 100644
index f158a71b6e5..00000000000
--- a/jetty-cdi/cdi-core/src/main/resources/META-INF/beans.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
\ No newline at end of file
diff --git a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/AbstractWeldTest.java b/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/AbstractWeldTest.java
deleted file mode 100644
index c71967763de..00000000000
--- a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/AbstractWeldTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core;
-
-import java.util.Set;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-
-import org.jboss.weld.environment.se.Weld;
-import org.jboss.weld.environment.se.WeldContainer;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-
-public abstract class AbstractWeldTest
-{
- public static class TestBean
- {
- public Bean bean;
- public CreationalContext cCtx;
- public T instance;
-
- public void destroy()
- {
- bean.destroy(instance,cCtx);
- }
- }
-
- @BeforeAll
- public static void initWeld()
- {
- weld = new Weld();
- container = weld.initialize();
- }
-
- @AfterAll
- public static void shutdownWeld()
- {
- weld.shutdown();
- }
-
- private static WeldContainer container;
- private static Weld weld;
-
- @SuppressWarnings("unchecked")
- public TestBean newInstance(Class clazz) throws Exception
- {
- TestBean testBean = new TestBean<>();
- Set> beans = container.getBeanManager().getBeans(clazz,AnyLiteral.INSTANCE);
- if (beans.size() > 0)
- {
- testBean.bean = (Bean)beans.iterator().next();
- testBean.cCtx = container.getBeanManager().createCreationalContext(testBean.bean);
- testBean.instance = (T)container.getBeanManager().getReference(testBean.bean,clazz,testBean.cCtx);
- return testBean;
- }
- else
- {
- throw new Exception(String.format("Can't find class %s",clazz));
- }
- }
-}
diff --git a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/NamedLiteralTest.java b/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/NamedLiteralTest.java
deleted file mode 100644
index 82f09de8d47..00000000000
--- a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/NamedLiteralTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-/**
- * Unit tests for class {@link NamedLiteral}.
- *
- * @see NamedLiteral
- */
-public class NamedLiteralTest
-{
-
- @Test
- public void testCreatesNamedLiteralWithNull()
- {
- assertEquals("", new NamedLiteral(null).value());
- }
-
- @Test
- public void testGetValue()
- {
- assertEquals("a b", new NamedLiteral("a b").value());
- }
-
-}
diff --git a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/LeanConsoleHandler.java b/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/LeanConsoleHandler.java
deleted file mode 100644
index 1941aeb23dc..00000000000
--- a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/LeanConsoleHandler.java
+++ /dev/null
@@ -1,112 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core.logging;
-
-import java.text.MessageFormat;
-import java.util.ResourceBundle;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.regex.Pattern;
-
-public class LeanConsoleHandler extends Handler
-{
- public static Handler createWithLevel(Level level)
- {
- LeanConsoleHandler handler = new LeanConsoleHandler();
- handler.setLevel(level);
- return handler;
- }
-
- @Override
- public void close() throws SecurityException
- {
- /* nothing to do here */
- }
-
- @Override
- public void flush()
- {
- /* nothing to do here */
- }
-
- public synchronized String formatMessage(LogRecord record)
- {
- String msg = getMessage(record);
-
- try
- {
- Object params[] = record.getParameters();
- if ((params == null) || (params.length == 0))
- {
- return msg;
- }
-
- if (Pattern.compile("\\{\\d+\\}").matcher(msg).find())
- {
- return MessageFormat.format(msg,params);
- }
-
- return msg;
- }
- catch (Exception ex)
- {
- return msg;
- }
- }
-
- private String getMessage(LogRecord record)
- {
- ResourceBundle bundle = record.getResourceBundle();
- if (bundle != null)
- {
- try
- {
- return bundle.getString(record.getMessage());
- }
- catch (java.util.MissingResourceException ex)
- {
- }
- }
-
- return record.getMessage();
- }
-
- @Override
- public void publish(LogRecord record)
- {
- StringBuilder buf = new StringBuilder();
- buf.append("[").append(record.getLevel().getName()).append("] ");
- String logname = record.getLoggerName();
- int idx = logname.lastIndexOf('.');
- if (idx > 0)
- {
- logname = logname.substring(idx + 1);
- }
- buf.append(logname);
- buf.append(": ");
- buf.append(formatMessage(record));
-
- System.out.println(buf.toString());
- if (record.getThrown() != null)
- {
- record.getThrown().printStackTrace(System.out);
- }
- }
-}
diff --git a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/LogFactory.java b/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/LogFactory.java
deleted file mode 100644
index 040fcfcdb26..00000000000
--- a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/LogFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core.logging;
-
-import java.util.logging.Logger;
-
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-public class LogFactory
-{
- @Produces
- public Logger createLogger(InjectionPoint injectionPoint)
- {
- return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
- }
-}
diff --git a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/Logging.java b/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/Logging.java
deleted file mode 100644
index 55181c487a0..00000000000
--- a/jetty-cdi/cdi-core/src/test/java/org/eclipse/jetty/cdi/core/logging/Logging.java
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.core.logging;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.logging.LogManager;
-
-public class Logging
-{
- public static void config()
- {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- URL url = cl.getResource("logging.properties");
- if (url != null)
- {
- try (InputStream in = url.openStream())
- {
- LogManager.getLogManager().readConfiguration(in);
- }
- catch (IOException e)
- {
- e.printStackTrace(System.err);
- }
- }
-
- System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.Jdk14Logger");
- }
-}
diff --git a/jetty-cdi/cdi-core/src/test/resources/logging.properties b/jetty-cdi/cdi-core/src/test/resources/logging.properties
deleted file mode 100644
index c0ff63eb82c..00000000000
--- a/jetty-cdi/cdi-core/src/test/resources/logging.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-handlers = org.eclipse.jetty.cdi.core.logging.LeanConsoleHandler
-.level=INFO
diff --git a/jetty-cdi/cdi-full-servlet/pom.xml b/jetty-cdi/cdi-full-servlet/pom.xml
deleted file mode 100644
index ff2fe9fce62..00000000000
--- a/jetty-cdi/cdi-full-servlet/pom.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
- org.eclipse.jetty.cdi
- jetty-cdi-parent
- 9.4.20-SNAPSHOT
-
- 4.0.0
- cdi-full-servlet
- Jetty :: CDI :: Dependencies
- http://www.eclipse.org/jetty
- pom
-
- 2.2.9.Final
-
-
-
-
- org.eclipse.jetty.cdi
- cdi-servlet
- ${project.version}
-
-
-
- javax.annotation
- javax.annotation-api
- 1.2
-
-
- org.mortbay.jasper
- apache-jsp
- ${jsp.version}
-
-
-
diff --git a/jetty-cdi/cdi-servlet/pom.xml b/jetty-cdi/cdi-servlet/pom.xml
deleted file mode 100644
index 3cd76d30529..00000000000
--- a/jetty-cdi/cdi-servlet/pom.xml
+++ /dev/null
@@ -1,90 +0,0 @@
-
-
- org.eclipse.jetty.cdi
- jetty-cdi-parent
- 9.4.20-SNAPSHOT
-
- 4.0.0
- cdi-servlet
- Jetty :: CDI :: Servlet
- http://www.eclipse.org/jetty
- jar
-
- 2.2.9.Final
- ${project.groupId}.servlet
-
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
-
-
- package
-
- single
-
-
-
- config
-
-
-
-
-
-
-
-
-
-
- org.eclipse.jetty.cdi
- cdi-core
- ${project.version}
-
-
- org.eclipse.jetty
- jetty-plus
- ${project.version}
-
-
- org.eclipse.jetty
- jetty-deploy
- ${project.version}
-
-
- org.jboss.weld.servlet
- weld-servlet-core
- ${weld.version}
-
-
- javax.el
- javax.el-api
-
-
- org.jboss.spec.javax.el
- jboss-el-api_3.0_spec
-
-
- org.jboss.spec.javax.annotation
- jboss-annotations-api_1.2_spec
-
-
- org.jboss.spec.javax.interceptor
- jboss-interceptors-api_1.2_spec
-
-
-
-
-
- org.eclipse.jetty
- apache-jsp
- ${project.version}
- test
-
-
- org.eclipse.jetty.toolchain
- jetty-test-helper
- test
-
-
-
diff --git a/jetty-cdi/cdi-servlet/src/main/config/etc/jetty-cdi.xml b/jetty-cdi/cdi-servlet/src/main/config/etc/jetty-cdi.xml
deleted file mode 100644
index 79ebdaee517..00000000000
--- a/jetty-cdi/cdi-servlet/src/main/config/etc/jetty-cdi.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/jetty-cdi/cdi-servlet/src/main/config/modules/cdi.mod b/jetty-cdi/cdi-servlet/src/main/config/modules/cdi.mod
deleted file mode 100644
index 26262df8dd4..00000000000
--- a/jetty-cdi/cdi-servlet/src/main/config/modules/cdi.mod
+++ /dev/null
@@ -1,7 +0,0 @@
-DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
-
-[description]
-Experimental CDI/Weld integration
-
-[depend]
-cdi1
diff --git a/jetty-cdi/cdi-servlet/src/main/config/modules/cdi1.mod b/jetty-cdi/cdi-servlet/src/main/config/modules/cdi1.mod
deleted file mode 100644
index c2deb6124f3..00000000000
--- a/jetty-cdi/cdi-servlet/src/main/config/modules/cdi1.mod
+++ /dev/null
@@ -1,39 +0,0 @@
-DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
-
-[description]
-Experimental CDI/Weld integration
-Deprecated in favour of cdi2 module.
-
-[depend]
-deploy
-annotations
-plus
-# JSP (and EL) are requirements for CDI and Weld
-jsp
-
-[files]
-lib/cdi/
-maven://javax.enterprise/cdi-api/1.2|lib/cdi/javax.enterprise.cdi-api-1.2.jar
-maven://javax.interceptor/javax.interceptor-api/1.2|lib/cdi/javax.interceptor-api-1.2.jar
-maven://javax.inject/javax.inject/1|lib/cdi/javax.inject-1.0.jar
-maven://org.jboss.weld.servlet/weld-servlet-core/2.4.3.Final|lib/cdi/weld-servlet-core-2.4.3.Final.jar
-maven://org.jboss.weld.environment/weld-environment-common/2.4.3.Final|lib/cdi/weld-environment-common-2.4.3.Final.jar
-maven://org.jboss.weld/weld-core-impl/2.4.3.Final|lib/cdi/weld-core-impl-2.4.3.Final.jar
-maven://org.jboss.classfilewriter/jboss-classfilewriter/1.1.2.Final|lib/cdi/jboss-classfilewriter-1.1.2.Final.jar
-maven://org.jboss.weld/weld-spi/2.4.SP1|lib/cdi/weld-spi-2.4.SP1.jar
-maven://org.jboss.weld/weld-api/2.4.SP1|lib/cdi/weld-api-2.4.SP1.jar
-maven://org.jboss.logging/jboss-logging/3.2.1.Final|lib/cdi/jboss-logging-3.2.1.Final.jar
-
-
-[lib]
-lib/cdi/*.jar
-lib/cdi-core-${jetty.version}.jar
-lib/cdi-servlet-${jetty.version}.jar
-
-[xml]
-etc/jetty-cdi.xml
-
-[license]
-Weld is an open source project hosted on Github and released under the Apache 2.0 license.
-http://weld.cdi-spec.org/
-http://www.apache.org/licenses/LICENSE-2.0.html
diff --git a/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java b/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java
deleted file mode 100644
index 600a219ff84..00000000000
--- a/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java
+++ /dev/null
@@ -1,145 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Set;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpSessionActivationListener;
-import javax.servlet.http.HttpSessionAttributeListener;
-import javax.servlet.http.HttpSessionBindingListener;
-import javax.servlet.http.HttpSessionIdListener;
-import javax.servlet.http.HttpSessionListener;
-
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.util.resource.Resource;
-import org.jboss.weld.environment.servlet.EnhancedListener;
-
-/**
- * Handy {@link ServletContextHandler} implementation that hooks up
- * all of the various CDI related components and listeners from Weld.
- */
-public class EmbeddedCdiHandler extends ServletContextHandler
-{
- private static final Logger LOG = Log.getLogger(EmbeddedCdiHandler.class);
-
- private static final String[] REQUIRED_BEANS_XML_PATHS = new String[] {
- "/WEB-INF/beans.xml",
- "/META-INF/beans.xml",
- "/WEB-INF/classes/META-INF/beans.xml"
- };
-
- public EmbeddedCdiHandler()
- {
- super();
- }
-
- public EmbeddedCdiHandler(int options)
- {
- super(options);
- }
-
- @Override
- protected void doStart() throws Exception
- {
- // Required of CDI
- Resource baseResource = getBaseResource();
- if (baseResource == null)
- {
- throw new NullPointerException("baseResource must be set (to so it can find the beans.xml)");
- }
-
- boolean foundBeansXml = false;
-
- // Verify that beans.xml is present, otherwise weld will fail silently.
- for(String beansXmlPath: REQUIRED_BEANS_XML_PATHS) {
- Resource res = baseResource.addPath(beansXmlPath);
- if (res == null)
- {
- // not found, skip it
- continue;
- }
-
- if (res.exists())
- {
- foundBeansXml = true;
- }
-
- if (res.isDirectory())
- {
- throw new IOException("Directory conflicts with expected file: " + res.getURI().toASCIIString());
- }
- }
-
- if (!foundBeansXml)
- {
- StringBuilder err = new StringBuilder();
- err.append("Unable to find required beans.xml from the baseResource: ");
- err.append(baseResource.getURI().toASCIIString()).append(System.lineSeparator());
- err.append("Searched for: ");
- for (String beansXmlPath : REQUIRED_BEANS_XML_PATHS)
- {
- err.append(System.lineSeparator());
- err.append(" ").append(beansXmlPath);
- }
- LOG.warn("ERROR: {}",err.toString());
- throw new IOException(err.toString());
- }
-
- // Initialize Weld
- JettyWeldInitializer.initContext(this);
-
- // Wire up Weld (what's usually done via the ServletContainerInitializer)
- ServletContext ctx = getServletContext();
-
- // Fake the call to ServletContainerInitializer
- ClassLoader orig = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(ctx.getClassLoader());
-
- EnhancedListener weldListener = new EnhancedListener();
- Set> classes = Collections.emptySet();
- weldListener.onStartup(classes,ctx);
-
- // add the rest of the Weld Listeners
- ctx.addListener(weldListener);
- if ((weldListener instanceof HttpSessionActivationListener)
- || (weldListener instanceof HttpSessionAttributeListener)
- || (weldListener instanceof HttpSessionBindingListener)
- || (weldListener instanceof HttpSessionListener)
- || (weldListener instanceof HttpSessionIdListener))
- {
- if (getSessionHandler() != null)
- getSessionHandler().addEventListener(weldListener);
- }
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(orig);
- }
-
- // Let normal ServletContextHandler startup continue its merry way
- super.doStart();
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/JettyWeldInitializer.java b/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/JettyWeldInitializer.java
deleted file mode 100644
index 4fe436559bc..00000000000
--- a/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/JettyWeldInitializer.java
+++ /dev/null
@@ -1,78 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import javax.naming.NamingException;
-import javax.naming.Reference;
-
-import org.eclipse.jetty.plus.jndi.Resource;
-import org.eclipse.jetty.server.handler.ContextHandler;
-import org.eclipse.jetty.webapp.ClasspathPattern;
-import org.eclipse.jetty.webapp.WebAppContext;
-
-/**
- * Utility class suitable for initializing CDI/Weld on Embedded Jetty
- */
-public class JettyWeldInitializer
-{
- /**
- * Initialize WebAppContext to support CDI/Weld.
- *
- * Initializes Context, then sets up WebAppContext system and server classes to allow Weld to operate from Server
- * level.
- *
- * Includes {@link #initContext(ContextHandler)} behavior as well.
- * @param webapp the webapp
- * @throws NamingException if unable to bind BeanManager context
- */
- public static void initWebApp(WebAppContext webapp) throws NamingException
- {
- initContext(webapp);
-
- // webapp cannot change / replace weld classes
- ClasspathPattern systemClasses = webapp.getSystemClasspathPattern();
- systemClasses.add("org.jboss.weld.");
- systemClasses.add("org.jboss.classfilewriter.");
- systemClasses.add("org.jboss.logging.");
- systemClasses.add("com.google.common.");
- systemClasses.add("org.eclipse.jetty.cdi.websocket.annotation.");
-
- // don't hide weld classes from webapps (allow webapp to use ones from system classloader)
- ClasspathPattern serverClasses = webapp.getServerClasspathPattern();
- serverClasses.add("-org.eclipse.jetty.cdi.websocket.annotation.");
- serverClasses.add("-org.eclipse.jetty.cdi.core.");
- serverClasses.add("-org.eclipse.jetty.cdi.servlet.");
- serverClasses.add("-org.jboss.weld.");
- serverClasses.add("-org.jboss.classfilewriter.");
- serverClasses.add("-org.jboss.logging.");
- serverClasses.add("-com.google.common.");
- }
-
- public static void initContext(ContextHandler handler) throws NamingException
- {
- // Add context specific weld container reference.
- // See https://issues.jboss.org/browse/WELD-1710
- // and https://github.com/weld/core/blob/2.2.5.Final/environments/servlet/core/src/main/java/org/jboss/weld/environment/servlet/WeldServletLifecycle.java#L244-L253
- handler.setInitParameter("org.jboss.weld.environment.container.class","org.jboss.weld.environment.jetty.JettyContainer");
-
- // Setup Weld BeanManager reference
- Reference ref = new Reference("javax.enterprise.inject.spi.BeanManager","org.jboss.weld.resources.ManagerObjectFactory",null);
- new Resource(handler,"BeanManager",ref);
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/WeldDeploymentBinding.java b/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/WeldDeploymentBinding.java
deleted file mode 100644
index 0502e35cc46..00000000000
--- a/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/WeldDeploymentBinding.java
+++ /dev/null
@@ -1,60 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import org.eclipse.jetty.deploy.App;
-import org.eclipse.jetty.deploy.AppLifeCycle;
-import org.eclipse.jetty.deploy.graph.Node;
-import org.eclipse.jetty.server.handler.ContextHandler;
-import org.eclipse.jetty.webapp.WebAppContext;
-
-/**
- * Perform some basic weld configuration of WebAppContext
- */
-@Deprecated
-public class WeldDeploymentBinding implements AppLifeCycle.Binding
-{
- @Override
- public String[] getBindingTargets()
- {
- return new String[] { "deploying" };
- }
-
- @Override
- public void processBinding(Node node, App app) throws Exception
- {
- ContextHandler handler = app.getContextHandler();
- if (handler == null)
- {
- throw new NullPointerException("No Handler created for App: " + app);
- }
-
- if (handler instanceof WebAppContext)
- {
- // Do webapp specific init
- WebAppContext webapp = (WebAppContext)handler;
- JettyWeldInitializer.initWebApp(webapp);
- }
- else
- {
- // Do general init
- JettyWeldInitializer.initContext(handler);
- }
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/Dumper.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/Dumper.java
deleted file mode 100644
index d78edac76d8..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/Dumper.java
+++ /dev/null
@@ -1,27 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-public interface Dumper
-{
- public void dump(PrintWriter out) throws IOException;
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/IsoTimeFormatter.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/IsoTimeFormatter.java
deleted file mode 100644
index 426275daba8..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/IsoTimeFormatter.java
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import javax.inject.Named;
-
-@Named("iso")
-public class IsoTimeFormatter implements TimeFormatter
-{
- @Override
- public String format(Calendar cal)
- {
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'",Locale.US);
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- return dateFormat.format(cal.getTime());
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/LocaleTimeFormatter.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/LocaleTimeFormatter.java
deleted file mode 100644
index e018ececbfa..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/LocaleTimeFormatter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-
-import javax.enterprise.inject.Default;
-import javax.inject.Named;
-
-@Named("locale")
-@Default
-public class LocaleTimeFormatter implements TimeFormatter
-{
- public static final TimeFormatter INSTANCE = new LocaleTimeFormatter();
-
- @Override
- public String format(Calendar cal)
- {
- return new SimpleDateFormat().format(cal.getTime());
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/RequestInfoServlet.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/RequestInfoServlet.java
deleted file mode 100644
index 9f99843f294..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/RequestInfoServlet.java
+++ /dev/null
@@ -1,69 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.cdi.core.NamedLiteral;
-
-@SuppressWarnings("serial")
-@WebServlet("/req-info")
-public class RequestInfoServlet extends HttpServlet
-{
- @Inject
- @Any
- private Instance dumpers;
-
- @Inject
- @Named("params")
- private Dumper defaultDumper;
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
- {
- resp.setContentType("text/plain");
- PrintWriter out = resp.getWriter();
-
- Dumper dumper = defaultDumper;
-
- String dumperId = req.getParameter("dumperId");
-
- if (dumperId != null)
- {
- Instance inst = dumpers.select(new NamedLiteral(dumperId));
- if (!inst.isAmbiguous() && !inst.isUnsatisfied())
- {
- dumper = inst.get();
- }
- }
-
- dumper.dump(out);
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/RequestParamsDumper.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/RequestParamsDumper.java
deleted file mode 100644
index 64818421f1d..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/RequestParamsDumper.java
+++ /dev/null
@@ -1,71 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.servlet.http.HttpServletRequest;
-
-@Named("params")
-@RequestScoped
-public class RequestParamsDumper implements Dumper
-{
- @Inject
- private HttpServletRequest request;
-
- @Override
- public void dump(PrintWriter out) throws IOException
- {
- out.printf("request is %s%n",request == null ? "NULL" : "PRESENT");
-
- if (request != null)
- {
- Map params = request.getParameterMap();
- List paramNames = new ArrayList<>();
- paramNames.addAll(params.keySet());
- Collections.sort(paramNames);
-
- out.printf("parameters.size = [%d]%n",params.size());
-
- for (String name : paramNames)
- {
- out.printf(" param[%s] = [",name);
- boolean delim = false;
- for (String val : params.get(name))
- {
- if (delim)
- {
- out.print(", ");
- }
- out.print(val);
- delim = true;
- }
- out.println("]");
- }
- }
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/TimeFormatter.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/TimeFormatter.java
deleted file mode 100644
index 909e7098d58..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/TimeFormatter.java
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import java.util.Calendar;
-
-public interface TimeFormatter
-{
- public String format(Calendar cal);
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/TimeServlet.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/TimeServlet.java
deleted file mode 100644
index 6af0cf6bd78..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/TimeServlet.java
+++ /dev/null
@@ -1,59 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import java.io.IOException;
-import java.util.Calendar;
-
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.cdi.core.NamedLiteral;
-
-@SuppressWarnings("serial")
-@WebServlet(urlPatterns = "/time")
-public class TimeServlet extends HttpServlet
-{
- @Inject
- @Any
- Instance formatters;
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
- {
- resp.setContentType("text/plain");
-
- String timeType = req.getParameter("type");
- TimeFormatter time = LocaleTimeFormatter.INSTANCE;
-
- Instance inst = formatters.select(new NamedLiteral(timeType));
- if (!inst.isAmbiguous() && !inst.isUnsatisfied())
- {
- time = inst.get();
- }
-
- resp.getWriter().println(time.format(Calendar.getInstance()));
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java
deleted file mode 100644
index 8fcbdef46fa..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.servlet;
-
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URI;
-
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
-import org.eclipse.jetty.util.IO;
-import org.eclipse.jetty.util.log.JettyLogHandler;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.util.resource.Resource;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class WeldInitializationTest
-{
- private static final Logger LOG = Log.getLogger(WeldInitializationTest.class);
- private static Server server;
- private static URI serverHttpURI;
-
- @BeforeAll
- public static void startServer() throws Exception
- {
- JettyLogHandler.config();
-
- server = new Server();
- ServerConnector connector = new ServerConnector(server);
- connector.setPort(0);
- server.addConnector(connector);
-
- EmbeddedCdiHandler context = new EmbeddedCdiHandler(ServletContextHandler.SESSIONS);
-
- File baseDir = MavenTestingUtils.getTestResourcesDir();
-
- context.setBaseResource(Resource.newResource(baseDir));
- context.setContextPath("/");
- server.setHandler(context);
-
- // Add some servlets
- context.addServlet(TimeServlet.class,"/time");
- context.addServlet(RequestInfoServlet.class,"/req-info");
-
- server.start();
-
- String host = connector.getHost();
- if (host == null)
- {
- host = "localhost";
- }
- int port = connector.getLocalPort();
- serverHttpURI = new URI(String.format("http://%s:%d/",host,port));
- }
-
- @AfterAll
- public static void stopServer()
- {
- try
- {
- server.stop();
- }
- catch (Exception e)
- {
- LOG.warn(e);
- }
- }
-
- @Test
- public void testRequestParamServletDefault() throws Exception
- {
- HttpURLConnection http = (HttpURLConnection) serverHttpURI.resolve("req-info").toURL().openConnection();
- assertThat("response code", http.getResponseCode(), is(200));
- try(InputStream inputStream = http.getInputStream())
- {
- String resp = IO.toString(inputStream);
- assertThat("Response", resp, containsString("request is PRESENT"));
- assertThat("Response", resp, containsString("parameters.size = [0]"));
- }
- }
-
- @Test
- public void testRequestParamServletAbc() throws Exception
- {
- HttpURLConnection http = (HttpURLConnection) serverHttpURI.resolve("req-info?abc=123").toURL().openConnection();
- assertThat("response code", http.getResponseCode(), is(200));
- try(InputStream inputStream = http.getInputStream())
- {
- String resp = IO.toString(inputStream);
- assertThat("Response", resp, containsString("request is PRESENT"));
- assertThat("Response", resp, containsString("parameters.size = [1]"));
- assertThat("Response", resp, containsString(" param[abc] = [123]"));
- }
- }
-}
diff --git a/jetty-cdi/cdi-servlet/src/test/resources/META-INF/beans.xml b/jetty-cdi/cdi-servlet/src/test/resources/META-INF/beans.xml
deleted file mode 100644
index f158a71b6e5..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/resources/META-INF/beans.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
\ No newline at end of file
diff --git a/jetty-cdi/cdi-servlet/src/test/resources/jetty-logging.properties b/jetty-cdi/cdi-servlet/src/test/resources/jetty-logging.properties
deleted file mode 100644
index aaf03af93a2..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/resources/jetty-logging.properties
+++ /dev/null
@@ -1,11 +0,0 @@
-org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
-# org.jboss.LEVEL=DEBUG
-org.eclipse.jetty.LEVEL=INFO
-
-# org.eclipse.jetty.util.DecoratedObjectFactory.LEVEL=DEBUG
-# org.eclipse.jetty.cdi.LEVEL=DEBUG
-
-# org.eclipse.jetty.LEVEL=DEBUG
-# org.eclipse.jetty.websocket.LEVEL=DEBUG
-# org.eclipse.jetty.websocket.client.LEVEL=DEBUG
-
diff --git a/jetty-cdi/cdi-servlet/src/test/resources/logging.properties b/jetty-cdi/cdi-servlet/src/test/resources/logging.properties
deleted file mode 100644
index cfec8c7ab58..00000000000
--- a/jetty-cdi/cdi-servlet/src/test/resources/logging.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-handlers = org.eclipse.jetty.util.log.JettyLogHandler
-.level=FINE
diff --git a/jetty-cdi/cdi-websocket/pom.xml b/jetty-cdi/cdi-websocket/pom.xml
deleted file mode 100644
index 7e313349d9e..00000000000
--- a/jetty-cdi/cdi-websocket/pom.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
- org.eclipse.jetty.cdi
- jetty-cdi-parent
- 9.4.20-SNAPSHOT
-
- 4.0.0
- cdi-websocket
- Jetty :: CDI :: WebSocket
- http://www.eclipse.org/jetty
- jar
-
- 2.2.9.Final
- ${project.groupId}.websocket
-
-
-
-
- org.eclipse.jetty.cdi
- cdi-core
- ${project.version}
-
-
- org.eclipse.jetty.websocket
- websocket-common
- ${project.version}
-
-
-
- org.eclipse.jetty
- apache-jsp
- ${project.version}
- test
-
-
- org.jboss.weld
- weld-core
- ${weld.version}
- test
-
-
- org.jboss.weld.se
- weld-se-core
- ${weld.version}
- test
-
-
- org.eclipse.jetty.cdi
- cdi-core
- ${project.version}
- tests
- test
-
-
- org.eclipse.jetty.cdi
- cdi-servlet
- ${project.version}
- test
-
-
- org.eclipse.jetty.websocket
- javax-websocket-server-impl
- ${project.version}
-
-
- org.eclipse.jetty.toolchain
- jetty-test-helper
- test
-
-
-
diff --git a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/AbstractContainerListener.java b/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/AbstractContainerListener.java
deleted file mode 100644
index b8586be0606..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/AbstractContainerListener.java
+++ /dev/null
@@ -1,74 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket;
-
-import org.eclipse.jetty.util.component.Container;
-import org.eclipse.jetty.util.component.LifeCycle;
-
-/**
- * Abstract implementation of listener that needs both Container events and LifeCycle events
- */
-@Deprecated
-public abstract class AbstractContainerListener implements LifeCycle.Listener, Container.InheritedListener
-{
- @Override
- public void beanAdded(Container parent, Object child)
- {
- if (child instanceof LifeCycle)
- {
- ((LifeCycle)child).addLifeCycleListener(this);
- }
- }
-
- @Override
- public void beanRemoved(Container parent, Object child)
- {
- if (child instanceof LifeCycle)
- {
- ((LifeCycle)child).removeLifeCycleListener(this);
- }
- }
-
- @Override
- public void lifeCycleFailure(LifeCycle event, Throwable cause)
- {
- }
-
- @Override
- public void lifeCycleStarted(LifeCycle event)
- {
- }
-
- @Override
- public void lifeCycleStarting(LifeCycle event)
- {
- }
-
- @Override
- public void lifeCycleStopped(LifeCycle event)
- {
-
- }
-
- @Override
- public void lifeCycleStopping(LifeCycle event)
- {
- }
-
-}
diff --git a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/JavaWebSocketSessionProducer.java b/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/JavaWebSocketSessionProducer.java
deleted file mode 100644
index 200f0b0ecf9..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/JavaWebSocketSessionProducer.java
+++ /dev/null
@@ -1,57 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket;
-
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.websocket.Session;
-
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-
-/**
- * Producer of {@link javax.websocket.Session} instances
- */
-@Deprecated
-public class JavaWebSocketSessionProducer
-{
- private static final Logger LOG = Log.getLogger(JavaWebSocketSessionProducer.class);
-
- @Produces
- public Session getSession(InjectionPoint injectionPoint)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("getSession({})",injectionPoint);
- }
- org.eclipse.jetty.websocket.api.Session sess = WebSocketScopeContext.current().getSession();
- if (sess == null)
- {
- throw new IllegalStateException("No Session Available");
- }
-
- if (sess instanceof javax.websocket.Session)
- {
- return (Session)sess;
- }
-
- throw new IllegalStateException("Incompatible Session, expected <" + javax.websocket.Session.class.getName() + ">, but got <"
- + sess.getClass().getName() + "> instead");
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/JettyWebSocketSessionProducer.java b/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/JettyWebSocketSessionProducer.java
deleted file mode 100644
index 7cdfafd93f7..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/JettyWebSocketSessionProducer.java
+++ /dev/null
@@ -1,56 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket;
-
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.websocket.api.Session;
-
-/**
- * Producer of {@link org.eclipse.jetty.websocket.api.Session} instances
- */
-@Deprecated
-public class JettyWebSocketSessionProducer
-{
- private static final Logger LOG = Log.getLogger(JettyWebSocketSessionProducer.class);
-
- @Produces
- public Session getSession(InjectionPoint injectionPoint)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("getSession({})",injectionPoint);
- }
- WebSocketScopeContext ctx = WebSocketScopeContext.current();
- if (ctx == null)
- {
- throw new IllegalStateException("Not in a " + WebSocketScope.class.getName());
- }
- org.eclipse.jetty.websocket.api.Session sess = ctx.getSession();
- if (sess == null)
- {
- throw new IllegalStateException("No Session Available");
- }
- return sess;
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketCdiInitializer.java b/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketCdiInitializer.java
deleted file mode 100644
index 9c8cbffc29c..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketCdiInitializer.java
+++ /dev/null
@@ -1,71 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket;
-
-import java.util.Set;
-
-import javax.servlet.ServletContainerInitializer;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
-import org.eclipse.jetty.server.handler.ContextHandler;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.util.component.ContainerLifeCycle;
-import org.eclipse.jetty.util.thread.ThreadClassLoaderScope;
-
-@Deprecated
-public class WebSocketCdiInitializer implements ServletContainerInitializer
-{
- public static void configureContext(ServletContextHandler context) throws ServletException
- {
- try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader()))
- {
- addListeners(context);
- }
- }
-
- @Override
- public void onStartup(Set> c, ServletContext context) throws ServletException
- {
- ContextHandler handler = ContextHandler.getContextHandler(context);
-
- if (handler == null)
- {
- throw new ServletException("Not running on Jetty, WebSocket+CDI support unavailable");
- }
-
- if (!(handler instanceof ServletContextHandler))
- {
- throw new ServletException("Not running in Jetty ServletContextHandler, WebSocket+CDI support unavailable");
- }
-
- ServletContextHandler jettyContext = (ServletContextHandler)handler;
- try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader()))
- {
- addListeners(jettyContext);
- }
- }
-
- private static void addListeners(ContainerLifeCycle container)
- {
- WebSocketCdiListener listener = new WebSocketCdiListener();
- container.addLifeCycleListener(listener);
- container.addEventListener(listener);
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketCdiListener.java b/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketCdiListener.java
deleted file mode 100644
index be7beb0f364..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketCdiListener.java
+++ /dev/null
@@ -1,138 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket;
-
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.CDI;
-
-import org.eclipse.jetty.cdi.core.AnyLiteral;
-import org.eclipse.jetty.cdi.core.ScopedInstance;
-import org.eclipse.jetty.util.component.ContainerLifeCycle;
-import org.eclipse.jetty.util.component.LifeCycle;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.websocket.api.Session;
-import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
-import org.eclipse.jetty.websocket.common.scopes.WebSocketSessionScope;
-
-@Deprecated
-public class WebSocketCdiListener extends AbstractContainerListener
-{
- static final Logger LOG = Log.getLogger(WebSocketCdiListener.class);
-
- @SuppressWarnings(
- { "rawtypes", "unchecked" })
- public static ScopedInstance newInstance(Class clazz)
- {
- BeanManager bm = CDI.current().getBeanManager();
-
- ScopedInstance sbean = new ScopedInstance();
- Set> beans = bm.getBeans(clazz,AnyLiteral.INSTANCE);
- if (!beans.isEmpty())
- {
- sbean.bean = beans.iterator().next();
- sbean.creationalContext = bm.createCreationalContext(sbean.bean);
- sbean.instance = bm.getReference(sbean.bean,clazz,sbean.creationalContext);
- return sbean;
- }
- else
- {
- throw new RuntimeException(String.format("Can't find class %s",clazz));
- }
- }
-
- public static class ContainerListener extends AbstractContainerListener
- {
- private static final Logger LOG = Log.getLogger(WebSocketCdiListener.ContainerListener.class);
- private final WebSocketContainerScope container;
- private final ScopedInstance wsScope;
-
- public ContainerListener(WebSocketContainerScope container)
- {
- this.container = container;
- this.wsScope = newInstance(WebSocketScopeContext.class);
- this.wsScope.instance.create();
- }
-
- @Override
- public void lifeCycleStarted(LifeCycle event)
- {
- if (event == container)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("starting websocket container [{}]",event);
- }
- wsScope.instance.begin();
- return;
- }
-
- if (event instanceof WebSocketSessionScope)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("starting websocket session [{}]",event);
- }
- wsScope.instance.setSession((Session)event);
- return;
- }
- }
-
- @Override
- public void lifeCycleStopped(LifeCycle event)
- {
- if (event == container)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("stopped websocket container [{}]",event);
- }
- this.wsScope.instance.end();
- this.wsScope.instance.destroy();
- this.wsScope.destroy();
- }
- }
- }
-
- @Override
- public void lifeCycleStarting(LifeCycle event)
- {
- if (event instanceof WebSocketContainerScope)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("started websocket container [{}]",event);
- }
- ContainerListener listener = new ContainerListener((WebSocketContainerScope)event);
- if (event instanceof ContainerLifeCycle)
- {
- ContainerLifeCycle container = (ContainerLifeCycle)event;
- container.addLifeCycleListener(listener);
- container.addEventListener(listener);
- }
- else
- {
- throw new RuntimeException("Unable to setup CDI against non-container: " + event.getClass().getName());
- }
- }
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketScopeContext.java b/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketScopeContext.java
deleted file mode 100644
index 64ab552e37b..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketScopeContext.java
+++ /dev/null
@@ -1,231 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket;
-
-import java.lang.annotation.Annotation;
-import java.util.List;
-import java.util.Set;
-
-import javax.enterprise.context.spi.Context;
-import javax.enterprise.context.spi.Contextual;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-
-import org.eclipse.jetty.cdi.core.AnyLiteral;
-import org.eclipse.jetty.cdi.core.ScopedInstance;
-import org.eclipse.jetty.cdi.core.SimpleBeanStore;
-import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.websocket.api.Session;
-
-/**
- * WebSocket Scope Context.
- *
- * A CDI Context definition for how CDI will use objects defined to belong to the WebSocketScope
- */
-@Deprecated
-public class WebSocketScopeContext implements Context
-{
- private static final Logger LOG = Log.getLogger(WebSocketScopeContext.class);
-
- private static ThreadLocal current = new ThreadLocal<>();
-
- public static WebSocketScopeContext current()
- {
- return current.get();
- }
-
- private SimpleBeanStore beanStore;
-
- @Inject
- private BeanManager beanManager;
-
- private ThreadLocal session = new ThreadLocal<>();
-
- public void begin()
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("{} begin()",this);
- }
- current.set(this);
- }
-
- public void create()
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("{} create()",this);
- }
- current.set(this);
- beanStore = new SimpleBeanStore();
- }
-
- public void destroy()
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("{} destroy()",this);
- }
-
- beanStore.destroy();
- }
-
- public void end()
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("{} end()",this);
- }
- beanStore.clear();
- }
-
- @SuppressWarnings({ "unchecked" })
- @Override
- public T get(Contextual contextual)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("{} get({})",this,contextual);
- }
-
- Bean bean = (Bean)contextual;
-
- if (bean.getBeanClass().isAssignableFrom(Session.class))
- {
- return (T)this.session;
- }
-
- if (beanStore == null)
- {
- return null;
- }
-
- List> beans = beanStore.getBeans(contextual);
-
- if ((beans != null) && (!beans.isEmpty()))
- {
- return (T)beans.get(0).instance;
- }
-
- return null;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T get(Contextual contextual, CreationalContext creationalContext)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("{} get({},{})",this,contextual,creationalContext);
- }
-
- Bean bean = (Bean)contextual;
-
- if (bean.getBeanClass().isAssignableFrom(Session.class))
- {
- return (T)this.session;
- }
-
- if (beanStore == null)
- {
- beanStore = new SimpleBeanStore();
- }
-
- List> beans = beanStore.getBeans(contextual);
-
- if ((beans != null) && (!beans.isEmpty()))
- {
- for (ScopedInstance> instance : beans)
- {
- if (instance.bean.equals(bean))
- {
- return (T)instance.instance;
- }
- }
- }
-
- // no bean found, create it
- T t = bean.create(creationalContext);
- ScopedInstance customInstance = new ScopedInstance<>();
- customInstance.bean = bean;
- customInstance.creationalContext = creationalContext;
- customInstance.instance = t;
- beanStore.addBean(customInstance);
- return t;
- }
-
- @Override
- public Class extends Annotation> getScope()
- {
- return WebSocketScope.class;
- }
-
- @Override
- public boolean isActive()
- {
- return true;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public T newInstance(Class clazz)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("newInstance({})",clazz);
- }
- Set> beans = beanManager.getBeans(clazz,AnyLiteral.INSTANCE);
- if (beans.isEmpty())
- {
- return null;
- }
-
- Bean bean = beans.iterator().next();
- CreationalContext cc = beanManager.createCreationalContext(bean);
- return (T)beanManager.getReference(bean,clazz,cc);
- }
-
- public void setSession(org.eclipse.jetty.websocket.api.Session sess)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("{} setSession({})",this,sess);
- }
- current.set(this);
- this.session.set(sess);
- }
-
- public org.eclipse.jetty.websocket.api.Session getSession()
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("{} getSession()",this);
- }
- return this.session.get();
- }
-
- @Override
- public String toString()
- {
- return String.format("%s@%X[%s]",this.getClass().getSimpleName(),hashCode(),beanStore);
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketScopeExtension.java b/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketScopeExtension.java
deleted file mode 100644
index 148f28d4b72..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/WebSocketScopeExtension.java
+++ /dev/null
@@ -1,75 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket;
-
-import javax.enterprise.context.Destroyed;
-import javax.enterprise.context.Initialized;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.BeforeBeanDiscovery;
-import javax.enterprise.inject.spi.Extension;
-
-import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-
-/**
- * Register the various WebSocket specific components for CDI
- */
-@Deprecated
-public class WebSocketScopeExtension implements Extension
-{
- private static final Logger LOG = Log.getLogger(WebSocketScopeExtension.class);
-
- public void addScope(@Observes final BeforeBeanDiscovery event)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("addScope()");
- }
- // Add our scope
- event.addScope(WebSocketScope.class,true,false);
- }
-
- public void registerContext(@Observes final AfterBeanDiscovery event)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("registerContext()");
- }
- // Register our context
- event.addContext(new WebSocketScopeContext());
- }
-
- public void logWsScopeInit(@Observes @Initialized(WebSocketScope.class) org.eclipse.jetty.websocket.api.Session sess)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Initialized @WebSocketScope - {}",sess);
- }
- }
-
- public void logWsScopeDestroyed(@Observes @Destroyed(WebSocketScope.class) org.eclipse.jetty.websocket.api.Session sess)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Destroyed @WebSocketScope - {}",sess);
- }
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/annotation/WebSocketScope.java b/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/annotation/WebSocketScope.java
deleted file mode 100644
index 9c4ec5fde80..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/java/org/eclipse/jetty/cdi/websocket/annotation/WebSocketScope.java
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.annotation;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.inject.Scope;
-
-/**
- * A CDI Context Scope for a WebSocket Session / Endpoint
- *
- * CAUTION: This is a highly speculative scope defined by Jetty. One that will likely be replaced by a formal spec later
- *
- * At the time of implementation (of this scope), no standard scope exists for websocket session lifecycle.
- */
-@Scope
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD })
-@Inherited
-@Documented
-@Deprecated
-public @interface WebSocketScope
-{
-
-}
diff --git a/jetty-cdi/cdi-websocket/src/main/resources/META-INF/beans.xml b/jetty-cdi/cdi-websocket/src/main/resources/META-INF/beans.xml
deleted file mode 100644
index aeeef5387ca..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/resources/META-INF/beans.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/jetty-cdi/cdi-websocket/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/jetty-cdi/cdi-websocket/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
deleted file mode 100644
index 93723bc0aec..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
+++ /dev/null
@@ -1 +0,0 @@
-org.eclipse.jetty.cdi.websocket.WebSocketScopeExtension
\ No newline at end of file
diff --git a/jetty-cdi/cdi-websocket/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer b/jetty-cdi/cdi-websocket/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer
deleted file mode 100644
index f527270e524..00000000000
--- a/jetty-cdi/cdi-websocket/src/main/resources/META-INF/services/javax.servlet.ServletContainerInitializer
+++ /dev/null
@@ -1 +0,0 @@
-org.eclipse.jetty.cdi.websocket.WebSocketCdiInitializer
\ No newline at end of file
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/CheckSocket.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/CheckSocket.java
deleted file mode 100644
index c616a7c6757..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/CheckSocket.java
+++ /dev/null
@@ -1,99 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.websocket.api.Session;
-import org.eclipse.jetty.websocket.api.WebSocketAdapter;
-import org.eclipse.jetty.websocket.api.annotations.WebSocket;
-
-@WebSocket
-public class CheckSocket extends WebSocketAdapter
-{
- private static final Logger LOG = Log.getLogger(CheckSocket.class);
- private CountDownLatch closeLatch = new CountDownLatch(1);
- private CountDownLatch openLatch = new CountDownLatch(1);
- public LinkedBlockingQueue textMessages = new LinkedBlockingQueue<>();
-
- public void awaitClose(int timeout, TimeUnit timeunit) throws InterruptedException
- {
- assertTrue(closeLatch.await(timeout,timeunit), "Timeout waiting for close");
- }
-
- public void awaitOpen(int timeout, TimeUnit timeunit) throws InterruptedException
- {
- assertTrue(openLatch.await(timeout,timeunit), "Timeout waiting for open");
- }
-
- public LinkedBlockingQueue getTextMessages()
- {
- return textMessages;
- }
-
- @Override
- public void onWebSocketClose(int statusCode, String reason)
- {
- LOG.debug("Close: {}, {}",statusCode,reason);
- super.onWebSocketClose(statusCode,reason);
- closeLatch.countDown();
- }
-
- @Override
- public void onWebSocketConnect(Session sess)
- {
- LOG.debug("Open: {}",sess);
- super.onWebSocketConnect(sess);
- openLatch.countDown();
- }
-
- @Override
- public void onWebSocketError(Throwable cause)
- {
- LOG.warn("WebSocket Error",cause);
- super.onWebSocketError(cause);
- }
-
- @Override
- public void onWebSocketText(String message)
- {
- LOG.debug("TEXT: {}",message);
- textMessages.add(message);
- }
-
- public void sendText(String msg) throws IOException
- {
- if (isConnected())
- {
- getRemote().sendString(msg);
- }
- }
-
- public void close(int statusCode, String reason)
- {
- getSession().close(statusCode,reason);
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicapp/BasicAppTest.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicapp/BasicAppTest.java
deleted file mode 100644
index d77f05db639..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicapp/BasicAppTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.basicapp;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.io.File;
-import java.net.URI;
-import java.util.concurrent.TimeUnit;
-
-import javax.websocket.server.ServerContainer;
-
-import org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler;
-import org.eclipse.jetty.cdi.websocket.CheckSocket;
-import org.eclipse.jetty.cdi.websocket.cdiapp.InfoSocket;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
-import org.eclipse.jetty.util.log.JettyLogHandler;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.websocket.api.StatusCode;
-import org.eclipse.jetty.websocket.client.WebSocketClient;
-import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class BasicAppTest
-{
- private static final Logger LOG = Log.getLogger(BasicAppTest.class);
-
- private static Server server;
- @SuppressWarnings("unused")
- private static URI serverHttpURI;
- private static URI serverWebsocketURI;
-
- @BeforeAll
- public static void startServer() throws Exception
- {
- JettyLogHandler.config();
-
- server = new Server();
- ServerConnector connector = new ServerConnector(server);
- connector.setPort(0);
- server.addConnector(connector);
-
- EmbeddedCdiHandler context = new EmbeddedCdiHandler();
-
- File baseDir = MavenTestingUtils.getTestResourcesDir();
-
- context.setBaseResource(Resource.newResource(baseDir));
- context.setContextPath("/");
- server.setHandler(context);
-
- // Add some websockets
- ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
- container.addEndpoint(EchoSocket.class);
- container.addEndpoint(InfoSocket.class);
-
- server.start();
-
- String host = connector.getHost();
- if (host == null)
- {
- host = "localhost";
- }
- int port = connector.getLocalPort();
- serverHttpURI = new URI(String.format("http://%s:%d/",host,port));
- serverWebsocketURI = new URI(String.format("ws://%s:%d/",host,port));
- }
-
- @AfterAll
- public static void stopServer()
- {
- try
- {
- server.stop();
- }
- catch (Exception e)
- {
- LOG.warn(e);
- }
- }
-
- @Test
- public void testWebSocketEcho() throws Exception
- {
- WebSocketClient client = new WebSocketClient();
- try
- {
- client.start();
- CheckSocket socket = new CheckSocket();
- client.connect(socket,serverWebsocketURI.resolve("/echo"));
-
- socket.awaitOpen(2,TimeUnit.SECONDS);
- socket.sendText("Hello World");
- socket.close(StatusCode.NORMAL,"Test complete");
- socket.awaitClose(2,TimeUnit.SECONDS);
-
- assertThat("Messages received",socket.getTextMessages().size(),is(1));
- String response = socket.getTextMessages().poll();
- System.err.println(response);
-
- assertThat("Message[0]",response,is("Hello World"));
- }
- finally
- {
- client.stop();
- }
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicapp/EchoSocket.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicapp/EchoSocket.java
deleted file mode 100644
index 57ec623a0ee..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicapp/EchoSocket.java
+++ /dev/null
@@ -1,57 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.basicapp;
-
-import javax.websocket.CloseReason;
-import javax.websocket.OnClose;
-import javax.websocket.OnMessage;
-import javax.websocket.OnOpen;
-import javax.websocket.Session;
-import javax.websocket.server.ServerEndpoint;
-
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-
-@ServerEndpoint("/echo")
-public class EchoSocket
-{
- private static final Logger LOG = Log.getLogger(EchoSocket.class);
- @SuppressWarnings("unused")
- private Session session;
-
- @OnOpen
- public void onOpen(Session session)
- {
- LOG.debug("onOpen(): {}",session);
- this.session = session;
- }
-
- @OnClose
- public void onClose(CloseReason close)
- {
- LOG.debug("onClose(): {}",close);
- this.session = null;
- }
-
- @OnMessage
- public String onMessage(String msg)
- {
- return msg;
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/Food.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/Food.java
deleted file mode 100644
index a4c933a2746..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/Food.java
+++ /dev/null
@@ -1,100 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.basicscope;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-
-public class Food
-{
- private boolean constructed = false;
- private boolean destroyed = false;
- private String name;
-
- @PreDestroy
- void destroy()
- {
- destroyed = true;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- Food other = (Food)obj;
- if (name == null)
- {
- if (other.name != null)
- {
- return false;
- }
- }
- else if (!name.equals(other.name))
- {
- return false;
- }
- return true;
- }
-
- public String getName()
- {
- return name;
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = (prime * result) + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- @PostConstruct
- void init()
- {
- constructed = true;
- }
-
- public boolean isConstructed()
- {
- return constructed;
- }
-
- public boolean isDestroyed()
- {
- return destroyed;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/Meal.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/Meal.java
deleted file mode 100644
index 549bddbbb43..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/Meal.java
+++ /dev/null
@@ -1,40 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.basicscope;
-
-import javax.inject.Inject;
-
-public class Meal
-{
- @Inject
- private Food entree;
-
- @Inject
- private Food side;
-
- public Food getEntree()
- {
- return entree;
- }
-
- public Food getSide()
- {
- return side;
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/ScopeBasicsTest.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/ScopeBasicsTest.java
deleted file mode 100644
index 278b61890a5..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/basicscope/ScopeBasicsTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.basicscope;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Bean;
-
-import org.eclipse.jetty.cdi.core.AnyLiteral;
-import org.eclipse.jetty.cdi.core.ScopedInstance;
-import org.eclipse.jetty.cdi.core.logging.Logging;
-import org.jboss.weld.environment.se.Weld;
-import org.jboss.weld.environment.se.WeldContainer;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class ScopeBasicsTest
-{
- private static Weld weld;
- private static WeldContainer container;
-
- @BeforeAll
- public static void startWeld()
- {
- Logging.config();
- weld = new Weld();
- container = weld.initialize();
- }
-
- @AfterAll
- public static void stopWeld()
- {
- weld.shutdown();
- }
-
- /**
- * Validation of Scope / Inject logic on non-websocket-scoped classes
- * @throws Exception on test failure
- */
- @Test
- public void testBasicBehavior() throws Exception
- {
- ScopedInstance meal1Bean = newInstance(Meal.class);
- Meal meal1 = meal1Bean.instance;
- ScopedInstance meal2Bean = newInstance(Meal.class);
- Meal meal2 = meal2Bean.instance;
-
- assertThat("Meals are not the same",meal1,not(sameInstance(meal2)));
-
- assertThat("Meal 1 Entree Constructed",meal1.getEntree().isConstructed(),is(true));
- assertThat("Meal 1 Side Constructed",meal1.getSide().isConstructed(),is(true));
-
- assertThat("Meal parts not the same",meal1.getEntree(),not(sameInstance(meal1.getSide())));
- assertThat("Meal entrees are the same",meal1.getEntree(),not(sameInstance(meal2.getEntree())));
- assertThat("Meal sides are the same",meal1.getSide(),not(sameInstance(meal2.getSide())));
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public static ScopedInstance newInstance(Class clazz) throws Exception
- {
- ScopedInstance sbean = new ScopedInstance();
- Set> beans = container.getBeanManager().getBeans(clazz,AnyLiteral.INSTANCE);
- if (beans.size() > 0)
- {
- sbean.bean = beans.iterator().next();
- sbean.creationalContext = container.getBeanManager().createCreationalContext(sbean.bean);
- sbean.instance = container.getBeanManager().getReference(sbean.bean,clazz,sbean.creationalContext);
- return sbean;
- }
- else
- {
- throw new Exception(String.format("Can't find class %s",clazz));
- }
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/CdiAppTest.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/CdiAppTest.java
deleted file mode 100644
index 07f0c7a9a43..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/CdiAppTest.java
+++ /dev/null
@@ -1,185 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.cdiapp;
-
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.io.File;
-import java.net.URI;
-import java.util.concurrent.TimeUnit;
-
-import javax.websocket.server.ServerContainer;
-
-import org.eclipse.jetty.cdi.servlet.EmbeddedCdiHandler;
-import org.eclipse.jetty.cdi.websocket.CheckSocket;
-import org.eclipse.jetty.cdi.websocket.WebSocketCdiInitializer;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
-import org.eclipse.jetty.util.log.JettyLogHandler;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.websocket.api.StatusCode;
-import org.eclipse.jetty.websocket.client.WebSocketClient;
-import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class CdiAppTest
-{
- private static final Logger LOG = Log.getLogger(CdiAppTest.class);
- private static Server server;
- private static URI serverWebsocketURI;
-
- @BeforeAll
- public static void startServer() throws Exception
- {
- JettyLogHandler.config();
-
- server = new Server();
- ServerConnector connector = new ServerConnector(server);
- connector.setPort(0);
- server.addConnector(connector);
-
- EmbeddedCdiHandler context = new EmbeddedCdiHandler();
- WebSocketCdiInitializer.configureContext(context);
-
- File baseDir = MavenTestingUtils.getTestResourcesDir();
-
- context.setBaseResource(Resource.newResource(baseDir));
- context.setContextPath("/");
- server.setHandler(context);
-
- // Add some websockets
- ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
- container.addEndpoint(EchoSocket.class);
- container.addEndpoint(InfoSocket.class);
-
- server.start();
-
- String host = connector.getHost();
- if (host == null)
- {
- host = "localhost";
- }
- int port = connector.getLocalPort();
- serverWebsocketURI = new URI(String.format("ws://%s:%d/",host,port));
- }
-
- @AfterAll
- public static void stopServer()
- {
- try
- {
- server.stop();
- }
- catch (Exception e)
- {
- LOG.warn(e);
- }
- }
-
- @Test
- public void testWebSocketActivated() throws Exception
- {
- WebSocketClient client = new WebSocketClient();
- try
- {
- client.start();
- CheckSocket socket = new CheckSocket();
- client.connect(socket,serverWebsocketURI.resolve("/echo"));
-
- socket.awaitOpen(2,TimeUnit.SECONDS);
- socket.sendText("Hello");
- socket.close(StatusCode.NORMAL,"Test complete");
- socket.awaitClose(2,TimeUnit.SECONDS);
-
- assertThat("Messages received",socket.getTextMessages().size(),is(1));
- assertThat("Message[0]",socket.getTextMessages().poll(),is("Hello"));
- }
- finally
- {
- client.stop();
- }
- }
-
- @Test
- public void testWebSocket_Info_FieldPresence() throws Exception
- {
- WebSocketClient client = new WebSocketClient();
- try
- {
- client.start();
- CheckSocket socket = new CheckSocket();
- client.connect(socket,serverWebsocketURI.resolve("/cdi-info"));
-
- socket.awaitOpen(2,TimeUnit.SECONDS);
- socket.sendText("info");
- socket.close(StatusCode.NORMAL,"Test complete");
- socket.awaitClose(2,TimeUnit.SECONDS);
-
- assertThat("Messages received",socket.getTextMessages().size(),is(1));
- String response = socket.getTextMessages().poll();
- System.err.println(response);
-
- assertThat("Message[0]",response,
- allOf(
- containsString("websocketSession is PRESENT"),
- containsString("httpSession is PRESENT"),
- containsString("servletContext is PRESENT")
- ));
- }
- finally
- {
- client.stop();
- }
- }
-
- @Test
- public void testWebSocket_Info_DataFromCdi() throws Exception
- {
- WebSocketClient client = new WebSocketClient();
- try
- {
- client.start();
- CheckSocket socket = new CheckSocket();
- client.connect(socket,serverWebsocketURI.resolve("/cdi-info"));
-
- socket.awaitOpen(2,TimeUnit.SECONDS);
- socket.sendText("data|stuff");
- socket.close(StatusCode.NORMAL,"Test complete");
- socket.awaitClose(2,TimeUnit.SECONDS);
-
- assertThat("Messages received",socket.getTextMessages().size(),is(2));
- String response = socket.getTextMessages().poll();
- System.out.println("[0]" + response);
- assertThat("Message[0]",response,containsString("Hello there stuff"));
- System.out.println("[1]" + socket.getTextMessages().poll());
- }
- finally
- {
- client.stop();
- }
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/DataMaker.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/DataMaker.java
deleted file mode 100644
index bf74023d362..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/DataMaker.java
+++ /dev/null
@@ -1,43 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.cdiapp;
-
-import javax.inject.Inject;
-
-import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.websocket.api.Session;
-
-public class DataMaker
-{
- private static final Logger LOG = Log.getLogger(DataMaker.class);
-
- @Inject
- @WebSocketScope
- private Session session;
-
- public void processMessage(String msg)
- {
- LOG.debug(".processMessage({})",msg);
- LOG.debug("session = {}",session);
-
- session.getRemote().sendStringByFuture("Hello there " + msg);
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/EchoSocket.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/EchoSocket.java
deleted file mode 100644
index 8b41a85c764..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/EchoSocket.java
+++ /dev/null
@@ -1,57 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.cdiapp;
-
-import javax.websocket.CloseReason;
-import javax.websocket.OnClose;
-import javax.websocket.OnMessage;
-import javax.websocket.OnOpen;
-import javax.websocket.Session;
-import javax.websocket.server.ServerEndpoint;
-
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-
-@ServerEndpoint("/echo")
-public class EchoSocket
-{
- private static final Logger LOG = Log.getLogger(EchoSocket.class);
- @SuppressWarnings("unused")
- private Session session;
-
- @OnOpen
- public void onOpen(Session session)
- {
- LOG.debug("onOpen(): {}",session);
- this.session = session;
- }
-
- @OnClose
- public void onClose(CloseReason close)
- {
- LOG.debug("onClose(): {}",close);
- this.session = null;
- }
-
- @OnMessage
- public String onMessage(String msg)
- {
- return msg;
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/InfoSocket.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/InfoSocket.java
deleted file mode 100644
index beb0c384279..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/cdiapp/InfoSocket.java
+++ /dev/null
@@ -1,94 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.cdiapp;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.logging.Level;
-
-import javax.enterprise.context.SessionScoped;
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpSession;
-import javax.websocket.CloseReason;
-import javax.websocket.OnClose;
-import javax.websocket.OnMessage;
-import javax.websocket.OnOpen;
-import javax.websocket.Session;
-import javax.websocket.server.ServerEndpoint;
-
-@ServerEndpoint("/cdi-info")
-public class InfoSocket
-{
- private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(InfoSocket.class.getName());
-
- @SessionScoped
- @Inject
- private HttpSession httpSession;
-
- @Inject
- private ServletContext servletContext;
-
- @Inject
- private DataMaker dataMaker;
-
- private Session session;
-
- @OnOpen
- public void onOpen(Session session)
- {
- LOG.log(Level.INFO,"onOpen(): {0}",session);
- this.session = session;
- }
-
- @OnClose
- public void onClose(CloseReason close)
- {
- LOG.log(Level.INFO,"onClose(): {}",close);
- this.session = null;
- }
-
- @OnMessage
- public String onMessage(String msg)
- {
- StringWriter str = new StringWriter();
- PrintWriter out = new PrintWriter(str);
-
- String args[] = msg.split("\\|");
-
- switch (args[0])
- {
- case "info":
- out.printf("websocketSession is %s%n",asPresent(session));
- out.printf("httpSession is %s%n",asPresent(httpSession));
- out.printf("servletContext is %s%n",asPresent(servletContext));
- break;
- case "data":
- dataMaker.processMessage(args[1]);
- break;
- }
-
- return str.toString();
- }
-
- private String asPresent(Object obj)
- {
- return obj == null ? "NULL" : "PRESENT";
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/BogusSession.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/BogusSession.java
deleted file mode 100644
index 0e1ed64ca52..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/BogusSession.java
+++ /dev/null
@@ -1,150 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.wsscope;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
-import org.eclipse.jetty.websocket.api.CloseStatus;
-import org.eclipse.jetty.websocket.api.RemoteEndpoint;
-import org.eclipse.jetty.websocket.api.Session;
-import org.eclipse.jetty.websocket.api.SuspendToken;
-import org.eclipse.jetty.websocket.api.UpgradeRequest;
-import org.eclipse.jetty.websocket.api.UpgradeResponse;
-import org.eclipse.jetty.websocket.api.WebSocketPolicy;
-
-/**
- * A bogus websocket Session concept object.
- *
- * Used to test the scope @Inject of this kind of Session. This is important to test, as the BogusSession does not have
- * a default constructor that CDI itself can use to create this object.
- *
- * This object would need to be added to the beanstore for this scope for later @Inject to use.
- */
-public class BogusSession implements Session
-{
- private final String id;
-
- public BogusSession(String id)
- {
- this.id = id;
- }
-
- @Override
- public String toString()
- {
- return String.format("BogusSession[id=%s]",id);
- }
-
- public String getId()
- {
- return id;
- }
-
- @Override
- public void close()
- {
- }
-
- @Override
- public void close(CloseStatus closeStatus)
- {
- }
-
- @Override
- public void close(int statusCode, String reason)
- {
- }
-
- @Override
- public void disconnect() throws IOException
- {
- }
-
- @Override
- public long getIdleTimeout()
- {
- return 0;
- }
-
- @Override
- public InetSocketAddress getLocalAddress()
- {
- return null;
- }
-
- @Override
- public WebSocketPolicy getPolicy()
- {
- return null;
- }
-
- @Override
- public String getProtocolVersion()
- {
- return null;
- }
-
- @Override
- public RemoteEndpoint getRemote()
- {
- return null;
- }
-
- @Override
- public InetSocketAddress getRemoteAddress()
- {
- return null;
- }
-
- @Override
- public UpgradeRequest getUpgradeRequest()
- {
- return null;
- }
-
- @Override
- public UpgradeResponse getUpgradeResponse()
- {
- return null;
- }
-
- @Override
- public boolean isOpen()
- {
- return false;
- }
-
- @Override
- public boolean isSecure()
- {
- return false;
- }
-
- @Override
- public void setIdleTimeout(long ms)
- {
- }
-
- @Override
- public SuspendToken suspend()
- {
- return null;
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/BogusSocket.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/BogusSocket.java
deleted file mode 100644
index cd296cdcef0..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/BogusSocket.java
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.wsscope;
-
-import javax.inject.Inject;
-
-import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
-import org.eclipse.jetty.websocket.api.Session;
-
-public class BogusSocket
-{
- @Inject
- @WebSocketScope
- private Session session;
-
- public Session getSession()
- {
- return session;
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/Food.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/Food.java
deleted file mode 100644
index 29810ee56ed..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/Food.java
+++ /dev/null
@@ -1,119 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.wsscope;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-
-import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
-
-@WebSocketScope
-public class Food
-{
- private boolean constructed = false;
- private boolean destroyed = false;
- private String name;
-
- public Food()
- {
- // default constructor (for CDI use)
- }
-
- public Food(String name)
- {
- this.name = name;
- }
-
- @PreDestroy
- void destroy()
- {
- destroyed = true;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- Food other = (Food)obj;
- if (name == null)
- {
- if (other.name != null)
- {
- return false;
- }
- }
- else if (!name.equals(other.name))
- {
- return false;
- }
- return true;
- }
-
- public String getName()
- {
- return name;
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = (prime * result) + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- @PostConstruct
- void init()
- {
- constructed = true;
- }
-
- public boolean isConstructed()
- {
- return constructed;
- }
-
- public boolean isDestroyed()
- {
- return destroyed;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- @Override
- public String toString()
- {
- return String.format("%s@%X[%s]",Food.class.getSimpleName(),hashCode(),name);
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/Meal.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/Meal.java
deleted file mode 100644
index 5f09dbbf1a0..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/Meal.java
+++ /dev/null
@@ -1,40 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.wsscope;
-
-import javax.inject.Inject;
-
-public class Meal
-{
- @Inject
- private Food entree;
-
- @Inject
- private Food side;
-
- public Food getEntree()
- {
- return entree;
- }
-
- public Food getSide()
- {
- return side;
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/WebSocketScopeBaselineTest.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/WebSocketScopeBaselineTest.java
deleted file mode 100644
index 2e1a74ead5a..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/WebSocketScopeBaselineTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.wsscope;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Bean;
-
-import org.eclipse.jetty.cdi.core.AnyLiteral;
-import org.eclipse.jetty.cdi.core.ScopedInstance;
-import org.eclipse.jetty.cdi.core.logging.Logging;
-import org.eclipse.jetty.cdi.websocket.WebSocketScopeContext;
-import org.eclipse.jetty.cdi.websocket.annotation.WebSocketScope;
-import org.jboss.weld.environment.se.Weld;
-import org.jboss.weld.environment.se.WeldContainer;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class WebSocketScopeBaselineTest
-{
- private static Weld weld;
- private static WeldContainer container;
-
- @BeforeAll
- public static void startWeld()
- {
- Logging.config();
- weld = new Weld();
- container = weld.initialize();
- }
-
- @AfterAll
- public static void stopWeld()
- {
- weld.shutdown();
- }
-
- /**
- * Test behavior of {@link WebSocketScope} in basic operation.
- *
- * Food is declared as part of WebSocketScope, and as such, only 1 instance of it can exist.
- * @throws Exception on test failure
- */
- @Test
- public void testScopeBehavior() throws Exception
- {
- ScopedInstance wsScopeBean = newInstance(WebSocketScopeContext.class);
- WebSocketScopeContext wsScope = wsScopeBean.instance;
-
- wsScope.create();
- Meal meal1;
- try
- {
- wsScope.begin();
- ScopedInstance meal1Bean = newInstance(Meal.class);
- meal1 = meal1Bean.instance;
- ScopedInstance meal2Bean = newInstance(Meal.class);
- Meal meal2 = meal2Bean.instance;
-
- assertThat("Meals are not the same",meal1,not(sameInstance(meal2)));
-
- assertThat("Meal 1 Entree Constructed",meal1.getEntree().isConstructed(),is(true));
- assertThat("Meal 1 Side Constructed",meal1.getSide().isConstructed(),is(true));
-
- /* Since Food is annotated with @WebSocketScope, there can only be one instance of it
- * in use with the 2 Meal objects.
- */
- assertThat("Meal parts not the same",meal1.getEntree(),sameInstance(meal1.getSide()));
- assertThat("Meal entrees are the same",meal1.getEntree(),sameInstance(meal2.getEntree()));
- assertThat("Meal sides are the same",meal1.getSide(),sameInstance(meal2.getSide()));
-
- meal1Bean.destroy();
- meal2Bean.destroy();
- }
- finally
- {
- wsScope.end();
- }
-
- Food entree1 = meal1.getEntree();
- Food side1 = meal1.getSide();
-
- assertThat("Meal 1 entree destroyed",entree1.isDestroyed(),is(false));
- assertThat("Meal 1 side destroyed",side1.isDestroyed(),is(false));
- wsScope.destroy();
-
- // assertThat("Meal 1 entree destroyed",entree1.isDestroyed(),is(true));
- // assertThat("Meal 1 side destroyed",side1.isDestroyed(),is(true));
- wsScopeBean.destroy();
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public static ScopedInstance newInstance(Class clazz) throws Exception
- {
- ScopedInstance sbean = new ScopedInstance();
- Set> beans = container.getBeanManager().getBeans(clazz,AnyLiteral.INSTANCE);
- if (beans.size() > 0)
- {
- sbean.bean = beans.iterator().next();
- sbean.creationalContext = container.getBeanManager().createCreationalContext(sbean.bean);
- sbean.instance = container.getBeanManager().getReference(sbean.bean,clazz,sbean.creationalContext);
- return sbean;
- }
- else
- {
- throw new Exception(String.format("Can't find class %s",clazz));
- }
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/WebSocketScopeSessionTest.java b/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/WebSocketScopeSessionTest.java
deleted file mode 100644
index 63358d2b759..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/java/org/eclipse/jetty/cdi/websocket/wsscope/WebSocketScopeSessionTest.java
+++ /dev/null
@@ -1,253 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.cdi.websocket.wsscope;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-import javax.enterprise.inject.spi.Bean;
-
-import org.eclipse.jetty.cdi.core.AnyLiteral;
-import org.eclipse.jetty.cdi.core.ScopedInstance;
-import org.eclipse.jetty.cdi.core.logging.Logging;
-import org.eclipse.jetty.cdi.websocket.WebSocketScopeContext;
-import org.eclipse.jetty.websocket.api.Session;
-import org.jboss.weld.environment.se.Weld;
-import org.jboss.weld.environment.se.WeldContainer;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-public class WebSocketScopeSessionTest
-{
- private static Weld weld;
- private static WeldContainer container;
-
- @BeforeAll
- public static void startWeld()
- {
- Logging.config();
- weld = new Weld();
- container = weld.initialize();
- }
-
- @AfterAll
- public static void stopWeld()
- {
- weld.shutdown();
- }
-
- @Test
- public void testSessionActivation() throws Exception
- {
- ScopedInstance wsScopeBean = newInstance(WebSocketScopeContext.class);
- WebSocketScopeContext wsScope = wsScopeBean.instance;
-
- wsScope.create();
- try
- {
- // Scope 1
- wsScope.begin();
- BogusSession sess = new BogusSession("1");
- wsScope.setSession(sess);
- ScopedInstance sock1Bean = newInstance(BogusSocket.class);
- BogusSocket sock1 = sock1Bean.instance;
- assertThat("Socket 1 Session",sock1.getSession().toString(),is(sess.toString()));
-
- sock1Bean.destroy();
- }
- finally
- {
- wsScope.end();
- }
-
- wsScope.destroy();
- wsScopeBean.destroy();
- }
-
- @Test
- public void testMultiSession_Sequential() throws Exception
- {
- ScopedInstance wsScope1Bean = newInstance(WebSocketScopeContext.class);
- WebSocketScopeContext wsScope1 = wsScope1Bean.instance;
-
- ScopedInstance wsScope2Bean = newInstance(WebSocketScopeContext.class);
- WebSocketScopeContext wsScope2 = wsScope2Bean.instance;
-
- wsScope1.create();
- try
- {
- // Scope 1
- wsScope1.begin();
- BogusSession sess = new BogusSession("1");
- wsScope1.setSession(sess);
- ScopedInstance sock1Bean = newInstance(BogusSocket.class);
- BogusSocket sock1 = sock1Bean.instance;
- assertThat("Socket 1 Session",sock1.getSession(),sameInstance((Session)sess));
- sock1Bean.destroy();
- }
- finally
- {
- wsScope1.end();
- }
-
- wsScope1.destroy();
- wsScope1Bean.destroy();
-
- wsScope2.create();
- try
- {
- // Scope 2
- wsScope2.begin();
- BogusSession sess = new BogusSession("2");
- wsScope2.setSession(sess);
- ScopedInstance sock2Bean = newInstance(BogusSocket.class);
- BogusSocket sock2 = sock2Bean.instance;
- assertThat("Socket 2 Session",sock2.getSession(),sameInstance((Session)sess));
- sock2Bean.destroy();
- }
- finally
- {
- wsScope2.end();
- }
-
- wsScope2.destroy();
- wsScope2Bean.destroy();
- }
-
- @Test
- public void testMultiSession_Overlapping() throws Exception
- {
- final CountDownLatch midLatch = new CountDownLatch(2);
- final CountDownLatch end1Latch = new CountDownLatch(1);
-
- Callable call1 = new Callable() {
- @Override
- public Session call() throws Exception
- {
- Session ret = null;
- ScopedInstance wsScope1Bean = newInstance(WebSocketScopeContext.class);
- WebSocketScopeContext wsScope1 = wsScope1Bean.instance;
-
- wsScope1.create();
- try
- {
- // Scope 1
- wsScope1.begin();
- BogusSession sess = new BogusSession("1");
- wsScope1.setSession(sess);
-
- midLatch.countDown();
- midLatch.await(1, TimeUnit.SECONDS);
-
- ScopedInstance sock1Bean = newInstance(BogusSocket.class);
- BogusSocket sock1 = sock1Bean.instance;
- assertThat("Socket 1 Session",sock1.getSession(),sameInstance((Session)sess));
- ret = sock1.getSession();
- sock1Bean.destroy();
- }
- finally
- {
- wsScope1.end();
- }
-
- wsScope1.destroy();
- wsScope1Bean.destroy();
- end1Latch.countDown();
- return ret;
- }
- };
-
- final CountDownLatch end2Latch = new CountDownLatch(1);
-
- Callable call2 = new Callable() {
- @Override
- public Session call() throws Exception
- {
- Session ret = null;
- ScopedInstance wsScope2Bean = newInstance(WebSocketScopeContext.class);
- WebSocketScopeContext wsScope2 = wsScope2Bean.instance;
-
- wsScope2.create();
- try
- {
- // Scope 2
- wsScope2.begin();
- BogusSession sess = new BogusSession("2");
- wsScope2.setSession(sess);
- ScopedInstance sock2Bean = newInstance(BogusSocket.class);
-
- midLatch.countDown();
- midLatch.await(1, TimeUnit.SECONDS);
-
- BogusSocket sock2 = sock2Bean.instance;
- ret = sock2.getSession();
- assertThat("Socket 2 Session",sock2.getSession(),sameInstance((Session)sess));
- sock2Bean.destroy();
- }
- finally
- {
- wsScope2.end();
- }
-
- wsScope2.destroy();
- wsScope2Bean.destroy();
- end2Latch.countDown();
- return ret;
- }
- };
-
- ExecutorService svc = Executors.newFixedThreadPool(4);
- Future fut1 = svc.submit(call1);
- Future fut2 = svc.submit(call2);
-
- Session sess1 = fut1.get(1,TimeUnit.SECONDS);
- Session sess2 = fut2.get(1,TimeUnit.SECONDS);
-
- assertThat("Sessions are different", sess1, not(sameInstance(sess2)));
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public static ScopedInstance newInstance(Class clazz)
- {
- ScopedInstance sbean = new ScopedInstance();
- Set> beans = container.getBeanManager().getBeans(clazz,AnyLiteral.INSTANCE);
- if (beans.size() > 0)
- {
- sbean.bean = beans.iterator().next();
- sbean.creationalContext = container.getBeanManager().createCreationalContext(sbean.bean);
- sbean.instance = container.getBeanManager().getReference(sbean.bean,clazz,sbean.creationalContext);
- return sbean;
- }
- else
- {
- throw new RuntimeException(String.format("Can't find class %s",clazz));
- }
- }
-}
diff --git a/jetty-cdi/cdi-websocket/src/test/resources/META-INF/beans.xml b/jetty-cdi/cdi-websocket/src/test/resources/META-INF/beans.xml
deleted file mode 100644
index f158a71b6e5..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/resources/META-INF/beans.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
\ No newline at end of file
diff --git a/jetty-cdi/cdi-websocket/src/test/resources/jetty-logging.properties b/jetty-cdi/cdi-websocket/src/test/resources/jetty-logging.properties
deleted file mode 100644
index eeed11d303b..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/resources/jetty-logging.properties
+++ /dev/null
@@ -1,15 +0,0 @@
-org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
-org.jetty.LEVEL=INFO
-org.jboss.LEVEL=INFO
-# org.eclipse.jetty.LEVEL=INFO
-
-# org.eclipse.jetty.util.component.LEVEL=DEBUG
-
-# org.eclipse.jetty.websocket.common.LEVEL=DEBUG
-# org.eclipse.jetty.util.DecoratedObjectFactory.LEVEL=DEBUG
-# org.eclipse.jetty.cdi.LEVEL=DEBUG
-
-# org.eclipse.jetty.LEVEL=DEBUG
-# org.eclipse.jetty.websocket.LEVEL=DEBUG
-# org.eclipse.jetty.websocket.client.LEVEL=DEBUG
-
diff --git a/jetty-cdi/cdi-websocket/src/test/resources/logging.properties b/jetty-cdi/cdi-websocket/src/test/resources/logging.properties
deleted file mode 100644
index cfec8c7ab58..00000000000
--- a/jetty-cdi/cdi-websocket/src/test/resources/logging.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-handlers = org.eclipse.jetty.util.log.JettyLogHandler
-.level=FINE
diff --git a/jetty-cdi/pom.xml b/jetty-cdi/pom.xml
index 4be7c1f2772..1459c105665 100644
--- a/jetty-cdi/pom.xml
+++ b/jetty-cdi/pom.xml
@@ -6,20 +6,32 @@
4.0.0org.eclipse.jetty.cdi
- jetty-cdi-parent
- Jetty :: CDI :: Parent
+ cdi-2
+ Jetty :: CDI 2http://www.eclipse.org/jetty
- pom
-
-
- cdi-core
- cdi-servlet
- cdi-full-servlet
- cdi-websocket
- cdi-2
- test-cdi-webapp
-
-
+ jar
+
+ ${project.groupId}.cdi2
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ package
+
+ single
+
+
+
+ config
+
+
+
+
+
+
+
diff --git a/jetty-cdi/cdi-2/src/main/config/etc/cdi2/jetty-cdi2.xml b/jetty-cdi/src/main/config/etc/cdi2/jetty-cdi2.xml
similarity index 100%
rename from jetty-cdi/cdi-2/src/main/config/etc/cdi2/jetty-cdi2.xml
rename to jetty-cdi/src/main/config/etc/cdi2/jetty-cdi2.xml
diff --git a/jetty-cdi/cdi-2/src/main/config/etc/cdi2/jetty-web-cdi2.xml b/jetty-cdi/src/main/config/etc/cdi2/jetty-web-cdi2.xml
similarity index 100%
rename from jetty-cdi/cdi-2/src/main/config/etc/cdi2/jetty-web-cdi2.xml
rename to jetty-cdi/src/main/config/etc/cdi2/jetty-web-cdi2.xml
diff --git a/jetty-cdi/cdi-2/src/main/config/modules/cdi2.mod b/jetty-cdi/src/main/config/modules/cdi2.mod
similarity index 100%
rename from jetty-cdi/cdi-2/src/main/config/modules/cdi2.mod
rename to jetty-cdi/src/main/config/modules/cdi2.mod
diff --git a/jetty-cdi/test-cdi-it/pom.xml b/jetty-cdi/test-cdi-it/pom.xml
deleted file mode 100644
index 2ab623e0b39..00000000000
--- a/jetty-cdi/test-cdi-it/pom.xml
+++ /dev/null
@@ -1,204 +0,0 @@
-
-
-
- org.eclipse.jetty.cdi
- jetty-cdi-parent
- 9.4.7-SNAPSHOT
-
- 4.0.0
- cdi-webapp-it
- jar
- Jetty :: CDI :: Test :: WebApp Integration Tests
- http://www.eclipse.org/jetty
-
- UTF-8
- UTF-8
- ${project.groupId}.cdi.webapp.it
- ${project.basedir}/src/test/scripts
- ${project.build.directory}/test-base
- ${project.build.directory}/test-home
-
-
-
- org.eclipse.jetty
- jetty-distribution
- ${project.version}
- zip
- runtime
-
-
- org.eclipse.jetty.cdi
- test-cdi-webapp
- ${project.version}
- war
- runtime
-
-
- org.eclipse.jetty.toolchain
- jetty-test-helper
- test
-
-
-
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
-
-
- true
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-apps-for-testing
- process-test-resources
-
- copy-dependencies
-
-
- test-cdi-webapp
- runtime
- war
- true
- true
- true
- ${test-base-dir}/webapps
-
-
-
- unpack-jetty-distro
- process-test-resources
-
- unpack-dependencies
-
-
- jetty-distribution
- runtime
- zip
- true
- ${test-home-dir}
- true
- true
-
-
-
-
-
- org.apache.maven.plugins
- maven-failsafe-plugin
-
-
-
- integration-test
- verify
-
-
-
-
-
- org.apache.maven.plugins
- maven-antrun-plugin
-
-
- start-jetty
- pre-integration-test
-
- run
-
-
-
-
-
- Integration Test : Setup Jetty
-
-
-
-
-
-
-
-
- Integration Test : Starting Jetty ...
-
-
-
-
-
-
-
-
-
-
- Integration Test : Jetty is now available
-
-
-
-
- stop-jetty
- post-integration-test
-
- run
-
-
-
-
-
- Integration Test : Stop Jetty
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- it-windows
-
-
- Windows
-
-
-
- cmd
- /c
- start-jetty.bat
- stop-jetty.bat
-
-
-
- it-unix
-
-
- unix
-
-
-
- sh
- --
- setup-jetty.sh
- start-jetty.sh
- stop-jetty.sh
-
-
-
-
diff --git a/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/HelloIT.java b/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/HelloIT.java
deleted file mode 100644
index 371d3464500..00000000000
--- a/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/HelloIT.java
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.tests;
-
-import static org.hamcrest.Matchers.*;
-import static org.junit.jupiter.api.Assertions.*;
-
-import java.net.URI;
-
-import org.eclipse.jetty.toolchain.test.SimpleRequest;
-import org.junit.jupiter.api.Test;
-
-/**
- * Basic tests for a simple @WebServlet with no CDI
- */
-public class HelloIT
-{
- @Test
- public void testBasic() throws Exception
- {
- URI serverURI = new URI("http://localhost:58080/cdi-webapp/");
- SimpleRequest req = new SimpleRequest(serverURI);
- assertThat(req.getString("hello"),is("Hello World" + System.lineSeparator()));
- }
-}
diff --git a/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/ServerInfoIT.java b/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/ServerInfoIT.java
deleted file mode 100644
index 7adc851a3f3..00000000000
--- a/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/ServerInfoIT.java
+++ /dev/null
@@ -1,47 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.tests;
-
-import static org.hamcrest.Matchers.*;
-import static org.junit.jupiter.api.Assertions.*;
-
-import java.net.URI;
-
-import org.eclipse.jetty.toolchain.test.SimpleRequest;
-import org.junit.jupiter.api.Test;
-
-public class ServerInfoIT
-{
- @Test
- public void testGET() throws Exception {
- URI serverURI = new URI("http://localhost:58080/cdi-webapp/");
- SimpleRequest req = new SimpleRequest(serverURI);
-
- // Typical response:
- // context = ServletContext@o.e.j.w.WebAppContext@37cb63fd{/cdi-webapp,
- // file:///tmp/jetty-0.0.0.0-58080-cdi-webapp.war-_cdi-webapp-any-417759194514596377.dir/webapp/,AVAILABLE}
- // {/cdi-webapp.war}\ncontext.contextPath = /cdi-webapp\ncontext.effective-version = 3.1\n
- assertThat(req.getString("serverinfo"),
- allOf(
- containsString("context = ServletContext@"),
- containsString("context.contextPath = /cdi-webapp"),
- containsString("context.effective-version = 3.1")
- ));
- }
-}
diff --git a/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/ws/SessionInfoIT.java b/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/ws/SessionInfoIT.java
deleted file mode 100644
index 21931d4b0d5..00000000000
--- a/jetty-cdi/test-cdi-it/src/test/java/org/eclipse/jetty/tests/ws/SessionInfoIT.java
+++ /dev/null
@@ -1,106 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.tests.ws;
-
-import static org.hamcrest.Matchers.*;
-import static org.junit.jupiter.api.Assertions.*;
-
-import java.net.URI;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.websocket.ClientEndpoint;
-import javax.websocket.CloseReason;
-import javax.websocket.ContainerProvider;
-import javax.websocket.OnClose;
-import javax.websocket.OnMessage;
-import javax.websocket.OnOpen;
-import javax.websocket.Session;
-import javax.websocket.WebSocketContainer;
-
-import org.eclipse.jetty.toolchain.test.EventQueue;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.junit.jupiter.api.Test;
-
-public class SessionInfoIT
-{
- @ClientEndpoint
- public static class ClientSessionInfoSocket
- {
- private static final Logger LOG = Log.getLogger(SessionInfoIT.ClientSessionInfoSocket.class);
-
- public CountDownLatch openLatch = new CountDownLatch(1);
- public CountDownLatch closeLatch = new CountDownLatch(1);
- public Session session;
- public EventQueue messages = new EventQueue<>();
- public CloseReason closeReason;
-
- @OnOpen
- public void onOpen(Session session)
- {
- LOG.info("onOpen(): {}", session);
- this.session = session;
- this.openLatch.countDown();
- }
-
- @OnClose
- public void onClose(CloseReason close)
- {
- LOG.info("onClose(): {}", close);
- this.session = null;
- this.closeReason = close;
- this.closeLatch.countDown();
- }
-
- @OnMessage
- public void onMessage(String message)
- {
- LOG.info("onMessage(): {}", message);
- this.messages.offer(message);
- }
- }
-
- @Test
- public void testSessionInfo() throws Exception
- {
- URI serverURI = new URI("ws://localhost:58080/cdi-webapp/");
-
- WebSocketContainer container = ContainerProvider.getWebSocketContainer();
-
- ClientSessionInfoSocket socket = new ClientSessionInfoSocket();
-
- container.connectToServer(socket,serverURI.resolve("sessioninfo"));
-
- assertThat("Await open", socket.openLatch.await(1,TimeUnit.SECONDS), is(true));
-
- socket.session.getBasicRemote().sendText("info");
- socket.messages.awaitEventCount(1,2,TimeUnit.SECONDS);
-
- System.out.printf("socket.messages.size = %s%n",socket.messages.size());
-
- String msg = socket.messages.poll();
- System.out.printf("Message is [%s]%n",msg);
-
- assertThat("Message", msg, containsString("HttpSession = HttpSession"));
-
- socket.session.getBasicRemote().sendText("close");
- assertThat("Await close", socket.closeLatch.await(1,TimeUnit.SECONDS),is(true));
- }
-}
diff --git a/jetty-cdi/test-cdi-it/src/test/resources/jetty-logging.properties b/jetty-cdi/test-cdi-it/src/test/resources/jetty-logging.properties
deleted file mode 100644
index 6e5209e3846..00000000000
--- a/jetty-cdi/test-cdi-it/src/test/resources/jetty-logging.properties
+++ /dev/null
@@ -1,10 +0,0 @@
-org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
-# org.jboss.LEVEL=DEBUG
-org.eclipse.jetty.LEVEL=INFO
-
-# org.eclipse.jetty.util.DecoratedObjectFactory.LEVEL=DEBUG
-
-# org.eclipse.jetty.LEVEL=DEBUG
-# org.eclipse.jetty.websocket.LEVEL=DEBUG
-# org.eclipse.jetty.websocket.client.LEVEL=DEBUG
-
diff --git a/jetty-cdi/test-cdi-it/src/test/scripts/setup-jetty.sh b/jetty-cdi/test-cdi-it/src/test/scripts/setup-jetty.sh
deleted file mode 100755
index 3dc240f073f..00000000000
--- a/jetty-cdi/test-cdi-it/src/test/scripts/setup-jetty.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env bash
-
-JAVA_HOME=$1
-JETTY_HOME=$2
-JETTY_BASE=$3
-
-echo \${java.home} : $JAVA_HOME
-echo \${jetty.home} : $JETTY_HOME
-echo \${jetty.base} : $JETTY_BASE
-
-cd "$JETTY_BASE"
-
-"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
- --approve-all-licenses \
- --add-to-start=deploy,http,annotations,websocket,cdi,logging
-
-"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
- --version
-
diff --git a/jetty-cdi/test-cdi-it/src/test/scripts/start-jetty.sh b/jetty-cdi/test-cdi-it/src/test/scripts/start-jetty.sh
deleted file mode 100755
index ea7843bf256..00000000000
--- a/jetty-cdi/test-cdi-it/src/test/scripts/start-jetty.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/env bash
-
-JAVA_HOME=$1
-JETTY_HOME=$2
-JETTY_BASE=$3
-
-echo \${java.home} : $JAVA_HOME
-echo \${jetty.home} : $JETTY_HOME
-echo \${jetty.base} : $JETTY_BASE
-
-cd "$JETTY_BASE"
-
-"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
- jetty.http.port=58080 \
- STOP.PORT=58181 STOP.KEY=it
-
-
diff --git a/jetty-cdi/test-cdi-it/src/test/scripts/stop-jetty.sh b/jetty-cdi/test-cdi-it/src/test/scripts/stop-jetty.sh
deleted file mode 100755
index 32e40774908..00000000000
--- a/jetty-cdi/test-cdi-it/src/test/scripts/stop-jetty.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-
-JAVA_HOME=$1
-JETTY_HOME=$2
-JETTY_BASE=$3
-
-cd "$JETTY_BASE"
-"$JAVA_HOME/bin/java" -jar "$JETTY_HOME/start.jar" \
- --stop STOP.PORT=58181 STOP.KEY=it
-
-
diff --git a/jetty-cdi/test-cdi-webapp/pom.xml b/jetty-cdi/test-cdi-webapp/pom.xml
deleted file mode 100644
index becb3b43e41..00000000000
--- a/jetty-cdi/test-cdi-webapp/pom.xml
+++ /dev/null
@@ -1,87 +0,0 @@
-
-
-
- org.eclipse.jetty.cdi
- jetty-cdi-parent
- 9.4.20-SNAPSHOT
-
- 4.0.0
- test-cdi-webapp
- war
- Jetty :: CDI :: Test :: WebApp
- http://www.eclipse.org/jetty
-
- UTF-8
- ${project.groupId}.cdi.webapp.noweld
-
-
-
- javax.servlet
- javax.servlet-api
- provided
-
-
- javax.websocket
- javax.websocket-api
- provided
-
-
- javax.enterprise
- cdi-api
- 1.1
- provided
-
-
- org.jboss.weld.servlet
- weld-servlet
- ${weld.version}
- test
-
-
-
- cdi-webapp
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
-
-
- true
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
-
-
- with-weld
- package
-
- single
-
-
-
- src/assembly/with-weld.xml
-
-
-
-
-
-
- org.eclipse.jetty
- jetty-maven-plugin
- ${project.version}
-
-
-
-
- org.eclipse.jetty.cdi
- cdi-full-servlet
- ${project.version}
- pom
-
-
-
-
-
-
diff --git a/jetty-cdi/test-cdi-webapp/src/assembly/with-weld.xml b/jetty-cdi/test-cdi-webapp/src/assembly/with-weld.xml
deleted file mode 100644
index ca1747115dd..00000000000
--- a/jetty-cdi/test-cdi-webapp/src/assembly/with-weld.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
- with-weld
-
- war
-
- false
-
-
- ${project.basedir}/src/main/webapp
- /
-
-
- ${project.build.outputDirectory}
- /WEB-INF/classes
-
-
-
-
- /WEB-INF/lib
- true
- false
- test
-
- *:cdi-api
- *:weld-servlet
-
-
-
-
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/HelloServlet.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/HelloServlet.java
deleted file mode 100644
index 2201dddefd5..00000000000
--- a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/HelloServlet.java
+++ /dev/null
@@ -1,42 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.tests;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * The most basic servlet here, no CDI use.
- */
-@SuppressWarnings("serial")
-@WebServlet("/hello")
-public class HelloServlet extends HttpServlet
-{
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
- {
- resp.setContentType("text/plain");
- resp.getWriter().println("Hello World");
- }
-}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ServerInfoServlet.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ServerInfoServlet.java
deleted file mode 100644
index 11b264b1998..00000000000
--- a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ServerInfoServlet.java
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.tests;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-@SuppressWarnings("serial")
-@WebServlet("/serverinfo")
-public class ServerInfoServlet extends HttpServlet
-{
- @Inject
- private ServletContext context;
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
- {
- resp.setContentType("text/plain");
-
- PrintWriter out = resp.getWriter();
- if (context == null)
- {
- out.println("context = null");
- return;
- }
- out.printf("context = %s%n",context);
- out.printf("context.contextPath = %s%n",context.getContextPath());
- out.printf("context.effective-version = %d.%d%n",context.getEffectiveMajorVersion(),context.getEffectiveMinorVersion());
- }
-}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULog.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULog.java
deleted file mode 100644
index dc7c7d7567f..00000000000
--- a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULog.java
+++ /dev/null
@@ -1,47 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.tests.logging;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class JULog
-{
- private final Logger log;
-
- public JULog(Class> clazz)
- {
- this.log = Logger.getLogger(clazz.getName());
- }
-
- public void info(String msg)
- {
- log.log(Level.INFO, msg);
- }
-
- public void info(String msg, Object ... args)
- {
- log.log(Level.INFO, msg, args);
- }
-
- public void warn(Throwable t)
- {
- log.log(Level.WARNING, "", t);
- }
-}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULogFactory.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULogFactory.java
deleted file mode 100644
index 4a24ac94aee..00000000000
--- a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULogFactory.java
+++ /dev/null
@@ -1,31 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.tests.logging;
-
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-public class JULogFactory
-{
- @Produces
- public JULog createJULog(InjectionPoint injectionPoint)
- {
- return new JULog(injectionPoint.getMember().getDeclaringClass());
- }
-}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ws/SessionInfoSocket.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ws/SessionInfoSocket.java
deleted file mode 100644
index efd1846e036..00000000000
--- a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ws/SessionInfoSocket.java
+++ /dev/null
@@ -1,98 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.tests.ws;
-
-import javax.inject.Inject;
-import javax.servlet.http.HttpSession;
-import javax.websocket.OnMessage;
-import javax.websocket.OnOpen;
-import javax.websocket.RemoteEndpoint;
-import javax.websocket.Session;
-import javax.websocket.server.ServerEndpoint;
-
-import org.eclipse.jetty.tests.logging.JULog;
-
-@ServerEndpoint(value = "/sessioninfo")
-public class SessionInfoSocket
-{
- @Inject
- private JULog LOG;
-
- @Inject
- private HttpSession httpSession;
-
- private Session wsSession;
-
- @OnOpen
- public void onOpen(Session session)
- {
- LOG.info("onOpen({0})",asClassId(session));
- this.wsSession = session;
- }
-
- @OnMessage
- public void onMessage(String message)
- {
- LOG.info("onMessage({0})",quoted(message));
-
- try
- {
- RemoteEndpoint.Basic remote = wsSession.getBasicRemote();
- LOG.info("Remote.Basic: {0}", remote);
-
- if ("info".equalsIgnoreCase(message))
- {
- LOG.info("returning 'info' details");
- remote.sendText("HttpSession = " + httpSession);
- }
- else if ("close".equalsIgnoreCase(message))
- {
- LOG.info("closing session");
- wsSession.close();
- }
- else
- {
- LOG.info("echoing message as-is");
- remote.sendText(message);
- }
- }
- catch (Throwable t)
- {
- LOG.warn(t);
- }
- }
-
- private String asClassId(Object obj)
- {
- if (obj == null)
- {
- return "";
- }
- return String.format("%s@%X",obj.getClass().getName(),obj.hashCode());
- }
-
- private String quoted(String str)
- {
- if (str == null)
- {
- return "";
- }
- return '"' + str + '"';
- }
-}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/beans.xml b/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/beans.xml
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/web.xml b/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index fe2940c4f8d..00000000000
--- a/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
- CDI Integration Test WebApp
-
-
- org.jboss.weld.environment.servlet.Listener
-
-
-
- Object factory for the CDI Bean Manager
- BeanManager
- javax.enterprise.inject.spi.BeanManager
-
-
-
From ee4726985ea6f52a1719c73e5cd25cf00db03a84 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Thu, 6 Jun 2019 14:58:06 -0500
Subject: [PATCH 22/45] Issue #3731 - removing remaining references to
experimental CDI 1 libs
---
jetty-bom/pom.xml | 10 ----------
.../administration/startup/screen-list-modules.adoc | 13 -------------
jetty-home/pom.xml | 5 -----
3 files changed, 28 deletions(-)
diff --git a/jetty-bom/pom.xml b/jetty-bom/pom.xml
index aabe661b69c..e4ab0d002ad 100644
--- a/jetty-bom/pom.xml
+++ b/jetty-bom/pom.xml
@@ -110,16 +110,6 @@
jetty-ant9.4.20-SNAPSHOT
-
- org.eclipse.jetty.cdi
- cdi-core
- 9.4.20-SNAPSHOT
-
-
- org.eclipse.jetty.cdi
- cdi-servlet
- 9.4.20-SNAPSHOT
- org.eclipse.jettyjetty-client
diff --git a/jetty-documentation/src/main/asciidoc/administration/startup/screen-list-modules.adoc b/jetty-documentation/src/main/asciidoc/administration/startup/screen-list-modules.adoc
index 3702cccecd1..fce1982a38e 100644
--- a/jetty-documentation/src/main/asciidoc/administration/startup/screen-list-modules.adoc
+++ b/jetty-documentation/src/main/asciidoc/administration/startup/screen-list-modules.adoc
@@ -56,19 +56,6 @@ Modules for tag '*':
LIB: lib/apache-jstl/*.jar
Enabled: transitive provider of apache-jstl for jstl
- Module: cdi
- : Experimental CDI/Weld integration
- Depend: cdi1
-
- Module: cdi1
- : Experimental CDI/Weld integration
- : Deprecated in favour of cdi2 module.
- Depend: deploy, annotations, plus, jsp
- LIB: lib/cdi/*.jar
- LIB: lib/cdi-core-${jetty.version}.jar
- LIB: lib/cdi-servlet-${jetty.version}.jar
- XML: etc/jetty-cdi.xml
-
Module: cdi2
: Jetty setup to support Weld/CDI2 with WELD inside the webapp
Depend: deploy
diff --git a/jetty-home/pom.xml b/jetty-home/pom.xml
index cef23d04e3b..1e9c227840e 100644
--- a/jetty-home/pom.xml
+++ b/jetty-home/pom.xml
@@ -672,11 +672,6 @@
jetty-spring${project.version}
-
- org.eclipse.jetty.cdi
- cdi-servlet
- ${project.version}
- org.jboss.loggingjboss-logging
From dc23b8da6a298c2e12f7dfedf36cfe8a64d560fe Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Wed, 12 Jun 2019 13:58:36 -0500
Subject: [PATCH 23/45] Issue #3731 - Bumping up version now that 9.4.19 is
released
Signed-off-by: Joakim Erdfelt
---
tests/test-webapps/test-cdi2-webapp/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/test-webapps/test-cdi2-webapp/pom.xml b/tests/test-webapps/test-cdi2-webapp/pom.xml
index 7e59dafca22..37f8c67440a 100644
--- a/tests/test-webapps/test-cdi2-webapp/pom.xml
+++ b/tests/test-webapps/test-cdi2-webapp/pom.xml
@@ -3,7 +3,7 @@
org.eclipse.jetty.teststest-webapps-parent
- 9.4.19-SNAPSHOT
+ 9.4.20-SNAPSHOT4.0.0
From db30cbd184075a249d640de40e7ccb274b72d2e9 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Wed, 12 Jun 2019 14:37:13 -0500
Subject: [PATCH 24/45] Issue #3700 - Adding felix webapp tests to discover
OSGi issues earlier
Signed-off-by: Joakim Erdfelt
---
tests/test-distribution/pom.xml | 7 ++
.../tests/distribution/OsgiAppTests.java | 69 ++++++++++++++++
tests/test-webapps/pom.xml | 1 +
tests/test-webapps/test-felix-webapp/pom.xml | 50 +++++++++++
.../org/eclipse/jetty/demo/AppListener.java | 82 +++++++++++++++++++
.../org/eclipse/jetty/demo/InfoServlet.java | 54 ++++++++++++
6 files changed, 263 insertions(+)
create mode 100644 tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/OsgiAppTests.java
create mode 100644 tests/test-webapps/test-felix-webapp/pom.xml
create mode 100755 tests/test-webapps/test-felix-webapp/src/main/java/org/eclipse/jetty/demo/AppListener.java
create mode 100644 tests/test-webapps/test-felix-webapp/src/main/java/org/eclipse/jetty/demo/InfoServlet.java
diff --git a/tests/test-distribution/pom.xml b/tests/test-distribution/pom.xml
index c26af378a94..c1b762cd0fb 100644
--- a/tests/test-distribution/pom.xml
+++ b/tests/test-distribution/pom.xml
@@ -85,6 +85,13 @@
${project.version}test
+
+ org.eclipse.jetty.tests
+ test-felix-webapp
+ ${project.version}
+ test
+ war
+
diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/OsgiAppTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/OsgiAppTests.java
new file mode 100644
index 00000000000..09cb1ef8478
--- /dev/null
+++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/OsgiAppTests.java
@@ -0,0 +1,69 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.tests.distribution;
+
+import java.io.File;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.jetty.client.api.ContentResponse;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class OsgiAppTests extends AbstractDistributionTest
+{
+ @Test
+ public void testFelixWebappStart() throws Exception
+ {
+ String jettyVersion = System.getProperty("jettyVersion");
+ DistributionTester distribution = DistributionTester.Builder.newInstance()
+ .jettyVersion(jettyVersion)
+ .mavenLocalRepository(System.getProperty("mavenRepoPath"))
+ .build();
+
+ String[] args1 = {
+ "--create-startd",
+ "--approve-all-licenses",
+ "--add-to-start=http,deploy,annotations,plus,resources"
+ };
+ try (DistributionTester.Run run1 = distribution.start(args1))
+ {
+ assertTrue(run1.awaitFor(5, TimeUnit.SECONDS));
+ assertEquals(0, run1.getExitValue());
+
+ File war = distribution.resolveArtifact("org.eclipse.jetty.tests:test-felix-webapp:war:" + jettyVersion);
+ distribution.installWarFile(war, "test");
+
+ int port = distribution.freePort();
+ try (DistributionTester.Run run2 = distribution.start("jetty.http.port=" + port))
+ {
+ assertTrue(run2.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS));
+
+ startHttpClient();
+ ContentResponse response = client.GET("http://localhost:" + port + "/test/info");
+ assertEquals(HttpStatus.OK_200, response.getStatus());
+ assertThat(response.getContentAsString(), containsString("Framework: org.apache.felix.framework"));
+ }
+ }
+ }
+}
diff --git a/tests/test-webapps/pom.xml b/tests/test-webapps/pom.xml
index 811613302a4..89c0bcb2b19 100644
--- a/tests/test-webapps/pom.xml
+++ b/tests/test-webapps/pom.xml
@@ -40,5 +40,6 @@
test-jndi-webapptest-http2-webapptest-simple-webapp
+ test-felix-webapp
\ No newline at end of file
diff --git a/tests/test-webapps/test-felix-webapp/pom.xml b/tests/test-webapps/test-felix-webapp/pom.xml
new file mode 100644
index 00000000000..454f1fe61da
--- /dev/null
+++ b/tests/test-webapps/test-felix-webapp/pom.xml
@@ -0,0 +1,50 @@
+
+
+
+ org.eclipse.jetty.tests
+ test-webapps-parent
+ 9.4.20-SNAPSHOT
+
+
+ 4.0.0
+ test-felix-webapp
+ Test :: Jetty Felix Webapp
+ war
+
+
+ ${project.groupId}.felix
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+ false
+
+
+
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ provided
+
+
+ org.apache.felix
+ org.apache.felix.framework
+ 5.6.2
+
+
+
diff --git a/tests/test-webapps/test-felix-webapp/src/main/java/org/eclipse/jetty/demo/AppListener.java b/tests/test-webapps/test-felix-webapp/src/main/java/org/eclipse/jetty/demo/AppListener.java
new file mode 100755
index 00000000000..69b780ae895
--- /dev/null
+++ b/tests/test-webapps/test-felix-webapp/src/main/java/org/eclipse/jetty/demo/AppListener.java
@@ -0,0 +1,82 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.demo;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ServiceLoader;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.annotation.WebListener;
+
+import org.osgi.framework.Constants;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+@WebListener
+public class AppListener implements ServletContextListener
+{
+ public void contextInitialized(ServletContextEvent sce)
+ {
+ Framework framework = initFelix();
+ sce.getServletContext().setAttribute(Framework.class.getName(), framework);
+ }
+
+ private Framework initFelix()
+ {
+ Map properties = new HashMap<>();
+
+ try
+ {
+ Path cacheDir = Files.createTempDirectory("felix-cache");
+ properties.put(Constants.FRAMEWORK_STORAGE, cacheDir.toAbsolutePath().toString());
+ properties.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
+ properties.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK);
+ properties.put(Constants.FRAMEWORK_BOOTDELEGATION, "*");
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable to configure Felix", e);
+ }
+
+ Framework framework = ServiceLoader.load(FrameworkFactory.class).iterator().next().newFramework(properties);
+
+ try
+ {
+ System.err.println("Initializing felix");
+ framework.init();
+ System.err.println("Starting felix");
+ framework.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.err);
+ throw new RuntimeException("Unable to start Felix", e);
+ }
+
+ return framework;
+ }
+
+ public void contextDestroyed(ServletContextEvent sce)
+ {
+ }
+}
diff --git a/tests/test-webapps/test-felix-webapp/src/main/java/org/eclipse/jetty/demo/InfoServlet.java b/tests/test-webapps/test-felix-webapp/src/main/java/org/eclipse/jetty/demo/InfoServlet.java
new file mode 100644
index 00000000000..ac33b980b81
--- /dev/null
+++ b/tests/test-webapps/test-felix-webapp/src/main/java/org/eclipse/jetty/demo/InfoServlet.java
@@ -0,0 +1,54 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.demo;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.launch.Framework;
+
+@WebServlet("/info")
+public class InfoServlet extends HttpServlet
+{
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
+ {
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType("text/plain");
+ resp.setCharacterEncoding("utf-8");
+
+ PrintWriter out = resp.getWriter();
+ Framework framework = (Framework)getServletContext().getAttribute(Framework.class.getName());
+ out.printf("Framework: %s\n", framework);
+ BundleContext bundleContext = framework.getBundleContext();
+ out.printf("BundleContext: %s\n", bundleContext);
+ Bundle bundleSelf = bundleContext.getBundle();
+ out.printf("BundleContext.bundle: %s\n", bundleSelf);
+ for (Bundle bundle : bundleContext.getBundles())
+ {
+ out.printf("bundle[]: %s\n", bundle);
+ }
+ }
+}
From 8c0f889abd79a006d5590c0b8036b9f72daa7543 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Fri, 14 Jun 2019 08:37:01 -0500
Subject: [PATCH 25/45] Issue #3698 - Updating javadoc on .initialize() method
purpose/meaning
Signed-off-by: Joakim Erdfelt
---
.../WebSocketServerContainerInitializer.java | 12 ++++++++++--
...iveWebSocketServletContainerInitializer.java | 13 +++++++++++--
.../server/WebSocketUpgradeFilter.java | 17 +++++++++++------
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
index ef025338ba3..f4e71a1f731 100644
--- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
+++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/deploy/WebSocketServerContainerInitializer.java
@@ -170,7 +170,15 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
* Immediately initialize the {@link ServletContext} with the default (and empty) {@link ServerContainer}.
*
*
- * This performs a subset of the behaviors that {@link #onStartup(Set, ServletContext)} does.
+ * This method is typically called from {@link #onStartup(Set, ServletContext)} itself or from
+ * another dependent {@link ServletContainerInitializer} that requires minimal setup to
+ * be performed.
+ *
+ *
+ * This method SHOULD NOT BE CALLED by users of Jetty.
+ * Use the {@link #configure(ServletContextHandler, Configurator)} method instead.
+ *
+ *
* There is no enablement check here, and no automatic deployment of endpoints at this point
* in time. It merely sets up the {@link ServletContext} so with the basics needed to start
* configuring for `javax.websocket.server` based endpoints.
@@ -208,7 +216,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
// Create Filter
if (isEnabledViaContext(context.getServletContext(), ADD_DYNAMIC_FILTER_KEY, true))
{
- WebSocketUpgradeFilter.initialize(context);
+ WebSocketUpgradeFilter.configure(context);
}
}
return serverContainer;
diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
index 51fdf9b7f3c..fd8d4f7b83e 100644
--- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
+++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.java
@@ -38,8 +38,17 @@ public class NativeWebSocketServletContainerInitializer implements ServletContai
* Immediately initialize the {@link ServletContextHandler} with the default {@link NativeWebSocketConfiguration}.
*
*
- * This will return the default {@link NativeWebSocketConfiguration} if already initialized,
- * and not create a new {@link NativeWebSocketConfiguration} each time it is called.
+ * This method is typically called from {@link #onStartup(Set, ServletContext)} itself or from
+ * another dependent {@link ServletContainerInitializer} that requires minimal setup to
+ * be performed.
+ *
+ *
+ * This method SHOULD NOT BE CALLED by users of Jetty.
+ * Use the {@link #configure(ServletContextHandler, Configurator)} method instead.
+ *
+ *
+ * This will return the default {@link NativeWebSocketConfiguration} if already initialized,
+ * and not create a new {@link NativeWebSocketConfiguration} each time it is called.
*
*
* @param context the context to work with
diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java
index 7f5613c366f..5aca83bb42d 100644
--- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java
+++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java
@@ -55,17 +55,22 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
public static final String ATTR_KEY = WebSocketUpgradeFilter.class.getName();
/**
- * Immediately initialize the default WebSocketUpgradeFilter.
+ * Configure the default WebSocketUpgradeFilter.
*
*
- * Return default {@link WebSocketUpgradeFilter} if
+ * This will return the default {@link WebSocketUpgradeFilter} on the
+ * provided {@link ServletContextHandler}, creating the filter if necessary.
+ *
+ *
+ * The default {@link WebSocketUpgradeFilter} is also available via
+ * the {@link ServletContext} attribute named {@code org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter}
*
*
* @param context the {@link ServletContextHandler} to use
* @return the configured default {@link WebSocketUpgradeFilter} instance
* @throws ServletException if the filer cannot be configured
*/
- public static WebSocketUpgradeFilter initialize(ServletContextHandler context) throws ServletException
+ public static WebSocketUpgradeFilter configure(ServletContextHandler context) throws ServletException
{
// Prevent double configure
WebSocketUpgradeFilter filter = (WebSocketUpgradeFilter) context.getAttribute(ATTR_KEY);
@@ -100,12 +105,12 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
* @param context the {@link ServletContextHandler} to use
* @return a configured {@link WebSocketUpgradeFilter} instance
* @throws ServletException if the filer cannot be configured
- * @deprecated use {@link #initialize(ServletContextHandler)} instead
+ * @deprecated use {@link #configure(ServletContextHandler)} instead
*/
@Deprecated
public static WebSocketUpgradeFilter configureContext(ServletContextHandler context) throws ServletException
{
- return initialize(context);
+ return configure(context);
}
/**
@@ -122,7 +127,7 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
{
throw new ServletException("Not running on Jetty, WebSocket support unavailable");
}
- return initialize(handler);
+ return configure(handler);
}
private NativeWebSocketConfiguration configuration;
From f54b6825283468ddbef6e9eaff2082e3511b180b Mon Sep 17 00:00:00 2001
From: Simone Bordet
Date: Sun, 16 Jun 2019 11:12:40 +0200
Subject: [PATCH 26/45] Fixes #3786 - ALPN support for Java 14.
Signed-off-by: Simone Bordet
---
.../src/main/config/modules/alpn-impl/alpn-14.mod | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-14.mod
diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-14.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-14.mod
new file mode 100644
index 00000000000..689601a4197
--- /dev/null
+++ b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-14.mod
@@ -0,0 +1,4 @@
+DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
+
+[depend]
+alpn-impl/alpn-9
From 1550d4f59a7d36ba9f18cf8191eec614e2312efe Mon Sep 17 00:00:00 2001
From: olivier lamy
Date: Sat, 15 Jun 2019 11:09:36 +1000
Subject: [PATCH 27/45] avoid depending on a range dependency from a transitive
dependency
Signed-off-by: olivier lamy
---
jetty-gcloud/jetty-gcloud-session-manager/pom.xml | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/jetty-gcloud/jetty-gcloud-session-manager/pom.xml b/jetty-gcloud/jetty-gcloud-session-manager/pom.xml
index 15c103fd57e..f9088835f35 100644
--- a/jetty-gcloud/jetty-gcloud-session-manager/pom.xml
+++ b/jetty-gcloud/jetty-gcloud-session-manager/pom.xml
@@ -33,6 +33,13 @@
+
+
+ io.grpc
+ grpc-core
+ 1.0.1
+ compile
+ com.google.auto.valueauto-value
From a18bd12ada2aabbb72cd142b05fffb0af6cabd6d Mon Sep 17 00:00:00 2001
From: Lachlan
Date: Thu, 13 Jun 2019 15:43:19 +1000
Subject: [PATCH 28/45] Issue #3762 - use the default port of 0 for WebSocket
tests
Signed-off-by: Lachlan Roberts
---
.../tests/WebSocketConnectionStatsTest.java | 72 +++----------------
.../tests/client/BadNetworkTest.java | 1 -
.../tests/client/ClientCloseTest.java | 1 -
.../tests/client/ClientSessionsTest.java | 1 -
.../tests/client/SlowClientTest.java | 1 -
.../tests/server/ServerCloseTest.java | 1 -
.../tests/server/SlowServerTest.java | 1 -
7 files changed, 10 insertions(+), 68 deletions(-)
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketConnectionStatsTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketConnectionStatsTest.java
index 68b16d1d909..a17eb1a7089 100644
--- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketConnectionStatsTest.java
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketConnectionStatsTest.java
@@ -33,15 +33,9 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.BufferUtil;
-import org.eclipse.jetty.websocket.api.CloseStatus;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
-import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
-import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
-import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
-import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
-import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.Generator;
@@ -60,52 +54,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class WebSocketConnectionStatsTest
{
-
- @WebSocket
- public static class ClientSocket
- {
- CountDownLatch closed = new CountDownLatch(1);
- int closeStatus;
- String closeReason;
- String behavior;
-
- @OnWebSocketConnect
- public void onOpen(Session session)
- {
- behavior = session.getPolicy().getBehavior().name();
- }
-
- @OnWebSocketClose
- public void onClose(int statusCode, String reason)
- {
- closeStatus = statusCode;
- closeReason = reason;
- closed.countDown();
- }
-
- @OnWebSocketError
- public void onError(Throwable cause)
- {
- cause.printStackTrace(System.err);
- }
-
- @Override
- public String toString()
- {
- return String.format("[%s@%s]", behavior, Integer.toHexString(hashCode()));
- }
- }
-
- @WebSocket
- public static class EchoSocket extends ClientSocket
- {
- @OnWebSocketMessage
- public void onMessage(Session session, String message)
- {
- session.getRemote().sendString(message, null);
- }
- }
-
public static class MyWebSocketServlet extends WebSocketServlet
{
@Override
@@ -115,11 +63,12 @@ public class WebSocketConnectionStatsTest
}
}
- Server server;
- WebSocketClient client;
- ConnectionStatistics statistics;
- CountDownLatch wsUpgradeComplete = new CountDownLatch(1);
- CountDownLatch wsConnectionClosed = new CountDownLatch(1);
+ private Server server;
+ private ServerConnector connector;
+ private WebSocketClient client;
+ private ConnectionStatistics statistics;
+ private CountDownLatch wsUpgradeComplete = new CountDownLatch(1);
+ private CountDownLatch wsConnectionClosed = new CountDownLatch(1);
@BeforeEach
public void start() throws Exception
@@ -139,8 +88,7 @@ public class WebSocketConnectionStatsTest
};
server = new Server();
- ServerConnector connector = new ServerConnector(server);
- connector.setPort(8080);
+ connector = new ServerConnector(server);
connector.addBean(statistics);
server.addConnector(connector);
@@ -175,8 +123,8 @@ public class WebSocketConnectionStatsTest
@Test
public void echoStatsTest() throws Exception
{
- URI uri = URI.create("ws://localhost:8080/testPath");
- ClientSocket socket = new ClientSocket();
+ URI uri = URI.create("ws://localhost:"+connector.getLocalPort()+"/testPath");
+ EventSocket socket = new EventSocket();
Future connect = client.connect(socket, uri);
final long numMessages = 10000;
@@ -208,7 +156,7 @@ public class WebSocketConnectionStatsTest
assertThat(statistics.getReceivedMessages(), is(numMessages + 2L));
WebSocketFrame textFrame = new TextFrame().setPayload(msgText);
- WebSocketFrame closeFrame = new CloseInfo(socket.closeStatus, socket.closeReason).asFrame();
+ WebSocketFrame closeFrame = new CloseInfo(socket.closeCode, socket.closeReason).asFrame();
final long textFrameSize = getFrameByteSize(textFrame);
final long closeFrameSize = getFrameByteSize(closeFrame);
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/BadNetworkTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/BadNetworkTest.java
index 2b51caf95d6..fe6df99bec0 100644
--- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/BadNetworkTest.java
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/BadNetworkTest.java
@@ -80,7 +80,6 @@ public class BadNetworkTest
server = new Server();
connector = new ServerConnector(server);
- connector.setPort(0);
server.addConnector(connector);
context = new ServletContextHandler();
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java
index c28d5aadae1..cd858295826 100644
--- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java
@@ -119,7 +119,6 @@ public class ClientCloseTest
server = new Server();
ServerConnector connector = new ServerConnector(server);
- connector.setPort(0);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java
index 8ce7e34a8da..dda19b04604 100644
--- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java
@@ -63,7 +63,6 @@ public class ClientSessionsTest
server = new Server();
ServerConnector connector = new ServerConnector(server);
- connector.setPort(0);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/SlowClientTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/SlowClientTest.java
index 27045eb17aa..f2bbde10ef5 100644
--- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/SlowClientTest.java
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/SlowClientTest.java
@@ -65,7 +65,6 @@ public class SlowClientTest
server = new Server();
ServerConnector connector = new ServerConnector(server);
- connector.setPort(0);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java
index 017482187ce..66260942988 100644
--- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java
@@ -65,7 +65,6 @@ public class ServerCloseTest
server = new Server();
ServerConnector connector = new ServerConnector(server);
- connector.setPort(0);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/SlowServerTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/SlowServerTest.java
index 19fb2cae723..2e8000be152 100644
--- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/SlowServerTest.java
+++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/SlowServerTest.java
@@ -64,7 +64,6 @@ public class SlowServerTest
server = new Server();
ServerConnector connector = new ServerConnector(server);
- connector.setPort(0);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler();
From 2f3eed86049600b9da385112168f7f8b658fd582 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Fri, 14 Jun 2019 11:20:08 -0500
Subject: [PATCH 29/45] Issue #3782 - reducing noise during testing
Signed-off-by: Joakim Erdfelt
---
jetty-server/src/test/resources/jetty-logging.properties | 1 +
1 file changed, 1 insertion(+)
diff --git a/jetty-server/src/test/resources/jetty-logging.properties b/jetty-server/src/test/resources/jetty-logging.properties
index 21db0759fe3..1ba30af5c5f 100644
--- a/jetty-server/src/test/resources/jetty-logging.properties
+++ b/jetty-server/src/test/resources/jetty-logging.properties
@@ -1,4 +1,5 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
+org.eclipse.jetty.LEVEL=WARN
#org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG
#org.eclipse.jetty.server.ConnectionLimit.LEVEL=DEBUG
From a1fe57a654db6a44449c0c7e40acb8217cc7eb28 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Fri, 14 Jun 2019 11:20:31 -0500
Subject: [PATCH 30/45] Issue #3782 - updating existing testcases
Signed-off-by: Joakim Erdfelt
---
.../ForwardedRequestCustomizerTest.java | 682 ++++++++++--------
1 file changed, 377 insertions(+), 305 deletions(-)
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
index db8a9ad64e0..5c38e601d52 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
@@ -19,25 +19,20 @@
package org.eclipse.jetty.server;
import java.io.IOException;
-import java.util.ArrayDeque;
-import java.util.Deque;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.eclipse.jetty.http.MimeTypes;
+import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.eclipse.jetty.util.IO;
-import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -46,11 +41,15 @@ public class ForwardedRequestCustomizerTest
private Server _server;
private LocalConnector _connector;
private RequestHandler _handler;
- final Deque _results = new ArrayDeque<>();
final AtomicBoolean _wasSecure = new AtomicBoolean(false);
final AtomicReference _sslSession = new AtomicReference<>();
final AtomicReference _sslCertificate = new AtomicReference<>();
-
+ final AtomicReference _scheme = new AtomicReference<>();
+ final AtomicReference _serverName = new AtomicReference<>();
+ final AtomicReference _serverPort = new AtomicReference<>();
+ final AtomicReference _remoteAddr = new AtomicReference<>();
+ final AtomicReference _remotePort = new AtomicReference<>();
+
ForwardedRequestCustomizer _customizer;
@BeforeEach
@@ -62,29 +61,25 @@ public class ForwardedRequestCustomizerTest
http.getHttpConfiguration().setRequestHeaderSize(512);
http.getHttpConfiguration().setResponseHeaderSize(512);
http.getHttpConfiguration().setOutputBufferSize(2048);
- http.getHttpConfiguration().addCustomizer(_customizer=new ForwardedRequestCustomizer());
- _connector = new LocalConnector(_server,http);
+ http.getHttpConfiguration().addCustomizer(_customizer = new ForwardedRequestCustomizer());
+ _connector = new LocalConnector(_server, http);
_server.addConnector(_connector);
_handler = new RequestHandler();
_server.setHandler(_handler);
- _handler._checker = new RequestTester()
+ _handler._checker = (request, response) ->
{
- @Override
- public boolean check(HttpServletRequest request,HttpServletResponse response)
- {
- _wasSecure.set(request.isSecure());
- _sslSession.set(String.valueOf(request.getAttribute("javax.servlet.request.ssl_session_id")));
- _sslCertificate.set(String.valueOf(request.getAttribute("javax.servlet.request.cipher_suite")));
- _results.add(request.getScheme());
- _results.add(request.getServerName());
- _results.add(Integer.toString(request.getServerPort()));
- _results.add(request.getRemoteAddr());
- _results.add(Integer.toString(request.getRemotePort()));
- return true;
- }
+ _wasSecure.set(request.isSecure());
+ _sslSession.set(String.valueOf(request.getAttribute("javax.servlet.request.ssl_session_id")));
+ _sslCertificate.set(String.valueOf(request.getAttribute("javax.servlet.request.cipher_suite")));
+ _scheme.set(request.getScheme());
+ _serverName.set(request.getServerName());
+ _serverPort.set(request.getServerPort());
+ _remoteAddr.set(request.getRemoteAddr());
+ _remotePort.set(request.getRemotePort());
+ return true;
};
-
+
_server.start();
}
@@ -92,391 +87,468 @@ public class ForwardedRequestCustomizerTest
public void destroy() throws Exception
{
_server.stop();
- _server.join();
}
@Test
public void testHostIpv4() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: 1.2.3.4:2222\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("1.2.3.4",_results.poll());
- assertEquals("2222",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: 1.2.3.4:2222\n" +
+ "\n"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("1.2.3.4"));
+ assertThat("serverPort", _serverPort.get(), is(2222));
}
@Test
public void testHostIpv6() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: [::1]:2222\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("[::1]",_results.poll());
- assertEquals("2222",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: [::1]:2222\n" +
+ "\n"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("[::1]"));
+ assertThat("serverPort", _serverPort.get(), is(2222));
}
-
-
@Test
public void testURIIpv4() throws Exception
{
- String response=_connector.getResponse(
- "GET http://1.2.3.4:2222/ HTTP/1.1\n"+
- "Host: wrong\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("1.2.3.4",_results.poll());
- assertEquals("2222",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET http://1.2.3.4:2222/ HTTP/1.1\n" +
+ "Host: wrong\n" +
+ "\n"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("1.2.3.4"));
+ assertThat("serverPort", _serverPort.get(), is(2222));
}
@Test
public void testURIIpv6() throws Exception
{
- String response=_connector.getResponse(
- "GET http://[::1]:2222/ HTTP/1.1\n"+
- "Host: wrong\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("[::1]",_results.poll());
- assertEquals("2222",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET http://[::1]:2222/ HTTP/1.1\n" +
+ "Host: wrong\n" +
+ "\n"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("[::1]"));
+ assertThat("serverPort", _serverPort.get(), is(2222));
}
-
+ /**
+ * RFC 7239: Section 4
+ *
+ * Examples of syntax.
+ */
@Test
public void testRFC7239_Examples_4() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Forwarded: for=\"_gazonk\"\n"+
- "Forwarded: For=\"[2001:db8:cafe::17]:4711\"\n"+
- "Forwarded: for=192.0.2.60;proto=http;by=203.0.113.43\n"+
- "Forwarded: for=192.0.2.43, for=198.51.100.17\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("[2001:db8:cafe::17]",_results.poll());
- assertEquals("4711",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Forwarded: for=\"_gazonk\"\n" +
+ "Forwarded: For=\"[2001:db8:cafe::17]:4711\"\n" +
+ "Forwarded: for=192.0.2.60;proto=http;by=203.0.113.43\n" +
+ "Forwarded: for=192.0.2.43, for=198.51.100.17\n" +
+ "\n"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("[2001:db8:cafe::17]"));
+ assertThat("remotePort", _remotePort.get(), is(4711));
}
-
+
+ /**
+ * RFC 7239: Section 7.1
+ *
+ * Examples of syntax with regards to HTTP header fields
+ */
@Test
public void testRFC7239_Examples_7_1() throws Exception
{
- _connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Forwarded: for=192.0.2.43,for=\"[2001:db8:cafe::17]\",for=unknown\n"+
- "\n");
- _connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Forwarded: for=192.0.2.43, for=\"[2001:db8:cafe::17]\", for=unknown\n"+
- "\n");
- _connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Forwarded: for=192.0.2.43\n"+
- "Forwarded: for=\"[2001:db8:cafe::17]\", for=unknown\n"+
- "\n");
+ // Without spaces
+ HttpTester.Response response1 = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Forwarded: for=192.0.2.43,for=\"[2001:db8:cafe::17]\",for=unknown\n" +
+ "\n"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("192.0.2.43",_results.poll());
- assertEquals("0",_results.poll());
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("192.0.2.43",_results.poll());
- assertEquals("0",_results.poll());
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("192.0.2.43",_results.poll());
- assertEquals("0",_results.poll());
+ assertThat("status", response1.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
+ assertThat("remotePort", _remotePort.get(), is(0));
+
+ // With spaces
+ HttpTester.Response response2 = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Forwarded: for=192.0.2.43, for=\"[2001:db8:cafe::17]\", for=unknown\n" +
+ "\n"));
+ assertThat("status", response2.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
+ assertThat("remotePort", _remotePort.get(), is(0));
+
+ // As multiple headers
+ HttpTester.Response response3 = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Forwarded: for=192.0.2.43\n" +
+ "Forwarded: for=\"[2001:db8:cafe::17]\", for=unknown\n" +
+ "\n"));
+
+ assertThat("status", response3.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
+ /**
+ * RFC 7239: Section 7.4
+ *
+ * Transition
+ */
@Test
public void testRFC7239_Examples_7_4() throws Exception
{
- _connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Forwarded: for=192.0.2.43, for=\"[2001:db8:cafe::17]\"\n"+
- "\n");
+ // Old syntax
+ HttpTester.Response response1 = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-For: 192.0.2.43, 2001:db8:cafe::17\n" +
+ "\n"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("192.0.2.43",_results.poll());
- assertEquals("0",_results.poll());
+ assertThat("status", response1.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
+ assertThat("remotePort", _remotePort.get(), is(0));
+
+ // New syntax
+ HttpTester.Response response2 = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Forwarded: for=192.0.2.43, for=\"[2001:db8:cafe::17]\"\n" +
+ "\n"));
+
+ assertThat("status", response2.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
+ /**
+ * RFC 7239: Section 7.5
+ *
+ * Example Usage
+ */
@Test
public void testRFC7239_Examples_7_5() throws Exception
{
- _connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Forwarded: for=192.0.2.43,for=198.51.100.17;by=203.0.113.60;proto=http;host=example.com\n"+
- "\n");
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Forwarded: for=192.0.2.43,for=198.51.100.17;by=203.0.113.60;proto=http;host=example.com\n" +
+ "\n"));
- assertEquals("http",_results.poll());
- assertEquals("example.com",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("192.0.2.43",_results.poll());
- assertEquals("0",_results.poll());
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("example.com"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
@Test
- public void testProto() throws Exception
+ public void testProto_OldSyntax() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "X-Forwarded-Proto: foobar\n"+
- "Forwarded: proto=https\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("https",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("443",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-Proto: https\n" +
+ "\n"));
+
+ assertTrue(_wasSecure.get(), "wasSecure");
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("https"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(443));
+ assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
+ assertThat("remotePort", _remotePort.get(), is(0));
+ }
+
+ @Test
+ public void testRFC7239_Proto() throws Exception
+ {
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Forwarded: proto=https\n" +
+ "\n"));
+
+ assertTrue(_wasSecure.get(), "wasSecure");
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("https"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(443));
+ assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
@Test
public void testFor() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "X-Forwarded-For: 10.9.8.7,6.5.4.3\n"+
- "X-Forwarded-For: 8.9.8.7,7.5.4.3\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("10.9.8.7",_results.poll());
- assertEquals("0",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-For: 10.9.8.7,6.5.4.3\n" +
+ "X-Forwarded-For: 8.9.8.7,7.5.4.3\n" +
+ "\n"));
+
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("10.9.8.7"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
@Test
public void testForIpv4WithPort() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "X-Forwarded-For: 10.9.8.7:1111,6.5.4.3:2222\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("10.9.8.7",_results.poll());
- assertEquals("1111",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-For: 10.9.8.7:1111,6.5.4.3:2222\n" +
+ "\n"));
+
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("10.9.8.7"));
+ assertThat("remotePort", _remotePort.get(), is(1111));
}
@Test
public void testForIpv6WithPort() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "X-Forwarded-For: [2001:db8:cafe::17]:1111,6.5.4.3:2222\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("[2001:db8:cafe::17]",_results.poll());
- assertEquals("1111",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-For: [2001:db8:cafe::17]:1111,6.5.4.3:2222\n" +
+ "\n"));
+
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("[2001:db8:cafe::17]"));
+ assertThat("remotePort", _remotePort.get(), is(1111));
}
@Test
public void testForIpv6AndPort() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "X-Forwarded-For: 1:2:3:4:5:6:7:8\n"+
- "X-Forwarded-Port: 2222\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("[1:2:3:4:5:6:7:8]",_results.poll());
- assertEquals("2222",_results.poll());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-For: 1:2:3:4:5:6:7:8\n" +
+ "X-Forwarded-Port: 2222\n" +
+ "\n"));
- response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "X-Forwarded-Port: 2222\n"+
- "X-Forwarded-For: 1:2:3:4:5:6:7:8\n"+
- "X-Forwarded-For: 7:7:7:7:7:7:7:7\n"+
- "X-Forwarded-Port: 3333\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("[1:2:3:4:5:6:7:8]",_results.poll());
- assertEquals("2222",_results.poll());
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("[1:2:3:4:5:6:7:8]"));
+ assertThat("remotePort", _remotePort.get(), is(2222));
+ }
+
+ @Test
+ public void testForIpv6AndPort_MultiField() throws Exception
+ {
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-Port: 2222\n" +
+ "X-Forwarded-For: 1:2:3:4:5:6:7:8\n" +
+ "X-Forwarded-For: 7:7:7:7:7:7:7:7\n" +
+ "X-Forwarded-Port: 3333\n" +
+ "\n"));
+
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("[1:2:3:4:5:6:7:8]"));
+ assertThat("remotePort", _remotePort.get(), is(2222));
}
@Test
public void testLegacyProto() throws Exception
{
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "X-Proxied-Https: on\n"+
- "\n");
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("https",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("443",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
- assertTrue(_wasSecure.get());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Proxied-Https: on\n" +
+ "\n"));
+ assertTrue(_wasSecure.get(), "wasSecure");
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("https"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(443));
+ assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
@Test
public void testSslSession() throws Exception
{
_customizer.setSslIsSecure(false);
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Proxy-Ssl-Id: Wibble\n"+
- "\n");
-
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
- assertFalse(_wasSecure.get());
- assertEquals("Wibble",_sslSession.get());
-
- _customizer.setSslIsSecure(true);
- response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Proxy-Ssl-Id: 0123456789abcdef\n"+
- "\n");
-
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("https",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("443",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
- assertTrue(_wasSecure.get());
- assertEquals("0123456789abcdef",_sslSession.get());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Proxy-Ssl-Id: Wibble\n" +
+ "\n"));
+
+ assertFalse(_wasSecure.get(), "wasSecure");
+ assertThat("sslSession", _sslSession.get(), is("Wibble"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
+ assertThat("remotePort", _remotePort.get(), is(0));
+
+ _customizer.setSslIsSecure(true);
+ response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Proxy-Ssl-Id: 0123456789abcdef\n" +
+ "\n"));
+
+ assertTrue(_wasSecure.get(), "wasSecure");
+ assertThat("sslSession", _sslSession.get(), is("0123456789abcdef"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("https"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(443));
+ assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
-
+
@Test
public void testSslCertificate() throws Exception
{
_customizer.setSslIsSecure(false);
- String response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Proxy-auth-cert: Wibble\n"+
- "\n");
-
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("http",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
- assertFalse(_wasSecure.get());
- assertEquals("Wibble",_sslCertificate.get());
-
-
- _customizer.setSslIsSecure(true);
- response=_connector.getResponse(
- "GET / HTTP/1.1\n"+
- "Host: myhost\n"+
- "Proxy-auth-cert: 0123456789abcdef\n"+
- "\n");
-
- assertThat(response, Matchers.containsString("200 OK"));
- assertEquals("https",_results.poll());
- assertEquals("myhost",_results.poll());
- assertEquals("443",_results.poll());
- assertEquals("0.0.0.0",_results.poll());
- assertEquals("0",_results.poll());
- assertTrue(_wasSecure.get());
- assertEquals("0123456789abcdef",_sslCertificate.get());
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Proxy-auth-cert: Wibble\n" +
+ "\n"));
+
+ assertFalse(_wasSecure.get(), "wasSecure");
+ assertThat("sslCertificate", _sslCertificate.get(), is("Wibble"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
+ assertThat("remotePort", _remotePort.get(), is(0));
+
+ _customizer.setSslIsSecure(true);
+ response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "Proxy-auth-cert: 0123456789abcdef\n" +
+ "\n"));
+
+ assertTrue(_wasSecure.get(), "wasSecure");
+ assertThat("sslCertificate", _sslCertificate.get(), is("0123456789abcdef"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("https"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(443));
+ assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
-
@Test
- public void testMixed() throws Exception
+ public void testMixed_For_Port_RFC_For() throws Exception
{
- String response = _connector.getResponse(
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
"GET / HTTP/1.1\n" +
"Host: myhost\n" +
"X-Forwarded-For: 11.9.8.7:1111,8.5.4.3:2222\n" +
"X-Forwarded-Port: 3333\n" +
- "Forwarded: for=192.0.2.43,for=198.51.100.17;by=203.0.113.60;proto=http;host=example.com\n"+
+ "Forwarded: for=192.0.2.43,for=198.51.100.17;by=203.0.113.60;proto=http;host=example.com\n" +
"X-Forwarded-For: 11.9.8.7:1111,8.5.4.3:2222\n" +
- "\n");
+ "\n"));
- assertEquals("http",_results.poll());
- assertEquals("example.com",_results.poll());
- assertEquals("80",_results.poll());
- assertEquals("192.0.2.43",_results.poll());
- assertEquals("0",_results.poll());
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("example.com"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
+ assertThat("remotePort", _remotePort.get(), is(0));
}
-
-
+
interface RequestTester
{
- boolean check(HttpServletRequest request,HttpServletResponse response) throws IOException;
+ boolean check(HttpServletRequest request, HttpServletResponse response) throws IOException;
}
private class RequestHandler extends AbstractHandler
{
private RequestTester _checker;
- @SuppressWarnings("unused")
- private String _content;
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
- ((Request)request).setHandled(true);
+ baseRequest.setHandled(true);
- if (request.getContentLength()>0
- && !MimeTypes.Type.FORM_ENCODED.asString().equals(request.getContentType())
- && !request.getContentType().startsWith("multipart/form-data"))
- _content=IO.toString(request.getInputStream());
-
- if (_checker!=null && _checker.check(request,response))
+ if (_checker != null && _checker.check(request, response))
response.setStatus(200);
else
response.sendError(500);
From 345750f9fdc6673fdbf01545d4b0cad074e4d694 Mon Sep 17 00:00:00 2001
From: Joakim Erdfelt
Date: Fri, 14 Jun 2019 12:28:58 -0500
Subject: [PATCH 31/45] Issue #3782 - X-Forwarded-Port refers to node listening
port
+ Updating testcases to test requestURL as well.
+ Adding new testcases for X-Forwarded-Port modifying only
the port of an existing `Host:` header.
Signed-off-by: Joakim Erdfelt
---
.../server/ForwardedRequestCustomizer.java | 24 ++++--
.../ForwardedRequestCustomizerTest.java | 78 ++++++++++++++++++-
2 files changed, 93 insertions(+), 9 deletions(-)
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
index e098a68e635..e9320300153 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
@@ -22,7 +22,6 @@ import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.InetSocketAddress;
-
import javax.servlet.ServletRequest;
import org.eclipse.jetty.http.HostPortHttpField;
@@ -448,6 +447,8 @@ public class ForwardedRequestCustomizer implements Customizer
size += 128;
_handles = new ArrayTrie<>(size);
+ _handles.put(HttpHeader.HOST.toString(), lookup.findVirtual(Forwarded.class, "handleHttpHost", type));
+
if (_forwardedCipherSuiteHeader != null && !_handles.put(_forwardedCipherSuiteHeader, lookup.findVirtual(Forwarded.class, "handleCipherSuite", type)))
continue;
if (_forwardedSslSessionIdHeader != null && !_handles.put(_forwardedSslSessionIdHeader, lookup.findVirtual(Forwarded.class, "handleSslSessionId", type)))
@@ -513,6 +514,7 @@ public class ForwardedRequestCustomizer implements Customizer
String _proto;
HostPort _for;
HostPort _host;
+ HostPort _httpHost;
public Forwarded(Request request, HttpConfiguration config)
{
@@ -523,6 +525,13 @@ public class ForwardedRequestCustomizer implements Customizer
_host = _forcedHost.getHostPort();
}
+ public void handleHttpHost(HttpField field)
+ {
+ _httpHost = new HostPort(field.getValue());
+ if (_host != null && _host instanceof XHostPort && "unknown".equals(_host.getHost()))
+ _host = new XHostPort(_httpHost.getHost(), _host.getPort());
+ }
+
public void handleCipherSuite(HttpField field)
{
_request.setAttribute("javax.servlet.request.cipher_suite", field.getValue());
@@ -547,6 +556,8 @@ public class ForwardedRequestCustomizer implements Customizer
{
if (_host==null)
_host = new XHostPort(getLeftMost(field.getValue()));
+ else if (_host instanceof XHostPort && "unknown".equals(_host.getHost()))
+ _host = new XHostPort(getLeftMost(field.getValue()), _host.getPort());
}
public void handleServer(HttpField field)
@@ -571,10 +582,13 @@ public class ForwardedRequestCustomizer implements Customizer
public void handlePort(HttpField field)
{
- if (_for == null)
- _for = new XHostPort("unknown", field.getIntValue());
- else if (_for instanceof XHostPort && _for.getPort()<=0)
- _for = new XHostPort(HostPort.normalizeHost(_for.getHost()), field.getIntValue());
+ if (_host == null)
+ {
+ String hostname = _httpHost != null ? _httpHost.getHost() : "unknown";
+ _host = new XHostPort(hostname, field.getIntValue());
+ }
+ else if (_host instanceof XHostPort && _host.getPort()<=0)
+ _host = new XHostPort(HostPort.normalizeHost(_host.getHost()), field.getIntValue());
}
public void handleHttps(HttpField field)
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
index 5c38e601d52..8f5ef3b0f81 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
@@ -49,6 +49,7 @@ public class ForwardedRequestCustomizerTest
final AtomicReference _serverPort = new AtomicReference<>();
final AtomicReference _remoteAddr = new AtomicReference<>();
final AtomicReference _remotePort = new AtomicReference<>();
+ final AtomicReference _requestURL = new AtomicReference<>();
ForwardedRequestCustomizer _customizer;
@@ -77,6 +78,7 @@ public class ForwardedRequestCustomizerTest
_serverPort.set(request.getServerPort());
_remoteAddr.set(request.getRemoteAddr());
_remotePort.set(request.getRemotePort());
+ _requestURL.set(request.getRequestURL().toString());
return true;
};
@@ -101,6 +103,7 @@ public class ForwardedRequestCustomizerTest
assertThat("scheme", _scheme.get(), is("http"));
assertThat("serverName", _serverName.get(), is("1.2.3.4"));
assertThat("serverPort", _serverPort.get(), is(2222));
+ assertThat("requestURL", _requestURL.get(), is("http://1.2.3.4:2222/"));
}
@Test
@@ -115,6 +118,7 @@ public class ForwardedRequestCustomizerTest
assertThat("scheme", _scheme.get(), is("http"));
assertThat("serverName", _serverName.get(), is("[::1]"));
assertThat("serverPort", _serverPort.get(), is(2222));
+ assertThat("requestURL", _requestURL.get(), is("http://[::1]:2222/"));
}
@Test
@@ -129,6 +133,7 @@ public class ForwardedRequestCustomizerTest
assertThat("scheme", _scheme.get(), is("http"));
assertThat("serverName", _serverName.get(), is("1.2.3.4"));
assertThat("serverPort", _serverPort.get(), is(2222));
+ assertThat("requestURL", _requestURL.get(), is("http://1.2.3.4:2222/"));
}
@Test
@@ -143,6 +148,7 @@ public class ForwardedRequestCustomizerTest
assertThat("scheme", _scheme.get(), is("http"));
assertThat("serverName", _serverName.get(), is("[::1]"));
assertThat("serverPort", _serverPort.get(), is(2222));
+ assertThat("requestURL", _requestURL.get(), is("http://[::1]:2222/"));
}
/**
@@ -168,6 +174,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("[2001:db8:cafe::17]"));
assertThat("remotePort", _remotePort.get(), is(4711));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
}
/**
@@ -192,6 +199,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
// With spaces
HttpTester.Response response2 = HttpTester.parseResponse(
@@ -206,6 +214,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
// As multiple headers
HttpTester.Response response3 = HttpTester.parseResponse(
@@ -222,6 +231,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
}
/**
@@ -246,6 +256,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
// New syntax
HttpTester.Response response2 = HttpTester.parseResponse(
@@ -261,6 +272,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
}
/**
@@ -284,6 +296,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://example.com/"));
}
@Test
@@ -303,6 +316,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(443));
assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("https://myhost/"));
}
@Test
@@ -322,6 +336,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(443));
assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("https://myhost/"));
}
@Test
@@ -341,6 +356,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("10.9.8.7"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
}
@Test
@@ -359,6 +375,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("10.9.8.7"));
assertThat("remotePort", _remotePort.get(), is(1111));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
}
@Test
@@ -377,6 +394,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("[2001:db8:cafe::17]"));
assertThat("remotePort", _remotePort.get(), is(1111));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
}
@Test
@@ -393,9 +411,10 @@ public class ForwardedRequestCustomizerTest
assertThat("status", response.getStatus(), is(200));
assertThat("scheme", _scheme.get(), is("http"));
assertThat("serverName", _serverName.get(), is("myhost"));
- assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("serverPort", _serverPort.get(), is(2222));
assertThat("remoteAddr", _remoteAddr.get(), is("[1:2:3:4:5:6:7:8]"));
- assertThat("remotePort", _remotePort.get(), is(2222));
+ assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost:2222/"));
}
@Test
@@ -414,9 +433,10 @@ public class ForwardedRequestCustomizerTest
assertThat("status", response.getStatus(), is(200));
assertThat("scheme", _scheme.get(), is("http"));
assertThat("serverName", _serverName.get(), is("myhost"));
- assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("serverPort", _serverPort.get(), is(2222));
assertThat("remoteAddr", _remoteAddr.get(), is("[1:2:3:4:5:6:7:8]"));
- assertThat("remotePort", _remotePort.get(), is(2222));
+ assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost:2222/"));
}
@Test
@@ -435,6 +455,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(443));
assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("https://myhost/"));
}
@Test
@@ -456,6 +477,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
_customizer.setSslIsSecure(true);
response = HttpTester.parseResponse(
@@ -473,6 +495,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(443));
assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("https://myhost/"));
}
@Test
@@ -494,6 +517,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
_customizer.setSslIsSecure(true);
response = HttpTester.parseResponse(
@@ -511,6 +535,51 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(443));
assertThat("remoteAddr", _remoteAddr.get(), is("0.0.0.0"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("https://myhost/"));
+ }
+
+ /**
+ * Resetting the server port via a forwarding header
+ */
+ @Test
+ public void testPort_For() throws Exception
+ {
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-Port: 4444\n" +
+ "X-Forwarded-For: 192.168.1.200\n" +
+ "\n"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(4444));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.168.1.200"));
+ assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost:4444/"));
+ }
+
+ /**
+ * Test setting the server Port before the "Host" header has been seen.
+ */
+ @Test
+ public void testPort_For_LateHost() throws Exception
+ {
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "X-Forwarded-Port: 4444\n" + // this order is intentional
+ "X-Forwarded-For: 192.168.1.200\n" +
+ "Host: myhost\n" + // leave this as the last header
+ "\n"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(4444));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.168.1.200"));
+ assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost:4444/"));
}
@Test
@@ -532,6 +601,7 @@ public class ForwardedRequestCustomizerTest
assertThat("serverPort", _serverPort.get(), is(80));
assertThat("remoteAddr", _remoteAddr.get(), is("192.0.2.43"));
assertThat("remotePort", _remotePort.get(), is(0));
+ assertThat("requestURL", _requestURL.get(), is("http://example.com/"));
}
interface RequestTester
From 9cf8cf3c0d60c7e92cf0239730183168e90a663b Mon Sep 17 00:00:00 2001
From: Greg Wilkins
Date: Mon, 17 Jun 2019 11:35:40 +0200
Subject: [PATCH 32/45] Issue #3782 X-Forwarded-Port can be remote or local
Added option for X-Forwarded-Port to be remote or local with default
being local.
Signed-off-by: Greg Wilkins
---
.../main/config/etc/jetty-http-forwarded.xml | 1 +
.../main/config/modules/http-forwarded.mod | 1 +
.../server/ForwardedRequestCustomizer.java | 93 ++++++++++++-------
.../ForwardedRequestCustomizerTest.java | 25 +++++
4 files changed, 89 insertions(+), 31 deletions(-)
diff --git a/jetty-server/src/main/config/etc/jetty-http-forwarded.xml b/jetty-server/src/main/config/etc/jetty-http-forwarded.xml
index 648d6c6a94f..8d0047cc54d 100644
--- a/jetty-server/src/main/config/etc/jetty-http-forwarded.xml
+++ b/jetty-server/src/main/config/etc/jetty-http-forwarded.xml
@@ -12,6 +12,7 @@
+
diff --git a/jetty-server/src/main/config/modules/http-forwarded.mod b/jetty-server/src/main/config/modules/http-forwarded.mod
index f67822065a4..7e6545a5902 100644
--- a/jetty-server/src/main/config/modules/http-forwarded.mod
+++ b/jetty-server/src/main/config/modules/http-forwarded.mod
@@ -24,6 +24,7 @@ etc/jetty-http-forwarded.xml
# jetty.httpConfig.forwardedProtoHeader=X-Forwarded-Proto
# jetty.httpConfig.forwardedForHeader=X-Forwarded-For
# jetty.httpConfig.forwardedPortHeader=X-Forwarded-Port
+# jetty.httpConfig.forwardedPortHeaderRemote=false
# jetty.httpConfig.forwardedHttpsHeader=X-Proxied-Https
# jetty.httpConfig.forwardedSslSessionIdHeader=Proxy-ssl-id
# jetty.httpConfig.forwardedCipherSuiteHeader=Proxy-auth-cert
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
index e9320300153..171384bd672 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
@@ -73,6 +73,7 @@ public class ForwardedRequestCustomizer implements Customizer
private String _forwardedProtoHeader = HttpHeader.X_FORWARDED_PROTO.toString();
private String _forwardedForHeader = HttpHeader.X_FORWARDED_FOR.toString();
private String _forwardedPortHeader = HttpHeader.X_FORWARDED_PORT.toString();
+ private boolean _forwardedPortHeaderRemote = false;
private String _forwardedHttpsHeader = "X-Proxied-Https";
private String _forwardedCipherSuiteHeader = "Proxy-auth-cert";
private String _forwardedSslSessionIdHeader = "Proxy-ssl-id";
@@ -251,6 +252,16 @@ public class ForwardedRequestCustomizer implements Customizer
}
}
+ public boolean isForwardedPortHeaderRemote()
+ {
+ return _forwardedPortHeaderRemote;
+ }
+
+ public void setForwardedPortHeaderRemote(boolean forwardedPortHeaderRemote)
+ {
+ _forwardedPortHeaderRemote = forwardedPortHeaderRemote;
+ }
+
/**
* Get the forwardedProtoHeader.
*
@@ -447,8 +458,6 @@ public class ForwardedRequestCustomizer implements Customizer
size += 128;
_handles = new ArrayTrie<>(size);
- _handles.put(HttpHeader.HOST.toString(), lookup.findVirtual(Forwarded.class, "handleHttpHost", type));
-
if (_forwardedCipherSuiteHeader != null && !_handles.put(_forwardedCipherSuiteHeader, lookup.findVirtual(Forwarded.class, "handleCipherSuite", type)))
continue;
if (_forwardedSslSessionIdHeader != null && !_handles.put(_forwardedSslSessionIdHeader, lookup.findVirtual(Forwarded.class, "handleSslSessionId", type)))
@@ -484,14 +493,22 @@ public class ForwardedRequestCustomizer implements Customizer
}
}
- private static class XHostPort extends HostPort
+ private static class PossiblyPartialHostPort extends HostPort
{
- XHostPort(String authority)
+ PossiblyPartialHostPort(String authority)
{
super(authority);
}
- XHostPort(String host, int port)
+ protected PossiblyPartialHostPort(String host, int port)
+ {
+ super(host, port);
+ }
+ }
+
+ private static class PortSetHostPort extends PossiblyPartialHostPort
+ {
+ PortSetHostPort(String host, int port)
{
super(host, port);
}
@@ -514,7 +531,6 @@ public class ForwardedRequestCustomizer implements Customizer
String _proto;
HostPort _for;
HostPort _host;
- HostPort _httpHost;
public Forwarded(Request request, HttpConfiguration config)
{
@@ -525,13 +541,6 @@ public class ForwardedRequestCustomizer implements Customizer
_host = _forcedHost.getHostPort();
}
- public void handleHttpHost(HttpField field)
- {
- _httpHost = new HostPort(field.getValue());
- if (_host != null && _host instanceof XHostPort && "unknown".equals(_host.getHost()))
- _host = new XHostPort(_httpHost.getHost(), _host.getPort());
- }
-
public void handleCipherSuite(HttpField field)
{
_request.setAttribute("javax.servlet.request.cipher_suite", field.getValue());
@@ -554,16 +563,24 @@ public class ForwardedRequestCustomizer implements Customizer
public void handleHost(HttpField field)
{
- if (_host==null)
- _host = new XHostPort(getLeftMost(field.getValue()));
- else if (_host instanceof XHostPort && "unknown".equals(_host.getHost()))
- _host = new XHostPort(getLeftMost(field.getValue()), _host.getPort());
+ if (!_forwardedPortHeaderRemote && !StringUtil.isEmpty(_forwardedPortHeader))
+ {
+ if (_host == null)
+ _host = new PossiblyPartialHostPort(getLeftMost(field.getValue()));
+ else if (_for instanceof PortSetHostPort)
+ _host = new HostPort(HostPort.normalizeHost(getLeftMost(field.getValue())), _host.getPort());
+ }
+ else if (_host==null)
+ {
+ _host = new HostPort(getLeftMost(field.getValue()));
+ }
}
public void handleServer(HttpField field)
{
- if (_proxyAsAuthority && _host==null)
- _host = new XHostPort(getLeftMost(field.getValue()));
+ if (_proxyAsAuthority)
+ return;
+ handleHost(field);
}
public void handleProto(HttpField field)
@@ -574,21 +591,35 @@ public class ForwardedRequestCustomizer implements Customizer
public void handleFor(HttpField field)
{
- if (_for==null)
- _for = new XHostPort(getLeftMost(field.getValue()));
- else if (_for instanceof XHostPort && "unknown".equals(_for.getHost()))
- _for = new XHostPort(HostPort.normalizeHost(getLeftMost(field.getValue())),_for.getPort());
+ if (_forwardedPortHeaderRemote && !StringUtil.isEmpty(_forwardedPortHeader))
+ {
+ if (_for == null)
+ _for = new PossiblyPartialHostPort(getLeftMost(field.getValue()));
+ else if (_for instanceof PortSetHostPort)
+ _for = new HostPort(HostPort.normalizeHost(getLeftMost(field.getValue())), _for.getPort());
+ }
+ else if (_for == null)
+ {
+ _for = new HostPort(getLeftMost(field.getValue()));
+ }
}
public void handlePort(HttpField field)
{
- if (_host == null)
+ if (_forwardedPortHeaderRemote)
{
- String hostname = _httpHost != null ? _httpHost.getHost() : "unknown";
- _host = new XHostPort(hostname, field.getIntValue());
+ if (_for == null)
+ _for = new PortSetHostPort(_request.getRemoteHost(), field.getIntValue());
+ else if (_for instanceof PossiblyPartialHostPort && _for.getPort() <= 0)
+ _for = new HostPort(HostPort.normalizeHost(_for.getHost()), field.getIntValue());
+ }
+ else
+ {
+ if (_host == null)
+ _host = new PortSetHostPort(_request.getServerName(), field.getIntValue());
+ else if (_host instanceof PossiblyPartialHostPort && _host.getPort() <= 0)
+ _host = new HostPort(HostPort.normalizeHost(_host.getHost()), field.getIntValue());
}
- else if (_host instanceof XHostPort && _host.getPort()<=0)
- _host = new XHostPort(HostPort.normalizeHost(_host.getHost()), field.getIntValue());
}
public void handleHttps(HttpField field)
@@ -616,19 +647,19 @@ public class ForwardedRequestCustomizer implements Customizer
break;
if (value.startsWith("_") || "unknown".equals(value))
break;
- if (_host == null || _host instanceof XHostPort)
+ if (_host == null || !(_host instanceof Rfc7239HostPort))
_host = new Rfc7239HostPort(value);
break;
case "for":
if (value.startsWith("_") || "unknown".equals(value))
break;
- if (_for == null || _for instanceof XHostPort)
+ if (_for == null || !(_for instanceof Rfc7239HostPort))
_for = new Rfc7239HostPort(value);
break;
case "host":
if (value.startsWith("_") || "unknown".equals(value))
break;
- if (_host == null || _host instanceof XHostPort)
+ if (_host == null || !(_host instanceof Rfc7239HostPort))
_host = new Rfc7239HostPort(value);
break;
case "proto":
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
index 8f5ef3b0f81..61181da2efc 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
@@ -560,6 +560,31 @@ public class ForwardedRequestCustomizerTest
assertThat("requestURL", _requestURL.get(), is("http://myhost:4444/"));
}
+
+
+ /**
+ * Resetting the server port via a forwarding header
+ */
+ @Test
+ public void testRemote_Port_For() throws Exception
+ {
+ _customizer.setForwardedPortHeaderRemote(true);
+ HttpTester.Response response = HttpTester.parseResponse(
+ _connector.getResponse(
+ "GET / HTTP/1.1\n" +
+ "Host: myhost\n" +
+ "X-Forwarded-Port: 4444\n" +
+ "X-Forwarded-For: 192.168.1.200\n" +
+ "\n"));
+ assertThat("status", response.getStatus(), is(200));
+ assertThat("scheme", _scheme.get(), is("http"));
+ assertThat("serverName", _serverName.get(), is("myhost"));
+ assertThat("serverPort", _serverPort.get(), is(80));
+ assertThat("remoteAddr", _remoteAddr.get(), is("192.168.1.200"));
+ assertThat("remotePort", _remotePort.get(), is(4444));
+ assertThat("requestURL", _requestURL.get(), is("http://myhost/"));
+ }
+
/**
* Test setting the server Port before the "Host" header has been seen.
*/
From e7e63a5617ffca484a1b1349f8c90eb826605023 Mon Sep 17 00:00:00 2001
From: Greg Wilkins
Date: Mon, 17 Jun 2019 14:00:30 +0200
Subject: [PATCH 33/45] Issue #3782 X-Forwarded-Port can be remote or local
Improved names and javadoc after review.
Signed-off-by: Greg Wilkins
---
.../main/config/etc/jetty-http-forwarded.xml | 2 +-
.../main/config/modules/http-forwarded.mod | 8 ++++-
.../server/ForwardedRequestCustomizer.java | 29 ++++++++++++-------
.../ForwardedRequestCustomizerTest.java | 2 +-
4 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/jetty-server/src/main/config/etc/jetty-http-forwarded.xml b/jetty-server/src/main/config/etc/jetty-http-forwarded.xml
index 8d0047cc54d..2c843733c2a 100644
--- a/jetty-server/src/main/config/etc/jetty-http-forwarded.xml
+++ b/jetty-server/src/main/config/etc/jetty-http-forwarded.xml
@@ -6,13 +6,13 @@
+
-
diff --git a/jetty-server/src/main/config/modules/http-forwarded.mod b/jetty-server/src/main/config/modules/http-forwarded.mod
index 7e6545a5902..e6303cd992e 100644
--- a/jetty-server/src/main/config/modules/http-forwarded.mod
+++ b/jetty-server/src/main/config/modules/http-forwarded.mod
@@ -16,15 +16,21 @@ etc/jetty-http-forwarded.xml
[ini-template]
### ForwardedRequestCustomizer Configuration
+## If true, only the RFC7239 Forwarded header is accepted
# jetty.httpConfig.forwardedOnly=false
+
+## if true, the proxy address obtained from X-Forwarded-Server or RFC7239 is used as the request authority.
# jetty.httpConfig.forwardedProxyAsAuthority=false
+
+## if true, the X-Forwarded-Port header applies to the authority, else it applies to the remote client address
+# jetty.httpConfig.forwardedPortAsAuthority=true
+
# jetty.httpConfig.forwardedHeader=Forwarded
# jetty.httpConfig.forwardedHostHeader=X-Forwarded-Host
# jetty.httpConfig.forwardedServerHeader=X-Forwarded-Server
# jetty.httpConfig.forwardedProtoHeader=X-Forwarded-Proto
# jetty.httpConfig.forwardedForHeader=X-Forwarded-For
# jetty.httpConfig.forwardedPortHeader=X-Forwarded-Port
-# jetty.httpConfig.forwardedPortHeaderRemote=false
# jetty.httpConfig.forwardedHttpsHeader=X-Proxied-Https
# jetty.httpConfig.forwardedSslSessionIdHeader=Proxy-ssl-id
# jetty.httpConfig.forwardedCipherSuiteHeader=Proxy-auth-cert
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
index 171384bd672..141af6eaaf4 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java
@@ -67,17 +67,17 @@ public class ForwardedRequestCustomizer implements Customizer
private static final Logger LOG = Log.getLogger(ForwardedRequestCustomizer.class);
private HostPortHttpField _forcedHost;
+ private boolean _proxyAsAuthority = false;
+ private boolean _forwardedPortAsAuthority = true;
private String _forwardedHeader = HttpHeader.FORWARDED.toString();
private String _forwardedHostHeader = HttpHeader.X_FORWARDED_HOST.toString();
private String _forwardedServerHeader = HttpHeader.X_FORWARDED_SERVER.toString();
private String _forwardedProtoHeader = HttpHeader.X_FORWARDED_PROTO.toString();
private String _forwardedForHeader = HttpHeader.X_FORWARDED_FOR.toString();
private String _forwardedPortHeader = HttpHeader.X_FORWARDED_PORT.toString();
- private boolean _forwardedPortHeaderRemote = false;
private String _forwardedHttpsHeader = "X-Proxied-Https";
private String _forwardedCipherSuiteHeader = "Proxy-auth-cert";
private String _forwardedSslSessionIdHeader = "Proxy-ssl-id";
- private boolean _proxyAsAuthority = false;
private boolean _sslIsSecure = true;
private Trie _handles;
@@ -252,14 +252,23 @@ public class ForwardedRequestCustomizer implements Customizer
}
}
- public boolean isForwardedPortHeaderRemote()
+ /**
+ * @return if true, the X-Forwarded-Port header applies to the authority,
+ * else it applies to the remote client address
+ */
+ public boolean getForwardedPortAsAuthority()
{
- return _forwardedPortHeaderRemote;
+ return _forwardedPortAsAuthority;
}
- public void setForwardedPortHeaderRemote(boolean forwardedPortHeaderRemote)
+ /**
+ * Set if the X-Forwarded-Port header will be used for Authority
+ * @param forwardedPortAsAuthority if true, the X-Forwarded-Port header applies to the authority,
+ * else it applies to the remote client address
+ */
+ public void setForwardedPortAsAuthority(boolean forwardedPortAsAuthority)
{
- _forwardedPortHeaderRemote = forwardedPortHeaderRemote;
+ _forwardedPortAsAuthority = forwardedPortAsAuthority;
}
/**
@@ -563,7 +572,7 @@ public class ForwardedRequestCustomizer implements Customizer
public void handleHost(HttpField field)
{
- if (!_forwardedPortHeaderRemote && !StringUtil.isEmpty(_forwardedPortHeader))
+ if (_forwardedPortAsAuthority && !StringUtil.isEmpty(_forwardedPortHeader))
{
if (_host == null)
_host = new PossiblyPartialHostPort(getLeftMost(field.getValue()));
@@ -591,7 +600,7 @@ public class ForwardedRequestCustomizer implements Customizer
public void handleFor(HttpField field)
{
- if (_forwardedPortHeaderRemote && !StringUtil.isEmpty(_forwardedPortHeader))
+ if (!_forwardedPortAsAuthority && !StringUtil.isEmpty(_forwardedPortHeader))
{
if (_for == null)
_for = new PossiblyPartialHostPort(getLeftMost(field.getValue()));
@@ -606,7 +615,7 @@ public class ForwardedRequestCustomizer implements Customizer
public void handlePort(HttpField field)
{
- if (_forwardedPortHeaderRemote)
+ if (!_forwardedPortAsAuthority)
{
if (_for == null)
_for = new PortSetHostPort(_request.getRemoteHost(), field.getIntValue());
@@ -647,7 +656,7 @@ public class ForwardedRequestCustomizer implements Customizer
break;
if (value.startsWith("_") || "unknown".equals(value))
break;
- if (_host == null || !(_host instanceof Rfc7239HostPort))
+ if (_proxyAsAuthority && (_host == null || !(_host instanceof Rfc7239HostPort)))
_host = new Rfc7239HostPort(value);
break;
case "for":
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
index 61181da2efc..c5537eaa2e0 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ForwardedRequestCustomizerTest.java
@@ -568,7 +568,7 @@ public class ForwardedRequestCustomizerTest
@Test
public void testRemote_Port_For() throws Exception
{
- _customizer.setForwardedPortHeaderRemote(true);
+ _customizer.setForwardedPortAsAuthority(false);
HttpTester.Response response = HttpTester.parseResponse(
_connector.getResponse(
"GET / HTTP/1.1\n" +
From 275f83c1d0503b12e2b308fead5f18ded4d4e952 Mon Sep 17 00:00:00 2001
From: Lachlan
Date: Tue, 18 Jun 2019 16:01:09 +1000
Subject: [PATCH 34/45] Issue #3785 - fix failures in QTP testLifeCycleStop
(#3788)
make sure the jobs are actually run before calling QTP.stop()
Signed-off-by: Lachlan Roberts
---
.../util/thread/QueuedThreadPoolTest.java | 29 ++++++++++---------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java
index e03322d7b74..0c11f81163c 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java
@@ -48,11 +48,12 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest
private class RunningJob implements Runnable
{
- private final CountDownLatch _run = new CountDownLatch(1);
- private final CountDownLatch _stopping = new CountDownLatch(1);
- private final CountDownLatch _stopped = new CountDownLatch(1);
- private final String _name;
- private final boolean _fail;
+ final CountDownLatch _run = new CountDownLatch(1);
+ final CountDownLatch _stopping = new CountDownLatch(1);
+ final CountDownLatch _stopped = new CountDownLatch(1);
+ final String _name;
+ final boolean _fail;
+
RunningJob()
{
this(null, false);
@@ -118,7 +119,7 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest
private class CloseableJob extends RunningJob implements Closeable
{
- private final CountDownLatch _closed = new CountDownLatch(1);
+ final CountDownLatch _closed = new CountDownLatch(1);
@Override
public void close() throws IOException
@@ -382,24 +383,24 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest
// Wait until the first 2 start running
waitForThreads(tp,2);
waitForIdle(tp,0);
+ assertTrue(job0._run.await(200, TimeUnit.MILLISECONDS));
+ assertTrue(job1._run.await(200, TimeUnit.MILLISECONDS));
// Queue should be empty after thread pool is stopped
tp.stop();
assertThat(tp.getQueue().size(), is(0));
// First 2 jobs closed by InterruptedException
- assertThat(job0._stopped.await(200, TimeUnit.MILLISECONDS), is(true));
- assertThat(job1._stopped.await(200, TimeUnit.MILLISECONDS), is(true));
+ assertTrue(job0._stopped.await(200, TimeUnit.MILLISECONDS));
+ assertTrue(job1._stopped.await(200, TimeUnit.MILLISECONDS));
// Verify RunningJobs in the queue have not been run
- assertThat(job2._run.await(200, TimeUnit.MILLISECONDS), is(false));
- assertThat(job4._run.await(200, TimeUnit.MILLISECONDS), is(false));
+ assertFalse(job2._run.await(200, TimeUnit.MILLISECONDS));
+ assertFalse(job4._run.await(200, TimeUnit.MILLISECONDS));
// Verify ClosableJobs have not been run but have been closed
- assertThat(job4._run.await(200, TimeUnit.MILLISECONDS), is(false));
- assertThat(job3._closed.await(200, TimeUnit.MILLISECONDS), is(true));
-
- tp.stop();
+ assertFalse(job3._run.await(200, TimeUnit.MILLISECONDS));
+ assertTrue(job3._closed.await(200, TimeUnit.MILLISECONDS));
}
From 862e6d008e99223ad048860dd69c19914732a4f7 Mon Sep 17 00:00:00 2001
From: Greg Wilkins
Date: Tue, 18 Jun 2019 09:50:18 +0200
Subject: [PATCH 35/45] Jetty 9.4.x 3755 annotation/jndi example cleanup
(#3763)
* Issue #3755 Annotation example cleanup
+ Created JettyDistribution class as common utility to locate a jetty distribution for examples.
+ Fixed ServerWithAnnotations to correctly use the test-spec-webapp
+ Added AttributeContainerMap as a better way to treat attribute values as beans. This avoids them appearing twice in a dump and always associates them with their key.
+ Added NamingDump and use it in EnvConfiguration and jetty-plus.xml so that a server dump will contain dumps of the server local tree and each contexts java:comp/env tree
+ Improved the dump format of NamingContext and WebAppContext
+ Improved the toString format of several associated classes
Signed-off-by: Greg Wilkins
---
.../jetty/embedded/JettyDistribution.java | 109 +++++++++++
.../eclipse/jetty/embedded/LikeJettyXml.java | 20 +-
.../org/eclipse/jetty/embedded/OneWebApp.java | 3 +-
.../jetty/embedded/ServerWithAnnotations.java | 18 +-
.../org/eclipse/jetty/jndi/NamingContext.java | 27 ++-
.../jetty/jndi/local/localContextRoot.java | 4 +-
.../org/eclipse/jetty/plus/jndi/EnvEntry.java | 6 +
.../org/eclipse/jetty/plus/jndi/Link.java | 6 +
.../eclipse/jetty/plus/jndi/NamingDump.java | 71 +++++++
.../eclipse/jetty/plus/jndi/NamingEntry.java | 32 ++--
.../jetty/plus/jndi/NamingEntryUtil.java | 4 +-
.../jetty/plus/webapp/EnvConfiguration.java | 47 ++---
.../src/main/plus-config/etc/jetty-plus.xml | 4 +
.../jetty/plus/jndi/TestNamingEntryUtil.java | 21 +--
.../jetty/server/LowResourceMonitor.java | 20 +-
.../java/org/eclipse/jetty/server/Server.java | 20 +-
.../util/component/AttributeContainerMap.java | 82 +++++++++
.../jetty/util/component/Container.java | 2 +-
.../util/component/ContainerLifeCycle.java | 12 +-
.../jetty/util/component/Dumpable.java | 174 ++++++++++--------
.../jetty/webapp/WebAppClassLoader.java | 2 +-
.../eclipse/jetty/webapp/WebAppContext.java | 48 +++--
22 files changed, 520 insertions(+), 212 deletions(-)
create mode 100644 examples/embedded/src/main/java/org/eclipse/jetty/embedded/JettyDistribution.java
create mode 100644 jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/NamingDump.java
create mode 100644 jetty-util/src/main/java/org/eclipse/jetty/util/component/AttributeContainerMap.java
diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/JettyDistribution.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/JettyDistribution.java
new file mode 100644
index 00000000000..0d3c3810606
--- /dev/null
+++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/JettyDistribution.java
@@ -0,0 +1,109 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.embedded;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import org.eclipse.jetty.util.StringUtil;
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
+
+/**
+ * A utility test class to locate a Jetty Distribution for testing purposes by searching:
+ *
+ *
The jetty.home system property
+ *
The JETTY_HOME environment variable
+ *
The working directory hierarchy with subdirectory jetty-distribution/target/home
+ *
+ */
+public class JettyDistribution
+{
+ private final static Logger LOG = Log.getLogger(JettyDistribution.class);
+ public final static Path DISTRIBUTION;
+
+ static
+ {
+ Path distro = asJettyDistribution(System.getProperty("jetty.home"));
+ if (distro==null)
+ distro = asJettyDistribution(System.getenv().get("JETTY_HOME"));
+
+ if (distro==null)
+ {
+ try
+ {
+ Path working = new File(".").getAbsoluteFile().getCanonicalFile().toPath();
+ while(distro == null && working !=null )
+ {
+ distro = asJettyDistribution(working.resolve("jetty-distribution/target/distribution").toString());
+ working = working.getParent();
+ }
+ }
+ catch(Throwable th)
+ {
+ LOG.warn(th);
+ }
+ }
+ DISTRIBUTION = distro;
+ }
+
+ private static Path asJettyDistribution(String test)
+ {
+ try
+ {
+ if (StringUtil.isBlank(test))
+ {
+ LOG.info("asJettyDistribution {} is blank", test);
+ return null;
+ }
+
+ File dir = new File(test);
+ if (!dir.exists() || !dir.isDirectory())
+ {
+ LOG.info("asJettyDistribution {} is not a directory", test);
+ return null;
+ }
+
+ File demoBase = new File(dir,"demo-base");
+ if (!demoBase.exists() || !demoBase.isDirectory())
+ {
+ LOG.info("asJettyDistribution {} has no demo-base", test);
+ return null;
+ }
+
+ LOG.info("asJettyDistribution {}", dir);
+ return dir.getAbsoluteFile().getCanonicalFile().toPath();
+ }
+ catch(Exception e)
+ {
+ LOG.ignore(e);
+ }
+ return null;
+ }
+
+ public static Path resolve(String path)
+ {
+ return DISTRIBUTION.resolve(path);
+ }
+
+ public static void main(String... arg)
+ {
+ System.err.println("Jetty Distribution is " + DISTRIBUTION);
+ }
+}
diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java
index 3a56eff6da9..1ad9f45f664 100644
--- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java
+++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java
@@ -19,7 +19,6 @@
package org.eclipse.jetty.embedded;
import java.io.File;
-import java.io.FileNotFoundException;
import java.lang.management.ManagementFactory;
import org.eclipse.jetty.deploy.DeploymentManager;
@@ -60,27 +59,14 @@ public class LikeJettyXml
public static void main( String[] args ) throws Exception
{
// Path to as-built jetty-distribution directory
- String jettyHomeBuild = "jetty-distribution/target/distribution";
-
+ String jettyHomeBuild = JettyDistribution.DISTRIBUTION.toString();
+
// Find jetty home and base directories
String homePath = System.getProperty("jetty.home", jettyHomeBuild);
- File start_jar = new File(homePath,"start.jar");
- if (!start_jar.exists())
- {
- homePath = jettyHomeBuild = "jetty-distribution/target/distribution";
- start_jar = new File(homePath,"start.jar");
- if (!start_jar.exists())
- throw new FileNotFoundException(start_jar.toString());
- }
-
File homeDir = new File(homePath);
String basePath = System.getProperty("jetty.base", homeDir + "/demo-base");
File baseDir = new File(basePath);
- if(!baseDir.exists())
- {
- throw new FileNotFoundException(baseDir.getAbsolutePath());
- }
// Configure jetty.home and jetty.base system properties
String jetty_home = homeDir.getAbsolutePath();
@@ -88,7 +74,6 @@ public class LikeJettyXml
System.setProperty("jetty.home", jetty_home);
System.setProperty("jetty.base", jetty_base);
-
// === jetty.xml ===
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
@@ -219,7 +204,6 @@ public class LikeJettyXml
lowResourcesMonitor.setPeriod(1000);
lowResourcesMonitor.setLowResourcesIdleTimeout(200);
lowResourcesMonitor.setMonitorThreads(true);
- lowResourcesMonitor.setMaxConnections(0);
lowResourcesMonitor.setMaxMemory(0);
lowResourcesMonitor.setMaxLowResourcesTime(5000);
server.addBean(lowResourcesMonitor);
diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
index e6457c784c0..454d0555b4c 100644
--- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
+++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
@@ -49,8 +49,7 @@ public class OneWebApp
// PlusConfiguration) to choosing where the webapp will unpack itself.
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
- File warFile = new File(
- "../../tests/test-jmx/jmx-webapp/target/jmx-webapp");
+ File warFile = JettyDistribution.resolve("demo-base/webapps/async-rest.war").toFile();
webapp.setWar(warFile.getAbsolutePath());
// A WebAppContext is a ContextHandler as well so it needs to be set to
diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java
index d5ed0c922ca..41b611d2543 100644
--- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java
+++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.embedded;
import java.io.File;
import org.eclipse.jetty.plus.jndi.EnvEntry;
+import org.eclipse.jetty.plus.jndi.NamingDump;
import org.eclipse.jetty.plus.jndi.Resource;
import org.eclipse.jetty.plus.jndi.Transaction;
import org.eclipse.jetty.security.HashLoginService;
@@ -47,16 +48,14 @@ public class ServerWithAnnotations
classlist.addBefore(
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration");
-
// Create a WebApp
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
- File warFile = new File(
- "jetty-distribution/target/distribution/demo-base/webapps/test.war");
+ File warFile = JettyDistribution.resolve("demo-base/webapps/test-spec.war").toFile();
webapp.setWar(warFile.getAbsolutePath());
webapp.setAttribute(
- "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
- ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$");
+ "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
+ ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$");
server.setHandler(webapp);
// Register new transaction manager in JNDI
@@ -64,10 +63,14 @@ public class ServerWithAnnotations
new Transaction(new com.acme.MockUserTransaction());
// Define an env entry with webapp scope.
- new EnvEntry(webapp, "maxAmount", new Double(100), true);
+ // THIS ENTRY IS OVERRIDEN BY THE ENTRY IN jetty-env.xml
+ new EnvEntry(webapp, "maxAmount", 100d, true);
// Register a mock DataSource scoped to the webapp
- new Resource(webapp, "jdbc/mydatasource", new com.acme.MockDataSource());
+ new Resource(server, "jdbc/mydatasource", new com.acme.MockDataSource());
+
+ // Add JNDI context to server for dump
+ server.addBean(new NamingDump());
// Configure a LoginService
HashLoginService loginService = new HashLoginService();
@@ -75,6 +78,7 @@ public class ServerWithAnnotations
loginService.setConfig("examples/embedded/src/test/resources/realm.properties");
server.addBean(loginService);
+
server.start();
server.dumpStdErr();
server.join();
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingContext.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingContext.java
index 1d147752c12..d0f7271f297 100644
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingContext.java
+++ b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/NamingContext.java
@@ -22,8 +22,10 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.naming.Binding;
@@ -126,7 +128,7 @@ public class NamingContext implements Context, Dumpable
this(env, name, parent, parser, null);
}
- private NamingContext(Hashtable env,
+ protected NamingContext(Hashtable env,
String name,
NamingContext parent,
NameParser parser,
@@ -143,14 +145,13 @@ public class NamingContext implements Context, Dumpable
}
/**
- * @return A shallow copy of the Context with the same bindings, but a copy of the Env
+ * @return A shallow copy of the Context with the same bindings, but with the passed environment
*/
- public NamingContext shallowCopy()
+ public Context shallowCopy(Hashtable env)
{
- return new NamingContext(_env, _name, _parent, _parser, _bindings);
+ return new NamingContext(env, _name, _parent, _parser, _bindings);
}
-
public boolean isDeepBindingSupported()
{
// look for deep binding support in _env
@@ -457,7 +458,7 @@ public class NamingContext implements Context, Dumpable
{
if(LOG.isDebugEnabled())
LOG.debug("Null or empty name, returning shallowCopy of this context");
- return shallowCopy();
+ return shallowCopy(_env);
}
if (cname.size() == 1)
@@ -541,7 +542,7 @@ public class NamingContext implements Context, Dumpable
if (cname == null || name.isEmpty())
{
- return shallowCopy();
+ return shallowCopy(_env);
}
if (cname.size() == 0)
@@ -1118,7 +1119,17 @@ public class NamingContext implements Context, Dumpable
@Override
public void dump(Appendable out,String indent) throws IOException
{
- Dumpable.dumpObjects(out,indent,this, _bindings);
+ Map bindings = new HashMap<>();
+ for (Map.Entry binding : _bindings.entrySet())
+ bindings.put(binding.getKey(), binding.getValue().getObject());
+
+ Dumpable.dumpObject(out, this);
+ Dumpable.dumpMapEntries(out, indent, bindings, _env.isEmpty());
+ if (!_env.isEmpty())
+ {
+ out.append(indent).append("+> environment\n");
+ Dumpable.dumpMapEntries(out, indent + " ", _env, true);
+ }
}
private Collection findListeners()
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/local/localContextRoot.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/local/localContextRoot.java
index f712d329be6..3ad31582062 100644
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/local/localContextRoot.java
+++ b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/local/localContextRoot.java
@@ -270,7 +270,7 @@ public class localContextRoot implements Context
if (cname == null || cname.isEmpty())
{
//If no name create copy of this context with same bindings, but with copy of the environment so it can be modified
- return __root.shallowCopy();
+ return __root.shallowCopy(_env);
}
if (cname.size() == 0)
@@ -339,7 +339,7 @@ public class localContextRoot implements Context
if ((cname == null) || cname.isEmpty())
{
- return __root.shallowCopy();
+ return __root.shallowCopy(_env);
}
if (cname.size() == 1)
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/EnvEntry.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/EnvEntry.java
index 8a08ae902e4..a6881343ea2 100644
--- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/EnvEntry.java
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/EnvEntry.java
@@ -56,4 +56,10 @@ public class EnvEntry extends NamingEntry
{
return this.overrideWebXml;
}
+
+ @Override
+ protected String toStringMetaData()
+ {
+ return "OverrideWebXml=" + overrideWebXml;
+ }
}
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/Link.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/Link.java
index aeb96e096e3..c0ee8a68563 100644
--- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/Link.java
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/Link.java
@@ -52,4 +52,10 @@ public class Link extends NamingEntry
{
return _link;
}
+
+ @Override
+ protected String toStringMetaData()
+ {
+ return _link;
+ }
}
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/NamingDump.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/NamingDump.java
new file mode 100644
index 00000000000..7be17835011
--- /dev/null
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/NamingDump.java
@@ -0,0 +1,71 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.plus.jndi;
+
+import javax.naming.InitialContext;
+
+import org.eclipse.jetty.util.StringUtil;
+import org.eclipse.jetty.util.component.Dumpable;
+
+/**
+ * A utility Dumpable to dump a JNDI naming context tree.
+ */
+public class NamingDump implements Dumpable
+{
+ private final ClassLoader _loader;
+ private final String _name;
+
+ public NamingDump()
+ {
+ this(null,"");
+ }
+
+ public NamingDump(ClassLoader loader, String name)
+ {
+ _loader = loader;
+ _name = name;
+ }
+
+ @Override
+ public void dump(Appendable out, String indent)
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ if (!StringUtil.isBlank(_name))
+ out.append(_name).append(" ");
+ if (_loader!=null)
+ Thread.currentThread().setContextClassLoader(_loader);
+ Object context = new InitialContext().lookup(_name);
+ if (context instanceof Dumpable)
+ ((Dumpable)context).dump(out, indent);
+ else
+ Dumpable.dumpObjects(out, indent, context);
+ }
+ catch(Throwable th)
+ {
+ throw new RuntimeException(th);
+ }
+ finally
+ {
+ if (_loader!=null)
+ Thread.currentThread().setContextClassLoader(loader);
+ }
+ }
+}
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/NamingEntry.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/NamingEntry.java
index 765064524cd..92a3ff0c216 100644
--- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/NamingEntry.java
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/jndi/NamingEntry.java
@@ -49,14 +49,7 @@ public abstract class NamingEntry
protected String _namingEntryNameString; //the name of the NamingEntry relative to the context it is stored in
protected String _objectNameString; //the name of the object relative to the context it is stored in
-
- @Override
- public String toString()
- {
- return _jndiName;
- }
-
-
+
/**
* Create a naming entry.
*
@@ -173,21 +166,21 @@ public abstract class NamingEntry
/**
* Save the NamingEntry for later use.
*
- * Saving is done by binding the NamingEntry
+ * Saving is done by binding both the NamingEntry
* itself, and the value it represents into
* JNDI. In this way, we can link to the
* value it represents later, but also
* still retrieve the NamingEntry itself too.
*
- * The object is bound at the jndiName passed in.
- * This NamingEntry is bound at __/jndiName.
+ * The object is bound at scope/jndiName and
+ * the NamingEntry is bound at scope/__/jndiName.
*