From 85566d03778318c3ca323b8a14eb267a3a0a2911 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 5 Jun 2019 07:49:59 -0500 Subject: [PATCH 01/15] 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-webapp test-http2-webapp test-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 02/15] 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 @@ war test + + org.eclipse.jetty.tests + test-cdi2-webapp + ${project.version} + war + test + org.eclipse.jetty.toolchain jetty-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.el javax.el-api + 3.0.0 - + org.jboss.weld.servlet weld-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 03/15] 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-api provided - - 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 04/15] 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 05/15] 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 06/15] 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 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.0 org.eclipse.jetty.cdi - jetty-cdi-parent - Jetty :: CDI :: Parent + cdi-2 + Jetty :: CDI 2 http://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 07/15] 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-ant 9.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.jetty jetty-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.logging jboss-logging From dc23b8da6a298c2e12f7dfedf36cfe8a64d560fe Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 12 Jun 2019 13:58:36 -0500 Subject: [PATCH 08/15] 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.tests test-webapps-parent - 9.4.19-SNAPSHOT + 9.4.20-SNAPSHOT 4.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 09/15] 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-webapp test-http2-webapp test-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 + 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 cc966dd1f2c0be0e6e2c73cace110869d1e61385 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 18 Jun 2019 10:13:56 -0500 Subject: [PATCH 10/15] Issue #3700 - Using newer felix version Signed-off-by: Joakim Erdfelt --- tests/test-webapps/test-felix-webapp/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-webapps/test-felix-webapp/pom.xml b/tests/test-webapps/test-felix-webapp/pom.xml index 454f1fe61da..f29fdbacdcf 100644 --- a/tests/test-webapps/test-felix-webapp/pom.xml +++ b/tests/test-webapps/test-felix-webapp/pom.xml @@ -44,7 +44,7 @@ org.apache.felix org.apache.felix.framework - 5.6.2 + 6.0.3 From 5eb3e73400b25d8ba654bf53e0085532206877e2 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 18 Jun 2019 11:03:06 -0500 Subject: [PATCH 11/15] Issue #3700 - Fixing TypeUtil and IncludeExcludeSet to work with null location + TypeUtil.getLocationOfClass() respects Class.getClassLoader() of null which means a class belonging to Boot ClassLoader, a Primitive, Void, or a dynamic in-memory class. Using system classloader is incorrect and invalid in Java 9+ + Fixing IncludeExcludeSet.test() to always return TRUE or FALSE never null. Signed-off-by: Joakim Erdfelt --- .../eclipse/jetty/util/IncludeExcludeSet.java | 4 ++-- .../java/org/eclipse/jetty/util/TypeUtil.java | 10 +++++--- .../org/eclipse/jetty/util/TypeUtilTest.java | 24 +++++++++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExcludeSet.java b/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExcludeSet.java index 3c93baeb645..a6e29c5787f 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExcludeSet.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExcludeSet.java @@ -169,7 +169,7 @@ public class IncludeExcludeSet implements Predicate

/** * Test Included and not Excluded * @param item The item to test - * @return Boolean.TRUE if item is included, Boolean.FALSE if item is excluded and null if neither + * @return Boolean.TRUE if item is included, Boolean.FALSE if item is excluded or neither */ public Boolean isIncludedAndNotExcluded(P item) { @@ -178,7 +178,7 @@ public class IncludeExcludeSet implements Predicate

if (_includePredicate.test(item)) return Boolean.TRUE; - return null; + return Boolean.FALSE; } public boolean hasIncludes() diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java index cb675f97cf5..eb63731bd18 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java @@ -562,10 +562,14 @@ public class TypeUtil String resourceName = clazz.getName().replace('.', '/') + ".class"; ClassLoader loader = clazz.getClassLoader(); - URL url = (loader == null ? ClassLoader.getSystemClassLoader() : loader).getResource(resourceName); - if (url != null) + // null means bootstrap classloader, primitive, void, or dynamic in-memory class + if (loader != null) { - return URIUtil.getJarSource(url.toURI()); + URL url = loader.getResource(resourceName); + if (url != null) + { + return URIUtil.getJarSource(url.toURI()); + } } } catch (URISyntaxException e) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/TypeUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/TypeUtilTest.java index 0e8a07cc8f3..96c4599c201 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/TypeUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/TypeUtilTest.java @@ -18,15 +18,11 @@ package org.eclipse.jetty.util; - import java.nio.file.Path; import java.nio.file.Paths; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnJre; -import org.junit.jupiter.api.condition.EnabledOnJre; -import org.junit.jupiter.api.condition.JRE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -149,6 +145,7 @@ public class TypeUtilTest assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),containsString("/classes/")); } + /* @Test @DisabledOnJre(JRE.JAVA_8) public void testGetLocation_JvmCore_JPMS() @@ -158,6 +155,15 @@ public class TypeUtilTest assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase)); } + @Test + @DisabledOnJre(JRE.JAVA_8) + public void testGetLocation_JavaLangThreadDeath_JPMS() + { + // Class from JVM core + String expectedJavaBase = "/java.base/"; + assertThat(TypeUtil.getLocationOfClass(java.lang.ThreadDeath.class).toASCIIString(),containsString(expectedJavaBase)); + } + @Test @EnabledOnJre(JRE.JAVA_8) public void testGetLocation_JvmCore_Java8RT() @@ -166,4 +172,14 @@ public class TypeUtilTest String expectedJavaBase = "/rt.jar"; assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase)); } + + @Test + @EnabledOnJre(JRE.JAVA_8) + public void testGetLocation_JavaLangThreadDeath_Java8RT() + { + // Class from JVM core + String expectedJavaBase = "/rt.jar"; + assertThat(TypeUtil.getLocationOfClass(java.lang.ThreadDeath.class).toASCIIString(),containsString(expectedJavaBase)); + } + */ } From 8d59302978d8107bfce40754ead29986940b5f94 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 20 Jun 2019 15:35:10 -0500 Subject: [PATCH 12/15] Issue #3700 - Reworking getLocationOfClass() + Reverting commit against IncludeExcludeSet + TypeUtil.getLocationOfClass is now MethodHandle based + new ModuleLocation class provides Module behaviors for Java 9+ Runtimes, and is used by new MethodHandle based getLocationOfClass + Jetty 10 doesn't need reflect complexity of ModuleLocation class and can be inlined as real code in TypeUtil + TypeUtil.getLocationOfClass is only guaranteed to return the URI to the container holding the location of the class, or null. - The JAR file - most common - The Directory - 2nd most common - a classpath dir entry - The jrt:// module reference - if a module reference + URLResource support for results of getLocationOfClass is deprecated (nothing was using it anyway) Signed-off-by: Joakim Erdfelt --- .../eclipse/jetty/util/IncludeExcludeSet.java | 4 +- .../eclipse/jetty/util/ModuleLocation.java | 164 ++++++++++++++++++ .../java/org/eclipse/jetty/util/TypeUtil.java | 147 ++++++++++++++-- .../org/eclipse/jetty/util/TypeUtilTest.java | 28 +-- .../jetty/util/resource/JrtResourceTest.java | 28 ++- .../jetty/webapp/ClasspathPattern.java | 17 +- 6 files changed, 337 insertions(+), 51 deletions(-) create mode 100644 jetty-util/src/main/java/org/eclipse/jetty/util/ModuleLocation.java diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExcludeSet.java b/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExcludeSet.java index a6e29c5787f..8ae8709a2e5 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExcludeSet.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/IncludeExcludeSet.java @@ -169,7 +169,7 @@ public class IncludeExcludeSet implements Predicate

/** * Test Included and not Excluded * @param item The item to test - * @return Boolean.TRUE if item is included, Boolean.FALSE if item is excluded or neither + * @return Boolean.TRUE if item is included, Boolean.FALSE if item is excluded or null if neither */ public Boolean isIncludedAndNotExcluded(P item) { @@ -178,7 +178,7 @@ public class IncludeExcludeSet implements Predicate

if (_includePredicate.test(item)) return Boolean.TRUE; - return Boolean.FALSE; + return null; } public boolean hasIncludes() diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ModuleLocation.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ModuleLocation.java new file mode 100644 index 00000000000..b24d226eb07 --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ModuleLocation.java @@ -0,0 +1,164 @@ +// +// ======================================================================== +// 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.util; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Optional; + +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; + +import static java.lang.invoke.MethodType.methodType; + +/** + * Equivalent of ... + * + *

+ * Module module = clazz.getModule();
+ * if (module != null)
+ * {
+ *     Configuration configuration = module.getLayer().configuration();
+ *     Optional resolvedModule = configuration.findModule(module.getName());
+ *     if (resolvedModule.isPresent())
+ *     {
+ *         ModuleReference moduleReference = resolvedModule.get().reference();
+ *         Optional location = moduleReference.location();
+ *         if (location.isPresent())
+ *         {
+ *             return location.get();
+ *         }
+ *     }
+ * }
+ * return null;
+ * 
+ * + * In Jetty 10, this entire class can be moved to direct calls to java.lang.Module in TypeUtil.getModuleLocation() + */ +class ModuleLocation +{ + private static final Logger LOG = Log.getLogger(ModuleLocation.class); + + private final Class classModule; + private final MethodHandle handleGetModule; + private final MethodHandle handleGetLayer; + private final MethodHandle handleConfiguration; + private final MethodHandle handleGetName; + private final MethodHandle handleOptionalResolvedModule; + private final MethodHandle handleReference; + private final MethodHandle handleLocation; + + public ModuleLocation() + { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + ClassLoader loader = ClassLoader.getSystemClassLoader(); + + try + { + classModule = loader.loadClass("java.lang.Module"); + handleGetModule = lookup.findVirtual(Class.class, "getModule", methodType(classModule)); + + Class classLayer = loader.loadClass("java.lang.ModuleLayer"); + handleGetLayer = lookup.findVirtual(classModule, "getLayer", methodType(classLayer)); + + Class classConfiguration = loader.loadClass("java.lang.module.Configuration"); + handleConfiguration = lookup.findVirtual(classLayer, "configuration", methodType(classConfiguration)); + + handleGetName = lookup.findVirtual(classModule, "getName", methodType(String.class)); + + Method findModuleMethod = classConfiguration.getMethod("findModule", new Class[]{String.class}); + handleOptionalResolvedModule = lookup.findVirtual(classConfiguration, "findModule", methodType(findModuleMethod.getReturnType(), String.class)); + + Class classResolvedModule = loader.loadClass("java.lang.module.ResolvedModule"); + Class classReference = loader.loadClass("java.lang.module.ModuleReference"); + handleReference = lookup.findVirtual(classResolvedModule, "reference", methodType(classReference)); + + Method locationMethod = classReference.getMethod("location"); + handleLocation = lookup.findVirtual(classReference, "location", methodType(locationMethod.getReturnType())); + } + catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) + { + throw new UnsupportedOperationException("Not supported on this runtime", e); + } + } + + public URI getModuleLocation(Class clazz) + { + try + { + // Module module = clazz.getModule(); + Object module = handleGetModule.invoke(clazz); + if (module == null) + { + return null; + } + + // ModuleLayer layer = module.getLayer(); + Object layer = handleGetLayer.invoke(module); + if (layer == null) + { + return null; + } + + // Configuration configuration = layer.configuration(); + Object configuration = handleConfiguration.invoke(layer); + if (configuration == null) + { + return null; + } + + // String moduleName = module.getName(); + String moduleName = (String)handleGetName.invoke(module); + if (moduleName == null) + { + return null; + } + + // Optional optionalResolvedModule = configuration.findModule(moduleName); + Optional optionalResolvedModule = (Optional)handleOptionalResolvedModule.invoke(configuration, moduleName); + if (!optionalResolvedModule.isPresent()) + { + return null; + } + + // ResolveModule resolved = optionalResolvedModule.get(); + Object resolved = optionalResolvedModule.get(); + + // ModuleReference moduleReference = resolved.reference(); + Object moduleReference = handleReference.invoke(resolved); + + // Optional location = moduleReference.location(); + Optional location = (Optional)handleLocation.invoke(moduleReference); + if (location != null || location.isPresent()) + { + return location.get(); + } + } + catch (Throwable ignored) + { + if (LOG.isDebugEnabled()) + { + LOG.ignore(ignored); + } + } + return null; + } +} diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java index eb63731bd18..9ce6e80ad76 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java @@ -19,14 +19,20 @@ package org.eclipse.jetty.util; import java.io.IOException; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.security.AccessController; import java.security.CodeSource; +import java.security.PrivilegedAction; import java.security.ProtectionDomain; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -36,6 +42,8 @@ import java.util.Map; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import static java.lang.invoke.MethodType.methodType; + /* ------------------------------------------------------------ */ /** @@ -171,6 +179,40 @@ public class TypeUtil } } + private static final MethodHandle[] LOCATION_METHODS; + private static final ModuleLocation MODULE_LOCATION; + + static + { + List locationMethods = new ArrayList<>(); + + MethodHandles.Lookup lookup = MethodHandles.lookup(); + MethodType type = methodType(URI.class, Class.class); + + try + { + locationMethods.add(lookup.findStatic(TypeUtil.class, "getCodeSourceLocation", type)); + ModuleLocation moduleLocation = null; + try + { + moduleLocation = new ModuleLocation(); + locationMethods.add(lookup.findStatic(TypeUtil.class, "getModuleLocation", type)); + } + catch (UnsupportedOperationException e) + { + LOG.info("JVM Runtime does not support Modules"); + } + MODULE_LOCATION = moduleLocation; + locationMethods.add(lookup.findStatic(TypeUtil.class, "getClassLoaderLocation", type)); + locationMethods.add(lookup.findStatic(TypeUtil.class, "getSystemClassLoaderLocation", type)); + LOCATION_METHODS = locationMethods.toArray(new MethodHandle[0]); + } + catch (Exception e) + { + throw new RuntimeException("Unable to establish Location Lookup Handles", e); + } + } + /* ------------------------------------------------------------ */ /** Array to List. *

@@ -543,38 +585,111 @@ public class TypeUtil } /* ------------------------------------------------------------ */ + + /** + * Attempt to find the Location of a loaded Class. + *

+ * This can be null for primitives, void, and in-memory classes. + *

+ * @param clazz the loaded class to find a location for. + * @return the location as a URI (this is a URI pointing to a holder of the class: a directory, + * a jar file, a {@code jrt://} resource, etc), or null of no location available. + */ public static URI getLocationOfClass(Class clazz) + { + URI location; + + for (MethodHandle locationMethod : LOCATION_METHODS) + { + try + { + location = (URI)locationMethod.invoke(clazz); + if (location != null) + { + return location; + } + } + catch (Throwable cause) + { + cause.printStackTrace(System.err); + } + } + return null; + } + + public static URI getClassLoaderLocation(Class clazz) + { + return getClassLoaderLocation(clazz, clazz.getClassLoader()); + } + + public static URI getSystemClassLoaderLocation(Class clazz) + { + return getClassLoaderLocation(clazz, ClassLoader.getSystemClassLoader()); + } + + public static URI getClassLoaderLocation(Class clazz, ClassLoader loader) + { + if (loader == null) + { + return null; + } + + try + { + String resourceName = clazz.getName().replace('.', '/') + ".class"; + if (loader != null) + { + URL url = loader.getResource(resourceName); + if (url != null) + { + URI uri = url.toURI(); + String uriStr = uri.toASCIIString(); + int idx = uriStr.indexOf(".jar!/"); + if (idx > 0) + { + return URI.create(uriStr.substring(0, idx + 4)); + } + return uri; + } + } + } + catch (URISyntaxException ignore) + { + } + return null; + } + + public static URI getCodeSourceLocation(Class clazz) { try { - ProtectionDomain domain = clazz.getProtectionDomain(); + ProtectionDomain domain = AccessController.doPrivileged((PrivilegedAction)() -> clazz.getProtectionDomain()); if (domain != null) { CodeSource source = domain.getCodeSource(); if (source != null) { URL location = source.getLocation(); - + if (location != null) + { return location.toURI(); - } - } - - String resourceName = clazz.getName().replace('.', '/') + ".class"; - ClassLoader loader = clazz.getClassLoader(); - // null means bootstrap classloader, primitive, void, or dynamic in-memory class - if (loader != null) - { - URL url = loader.getResource(resourceName); - if (url != null) - { - return URIUtil.getJarSource(url.toURI()); + } } } } - catch (URISyntaxException e) + catch (URISyntaxException ignore) { - LOG.debug(e); + } + return null; + } + + public static URI getModuleLocation(Class clazz) + { + // In Jetty 10, this method can be implemented directly, without reflection + if (MODULE_LOCATION != null) + { + return MODULE_LOCATION.getModuleLocation(clazz); } return null; } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/TypeUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/TypeUtilTest.java index 96c4599c201..3ef1ecd4c8a 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/TypeUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/TypeUtilTest.java @@ -21,8 +21,10 @@ package org.eclipse.jetty.util; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.EnabledOnJre; +import org.junit.jupiter.api.condition.JRE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -100,7 +102,7 @@ public class TypeUtilTest } @Test - public void testIsTrue() throws Exception + public void testIsTrue() { assertTrue(TypeUtil.isTrue(Boolean.TRUE)); assertTrue(TypeUtil.isTrue(true)); @@ -115,7 +117,7 @@ public class TypeUtilTest } @Test - public void testIsFalse() throws Exception + public void testIsFalse() { assertTrue(TypeUtil.isFalse(Boolean.FALSE)); assertTrue(TypeUtil.isFalse(false)); @@ -130,28 +132,31 @@ public class TypeUtilTest } @Test - public void testGetLocationOfClass() throws Exception + public void testGetLocationOfClass_FromMavenRepo() { - String mavenRepoPathProperty = System.getProperty( "mavenRepoPath"); + String mavenRepoPathProperty = System.getProperty("mavenRepoPath"); assumeTrue(mavenRepoPathProperty != null); - Path mavenRepoPath = Paths.get( mavenRepoPathProperty ); + Path mavenRepoPath = Paths.get(mavenRepoPathProperty); String mavenRepo = mavenRepoPath.toFile().getPath().replaceAll("\\\\", "/"); // Classes from maven dependencies - assertThat(TypeUtil.getLocationOfClass(Assertions.class).toASCIIString(),containsString(mavenRepo)); - + assertThat(TypeUtil.getLocationOfClass(org.junit.jupiter.api.Assertions.class).toASCIIString(), containsString(mavenRepo)); + } + + @Test + public void getLocationOfClass_ClassDirectory() + { // Class from project dependencies assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),containsString("/classes/")); } - /* @Test @DisabledOnJre(JRE.JAVA_8) public void testGetLocation_JvmCore_JPMS() { // Class from JVM core - String expectedJavaBase = "/java.base/"; + String expectedJavaBase = "/java.base"; assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase)); } @@ -160,7 +165,7 @@ public class TypeUtilTest public void testGetLocation_JavaLangThreadDeath_JPMS() { // Class from JVM core - String expectedJavaBase = "/java.base/"; + String expectedJavaBase = "/java.base"; assertThat(TypeUtil.getLocationOfClass(java.lang.ThreadDeath.class).toASCIIString(),containsString(expectedJavaBase)); } @@ -181,5 +186,4 @@ public class TypeUtilTest String expectedJavaBase = "/rt.jar"; assertThat(TypeUtil.getLocationOfClass(java.lang.ThreadDeath.class).toASCIIString(),containsString(expectedJavaBase)); } - */ } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/JrtResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/JrtResourceTest.java index d8da1f91028..00a230c7773 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/JrtResourceTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/JrtResourceTest.java @@ -18,28 +18,27 @@ package org.eclipse.jetty.util.resource; +import java.net.URI; + +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.TypeUtil; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; -import java.net.URI; - -import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.TypeUtil; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnJre; -import org.junit.jupiter.api.condition.JRE; - public class JrtResourceTest { - private String testResURI = MavenTestingUtils.getTestResourcesDir().getAbsoluteFile().toURI().toASCIIString(); - @Test @DisabledOnJre(JRE.JAVA_8) + @Disabled("Not supported on Java 9+ Module API") public void testResourceFromUriForString() throws Exception { @@ -57,6 +56,7 @@ public class JrtResourceTest @Test @DisabledOnJre(JRE.JAVA_8) + @Disabled("Not supported on Java 9+ Module API") public void testResourceFromStringForString() throws Exception { @@ -73,6 +73,7 @@ public class JrtResourceTest @Test @DisabledOnJre(JRE.JAVA_8) + @Disabled("Not supported on Java 9+ Module API") public void testResourceFromURLForString() throws Exception { @@ -111,7 +112,4 @@ public class JrtResourceTest assertThat(resource.isDirectory(), is(false)); assertThat(resource.length(),is(-1L)); } - - - } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java index ee203b35e50..6903c2d9bfa 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java @@ -725,13 +725,18 @@ public class ClasspathPattern extends AbstractSet if (Boolean.FALSE==byName) return false; - Boolean byLocation = locations.isIncludedAndNotExcluded(location.get()); - if (Boolean.FALSE==byLocation) - return false; + URI uri = location.get(); + if (uri != null) + { + Boolean byLocation = locations.isIncludedAndNotExcluded(uri); + if (Boolean.FALSE == byLocation) + return false; - return Boolean.TRUE.equals(byName) - || Boolean.TRUE.equals(byLocation) - || !(names.hasIncludes() || locations.hasIncludes()); + return Boolean.TRUE.equals(byName) + || Boolean.TRUE.equals(byLocation) + || !(names.hasIncludes() || locations.hasIncludes()); + } + return false; } } From 1118750139b3200006274ab855e8680aec3d21af Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 21 Jun 2019 06:55:59 -0500 Subject: [PATCH 13/15] Issue #3700 - Fixing bad ClasspathPatternTest assumptions Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/util/TypeUtil.java | 10 +++++++--- .../jetty/webapp/ClasspathPatternTest.java | 16 ++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java index 24a4f4414b1..f4e63fc2e40 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java @@ -684,10 +684,14 @@ public class TypeUtil { URI uri = url.toURI(); String uriStr = uri.toASCIIString(); - int idx = uriStr.indexOf(".jar!/"); - if (idx > 0) + if(uriStr.startsWith("jar:file:")) { - return URI.create(uriStr.substring(0, idx + 4)); + uriStr = uriStr.substring(4); + int idx = uriStr.indexOf("!/"); + if (idx > 0) + { + return URI.create(uriStr.substring(0, idx)); + } } return uri; } diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java index 117d553deda..735fb446a1a 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/ClasspathPatternTest.java @@ -18,12 +18,7 @@ package org.eclipse.jetty.webapp; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.net.URI; -import java.nio.file.Paths; import java.util.Arrays; import org.eclipse.jetty.util.TypeUtil; @@ -34,6 +29,10 @@ import org.junit.jupiter.api.condition.DisabledOnJre; import org.junit.jupiter.api.condition.EnabledOnJre; import org.junit.jupiter.api.condition.JRE; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class ClasspathPatternTest { private final ClasspathPattern _pattern = new ClasspathPattern(); @@ -122,15 +121,12 @@ public class ClasspathPatternTest { // jar from JVM classloader URI loc_string = TypeUtil.getLocationOfClass(String.class); - // System.err.println(loc_string); // a jar from maven repo jar URI loc_junit = TypeUtil.getLocationOfClass(Test.class); - // System.err.println(loc_junit); // class file URI loc_test = TypeUtil.getLocationOfClass(ClasspathPatternTest.class); - // System.err.println(loc_test); ClasspathPattern pattern = new ClasspathPattern(); pattern.include("something"); @@ -139,7 +135,7 @@ public class ClasspathPatternTest assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(false)); // Add directory for both JVM classes - pattern.include(Paths.get(loc_string).getParent().toUri().toString()); + pattern.include(loc_string.toASCIIString()); // Add jar for individual class and classes directory pattern.include(loc_junit.toString(), loc_test.toString()); @@ -220,7 +216,7 @@ public class ClasspathPatternTest assertThat(pattern.match(ClasspathPatternTest.class), Matchers.is(true)); // Add directory for both JVM classes - pattern.exclude(Paths.get(loc_string).getParent().toUri().toString()); + pattern.exclude(loc_string.toString()); // Add jar for individual class and classes directory pattern.exclude(loc_junit.toString(), loc_test.toString()); From af4dd0285ff2db4332ad170efa83210b859690b4 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 21 Jun 2019 07:05:55 -0500 Subject: [PATCH 14/15] Issue #3798 - Prevent NPE on null or partial URI in ClasspathPattern + Not allowing URI to be null or non-absolute for location or module tests. Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/webapp/ClasspathPattern.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java index 938696e9c37..71b9cf4f2e6 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java @@ -353,6 +353,8 @@ public class ClasspathPattern extends AbstractSet @Override public boolean test(URI uri) { + if ((uri == null) || (!uri.isAbsolute())) + return false; if (!uri.getScheme().equals("file")) return false; Path path = Paths.get(uri); @@ -390,6 +392,8 @@ public class ClasspathPattern extends AbstractSet @Override public boolean test(URI uri) { + if ((uri == null) || (!uri.isAbsolute())) + return false; if (!uri.getScheme().equalsIgnoreCase("jrt")) return false; String module = uri.getPath(); @@ -443,6 +447,8 @@ public class ClasspathPattern extends AbstractSet @Override public boolean test(URI name) { + if ((name == null) || (!name.isAbsolute())) + return false; return _byLocation.test(name) || _byModule.test(name); } From 77526a15186ec86b04190ee0cb81d6a6cfc887a3 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 21 Jun 2019 14:35:46 -0500 Subject: [PATCH 15/15] Issue #3731 - Adding back cdi.mod pointing to cdi2.mod Signed-off-by: Joakim Erdfelt --- jetty-cdi/src/main/config/modules/cdi.mod | 7 +++++++ jetty-cdi/src/main/config/modules/cdi2.mod | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 jetty-cdi/src/main/config/modules/cdi.mod diff --git a/jetty-cdi/src/main/config/modules/cdi.mod b/jetty-cdi/src/main/config/modules/cdi.mod new file mode 100644 index 00000000000..749aafe4ff6 --- /dev/null +++ b/jetty-cdi/src/main/config/modules/cdi.mod @@ -0,0 +1,7 @@ +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html + +[description] +Jetty setup to support Weld/CDI2 with WELD inside the webapp + +[depend] +cdi2 diff --git a/jetty-cdi/src/main/config/modules/cdi2.mod b/jetty-cdi/src/main/config/modules/cdi2.mod index 2461212f798..2284de8abec 100644 --- a/jetty-cdi/src/main/config/modules/cdi2.mod +++ b/jetty-cdi/src/main/config/modules/cdi2.mod @@ -1,4 +1,4 @@ -DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html +# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html [description] Jetty setup to support Weld/CDI2 with WELD inside the webapp