This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit cb2b4d522263d4d63c144146e181efaca7e0cdbd Author: opencode <[email protected]> AuthorDate: Fri Nov 6 14:05:58 2026 +0100 Add CDI 4.1 integration test for the OWB module Deploy a CDI 4.1 webapp in embedded Tomcat and exercise servlet injection, request scope, BeanContainer.isMatchingBean() and interceptor bindings against the shaded module JAR. --- modules/owb/pom.xml | 71 ++++++++ .../webbeans/web/tomcat/OpenWebBeansCdi41IT.java | 178 +++++++++++++++++++++ modules/owb/src/test/webapp/WEB-INF/beans.xml | 21 +++ .../webbeans/web/tomcat/testapp/Cdi41Features.java | 42 +++++ .../webbeans/web/tomcat/testapp/Cdi41Servlet.java | 67 ++++++++ .../webbeans/web/tomcat/testapp/Greeting.java | 27 ++++ .../web/tomcat/testapp/MatchingTarget.java | 23 +++ .../web/tomcat/testapp/RequestScopedBean.java | 31 ++++ .../apache/webbeans/web/tomcat/testapp/Traced.java | 32 ++++ .../webbeans/web/tomcat/testapp/TracedService.java | 28 ++++ .../web/tomcat/testapp/TracingInterceptor.java | 35 ++++ webapps/docs/cdi.xml | 1 + 12 files changed, 556 insertions(+) diff --git a/modules/owb/pom.xml b/modules/owb/pom.xml index a0e540296f..e27ec6e930 100644 --- a/modules/owb/pom.xml +++ b/modules/owb/pom.xml @@ -37,7 +37,9 @@ <jakarta-interceptor.version>2.2.0</jakarta-interceptor.version> <jakarta-enterprise-cdi.version>4.1.0</jakarta-enterprise-cdi.version> <jakarta-annotation-api.version>3.0.0</jakarta-annotation-api.version> + <jakarta-el.version>6.0.1</jakarta-el.version> <tomcat.version>12.0.0-SNAPSHOT</tomcat.version> + <junit.version>5.11.4</junit.version> </properties> <dependencies> @@ -90,6 +92,19 @@ <version>${tomcat.version}</version> <scope>provided</scope> </dependency> + <!-- Test dependencies --> + <dependency> + <groupId>jakarta.el</groupId> + <artifactId>jakarta.el-api</artifactId> + <version>${jakarta-el.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -101,6 +116,25 @@ <release>21</release> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <id>create-empty-classes-dir</id> + <phase>pre-integration-test</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <target> + <mkdir dir="${project.build.directory}/empty-classes"/> + </target> + </configuration> + </execution> + </executions> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> @@ -143,6 +177,43 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>3.5.2</version> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + <configuration> + <!-- Test the shaded JAR rather than the unshaded classes --> + <classesDirectory>${project.build.directory}/empty-classes</classesDirectory> + <additionalClasspathElements> + <additionalClasspathElement>${project.build.directory}/${project.build.finalName}.jar</additionalClasspathElement> + </additionalClasspathElements> + <classpathDependencyExcludes> + <classpathDependencyExclude>org.apache.openwebbeans:openwebbeans-spi</classpathDependencyExclude> + <classpathDependencyExclude>org.apache.openwebbeans:openwebbeans-impl</classpathDependencyExclude> + <classpathDependencyExclude>org.apache.openwebbeans:openwebbeans-web</classpathDependencyExclude> + <classpathDependencyExclude>org.apache.openwebbeans:openwebbeans-el22</classpathDependencyExclude> + <classpathDependencyExclude>org.apache.xbean:xbean-finder-shaded</classpathDependencyExclude> + <classpathDependencyExclude>org.apache.xbean:xbean-asm9-shaded</classpathDependencyExclude> + <classpathDependencyExclude>jakarta.enterprise:jakarta.enterprise.cdi-api</classpathDependencyExclude> + <classpathDependencyExclude>jakarta.enterprise:jakarta.enterprise.lang-model</classpathDependencyExclude> + <classpathDependencyExclude>jakarta.inject:jakarta.inject-api</classpathDependencyExclude> + <classpathDependencyExclude>jakarta.interceptor:jakarta.interceptor-api</classpathDependencyExclude> + <classpathDependencyExclude>jakarta.annotation:jakarta.annotation-api</classpathDependencyExclude> + </classpathDependencyExcludes> + <systemPropertyVariables> + <owb.test.webapp>${project.basedir}/src/test/webapp</owb.test.webapp> + <owb.test.jar>${project.build.directory}/${project.build.finalName}.jar</owb.test.jar> + </systemPropertyVariables> + </configuration> + </plugin> </plugins> </build> diff --git a/modules/owb/src/test/java/org/apache/webbeans/web/tomcat/OpenWebBeansCdi41IT.java b/modules/owb/src/test/java/org/apache/webbeans/web/tomcat/OpenWebBeansCdi41IT.java new file mode 100644 index 0000000000..53638d9d88 --- /dev/null +++ b/modules/owb/src/test/java/org/apache/webbeans/web/tomcat/OpenWebBeansCdi41IT.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.time.Duration; +import java.util.List; +import java.util.Locale; +import java.util.stream.Stream; + +import javax.tools.Diagnostic; +import javax.tools.DiagnosticCollector; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + +import org.apache.catalina.startup.Tomcat; +import org.apache.webbeans.config.WebBeansContext; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +class OpenWebBeansCdi41IT { + + private static final String CONTEXT_PATH = "/owb-cdi41"; + + @TempDir + Path tempDir; + + @Test + void cdi41Webapp() throws Exception { + Path webappSource = Path.of(System.getProperty("owb.test.webapp")); + Path shadedJar = Path.of(System.getProperty("owb.test.jar")); + + assertEquals(shadedJar.toRealPath(), + Path.of(OpenWebBeansListener.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .toRealPath(), + "The test must run against the shaded module JAR"); + assertEquals(shadedJar.toRealPath(), + Path.of(WebBeansContext.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .toRealPath(), + "The test must use the OpenWebBeans classes from the shaded module JAR"); + + Path webapp = tempDir.resolve("webapp"); + copyTree(webappSource.resolve("WEB-INF"), webapp.resolve("WEB-INF")); + Path classes = webapp.resolve("WEB-INF/classes"); + Files.createDirectories(classes); + compile(webappSource.resolve("src"), classes, shadedJar); + + Path base = tempDir.resolve("tomcat"); + Tomcat tomcat = new Tomcat(); + tomcat.setBaseDir(base.toString()); + tomcat.setPort(0); + tomcat.getConnector(); + tomcat.getServer().setPort(-1); + + OpenWebBeansListener listener = new OpenWebBeansListener(); + listener.setStartWithoutBeansXml(false); + tomcat.getServer().addLifecycleListener(listener); + + // The test webapp does not use JSPs and tomcat-jasper is not required. + tomcat.setAddDefaultWebXmlToWebapp(false); + tomcat.addWebapp(CONTEXT_PATH, webapp.toString()); + tomcat.start(); + try { + int port = tomcat.getConnector().getLocalPort(); + assertTrue(port > 0, "Tomcat did not start an HTTP connector"); + + HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build(); + URI baseUri = URI.create("http://127.0.0.1:" + port + CONTEXT_PATH + "/"); + + assertEquals("hello-owb-4.1.1", get(client, baseUri.resolve("hello"))); + + String firstRequest = get(client, baseUri.resolve("request")); + String secondRequest = get(client, baseUri.resolve("request")); + assertNotEquals(firstRequest, secondRequest, + "The request scoped bean was not recreated for each request"); + assertFalse(firstRequest.isEmpty()); + assertFalse(secondRequest.isEmpty()); + + assertEquals("true", get(client, baseUri.resolve("matching"))); + assertEquals("bound:ok", get(client, baseUri.resolve("interceptor"))); + } finally { + try { + tomcat.stop(); + } finally { + tomcat.destroy(); + } + } + } + + private static String get(HttpClient client, URI uri) throws IOException, InterruptedException { + HttpRequest request = HttpRequest.newBuilder(uri).timeout(Duration.ofSeconds(10)).GET().build(); + HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); + assertEquals(200, response.statusCode(), "Unexpected response for " + uri + ": " + response.body()); + return response.body().strip(); + } + + private static void compile(Path sourceDir, Path classesDir, Path shadedJar) throws IOException { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + assertNotNull(compiler, "A JDK is required to run this test"); + + List<Path> sources; + try (Stream<Path> stream = Files.walk(sourceDir)) { + sources = stream.filter(Files::isRegularFile) + .filter(path -> path.toString().endsWith(".java")) + .toList(); + } + + String compileClasspath = System.getProperty("surefire.test.class.path"); + if (compileClasspath == null || compileClasspath.isBlank()) { + compileClasspath = System.getProperty("java.class.path"); + } + compileClasspath = compileClasspath + File.pathSeparator + shadedJar; + + DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); + try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, Locale.ROOT, + StandardCharsets.UTF_8)) { + Iterable<? extends JavaFileObject> units = fileManager.getJavaFileObjectsFromPaths(sources); + List<String> options = List.of( + "--release", "21", + "-proc:none", + "-classpath", compileClasspath, + "-d", classesDir.toString()); + boolean success = compiler.getTask(null, fileManager, diagnostics, options, null, units).call(); + if (!success) { + StringBuilder message = new StringBuilder("Failed to compile the test webapp:"); + for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) { + message.append(System.lineSeparator()).append(diagnostic); + } + throw new IllegalStateException(message.toString()); + } + } + } + + private static void copyTree(Path source, Path target) throws IOException { + try (Stream<Path> stream = Files.walk(source)) { + for (Path path : stream.toList()) { + Path destination = target.resolve(source.relativize(path)); + if (Files.isDirectory(path)) { + Files.createDirectories(destination); + } else { + Files.createDirectories(destination.getParent()); + Files.copy(path, destination, StandardCopyOption.REPLACE_EXISTING); + } + } + } + } +} diff --git a/modules/owb/src/test/webapp/WEB-INF/beans.xml b/modules/owb/src/test/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..abc684f5de --- /dev/null +++ b/modules/owb/src/test/webapp/WEB-INF/beans.xml @@ -0,0 +1,21 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_1.xsd" + version="4.1" + bean-discovery-mode="all"/> diff --git a/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Cdi41Features.java b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Cdi41Features.java new file mode 100644 index 0000000000..be52ef3d28 --- /dev/null +++ b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Cdi41Features.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat.testapp; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Set; + +import jakarta.enterprise.context.Dependent; +import jakarta.enterprise.inject.Default; +import jakarta.enterprise.inject.spi.BeanContainer; +import jakarta.enterprise.inject.spi.CDI; + +@Dependent +public class Cdi41Features { + + public boolean matching() { + BeanContainer container = CDI.current().getBeanContainer(); + + Set<Type> beanTypes = Set.of(MatchingTarget.class, Object.class); + Set<Annotation> qualifiers = Set.of(Default.Literal.INSTANCE); + + boolean match = container.isMatchingBean(beanTypes, qualifiers, MatchingTarget.class, qualifiers); + boolean noMatch = container.isMatchingBean(beanTypes, qualifiers, String.class, qualifiers); + + return match && !noMatch; + } +} diff --git a/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Cdi41Servlet.java b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Cdi41Servlet.java new file mode 100644 index 0000000000..49171da897 --- /dev/null +++ b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Cdi41Servlet.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat.testapp; + +import java.io.IOException; + +import jakarta.inject.Inject; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(urlPatterns = { "/hello", "/request", "/matching", "/interceptor" }) +public class Cdi41Servlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Inject + private Greeting greeting; + + @Inject + private RequestScopedBean requestScopedBean; + + @Inject + private Cdi41Features cdi41Features; + + @Inject + private TracedService tracedService; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + String result; + switch (request.getServletPath()) { + case "/hello": + result = greeting.message(); + break; + case "/request": + result = requestScopedBean.getId(); + break; + case "/matching": + result = Boolean.toString(cdi41Features.matching()); + break; + case "/interceptor": + result = tracedService.hello(); + break; + default: + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return; + } + response.setContentType("text/plain"); + response.getWriter().println(result); + } +} diff --git a/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Greeting.java b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Greeting.java new file mode 100644 index 0000000000..843fcae8f5 --- /dev/null +++ b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Greeting.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat.testapp; + +import jakarta.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class Greeting { + + public String message() { + return "hello-owb-4.1.1"; + } +} diff --git a/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/MatchingTarget.java b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/MatchingTarget.java new file mode 100644 index 0000000000..fdf82e9b6e --- /dev/null +++ b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/MatchingTarget.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat.testapp; + +import jakarta.enterprise.context.Dependent; + +@Dependent +public class MatchingTarget { +} diff --git a/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/RequestScopedBean.java b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/RequestScopedBean.java new file mode 100644 index 0000000000..72c74b3338 --- /dev/null +++ b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/RequestScopedBean.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat.testapp; + +import java.util.UUID; + +import jakarta.enterprise.context.RequestScoped; + +@RequestScoped +public class RequestScopedBean { + + private final String id = UUID.randomUUID().toString(); + + public String getId() { + return id; + } +} diff --git a/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Traced.java b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Traced.java new file mode 100644 index 0000000000..2bddf63c74 --- /dev/null +++ b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/Traced.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat.testapp; + +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 jakarta.interceptor.InterceptorBinding; + +@Inherited +@InterceptorBinding +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD }) +public @interface Traced { +} diff --git a/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/TracedService.java b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/TracedService.java new file mode 100644 index 0000000000..9916b4406e --- /dev/null +++ b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/TracedService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat.testapp; + +import jakarta.enterprise.context.ApplicationScoped; + +@Traced +@ApplicationScoped +public class TracedService { + + public String hello() { + return "ok"; + } +} diff --git a/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/TracingInterceptor.java b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/TracingInterceptor.java new file mode 100644 index 0000000000..816e64822e --- /dev/null +++ b/modules/owb/src/test/webapp/src/org/apache/webbeans/web/tomcat/testapp/TracingInterceptor.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.webbeans.web.tomcat.testapp; + +import jakarta.annotation.Priority; +import jakarta.interceptor.AroundInvoke; +import jakarta.interceptor.Interceptor; +import jakarta.interceptor.InvocationContext; + +@Traced +@Interceptor +@Priority(Interceptor.Priority.APPLICATION) +public class TracingInterceptor { + + @AroundInvoke + public Object aroundInvoke(InvocationContext context) throws Exception { + boolean found = context.getInterceptorBindings().stream() + .anyMatch(annotation -> annotation.annotationType() == Traced.class); + return (found ? "bound:" : "missing:") + context.proceed(); + } +} diff --git a/webapps/docs/cdi.xml b/webapps/docs/cdi.xml index df491d5bf6..d8e9f5e98e 100644 --- a/webapps/docs/cdi.xml +++ b/webapps/docs/cdi.xml @@ -56,6 +56,7 @@ The process to build CDI support is the following. <source><![CDATA[cd $TOMCAT_SRC/modules/owb mvn clean && mvn package]]></source> + The module integration tests can be run with <code>mvn clean verify</code>. The resulting JAR at <code>target/tomcat-owb-x.y.z.jar</code> (where x.y.z depends on the Apache OpenWebBeans version used during the build) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
