Move CDI integration tests to a common CDI-Integration module (#4280)
Signed-off-by: Jan Supol <jan.supol@oracle.com>
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/pom.xml b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/pom.xml
new file mode 100644
index 0000000..c71a619
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/pom.xml
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-beanvalidation-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-beanvalidation-webapp</name>
+
+ <description>Jersey CDI/Bean Validation test web application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ <exclusions>
+ <!-- Remove ancient javax.el that causes problems with Hibernate -->
+ <exclusion>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-bean-validation</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate.validator</groupId>
+ <artifactId>hibernate-validator-cdi</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-weld2-se</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-validation</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>run-external-tests</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${external.container.factory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${external.container.port}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- External test container configuration is done via properties to allow overriding via command line. -->
+ <external.container.factory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</external.container.factory>
+ <external.container.port>8080</external.container.port>
+ <maven.test.skip>false</maven.test.skip>
+ </properties>
+ </profile>
+ </profiles>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ </build>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiApplication.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiApplication.java
new file mode 100644
index 0000000..5956ab2
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiApplication.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ * This one is configured as a CDI bean.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/cdi")
+@ApplicationScoped
+public class CdiApplication extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(CdiFieldInjectedResource.class);
+ add(CdiParamInjectedResource.class);
+ add(CdiPropertyInjectedResource.class);
+ add(CdiOldFashionedResource.class);
+
+ add(CdiValidationInterceptor.class);
+ }};
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiFieldInjectedResource.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiFieldInjectedResource.java
new file mode 100644
index 0000000..f355e8c
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiFieldInjectedResource.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.enterprise.context.RequestScoped;
+
+import javax.inject.Inject;
+import javax.validation.ConstraintViolationException;
+import javax.validation.constraints.NotNull;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * This CDI backed resource should get validated and validation result field injected.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("validated/field")
+@RequestScoped
+public class CdiFieldInjectedResource {
+
+ @Inject
+ ValidationResult validationResult;
+
+ @Inject
+ NonJaxRsValidatedBean cdiBean;
+
+ @QueryParam("q")
+ @NotNull
+ String q;
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field injected validation bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate() {
+
+ return validationResult.getViolationCount();
+ }
+
+ /**
+ * Return number of validation issues for non JAX-RS bean.
+ * This is to make sure the implicit Hibernate validator
+ * is functioning for raw CDI beans, where Jersey
+ * is not involved in method invocation.
+ *
+ * @return number of validation issues revealed when invoking injected CDI bean.
+ */
+ @Path("validate/non-jaxrs")
+ @GET
+ public int getValidateNonJaxRs(@QueryParam("h") String h) {
+
+ try {
+ cdiBean.echo(h);
+ return 0;
+ } catch (ConstraintViolationException ex) {
+ return ex.getConstraintViolations().size();
+ }
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiOldFashionedResource.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiOldFashionedResource.java
new file mode 100644
index 0000000..c27e9bc
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiOldFashionedResource.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.validation.constraints.NotNull;
+
+/**
+ * This CDI backed resource should get validated.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("old/fashioned")
+@RequestScoped
+public class CdiOldFashionedResource {
+
+ /**
+ * Query param getter.
+ *
+ * @return query param value.
+ */
+ @Path("validate")
+ @GET
+ public String getQ(@QueryParam("q") @NotNull String q) {
+
+ return q;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiParamInjectedResource.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiParamInjectedResource.java
new file mode 100644
index 0000000..0c014e1
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiParamInjectedResource.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.enterprise.context.RequestScoped;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * This CDI backed resource should get validated.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("validated/param")
+@RequestScoped
+public class CdiParamInjectedResource {
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from param injected validation bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate(@QueryParam("q") @NotNull String q, @Context ValidationResult validationResult) {
+
+ return validationResult.getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiPropertyInjectedResource.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiPropertyInjectedResource.java
new file mode 100644
index 0000000..39664ea
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiPropertyInjectedResource.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * This CDI backed resource should get validated and validation result property injected.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("validated/property")
+@RequestScoped
+public class CdiPropertyInjectedResource {
+
+ private ValidationResult validationResult;
+
+ @Inject
+ public void setValidationResult(ValidationResult validationResult) {
+ this.validationResult = validationResult;
+ }
+
+ public ValidationResult getValidationResult() {
+ return validationResult;
+ }
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field injected validation bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate(@QueryParam("q") @NotNull String q) {
+
+ return getValidationResult().getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationInterceptor.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationInterceptor.java
new file mode 100644
index 0000000..ff5c1c2
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationInterceptor.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.validation.ConstraintViolationException;
+import javax.validation.ValidationException;
+
+import org.glassfish.jersey.server.spi.ValidationInterceptor;
+import org.glassfish.jersey.server.spi.ValidationInterceptorContext;
+
+import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy;
+
+/**
+ * CDI backed interceptor to handle validation issues.
+ *
+ * @author Jaku Podlesak
+ */
+@ApplicationScoped
+public class CdiValidationInterceptor implements ValidationInterceptor {
+
+ private final CdiValidationResult validationResult;
+ private final CdiPropertyInjectedResource pir;
+
+ /**
+ * Empty constructor to make CDI happy.
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ public CdiValidationInterceptor() {
+ this.validationResult = null;
+ this.pir = null;
+ }
+
+ /**
+ * Injection constructor.
+ *
+ * @param validationResult CDI implementation of validation result.
+ * @param resource CDI property-injected JAX-RS resource.
+ */
+ @Inject
+ public CdiValidationInterceptor(CdiValidationResult validationResult, CdiPropertyInjectedResource resource) {
+ this.validationResult = validationResult;
+ this.pir = resource;
+ }
+
+ @Override
+ public void onValidate(ValidationInterceptorContext ctx) throws ValidationException {
+
+ final Object resource = ctx.getResource();
+ if (resource instanceof TargetInstanceProxy) {
+ ctx.setResource(((TargetInstanceProxy) resource).getTargetInstance());
+ }
+
+ try {
+ ctx.proceed();
+ } catch (ConstraintViolationException constraintViolationException) {
+
+ // First check for a property
+ if (ValidationResultUtil.hasValidationResultProperty(resource)) {
+ final Method validationResultGetter = ValidationResultUtil.getValidationResultGetter(resource);
+ ValidationResultUtil.updateValidationResultProperty(resource, validationResultGetter,
+ constraintViolationException.getConstraintViolations());
+ pir.setValidationResult(validationResult);
+ } else {
+ // Then check for a field
+ final Field vr = ValidationResultUtil.getValidationResultField(resource);
+ if (vr != null) {
+ // we have the right guy, no need to use reflection:
+ validationResult.setViolations(constraintViolationException.getConstraintViolations());
+ } else {
+ if (isValidationResultInArgs(ctx.getArgs())) {
+ this.validationResult.setViolations(constraintViolationException.getConstraintViolations());
+ } else {
+ throw constraintViolationException;
+ }
+ }
+ }
+ }
+ }
+
+ private boolean isValidationResultInArgs(Object[] args) {
+ for (Object a : args) {
+ if (a != null) {
+ Class<?> argClass = a.getClass();
+ do {
+ if (ValidationResult.class.isAssignableFrom(argClass)) {
+ return true;
+ }
+ argClass = argClass.getSuperclass();
+ } while (argClass != Object.class);
+ }
+ }
+ return false;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResult.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResult.java
new file mode 100644
index 0000000..1cabb79
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResult.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.RequestScoped;
+import javax.validation.ConstraintViolation;
+
+/**
+ * CDI implementation of validation result.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+public class CdiValidationResult implements ValidationResult {
+
+ private Set<ConstraintViolation<?>> constraintViolationSet;
+
+ public void setViolations(Set<ConstraintViolation<?>> violations) {
+ this.constraintViolationSet = new HashSet<>(violations);
+ }
+
+ @Override
+ public Set<ConstraintViolation<?>> getAllViolations() {
+ return constraintViolationSet;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return (constraintViolationSet != null) ? !constraintViolationSet.isEmpty() : false;
+ }
+
+ @Override
+ public int getViolationCount() {
+ return (constraintViolationSet != null) ? constraintViolationSet.size() : 0;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResultBinder.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResultBinder.java
new file mode 100644
index 0000000..52bdb79
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResultBinder.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.util.Set;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+
+import org.glassfish.jersey.ext.cdi1x.internal.CdiUtil;
+import org.glassfish.jersey.ext.cdi1x.internal.GenericCdiBeanSupplier;
+import org.glassfish.jersey.internal.inject.Binding;
+import org.glassfish.jersey.internal.inject.Bindings;
+import org.glassfish.jersey.internal.inject.InjectionManager;
+import org.glassfish.jersey.server.spi.ComponentProvider;
+
+/**
+ * Utility that binds HK2 factory to provide CDI managed validation result bean.
+ * This is to make sure validation result could be injected as a resource method parameter
+ * even when running in CDI environment.
+ */
+public class CdiValidationResultBinder implements Extension, ComponentProvider {
+
+ @Inject
+ BeanManager beanManager;
+
+ InjectionManager injectionManager;
+
+ @Override
+ public void initialize(InjectionManager injectionManager) {
+ this.injectionManager = injectionManager;
+ this.beanManager = CdiUtil.getBeanManager();
+ }
+
+ @Override
+ public boolean bind(Class<?> component, Set<Class<?>> providerContracts) {
+ return false;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void done() {
+ if (beanManager != null) { // in CDI environment
+ Binding binding = Bindings
+ .supplier(new GenericCdiBeanSupplier(
+ CdiValidationResult.class, injectionManager, beanManager, true))
+ .to(CdiValidationResult.class)
+ .to(ValidationResult.class);
+
+ injectionManager.register(binding);
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2Application.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2Application.java
new file mode 100644
index 0000000..3d1c29d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2Application.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.ws.rs.ApplicationPath;
+
+import javax.enterprise.inject.Vetoed;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.process.internal.RequestScoped;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application to configure resources.
+ * This one will get fully managed by HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/hk2")
+@Vetoed
+public class Hk2Application extends ResourceConfig {
+
+ public Hk2Application() {
+ super(Hk2ParamInjectedResource.class,
+ Hk2FieldInjectedResource.class,
+ Hk2PropertyInjectedResource.class,
+ Hk2OldFashionedResource.class);
+
+ register(new Hk2ValidationInterceptor.Binder());
+ register(new AbstractBinder(){
+
+ @Override
+ protected void configure() {
+ bindAsContract(Hk2ValidationResult.class).to(ValidationResult.class).in(RequestScoped.class);
+ }
+ });
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2FieldInjectedResource.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2FieldInjectedResource.java
new file mode 100644
index 0000000..8d41193
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2FieldInjectedResource.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * This one should get validated.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("validated/field")
+@Vetoed
+public class Hk2FieldInjectedResource {
+
+ @QueryParam("q")
+ @NotNull
+ String q;
+
+ @Context
+ ValidationResult validationResult;
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field produced bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate() {
+ return validationResult.getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2OldFashionedResource.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2OldFashionedResource.java
new file mode 100644
index 0000000..cad09b2
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2OldFashionedResource.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.constraints.NotNull;
+
+/**
+ * This HK2 managed resource should get validated.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("old/fashioned")
+@Vetoed
+public class Hk2OldFashionedResource {
+
+ /**
+ * Query param getter.
+ *
+ * @return query parameter value.
+ */
+ @Path("validate")
+ @GET
+ public String getQ(@QueryParam("q") @NotNull String q) {
+
+ return q;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ParamInjectedResource.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ParamInjectedResource.java
new file mode 100644
index 0000000..7728903
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ParamInjectedResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * This HK2 managed resource should get validated and validation
+ * result injected via resource method parameter.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("validated/param")
+@Vetoed
+public class Hk2ParamInjectedResource {
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field produced bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate(@QueryParam("q") @NotNull String q, @Context Hk2ValidationResult validationResult) {
+
+ return validationResult.getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2PropertyInjectedResource.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2PropertyInjectedResource.java
new file mode 100644
index 0000000..44ce591
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2PropertyInjectedResource.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * This one should get validated.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("validated/property")
+@Vetoed
+public class Hk2PropertyInjectedResource {
+
+ @QueryParam("q")
+ @NotNull
+ String q;
+
+ ValidationResult validationResult;
+
+ public ValidationResult getValidationResult() {
+ return validationResult;
+ }
+
+ @Context
+ public void setValidationResult(ValidationResult validationResult) {
+ this.validationResult = validationResult;
+ }
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field produced bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate() {
+ return validationResult.getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationInterceptor.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationInterceptor.java
new file mode 100644
index 0000000..985453d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationInterceptor.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.function.Supplier;
+
+import javax.ws.rs.core.Context;
+
+import javax.enterprise.inject.Vetoed;
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import javax.validation.ConstraintViolationException;
+import javax.validation.ValidationException;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.spi.ValidationInterceptor;
+import org.glassfish.jersey.server.spi.ValidationInterceptorContext;
+
+/**
+ * HK2 managed validation interceptor.
+ */
+@Vetoed
+public class Hk2ValidationInterceptor implements ValidationInterceptor {
+
+
+ private final Provider<Hk2ValidationResult> validationResult;
+
+ public Hk2ValidationInterceptor(Provider<Hk2ValidationResult> validationResult) {
+ this.validationResult = validationResult;
+ }
+
+ public static class Binder extends AbstractBinder {
+
+ @Override
+ protected void configure() {
+ bindFactory(ValidationInterceptorFactory.class, Singleton.class)
+ .to(ValidationInterceptor.class);
+ }
+
+ }
+
+ private static class ValidationInterceptorFactory implements Supplier<ValidationInterceptor> {
+
+ @Inject
+ Provider<Hk2ValidationResult> validationResultProvider;
+
+ @Override
+ public ValidationInterceptor get() {
+ return new Hk2ValidationInterceptor(validationResultProvider);
+ }
+ }
+
+ @Override
+ public void onValidate(
+ ValidationInterceptorContext ctx) throws ValidationException {
+ try {
+ ctx.proceed();
+ } catch (ConstraintViolationException ex) {
+ ensureValidationResultInjected(ctx, ex);
+ validationResult.get().setViolations(ex.getConstraintViolations());
+ }
+ }
+
+ private void ensureValidationResultInjected(
+ final ValidationInterceptorContext ctx, final ConstraintViolationException ex) {
+
+ if (!isValidationResultInArgs(ctx.getArgs())
+ && !isValidationResultInResource(ctx)
+ && !hasValidationResultProperty(ctx.getResource())) {
+
+ throw ex;
+ }
+ }
+
+ private boolean isValidationResultInResource(ValidationInterceptorContext ctx) {
+ Class<?> clazz = ctx.getResource().getClass();
+ do {
+ for (Field f : clazz.getDeclaredFields()) {
+ // Of ValidationResult and JAX-RS injectable
+ if (ValidationResult.class.isAssignableFrom(f.getType())
+ && f.getAnnotation(Context.class) != null) {
+ return true;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return false;
+ }
+
+ private boolean isValidationResultInArgs(Object[] args) {
+ for (Object a : args) {
+ if (a != null && ValidationResult.class.isAssignableFrom(a.getClass())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Determines if a resource has a property of type {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @param resource resource instance.
+ * @return outcome of test.
+ */
+ public static boolean hasValidationResultProperty(final Object resource) {
+ return getValidationResultGetter(resource) != null && getValidationResultSetter(resource) != null;
+ }
+
+ /**
+ * Returns a getter for {@code javax.mvc.validation.ValidationResult} or {@code null}
+ * if one cannot be found.
+ *
+ * @param resource resource instance.
+ * @return getter or {@code null} if not available.
+ */
+ public static Method getValidationResultGetter(final Object resource) {
+ Class<?> clazz = resource.getClass();
+ do {
+ for (Method m : clazz.getDeclaredMethods()) {
+ if (isValidationResultGetter(m)) {
+ return m;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Determines if a method is a getter for {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @param m method to test.
+ * @return outcome of test.
+ */
+ private static boolean isValidationResultGetter(Method m) {
+ return m.getName().startsWith("get")
+ && ValidationResult.class.isAssignableFrom(m.getReturnType())
+ && Modifier.isPublic(m.getModifiers()) && m.getParameterTypes().length == 0;
+ }
+
+ /**
+ * Returns a setter for {@code javax.mvc.validation.ValidationResult} or {@code null}
+ * if one cannot be found.
+ *
+ * @param resource resource instance.
+ * @return setter or {@code null} if not available.
+ */
+ public static Method getValidationResultSetter(final Object resource) {
+ Class<?> clazz = resource.getClass();
+ do {
+ for (Method m : clazz.getDeclaredMethods()) {
+ if (isValidationResultSetter(m)) {
+ return m;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Determines if a method is a setter for {@code javax.mvc.validation.ValidationResult}.
+ * As a CDI initializer method, it must be annotated with {@link javax.inject.Inject}.
+ *
+ * @param m method to test.
+ * @return outcome of test.
+ */
+ private static boolean isValidationResultSetter(Method m) {
+ return m.getName().startsWith("set") && m.getParameterTypes().length == 1
+ && ValidationResult.class.isAssignableFrom(m.getParameterTypes()[0])
+ && m.getReturnType() == Void.TYPE && Modifier.isPublic(m.getModifiers())
+ && m.getAnnotation(Context.class) != null;
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationResult.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationResult.java
new file mode 100644
index 0000000..f286105
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationResult.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.ConstraintViolation;
+
+/**
+ * HK2 managed validation result bean.
+ */
+@Vetoed
+public class Hk2ValidationResult implements ValidationResult {
+
+ Set<ConstraintViolation<?>> constraintViolationSet;
+
+ public void setViolations(Set<ConstraintViolation<?>> violations) {
+ this.constraintViolationSet = new HashSet<>(violations);
+ }
+
+ @Override
+ public Set<ConstraintViolation<?>> getAllViolations() {
+ return constraintViolationSet;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return (constraintViolationSet != null) ? !constraintViolationSet.isEmpty() : false;
+ }
+
+ @Override
+ public int getViolationCount() {
+ return (constraintViolationSet != null) ? constraintViolationSet.size() : 0;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/NonJaxRsValidatedBean.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/NonJaxRsValidatedBean.java
new file mode 100644
index 0000000..9c26a84
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/NonJaxRsValidatedBean.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.enterprise.context.RequestScoped;
+import javax.validation.constraints.NotNull;
+
+/**
+ * CDI bean that gets validated by Hibernate validator directly.
+ * This is to ensure Jersey interceptor wrapper
+ * does not block the original validator from functioning
+ * on raw CDI beans.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+public class NonJaxRsValidatedBean {
+
+ public String echo(@NotNull String value) {
+ return value;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResult.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResult.java
new file mode 100644
index 0000000..b723793
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResult.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+
+/**
+ * An interface to be utilized when resource method validation issues
+ * are to be handled within actual resource method.
+ */
+public interface ValidationResult {
+
+ /**
+ * Returns an immutable set of all constraint violations detected.
+ *
+ * @return All constraint violations detected
+ */
+ public Set<ConstraintViolation<?>> getAllViolations();
+
+ /**
+ * Returns <code>true</code> if there is at least one constraint violation.
+ * Same as checking whether {@link #getViolationCount()} is greater than zero.
+ *
+ * @return <code>true</code> if there is at least one constraint violation.
+ */
+ public boolean isFailed();
+
+ /**
+ * Returns the total number of constraint violations detected. Same as calling
+ * <code>getAllViolations().size()</code>.
+ *
+ * @return The number of constraint violations
+ */
+ int getViolationCount();
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResultUtil.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResultUtil.java
new file mode 100644
index 0000000..906da13
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResultUtil.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Set;
+
+import javax.enterprise.inject.Vetoed;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.validation.ConstraintViolation;
+
+/**
+ * Helper class to implement support for {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @author Santiago Pericas-Geertsen
+ */
+@Vetoed
+public final class ValidationResultUtil {
+
+ private static final String VALIDATION_RESULT = ValidationResult.class.getName();
+
+ private ValidationResultUtil() {
+ throw new AssertionError("Instantiation not allowed.");
+ }
+
+ /**
+ * Search for a {@code javax.mvc.validation.ValidationResult} field in the resource's
+ * class hierarchy. Field must be annotated with {@link javax.inject.Inject}.
+ *
+ * @param resource resource instance.
+ * @return field or {@code null} if none is found.
+ */
+ public static Field getValidationResultField(final Object resource) {
+ Class<?> clazz = resource.getClass();
+ do {
+ for (Field f : clazz.getDeclaredFields()) {
+ // Of ValidationResult and CDI injectable
+ if (f.getType().getName().equals(VALIDATION_RESULT)
+ && f.getAnnotation(Inject.class) != null) {
+ return f;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Updates a {@code javax.mvc.validation.ValidationResult} field. In pseudo-code:
+ * <p/>
+ * resource.field.setViolations(constraints)
+ *
+ * @param resource resource instance.
+ * @param field field to be updated.
+ * @param constraints new set of constraints.
+ */
+ public static void updateValidationResultField(Object resource, Field field,
+ Set<ConstraintViolation<?>> constraints) {
+ try {
+ field.setAccessible(true);
+ final Object obj = field.get(resource);
+ Method setter;
+ try {
+ setter = obj.getClass().getMethod("setViolations", Set.class);
+ } catch (NoSuchMethodException e) {
+ setter = obj.getClass().getSuperclass().getMethod("setViolations", Set.class);
+ }
+ setter.invoke(obj, constraints);
+ } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ // ignore for now
+ System.out.println("Damn it...");
+ } catch (Throwable t) {
+ System.out.println("What the heck...");
+ }
+ }
+
+ /**
+ * Updates a {@code javax.mvc.validation.ValidationResult} property. In pseudo-code:
+ * <p/>
+ * obj = getter.invoke(resource);
+ * obj.setViolations(constraints);
+ * setter.invoke(resource, obj);
+ *
+ * @param resource resource instance.
+ * @param getter getter to be used.
+ * @param constraints new set of constraints.
+ */
+ public static void updateValidationResultProperty(Object resource, Method getter,
+ Set<ConstraintViolation<?>> constraints) {
+ try {
+ final Object obj = getter.invoke(resource);
+ Method setViolations;
+ try {
+ setViolations = obj.getClass().getMethod("setViolations", Set.class);
+ } catch (NoSuchMethodException e) {
+ setViolations = obj.getClass().getSuperclass().getMethod("setViolations", Set.class);
+ }
+ setViolations.invoke(obj, constraints);
+
+ final Method setter = getValidationResultSetter(resource);
+
+ if (setter != null) {
+ setter.invoke(resource, obj);
+ }
+ } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ // ignore for now
+ }
+ }
+
+ /**
+ * Determines if a resource has a property of type {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @param resource resource instance.
+ * @return outcome of test.
+ */
+ public static boolean hasValidationResultProperty(final Object resource) {
+ return getValidationResultGetter(resource) != null && getValidationResultSetter(resource) != null;
+ }
+
+ /**
+ * Returns a getter for {@code javax.mvc.validation.ValidationResult} or {@code null}
+ * if one cannot be found.
+ *
+ * @param resource resource instance.
+ * @return getter or {@code null} if not available.
+ */
+ public static Method getValidationResultGetter(final Object resource) {
+ Class<?> clazz = resource.getClass();
+ do {
+ for (Method m : clazz.getDeclaredMethods()) {
+ if (isValidationResultGetter(m)) {
+ return m;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Determines if a method is a getter for {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @param m method to test.
+ * @return outcome of test.
+ */
+ private static boolean isValidationResultGetter(Method m) {
+ return m.getName().startsWith("get")
+ && m.getReturnType().getName().equals(VALIDATION_RESULT)
+ && Modifier.isPublic(m.getModifiers()) && m.getParameterTypes().length == 0;
+ }
+
+ /**
+ * Returns a setter for {@code javax.mvc.validation.ValidationResult} or {@code null}
+ * if one cannot be found.
+ *
+ * @param resource resource instance.
+ * @return setter or {@code null} if not available.
+ */
+ public static Method getValidationResultSetter(final Object resource) {
+ return getValidationResultSetter(resource.getClass());
+ }
+
+ private static Method getValidationResultSetter(final Class<?> resourceClass) {
+ Class<?> clazz = resourceClass;
+ do {
+ for (Method m : clazz.getDeclaredMethods()) {
+ if (isValidationResultSetter(m)) {
+ return m;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Determines if a method is a setter for {@code javax.mvc.validation.ValidationResult}.
+ * As a CDI initializer method, it must be annotated with {@link javax.inject.Inject}.
+ *
+ * @param m method to test.
+ * @return outcome of test.
+ */
+ private static boolean isValidationResultSetter(Method m) {
+ return m.getName().startsWith("set") && m.getParameterTypes().length == 1
+ && m.getParameterTypes()[0].getName().equals(VALIDATION_RESULT)
+ && m.getReturnType() == Void.TYPE && Modifier.isPublic(m.getModifiers())
+ && m.getAnnotation(Inject.class) != null;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/beans.xml b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..d036d62
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.bv.CdiValidationResultBinder
\ No newline at end of file
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider
new file mode 100644
index 0000000..d036d62
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.bv.CdiValidationResultBinder
\ No newline at end of file
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..1d9cc6c
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
+
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/BaseValidationTest.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/BaseValidationTest.java
new file mode 100644
index 0000000..12a9681
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/BaseValidationTest.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.net.URI;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Common test for resource validation. The same set of tests is used
+ * for the following scenarios: Grizzly based combined deployment with CDI enabled,
+ * WAR based combined deployment with CDI enabled, Grizzly based deployment without CDI enabled.
+ *
+ * @author Jakub Podlesak
+ */
+public abstract class BaseValidationTest extends JerseyTest {
+
+ public abstract String getAppPath();
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-beanvalidation-webapp").path(getAppPath()).build();
+ }
+
+ @Test
+ public void testParamValidatedResourceNoParam() throws Exception {
+ _testParamValidatedResourceNoParam(target());
+ }
+
+ public static void _testParamValidatedResourceNoParam(final WebTarget target) throws Exception {
+
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("param").path("validate")
+ .request().get(Integer.class);
+
+ assertThat(errors, is(1));
+ }
+
+ @Test
+ public void testParamValidatedResourceParamProvided() throws Exception {
+ _testParamValidatedResourceParamProvided(target());
+ }
+
+ public static void _testParamValidatedResourceParamProvided(WebTarget target) throws Exception {
+ Integer errors = target.register(LoggingFeature.class).path("validated").path("field").path("validate")
+ .queryParam("q", "one").request().get(Integer.class);
+ assertThat(errors, is(0));
+ }
+
+ @Test
+ public void testFieldValidatedResourceNoParam() throws Exception {
+ _testFieldValidatedResourceNoParam(target());
+ }
+
+ public static void _testFieldValidatedResourceNoParam(final WebTarget target) throws Exception {
+
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("field").path("validate")
+ .request().get(Integer.class);
+
+ assertThat(errors, is(1));
+ }
+
+ @Test
+ public void testFieldValidatedResourceParamProvided() throws Exception {
+ _testFieldValidatedResourceParamProvided(target());
+ }
+
+ public static void _testFieldValidatedResourceParamProvided(final WebTarget target) throws Exception {
+ Integer errors = target.register(LoggingFeature.class).path("validated").path("field").path("validate")
+ .queryParam("q", "one").request().get(Integer.class);
+ assertThat(errors, is(0));
+ }
+
+ @Test
+ public void testPropertyValidatedResourceNoParam() throws Exception {
+ _testPropertyValidatedResourceNoParam(target());
+ }
+
+ public static void _testPropertyValidatedResourceNoParam(final WebTarget target) throws Exception {
+
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("property").path("validate")
+ .request().get(Integer.class);
+
+ assertThat(errors, is(1));
+ }
+
+ @Test
+ public void testPropertyValidatedResourceParamProvided() throws Exception {
+ _testPropertyValidatedResourceParamProvided(target());
+ }
+
+ public static void _testPropertyValidatedResourceParamProvided(final WebTarget target) throws Exception {
+ Integer errors = target.register(LoggingFeature.class).path("validated").path("property").path("validate")
+ .queryParam("q", "one").request().get(Integer.class);
+ assertThat(errors, is(0));
+ }
+
+ @Test
+ public void testOldFashionedResourceNoParam() {
+ _testOldFashionedResourceNoParam(target());
+ }
+
+ public static void _testOldFashionedResourceNoParam(final WebTarget target) {
+
+ Response response = target.register(LoggingFeature.class)
+ .path("old").path("fashioned").path("validate")
+ .request().get();
+
+ assertThat(response.getStatus(), is(400));
+ }
+
+ @Test
+ public void testOldFashionedResourceParamProvided() throws Exception {
+ _testOldFashionedResourceParamProvided(target());
+ }
+
+ public static void _testOldFashionedResourceParamProvided(final WebTarget target) throws Exception {
+ String response = target.register(LoggingFeature.class).path("old").path("fashioned").path("validate")
+ .queryParam("q", "one").request().get(String.class);
+ assertThat(response, is("one"));
+ }
+
+ public static void _testNonJaxRsValidationFieldValidatedResourceNoParam(final WebTarget target) {
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("field").path("validate").path("non-jaxrs")
+ .queryParam("q", "not-important-just-to-get-this-through-jax-rs").request().get(Integer.class);
+
+ assertThat(errors, is(1));
+ }
+
+ public static void _testNonJaxRsValidationFieldValidatedResourceParamProvided(final WebTarget target) {
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("field").path("validate").path("non-jaxrs")
+ .queryParam("q", "not-important-just-to-get-this-through-jax-rs")
+ .queryParam("h", "bummer")
+ .request().get(Integer.class);
+
+ assertThat(errors, is(0));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/CombinedTest.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/CombinedTest.java
new file mode 100644
index 0000000..b1b2961
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/CombinedTest.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Properties;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainerProvider;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.TestProperties;
+
+import org.glassfish.grizzly.http.server.HttpHandler;
+import org.glassfish.grizzly.http.server.HttpServer;
+
+import org.hamcrest.CoreMatchers;
+import org.jboss.weld.environment.se.Weld;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test both Jersey apps running simultaneously within a single Grizzly HTTP server
+ * to make sure injection managers do not interfere. The test is not executed
+ * if other than the default (Grizzly) test container has been set.
+ * For Servlet based container testing, the other two tests, {@link RawCdiTest} and {@link RawHk2Test},
+ * do the same job, because the WAR application contains both Jersey apps already.
+ *
+ * @author Jakub Podlesak
+ */
+public class CombinedTest {
+
+ public static final String CDI_URI = "/cdi";
+ public static final String HK2_URI = "/hk2";
+
+ public static final String PORT_NUMBER = getSystemProperty(TestProperties.CONTAINER_PORT,
+ Integer.toString(TestProperties.DEFAULT_CONTAINER_PORT));
+
+ private static final URI BASE_HK2_URI = URI.create("http://localhost:" + PORT_NUMBER + HK2_URI);
+ private static final URI BASE_CDI_URI = URI.create("http://localhost:" + PORT_NUMBER + CDI_URI);
+
+ private static final boolean isDefaultTestContainerFactorySet = isDefaultTestContainerFactorySet();
+
+ Weld weld;
+ HttpServer cdiServer;
+
+ Client client;
+ WebTarget cdiTarget, hk2Target;
+
+ @Before
+ public void before() throws IOException {
+ if (isDefaultTestContainerFactorySet && Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ initializeWeld();
+ startGrizzlyContainer();
+ initializeClient();
+ }
+ }
+
+ @Before
+ public void beforeIsImmediate() {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+ }
+
+ @After
+ public void after() {
+ if (isDefaultTestContainerFactorySet && Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ cdiServer.shutdownNow();
+ weld.shutdown();
+ client.close();
+ }
+ }
+
+ @Test
+ public void testParamValidatedResourceNoParam() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testParamValidatedResourceNoParam(cdiTarget);
+ BaseValidationTest._testParamValidatedResourceNoParam(hk2Target);
+ }
+
+ @Test
+ public void testParamValidatedResourceParamProvided() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testParamValidatedResourceParamProvided(cdiTarget);
+ BaseValidationTest._testParamValidatedResourceParamProvided(hk2Target);
+ }
+
+ @Test
+ public void testFieldValidatedResourceNoParam() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testFieldValidatedResourceNoParam(cdiTarget);
+ BaseValidationTest._testFieldValidatedResourceNoParam(hk2Target);
+ }
+
+ @Test
+ public void testFieldValidatedResourceParamProvided() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testFieldValidatedResourceParamProvided(cdiTarget);
+ BaseValidationTest._testFieldValidatedResourceParamProvided(hk2Target);
+ }
+
+ @Test
+ public void testPropertyValidatedResourceNoParam() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testPropertyValidatedResourceNoParam(cdiTarget);
+ BaseValidationTest._testPropertyValidatedResourceNoParam(hk2Target);
+ }
+
+ @Test
+ public void testPropertyValidatedResourceParamProvided() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testPropertyValidatedResourceParamProvided(cdiTarget);
+ BaseValidationTest._testPropertyValidatedResourceParamProvided(hk2Target);
+ }
+
+ @Test
+ public void testOldFashionedResourceNoParam() {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testOldFashionedResourceNoParam(cdiTarget);
+ BaseValidationTest._testOldFashionedResourceNoParam(hk2Target);
+ }
+
+ @Test
+ public void testOldFashionedResourceParamProvided() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testOldFashionedResourceParamProvided(cdiTarget);
+ BaseValidationTest._testOldFashionedResourceParamProvided(hk2Target);
+ }
+
+ @Test
+ public void testNonJaxRsValidationFieldValidatedResourceNoParam() {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testNonJaxRsValidationFieldValidatedResourceNoParam(cdiTarget);
+ }
+
+ @Test
+ public void testNonJaxRsValidationFieldValidatedResourceParamProvided() {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testNonJaxRsValidationFieldValidatedResourceParamProvided(cdiTarget);
+ }
+
+ private void initializeWeld() {
+ weld = new Weld();
+ weld.initialize();
+ }
+
+ private void startGrizzlyContainer() throws IOException {
+ final ResourceConfig cdiConfig = ResourceConfig.forApplicationClass(CdiApplication.class);
+ final ResourceConfig hk2Config = ResourceConfig.forApplicationClass(Hk2Application.class);
+
+ cdiServer = GrizzlyHttpServerFactory.createHttpServer(BASE_CDI_URI, cdiConfig, false);
+ final HttpHandler hk2Handler = createGrizzlyContainer(hk2Config);
+ cdiServer.getServerConfiguration().addHttpHandler(hk2Handler, HK2_URI);
+ cdiServer.start();
+ }
+
+ private void initializeClient() {
+ client = ClientBuilder.newClient();
+ cdiTarget = client.target(BASE_CDI_URI);
+ hk2Target = client.target(BASE_HK2_URI);
+ }
+
+ private GrizzlyHttpContainer createGrizzlyContainer(ResourceConfig resourceConfig) {
+ return (new GrizzlyHttpContainerProvider()).createContainer(GrizzlyHttpContainer.class, resourceConfig);
+ }
+
+ private static boolean isDefaultTestContainerFactorySet() {
+ final String testContainerFactory = getSystemProperty(TestProperties.CONTAINER_FACTORY, null);
+ return testContainerFactory == null || TestProperties.DEFAULT_CONTAINER_FACTORY.equals(testContainerFactory);
+ }
+
+ private static String getSystemProperty(final String propertyName, final String defaultValue) {
+ final Properties systemProperties = System.getProperties();
+ return systemProperties.getProperty(propertyName, defaultValue);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawCdiTest.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawCdiTest.java
new file mode 100644
index 0000000..8932fc8
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawCdiTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+
+import org.jboss.weld.environment.se.Weld;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Validation result test for CDI environment.
+ *
+ * @author Jakub Podlesak
+ */
+public class RawCdiTest extends BaseValidationTest {
+
+ Weld weld;
+
+ @Before
+ public void setup() {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ weld = new Weld();
+ weld.initialize();
+ }
+ super.setUp();
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ weld.shutdown();
+ }
+ super.tearDown();
+ }
+ }
+
+ @Override
+ protected Application configure() {
+ return ResourceConfig.forApplicationClass(CdiApplication.class);
+ }
+
+ @Override
+ public String getAppPath() {
+ return "cdi";
+ }
+
+ @Test
+ public void testNonJaxRsValidationFieldValidatedResourceNoParam() {
+ BaseValidationTest._testNonJaxRsValidationFieldValidatedResourceNoParam(target());
+ }
+
+ @Test
+ public void testNonJaxRsValidationFieldValidatedResourceParamProvided() {
+ BaseValidationTest._testNonJaxRsValidationFieldValidatedResourceParamProvided(target());
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawHk2Test.java b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawHk2Test.java
new file mode 100644
index 0000000..43e551b
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawHk2Test.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.bv;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Validation result test for raw HK2 environment.
+ *
+ * @author Jakub Podlesak
+ */
+public class RawHk2Test extends BaseValidationTest {
+
+ @Override
+ protected Application configure() {
+ return ResourceConfig.forApplicationClass(Hk2Application.class);
+ }
+
+ @Override
+ public String getAppPath() {
+ return "hk2";
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/pom.xml b/tests/integration/cdi-integration/cdi-ejb-test-webapp/pom.xml
new file mode 100644
index 0000000..c5654f7
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-ejb-test-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-ejb-webapp</name>
+
+ <description>Jersey CDI/EJB test web application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.ejb</groupId>
+ <artifactId>jakarta.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/BasicTimer.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/BasicTimer.java
new file mode 100644
index 0000000..775fae0
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/BasicTimer.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * Basic timer implementation to be reused for various types of beans.
+ *
+ * @author Jakub Podlesak
+ */
+public abstract class BasicTimer {
+
+ long ms;
+
+ /**
+ * Provide information on internal timer millisecond value.
+ *
+ * @return milliseconds when the current bean has been post-constructed.
+ */
+ public long getMiliseconds() {
+ return ms;
+ }
+
+ /**
+ * Initialize this timer with the current time.
+ */
+ @PostConstruct
+ public void init() {
+ this.ms = System.currentTimeMillis();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiAppScopedTimer.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiAppScopedTimer.java
new file mode 100644
index 0000000..19dd3e5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiAppScopedTimer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Application scoped CDI bean to be injected into EJB resources.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationScoped
+public class CdiAppScopedTimer extends BasicTimer {
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedResource.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedResource.java
new file mode 100644
index 0000000..cf152eb
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedResource.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * Request scoped CDI bean injected with EJB timers.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("request-scoped")
+public class CdiRequestScopedResource {
+
+ @EJB EjbSingletonTimer ejbInjectedTimer;
+ @Inject EjbSingletonTimer jsr330InjectedTimer;
+ @Inject CdiAppScopedTimer cdiTimer;
+
+ @GET
+ @Path("ejb-injected-timer")
+ public String getEjbTime() {
+ return Long.toString(ejbInjectedTimer.getMiliseconds());
+ }
+
+ @GET
+ @Path("jsr330-injected-timer")
+ public String getJsr330Time() {
+ return Long.toString(jsr330InjectedTimer.getMiliseconds());
+ }
+
+ @GET
+ public String getMyself() {
+ return this.toString();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedTimer.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedTimer.java
new file mode 100644
index 0000000..362f220
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedTimer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * Request scoped CDI timer.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+public class CdiRequestScopedTimer extends BasicTimer {
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonResource.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonResource.java
new file mode 100644
index 0000000..ffbd70e
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ejb.Singleton;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * EJB singleton session bean injected with CDI timers.
+ *
+ * @author Jakub Podlesak
+ */
+@Singleton
+@Path("singleton")
+public class EjbSingletonResource {
+
+ @Inject CdiRequestScopedTimer requestScopedTimer;
+ @Inject CdiAppScopedTimer appScopedTimer;
+
+ @GET
+ @Path("request-scoped-timer")
+ public String getReqTime() {
+ return Long.toString(requestScopedTimer.getMiliseconds());
+ }
+
+ @GET
+ @Path("app-scoped-timer")
+ public String getAppTime() {
+ return Long.toString(appScopedTimer.getMiliseconds());
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonTimer.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonTimer.java
new file mode 100644
index 0000000..8077c5f
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonTimer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ejb.Singleton;
+
+/**
+ * EJB singleton timer.
+ *
+ * @author Jakub Podlesak
+ */
+@Singleton
+public class EjbSingletonTimer extends BasicTimer {
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatefulResource.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatefulResource.java
new file mode 100644
index 0000000..c40bbcb
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatefulResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ejb.Stateful;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * EJB backed JAX-RS resource injected with CDI service providers.
+ *
+ * @author Jakub Podlesak
+ */
+@Stateful
+@Path("stateful")
+public class EjbStatefulResource {
+
+ @Inject CdiRequestScopedTimer requestScopedTimer;
+ @Inject CdiAppScopedTimer appScopedTimer;
+
+ @GET
+ @Path("request-scoped-timer")
+ public String getReqTime() {
+ return Long.toString(requestScopedTimer.getMiliseconds());
+ }
+
+ @GET
+ @Path("app-scoped-timer")
+ public String getAppTime() {
+ return Long.toString(appScopedTimer.getMiliseconds());
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessResource.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessResource.java
new file mode 100644
index 0000000..656b945
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * EJB session bean injected with CDI service providers.
+ *
+ * @author Jakub Podlesak
+ */
+@Stateless
+@Path("stateless")
+public class EjbStatelessResource {
+
+ @Inject CdiRequestScopedTimer requestScopedTimer;
+ @Inject CdiAppScopedTimer appScopedTimer;
+
+ @GET
+ @Path("request-scoped-timer")
+ public String getReqTime() {
+ return Long.toString(requestScopedTimer.getMiliseconds());
+ }
+
+ @GET
+ @Path("app-scoped-timer")
+ public String getAppTime() {
+ return Long.toString(appScopedTimer.getMiliseconds());
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessTimer.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessTimer.java
new file mode 100644
index 0000000..7ea94a1
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessTimer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ejb.Stateless;
+
+/**
+ * EJB session timer bean.
+ *
+ * @author Jakub Podlesak
+ */
+@Stateless
+public class EjbStatelessTimer extends BasicTimer {
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..8dcb555
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/*")
+public class MyApplication extends Application {
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(CdiRequestScopedResource.class);
+ classes.add(CdiRequestScopedTimer.class);
+ classes.add(CdiAppScopedTimer.class);
+ classes.add(EjbStatelessResource.class);
+ classes.add(EjbStatefulResource.class);
+ classes.add(EjbSingletonResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..71e6b6e
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+</web-app>
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiIntoEjbTest.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiIntoEjbTest.java
new file mode 100644
index 0000000..d98c072
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiIntoEjbTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test CDI timers injected into EJB beans.
+ *
+ * @author Jakub Podlesak
+ */
+public class CdiIntoEjbTest extends TestBase {
+
+ @Test
+ public void testStateless() {
+ _testRequestScoped("stateless");
+ _testAppScoped("stateless");
+ }
+
+ @Test
+ public void testStateful() {
+ _testRequestScoped("stateful");
+ _testAppScoped("stateful");
+ }
+
+ @Test
+ public void testSingleton() {
+ _testRequestScoped("singleton");
+ _testAppScoped("singleton");
+ }
+
+ private void _testRequestScoped(final String ejbType) {
+
+ final WebTarget target = target().path(ejbType).path("request-scoped-timer");
+ long firstMillis = _getMillis(target);
+ sleep(2);
+ long secondMillis = _getMillis(target);
+
+ assertTrue("Second request should have greater millis!", secondMillis > firstMillis);
+ }
+
+ private void _testAppScoped(final String ejbType) {
+
+ final WebTarget target = target().path(ejbType).path("app-scoped-timer");
+ long firstMillis = _getMillis(target);
+ sleep(2);
+ long secondMillis = _getMillis(target);
+
+ assertTrue("Second request should have the same millis!", secondMillis == firstMillis);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EjbIntoCdiTest.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EjbIntoCdiTest.java
new file mode 100644
index 0000000..b27b0ce
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EjbIntoCdiTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.equalTo;
+
+/**
+ * Test EJB timers injected into CDI beans.
+ *
+ * @author Jakub Podlesak
+ */
+public class EjbIntoCdiTest extends TestBase {
+
+ @Test
+ public void testInjection() {
+
+ final WebTarget cdiResource = target().path("request-scoped");
+ final WebTarget ejbInjectedTimer = cdiResource.path("ejb-injected-timer");
+ final WebTarget jsr330InjectedTimer = cdiResource.path("jsr330-injected-timer");
+
+ String firstResource = cdiResource.request().get(String.class);
+ long firstMillis = _getMillis(ejbInjectedTimer);
+ sleep(2);
+ String secondResource = cdiResource.request().get(String.class);
+ long secondMillis = _getMillis(jsr330InjectedTimer);
+
+ assertThat(firstMillis, equalTo(secondMillis));
+ assertThat(firstResource, not(equalTo(secondResource)));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TestBase.java b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TestBase.java
new file mode 100644
index 0000000..670e4fc
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TestBase.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.net.URI;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak
+ */
+public class TestBase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-ejb-test-webapp").build();
+ }
+
+ protected long _getMillis(final WebTarget target) throws NumberFormatException {
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), is(200));
+ return Long.decode(response.readEntity(String.class));
+ }
+
+ protected void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(CdiIntoEjbTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+}
+
diff --git a/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/pom.xml b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/pom.xml
new file mode 100644
index 0000000..7e72a9c
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-iface-with-non-jaxrs-impl-test-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-iface-with-non-jaxrs-impl-test-webapp</name>
+
+ <description>Jersey CDI using non JAX-RS implementation for CDI injection</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiEcho.java b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiEcho.java
new file mode 100644
index 0000000..c06d823
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiEcho.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Raw CDI implementation of {@link Echo} service.
+ *
+ * @author Jakub Podlesak
+ */
+public class CdiEcho implements Echo {
+
+ @Override
+ public String echo(String s) {
+ return String.format("CDI ECHOED %s", s);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Echo.java b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Echo.java
new file mode 100644
index 0000000..66db32d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Echo.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Echo service interface.
+ *
+ * @author Jakub Podlesak
+ */
+public interface Echo {
+
+ /**
+ * Echo service method;
+ *
+ * @param s input
+ * @return echoed input
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
new file mode 100644
index 0000000..ae452a3
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * JAX-RS resource class backed by CDI bean.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("echo")
+public class EchoResource {
+
+ // CDI injection, HK2 should back off
+ // even if EchoImpl is not directly used here
+ // and could appear as HK2 custom bound type
+ // to Jersey CDI extension
+ @Inject Echo echoService;
+
+ @GET
+ public String cdiEcho(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..c4e6553
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/*")
+public class MyApplication extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<>();
+ classes.add(EchoResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..71e6b6e
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+</web-app>
diff --git a/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EchoResourceTest.java b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EchoResourceTest.java
new file mode 100644
index 0000000..7791a8f
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EchoResourceTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.net.URI;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.startsWith;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak
+ */
+public class EchoResourceTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-iface-with-non-jaxrs-impl-test-webapp").build();
+ }
+
+ @Test
+ public void testCdiInjection() throws Exception {
+ final Response response = target().path("echo").queryParam("s", "I").request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), startsWith("CDI ECHOED"));
+ }
+
+ protected void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(EchoResourceTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-log-check/pom.xml b/tests/integration/cdi-integration/cdi-log-check/pom.xml
new file mode 100644
index 0000000..15415d3
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/pom.xml
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-log-check</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-log-check</name>
+
+ <description>Jersey CDI test web application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.interceptor</groupId>
+ <artifactId>jakarta.interceptor-api</artifactId>
+ <version>${javax.interceptor.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework</groupId>
+ <artifactId>jersey-test-framework-util</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-weld2-se</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>run-external-tests</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${external.container.factory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${external.container.port}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- External test container configuration is done via properties to allow overriding via command line. -->
+ <external.container.factory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</external.container.factory>
+ <external.container.port>8080</external.container.port>
+ <maven.test.skip>false</maven.test.skip>
+ </properties>
+ </profile>
+ </profiles>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/ClassBean.java b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/ClassBean.java
new file mode 100644
index 0000000..c87660d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/ClassBean.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+package org.glassfish.jersey.tests.cdi.resources;
+
+public interface ClassBean {
+ Class<?> get();
+
+ void set(Class<?> clazz);
+}
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
new file mode 100644
index 0000000..0c6e0c3
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Path("echo")
+@RequestScoped
+@Fooed
+public class EchoResource {
+ public static final String OK = "OK";
+
+ @Inject
+ WarningClass warningClass;
+
+ @GET
+ public String get() {
+ return OK;
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/FooInterceptor.java b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/FooInterceptor.java
new file mode 100644
index 0000000..617a6e9
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/FooInterceptor.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.annotation.Priority;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Intercepted;
+import javax.enterprise.inject.spi.Bean;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import java.io.Serializable;
+
+@Interceptor
+@Fooed
+public class FooInterceptor implements Serializable {
+
+ @Inject
+ @Intercepted
+ private Bean<?> interceptedBean;
+ private static final long serialVersionUID = 1L;
+
+ @Inject
+ WarningClass warningClass;
+
+ @AroundInvoke
+ public Object intercept(InvocationContext invocationContext) throws Exception {
+ warningClass.set(interceptedBean.getBeanClass());
+ return invocationContext.proceed();
+ }
+}
+
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/Fooed.java b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/Fooed.java
new file mode 100644
index 0000000..c815632
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/Fooed.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.interceptor.InterceptorBinding;
+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;
+
+@Inherited
+@InterceptorBinding
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD, ElementType.TYPE})
+public @interface Fooed {
+}
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..3942f35
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import org.glassfish.jersey.server.ServerProperties;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+@ApplicationPath("/*")
+public class MyApplication extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<>();
+ classes.add(EchoResource.class);
+ classes.add(WarningResource.class);
+ return classes;
+ }
+
+ @Override
+ public Map<String, Object> getProperties() {
+ final Map<String, Object> properties = new HashMap<>();
+ properties.put(ServerProperties.WADL_FEATURE_DISABLE, true);
+ return properties;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/WarningClass.java b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/WarningClass.java
new file mode 100644
index 0000000..7dcc12e
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/WarningClass.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class WarningClass implements ClassBean {
+ private Class<?> clazz = WarningClass.class;
+
+ @Override
+ public Class<?> get() {
+ return clazz;
+ }
+
+ @Override
+ public void set(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/WarningResource.java b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/WarningResource.java
new file mode 100644
index 0000000..2c736e9
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/java/org/glassfish/jersey/tests/cdi/resources/WarningResource.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Path("warning")
+@RequestScoped
+public class WarningResource {
+ @Inject
+ WarningClass warningClass;
+
+ @GET
+ public String get() {
+ return warningClass.get().getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/resources/META-INF/beans.xml b/tests/integration/cdi-integration/cdi-log-check/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..ea4422d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+
+<beans
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+ <interceptors>
+ <class>org.glassfish.jersey.tests.cdi.resources.FooInterceptor</class>
+ </interceptors>
+</beans>
+
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-integration/cdi-log-check/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..daed0f5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+</web-app>
diff --git a/tests/integration/cdi-integration/cdi-log-check/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiComponentProviderWarningTest.java b/tests/integration/cdi-integration/cdi-log-check/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiComponentProviderWarningTest.java
new file mode 100644
index 0000000..24dd485
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-log-check/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiComponentProviderWarningTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.internal.LocalizationMessages;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.jboss.weld.environment.se.Weld;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ws.rs.core.Application;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import static org.junit.Assert.assertEquals;
+
+public class CdiComponentProviderWarningTest extends JerseyTest {
+ private Weld weld;
+
+ @Before
+ public void setup() {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ weld = new Weld();
+ weld.initialize();
+ }
+ super.setUp();
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ weld.shutdown();
+ }
+ super.tearDown();
+ }
+ }
+
+ @Override
+ protected Application configure() {
+ set(TestProperties.RECORD_LOG_LEVEL, Level.WARNING.intValue());
+ return new MyApplication();
+ }
+
+ @Test
+ public void testWarning() {
+ String echo = target("echo").request().get(String.class);
+ assertEquals(echo, EchoResource.OK);
+
+ String resource = target("warning").request().get(String.class);
+ assertEquals(resource, EchoResource.class.getName());
+
+ String warning = LocalizationMessages.PARAMETER_UNRESOLVABLE(echo, echo, echo);
+ String searchInLog = warning.substring(warning.lastIndexOf(echo) + echo.length());
+
+ List<?> logRecords = getLoggedRecords();
+ for (final LogRecord logRecord : getLoggedRecords()) {
+ if (logRecord.getLoggerName().equals("org.glassfish.jersey.internal.Errors")
+ && logRecord.getMessage().contains(searchInLog)) {
+ Assert.fail("Checking CDI bean is a JAX-RS resource should not cast warnings");
+ }
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/ear/pom.xml b/tests/integration/cdi-integration/cdi-multimodule/ear/pom.xml
new file mode 100644
index 0000000..556ded5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/ear/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>cdi-multimodule-ear</artifactId>
+ <packaging>ear</packaging>
+ <name>jersey-tests-integration-cdi-multimodule-ear</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ <version>6</version>
+ <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
+ <modules>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-multimodule-war1</artifactId>
+ </webModule>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-multimodule-war2</artifactId>
+ </webModule>
+ <jarModule>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-multimodule-lib</artifactId>
+ </jarModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-multimodule-war1</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-multimodule-war2</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-multimodule-lib</artifactId>
+ <type>jar</type>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-multimodule/lib/pom.xml b/tests/integration/cdi-integration/cdi-multimodule/lib/pom.xml
new file mode 100644
index 0000000..30f01e4
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/lib/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>cdi-multimodule-lib</artifactId>
+ <packaging>jar</packaging>
+ <name>jersey-tests-integration-cdi-multimodule-lib</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.ejb</groupId>
+ <artifactId>jakarta.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedDependentBean.java b/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedDependentBean.java
new file mode 100644
index 0000000..5268a53
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedDependentBean.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.lib;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * CDI managed bean, that gets JAX-RS injected. This bean is being consumed
+ * by all web apps within an EAR packaged enterprise application.
+ *
+ * @author Jakub Podlesak
+ */
+public class JaxRsInjectedDependentBean {
+
+ @Context
+ UriInfo uriInfo;
+
+ @HeaderParam("x-test")
+ String testHeader;
+
+ /**
+ * Get me URI info.
+ *
+ * @return URI info from the JAX-RS layer.
+ */
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ /**
+ * Get me the actual request test header.
+ *
+ * @return actual request URI info.
+ */
+ public String getTestHeader() {
+ return testHeader;
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedRequestScopedBean.java b/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedRequestScopedBean.java
new file mode 100644
index 0000000..3397e89
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedRequestScopedBean.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.lib;
+
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * CDI managed bean, that gets JAX-RS injected. This bean is being consumed
+ * by all web apps within an EAR packaged enterprise application.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+public class JaxRsInjectedRequestScopedBean {
+
+ @Context
+ UriInfo uriInfo;
+
+ @HeaderParam("x-test")
+ String testHeader;
+
+ /**
+ * Get me the actual JAX-RS request URI info.
+ *
+ * @return actual request URI info.
+ */
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ /**
+ * Get me the actual request test header.
+ *
+ * @return actual request URI info.
+ */
+ public String getTestHeader() {
+ return testHeader;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/resources/META-INF/beans.xml b/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..3b46d69
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/lib/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-multimodule/pom.xml b/tests/integration/cdi-integration/cdi-multimodule/pom.xml
new file mode 100644
index 0000000..962183d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-multimodule</artifactId>
+ <packaging>pom</packaging>
+ <name>jersey-tests-integration-cdi-multimodule</name>
+
+ <description>
+ CDI Multi-Module
+ </description>
+
+ <modules>
+ <module>lib</module>
+ <module>war1</module>
+ <module>war2</module>
+ <module>ear</module>
+ </modules>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war1/pom.xml b/tests/integration/cdi-integration/cdi-multimodule/war1/pom.xml
new file mode 100644
index 0000000..4c45acb
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war1/pom.xml
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>cdi-multimodule-war1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-cdi-multimodule-war</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.servlet</groupId>
+ <artifactId>jakarta.servlet-api</artifactId>
+ <version>${servlet4.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>cdi-multimodule-lib</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/AppScopedJaxRsResource.java b/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/AppScopedJaxRsResource.java
new file mode 100644
index 0000000..01d014f
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/AppScopedJaxRsResource.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web1;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedDependentBean;
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedRequestScopedBean;
+
+/**
+ * JAX-RS resource backed by an application scoped CDI bean.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("app-scoped")
+@ApplicationScoped
+public class AppScopedJaxRsResource {
+
+ @Inject
+ JaxRsInjectedRequestScopedBean reqScopedBean;
+
+ @Path("req/header")
+ @GET
+ public String getReqHeader() {
+ return reqScopedBean.getTestHeader();
+ }
+
+ @Path("req/uri/{p}")
+ @GET
+ public String getReqUri() {
+ return reqScopedBean.getUriInfo().getRequestUri().toString();
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsApp.java b/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsApp.java
new file mode 100644
index 0000000..7e4795a
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsApp.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web1;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application resource configuration.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/")
+public class JaxRsApp extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(RequestScopedJaxRsResource.class);
+ add(AppScopedJaxRsResource.class);
+ }};
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/RequestScopedJaxRsResource.java b/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/RequestScopedJaxRsResource.java
new file mode 100644
index 0000000..4b9916b
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/RequestScopedJaxRsResource.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web1;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedDependentBean;
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedRequestScopedBean;
+
+/**
+ * JAX-RS resource backed by a request scoped CDI bean.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("request-scoped")
+@RequestScoped
+public class RequestScopedJaxRsResource {
+
+ @Inject
+ JaxRsInjectedDependentBean dependentBean;
+
+ @Inject
+ JaxRsInjectedRequestScopedBean reqScopedBean;
+
+ @Path("req/header")
+ @GET
+ public String getReqHeader() {
+ return reqScopedBean.getTestHeader();
+ }
+
+ @Path("dependent/header")
+ @GET
+ public String getDependentHeader() {
+ return dependentBean.getTestHeader();
+ }
+
+ @Path("req/uri/{p}")
+ @GET
+ public String getReqUri() {
+ return reqScopedBean.getUriInfo().getRequestUri().toString();
+ }
+
+ @Path("dependent/uri/{p}")
+ @GET
+ public String getAppUri() {
+ return dependentBean.getUriInfo().getRequestUri().toString();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/webapp/index.jsp b/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/webapp/index.jsp
new file mode 100644
index 0000000..d9c02e5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war1/src/main/webapp/index.jsp
@@ -0,0 +1,31 @@
+<%--
+
+ Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+--%>
+
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>JSP Page</title>
+ </head>
+ <body>
+ <h1>Hello World!</h1>
+ </body>
+</html>
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsCdiIntegrationTest.java b/tests/integration/cdi-integration/cdi-multimodule/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsCdiIntegrationTest.java
new file mode 100644
index 0000000..aa74ae4
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsCdiIntegrationTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web1;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Test for CDI web application resources. The JAX-RS resources use CDI components from a library jar.
+ *
+ * @author Jakub Podlesak
+ */
+public class JaxRsCdiIntegrationTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new JaxRsApp();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-multimodule-war1").build();
+ }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(LoggingFeature.class);
+ }
+
+ @Test
+ public void testUriInfoInjectionReqScopedResourceDependentBean() {
+ _testResource("request-scoped/dependent");
+ }
+
+ @Test
+ public void testUriInfoInjectionReqScopedResourceRequestScopedBean() {
+ _testResource("request-scoped/req");
+ }
+
+ @Test
+ public void testUriInfoInjectionAppScopedResourceRequestScopedBean() {
+ _testResource("app-scoped/req");
+ }
+
+ private void _testResource(String resourcePath) {
+ _testUriInfo(resourcePath);
+ _testHeader(resourcePath);
+ }
+
+ private void _testUriInfo(String resourcePath) {
+
+ _testSinglePathUriUnfo(resourcePath, "one");
+ _testSinglePathUriUnfo(resourcePath, "two");
+ _testSinglePathUriUnfo(resourcePath, "three");
+ }
+
+ private void _testSinglePathUriUnfo(final String resourcePath, final String pathParam) {
+
+ final URI baseUri = getBaseUri();
+ final String expectedResult = baseUri.resolve(resourcePath + "/uri/" + pathParam).toString();
+
+ final Response response = target().path(resourcePath).path("uri").path(pathParam).request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+
+ private void _testHeader(final String resourcePath) {
+
+ _testSingleHeader(resourcePath, "one");
+ _testSingleHeader(resourcePath, "two");
+ _testSingleHeader(resourcePath, "three");
+ }
+
+ private void _testSingleHeader(final String resourcePath, final String headerValue) {
+
+ final String expectedResult = headerValue;
+
+ final Response response = target().path(resourcePath).path("header").request().header("x-test", headerValue).get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war2/pom.xml b/tests/integration/cdi-integration/cdi-multimodule/war2/pom.xml
new file mode 100644
index 0000000..e65b4aa
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war2/pom.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>cdi-multimodule-war2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-cdi-multimodule-war2</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>cdi-multimodule-lib</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppOne.java b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppOne.java
new file mode 100644
index 0000000..333f83e
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppOne.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web2;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * First JAX-RS application resource configuration.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("one")
+public class JaxRsAppOne extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(SharedRequestScopedJaxRsResource.class);
+ add(SharedAppScopedJaxRsResource.class);
+ }};
+ }
+}
+
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppTwo.java b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppTwo.java
new file mode 100644
index 0000000..676416a
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppTwo.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web2;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Second JAX-RS application resource configuration.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("two")
+public class JaxRsAppTwo extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(SharedRequestScopedJaxRsResource.class);
+ add(SharedAppScopedJaxRsResource.class);
+ }};
+ }
+}
+
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedAppScopedJaxRsResource.java b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedAppScopedJaxRsResource.java
new file mode 100644
index 0000000..392ab38
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedAppScopedJaxRsResource.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web2;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedDependentBean;
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedRequestScopedBean;
+
+/**
+ * JAX-RS resource backed by an application scoped CDI bean.
+ * This one is being shared between the two JAX-RS apps
+ * {@link JaxRsAppOne} and {@link JaxRsAppTwo}.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("app-scoped")
+@ApplicationScoped
+public class SharedAppScopedJaxRsResource {
+
+ @Inject
+ JaxRsInjectedDependentBean dependentBean;
+
+ @Inject
+ JaxRsInjectedRequestScopedBean reqScopedBean;
+
+ @Path("req/header")
+ @GET
+ public String getReqHeader() {
+ return reqScopedBean.getTestHeader();
+ }
+
+ @Path("dependent/header")
+ @GET
+ public String getDependentHeader() {
+ return dependentBean.getTestHeader();
+ }
+
+ @Path("req/uri/{p}")
+ @GET
+ public String getReqUri() {
+ return reqScopedBean.getUriInfo().getRequestUri().toString();
+ }
+
+ @Path("dependent/uri/{p}")
+ @GET
+ public String getAppUri() {
+ return dependentBean.getUriInfo().getRequestUri().toString();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedRequestScopedJaxRsResource.java b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedRequestScopedJaxRsResource.java
new file mode 100644
index 0000000..4e5f686
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedRequestScopedJaxRsResource.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web2;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedDependentBean;
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedRequestScopedBean;
+
+/**
+ * JAX-RS resource backed by a request scoped CDI bean.
+ * This one is being shared between the two JAX-RS apps
+ * {@link JaxRsAppOne} and {@link JaxRsAppTwo}.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("request-scoped")
+@RequestScoped
+public class SharedRequestScopedJaxRsResource {
+
+ @Inject
+ JaxRsInjectedDependentBean dependentBean;
+
+ @Inject
+ JaxRsInjectedRequestScopedBean reqScopedBean;
+
+ @Path("req/header")
+ @GET
+ public String getReqHeader() {
+ return reqScopedBean.getTestHeader();
+ }
+
+ @Path("dependent/header")
+ @GET
+ public String getDependentHeader() {
+ return dependentBean.getTestHeader();
+ }
+
+ @Path("req/uri/{p}")
+ @GET
+ public String getReqUri() {
+ return reqScopedBean.getUriInfo().getRequestUri().toString();
+ }
+
+ @Path("dependent/uri/{p}")
+ @GET
+ public String getAppUri() {
+ return dependentBean.getUriInfo().getRequestUri().toString();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/webapp/index.jsp b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/webapp/index.jsp
new file mode 100644
index 0000000..d9c02e5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war2/src/main/webapp/index.jsp
@@ -0,0 +1,31 @@
+<%--
+
+ Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+--%>
+
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>JSP Page</title>
+ </head>
+ <body>
+ <h1>Hello World!</h1>
+ </body>
+</html>
diff --git a/tests/integration/cdi-integration/cdi-multimodule/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsCdiIntegrationTest.java b/tests/integration/cdi-integration/cdi-multimodule/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsCdiIntegrationTest.java
new file mode 100644
index 0000000..b6c4f0c
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multimodule/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsCdiIntegrationTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.multimodule.cdi.web2;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Test for CDI web application resources. The JAX-RS resources use CDI components from a library jar.
+ *
+ * @author Jakub Podlesak
+ */
+public class JaxRsCdiIntegrationTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new JaxRsAppOne();
+ }
+
+// @Override
+// protected URI getBaseUri() {
+// return UriBuilder.fromUri(super.getBaseUri()).path("cdi-multimodule-war1").build();
+// }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(LoggingFeature.class);
+ }
+
+ @Test
+ public void testUriInfoInjectionReqScopedResourceDependentBean() {
+
+ _testResource("cdi-multimodule-war2/one/request-scoped/dependent");
+ _testResource("cdi-multimodule-war2/two/request-scoped/dependent");
+ }
+
+ @Test
+ public void testUriInfoInjectionReqScopedResourceRequestScopedBean() {
+
+ _testResource("cdi-multimodule-war2/one/request-scoped/req");
+ _testResource("cdi-multimodule-war2/two/request-scoped/req");
+ }
+
+ @Test
+ public void testUriInfoInjectionAppScopedResourceRequestScopedBean() {
+
+ _testResource("cdi-multimodule-war2/one/app-scoped/req");
+ _testResource("cdi-multimodule-war2/two/app-scoped/req");
+ }
+
+ @Ignore("until JERSEY-2914 gets resolved")
+ @Test
+ public void testUriInfoInjectionAppScopedResourceDependentBean() {
+
+ _testResource("cdi-multimodule-war2/one/app-scoped/dependent");
+ _testResource("cdi-multimodule-war2/two/app-scoped/dependent");
+ }
+
+ private void _testResource(String resourcePath) {
+ _testUriInfo(resourcePath);
+ _testHeader(resourcePath);
+ }
+
+ private void _testUriInfo(String resourcePath) {
+
+ _testSinglePathUriUnfo(resourcePath, "one");
+ _testSinglePathUriUnfo(resourcePath, "two");
+ _testSinglePathUriUnfo(resourcePath, "three");
+ }
+
+ private void _testSinglePathUriUnfo(final String resourcePath, final String pathParam) {
+
+ final URI baseUri = getBaseUri();
+ final String expectedResult = baseUri.resolve(resourcePath + "/uri/" + pathParam).toString();
+
+ final Response response = target().path(resourcePath).path("uri").path(pathParam).request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+
+ private void _testHeader(final String resourcePath) {
+
+ _testSingleHeader(resourcePath, "one");
+ _testSingleHeader(resourcePath, "two");
+ _testSingleHeader(resourcePath, "three");
+ }
+
+ private void _testSingleHeader(final String resourcePath, final String headerValue) {
+
+ final String expectedResult = headerValue;
+
+ final Response response = target().path(resourcePath).path("header").request().header("x-test", headerValue).get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multipart-webapp/pom.xml b/tests/integration/cdi-integration/cdi-multipart-webapp/pom.xml
new file mode 100644
index 0000000..84d0166
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multipart-webapp/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-multipart-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-multipart-webapp</name>
+
+ <description>Jersey CDI test web application that uses multipart feature</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java b/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
new file mode 100644
index 0000000..c0331ba
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+
+
+/**
+ * GF-21033 reproducer. Just a resource using multi-part support.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("/echo")
+@RequestScoped
+public class EchoResource {
+
+ /**
+ * We want to consume form data using multi-part provider.
+ *
+ * @param input form data
+ * @return input data
+ */
+ @POST
+ public Response echoMultipart(@FormDataParam ("input") String input) {
+ return Response.ok(input).build();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..22a752f
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+
+/**
+ * GF-21033 reproducer. This is to make sure Jersey's multipart
+ * feature could work in GF with CDI.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/*")
+public class MyApplication extends Application {
+
+ static final Set<Class<?>> classes = new HashSet<Class<?>>();
+
+ static {
+ classes.add(EchoResource.class);
+ classes.add(MultiPartFeature.class);
+ }
+ @Override
+ public Set<Class<?>> getClasses() {
+ return classes;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..aaf0547
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multipart-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-multipart-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MultipartFeatureTest.java b/tests/integration/cdi-integration/cdi-multipart-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MultipartFeatureTest.java
new file mode 100644
index 0000000..c5c9250
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-multipart-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MultipartFeatureTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Part of GF-21033 reproducer. Make sure form data processed by the Jersey multi-part
+ * feature make it forth and back all right.
+ *
+ * <p/>Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class MultipartFeatureTest extends JerseyTest {
+
+ final String TestFormDATA;
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"No matter what"},
+ {"You should never"},
+ {"ever"},
+ {"just give up"}
+ });
+ }
+
+ public MultipartFeatureTest(String TestFormDATA) {
+ this.TestFormDATA = TestFormDATA;
+ }
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-multipart-webapp").build();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ config.register(MultiPartFeature.class);
+ }
+
+ @Test
+ public void testPostFormData() {
+
+ final WebTarget target = target().path("echo");
+
+ FormDataMultiPart formData = new FormDataMultiPart().field("input", TestFormDATA);
+
+ final Response response = target.request().post(Entity.entity(formData, MediaType.MULTIPART_FORM_DATA_TYPE));
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is(TestFormDATA));
+ }
+}
+
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/pom.xml b/tests/integration/cdi-integration/cdi-test-webapp/pom.xml
new file mode 100644
index 0000000..7d09709
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/pom.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-test-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-webapp</name>
+
+ <description>Jersey CDI test web application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-weld2-se</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>run-external-tests</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${external.container.factory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${external.container.port}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- External test container configuration is done via properties to allow overriding via command line. -->
+ <external.container.factory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</external.container.factory>
+ <external.container.port>8080</external.container.port>
+ <maven.test.skip>false</maven.test.skip>
+ </properties>
+ </profile>
+ </profiles>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectedResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectedResource.java
new file mode 100644
index 0000000..59dd46c
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectedResource.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.MatrixParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+/**
+ * JERSEY-2526 reproducer. CDI managed JAX-RS root resource
+ * that is constructor injected with JAX-RS parameters provided by Jersey
+ * and a single String parameter coming from application provided CDI producer,
+ * {@link CustomCdiProducer}.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("ctor-injected/{p}")
+@RequestScoped
+public class ConstructorInjectedResource {
+
+ String pathParam;
+ String queryParam;
+ String matrixParam;
+ String headerParam;
+ String cdiParam;
+
+ /**
+ * WLS requires this.
+ */
+ public ConstructorInjectedResource() {
+ }
+
+ /**
+ * This will get CDI injected with JAX-RS provided parameters.
+ *
+ * @param pathParam path parameter from the actual request.
+ * @param queryParam query parameter q from the actual request.
+ * @param matrixParam matrix parameter m from the actual request.
+ * @param headerParam Accept header parameter from the actual request.
+ * @param cdiParam custom CDI produced string.
+ */
+ @Inject
+ public ConstructorInjectedResource(
+ @PathParam("p") String pathParam,
+ @QueryParam("q") String queryParam,
+ @MatrixParam("m") String matrixParam,
+ @HeaderParam("Custom-Header") String headerParam,
+ @CustomCdiProducer.Qualifier String cdiParam) {
+
+ this.pathParam = pathParam;
+ this.queryParam = queryParam;
+ this.matrixParam = matrixParam;
+ this.headerParam = headerParam;
+ this.cdiParam = cdiParam;
+ }
+
+ /**
+ * Provide string representation of a single injected parameter
+ * given by the actual path parameter (that is also injected).
+ *
+ * @return a single parameter value.
+ */
+ @GET
+ public String getParameter() {
+
+ switch (pathParam) {
+
+ case "pathParam": return pathParam;
+ case "queryParam": return queryParam;
+ case "matrixParam": return matrixParam;
+ case "headerParam": return headerParam;
+ case "cdiParam": return cdiParam;
+
+ default: throw new WebApplicationException(Response.Status.BAD_REQUEST);
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CounterResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CounterResource.java
new file mode 100644
index 0000000..06239ff
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CounterResource.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * Part of JERSEY-2461 reproducer. This one will get injected with a CDI extension.
+ * HK2 should not mess up with this.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("counter")
+public class CounterResource {
+
+ final CustomExtension e;
+
+ /**
+ * To make CDI happy... namely to make the bean proxy-able.
+ */
+ public CounterResource() {
+ this.e = null;
+ }
+
+ /**
+ * This one will get used at runtime actually.
+ *
+ * @param extension current application CDI custom extension.
+ */
+ @Inject
+ public CounterResource(CustomExtension extension) {
+ this.e = extension;
+ }
+
+ /**
+ * Return custom extension counter state.
+ *
+ * @return next count.
+ */
+ @GET
+ public int getCount() {
+ return e.getCount();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomCdiProducer.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomCdiProducer.java
new file mode 100644
index 0000000..79edb6a
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomCdiProducer.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.Produces;
+
+/**
+ * CDI producer to help us make sure HK2 do not mess up with
+ * types backed by CDI producers.
+ *
+ * @author Jakub Podlesak
+ */
+public class CustomCdiProducer {
+
+ /**
+ * Custom qualifier to work around https://java.net/jira/browse/GLASSFISH-20285
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
+ @javax.inject.Qualifier
+ public static @interface Qualifier {
+ }
+
+ /**
+ * To cover field producer.
+ */
+ @Produces
+ public static FieldProducedBean<String> field = new FieldProducedBean<>("field");
+
+ /**
+ * To cover method producer.
+ *
+ * @return bean instance to inject
+ */
+ @Produces
+ public MethodProducedBean<String> produceBean() {
+ return new MethodProducedBean<>("method");
+ }
+
+ /**
+ * Part of JERSEY-2526 reproducer. This one is used
+ * to inject constructor of {@link ConstructorInjectedResource}.
+ *
+ * @return fixed string value.
+ */
+ @Produces
+ @Qualifier
+ public String produceString() {
+ return "cdi-produced";
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomExtension.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomExtension.java
new file mode 100644
index 0000000..7bf09f2
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomExtension.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.enterprise.inject.spi.Extension;
+
+/**
+ * Part of JERSEY-2461 reproducer. We need an extension that we could inject,
+ * to make sure HK2 custom binding does not attempt to mess up.
+ *
+ * @author Jakub Podlesak
+ */
+public class CustomExtension implements Extension {
+
+ private AtomicInteger counter = new AtomicInteger();
+
+ /**
+ * A made up functionality. Does not really matter. CDI
+ * would refuse to deploy the application if something went wrong.
+ *
+ * @return next count.
+ */
+ public int getCount() {
+ return counter.incrementAndGet();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
new file mode 100644
index 0000000..1f0ceca
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.inject.Qualifier;
+
+/**
+ * Simple echo service to test injections using {@link Qualifier}.
+ *
+ * @author Jakub Podlesak
+ */
+public interface EchoService {
+
+ /**
+ * Provide an echoed response.
+ *
+ * @param s String to be echoed.
+ * @return echoed input.
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FieldProducedBean.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FieldProducedBean.java
new file mode 100644
index 0000000..db9b00b
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FieldProducedBean.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.inject.Vetoed;
+
+/**
+ * A bean that would be produced by a CDI producer field.
+ * This is to make sure we do not mess up with CDI producers with HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@Vetoed
+public class FieldProducedBean<T> implements ValueHolder<T> {
+
+ private final T value;
+
+ /**
+ * Make an instance with given value.
+ *
+ * @param value
+ */
+ public FieldProducedBean(T value) {
+ this.value = value;
+ }
+
+ @Override
+ public T getValue() {
+ return value;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FirstNonJaxRsBeanInjectedResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FirstNonJaxRsBeanInjectedResource.java
new file mode 100644
index 0000000..50b0856
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FirstNonJaxRsBeanInjectedResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * JAX-RS resource that gets injected with a CDI managed bean,
+ * that includes JAX-RS injection points. The very same bean
+ * gets injected also to {@link FirstNonJaxRsBeanInjectedResource}.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("non-jaxrs-bean-injected")
+@RequestScoped
+public class FirstNonJaxRsBeanInjectedResource {
+
+ @Inject
+ JaxRsInjectedBean bean;
+
+ @GET
+ @Path("path/1")
+ public String getPath() {
+ return bean.getUriInfo().getPath();
+ }
+
+ @GET
+ @Path("header/1")
+ public String getAcceptHeader() {
+ return bean.getTestHeader();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentExceptionMapper.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentExceptionMapper.java
new file mode 100644
index 0000000..e6d1ee6
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentExceptionMapper.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import javax.annotation.ManagedBean;
+import javax.annotation.PostConstruct;
+
+/**
+ * JAX-RS exception mapper registered as a CDI managed bean.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak
+ */
+@Provider
+@ManagedBean
+public class JCDIBeanDependentExceptionMapper implements ExceptionMapper<JDCIBeanDependentException> {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanDependentExceptionMapper.class.getName());
+
+ @Context
+ private UriInfo uiFieldInject;
+
+ @Context
+ private ResourceContext resourceContext;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ LOGGER.log(Level.INFO, String.format("In post construct of %s", this));
+ ensureInjected();
+ }
+
+ @Override
+ public Response toResponse(JDCIBeanDependentException exception) {
+ ensureInjected();
+ return Response.serverError().entity("JDCIBeanDependentException").build();
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldInject == null || uiMethodInject == null || resourceContext == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentPerRequestResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentPerRequestResource.java
new file mode 100644
index 0000000..9626616
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentPerRequestResource.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import javax.annotation.ManagedBean;
+import javax.annotation.Resource;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.RequestScoped;
+
+
+/**
+ * Request scoped JAX-RS resource registered as a CDI managed bean.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak
+ */
+@Path("/jcdibean/dependent/per-request")
+@ManagedBean
+@RequestScoped
+public class JCDIBeanDependentPerRequestResource {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanDependentPerRequestResource.class.getName());
+
+ @Resource(name = "injectedResource")
+ private int injectedResource = 0;
+
+ @Context
+ private UriInfo uiFieldInject;
+
+ @Context
+ private ResourceContext rc;
+
+ @QueryParam("x")
+ private String x;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+
+ ensureInjected();
+
+ LOGGER.info(String.format(
+ "In post construct of %s; uiFieldInject: %s; uiMethodInject: %s",
+ this, uiFieldInject, uiMethodInject));
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getMessage() {
+
+ ensureInjected();
+
+ LOGGER.info(String.format(
+ "In getMessage of %s; uiFieldInject: %s; uiMethodInject: %s",
+ this, uiFieldInject, uiMethodInject));
+
+ return String.format("%s: queryParam=%s %d", uiFieldInject.getRequestUri().toString(), x, injectedResource++);
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("In pre destroy of %s", this));
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldInject == null || uiMethodInject == null || rc == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentResource.java
new file mode 100644
index 0000000..7547cc5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentResource.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Test case for JERSEY-1747.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("/jcdibean/dependent/timer")
+public class JCDIBeanDependentResource {
+
+ @Inject
+ JCDIBeanRequestScopedTimer timer;
+
+ @GET
+ @Produces("text/plain")
+ public String getValue() {
+ return Long.toString(timer.getMiliseconds());
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentSingletonResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentSingletonResource.java
new file mode 100644
index 0000000..d7e9bb0
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentSingletonResource.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import javax.annotation.ManagedBean;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Application scoped JAX-RS resource registered as CDI managed bean.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak
+ */
+@Path("/jcdibean/dependent/singleton/{p}")
+@ApplicationScoped
+@ManagedBean
+public class JCDIBeanDependentSingletonResource {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanDependentSingletonResource.class.getName());
+
+ @Resource(name = "injectedResource")
+ private int counter = 0;
+
+ @Context
+ private UriInfo uiFieldinject;
+
+ @Context
+ private ResourceContext resourceContext;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ LOGGER.info(String.format("In post construct of %s", this));
+ ensureInjected();
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getMessage(@PathParam("p") String p) {
+ LOGGER.info(String.format(
+ "In getMessage in %s; uiFieldInject: %s; uiMethodInject: %s", this, uiFieldinject, uiMethodInject));
+ ensureInjected();
+
+ return String.format("%s: p=%s, queryParam=%s",
+ uiFieldinject.getRequestUri().toString(), p, uiMethodInject.getQueryParameters().getFirst("x"));
+ }
+
+ @Path("exception")
+ public String getException() {
+ throw new JDCIBeanDependentException();
+ }
+
+ @Path("counter")
+ @GET
+ public synchronized String getCounter() {
+ return Integer.toString(counter++);
+ }
+
+ @Path("counter")
+ @PUT
+ public synchronized void setCounter(String counter) {
+ this.counter = Integer.decode(counter);
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("In pre destroy of %s", this));
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldinject == null || uiMethodInject == null || resourceContext == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanExceptionMapper.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanExceptionMapper.java
new file mode 100644
index 0000000..d6a06ed
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanExceptionMapper.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * JAX-RS exception mapper registered as CDI managed bean.
+ *
+ * @author Paul Sandoz
+ */
+@Provider
+@ApplicationScoped
+public class JCDIBeanExceptionMapper implements ExceptionMapper<JDCIBeanException> {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanExceptionMapper.class.getName());
+
+ @Context
+ private UriInfo uiFieldInject;
+
+ @Context
+ private ResourceContext rc;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ ensureInjected();
+ LOGGER.info(String.format("In post construct of %s", this));
+ }
+
+ @Override
+ public Response toResponse(JDCIBeanException exception) {
+ ensureInjected();
+ return Response.serverError().entity("JDCIBeanException").build();
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldInject == null || uiMethodInject == null || rc == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanPerRequestResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanPerRequestResource.java
new file mode 100644
index 0000000..38a6054
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanPerRequestResource.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * Request scoped JAX-RS resource registered.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak
+ */
+@Path("/jcdibean/per-request")
+@RequestScoped
+public class JCDIBeanPerRequestResource {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanPerRequestResource.class.getName());
+
+ @Resource(name = "injectedResource")
+ private int injectedResource = 0;
+
+ @Context
+ private UriInfo uiFieldInject;
+
+ @Context
+ private ResourceContext rc;
+
+ @QueryParam("x")
+ private String x;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+
+ ensureInjected();
+
+ LOGGER.info(String.format(
+ "In post construct of %s; uiFieldInject: %s; uiMethodInject: %s",
+ this, uiFieldInject, uiMethodInject));
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getMessage() {
+
+ ensureInjected();
+
+ LOGGER.info(String.format(
+ "In getMessage of %s; uiFieldInject: %s; uiMethodInject: %s",
+ this, uiFieldInject, uiMethodInject));
+
+ return String.format("%s: queryParam=%s %d", uiFieldInject.getRequestUri().toString(), x, injectedResource++);
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("In pre destroy of %s", this));
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldInject == null || uiMethodInject == null || rc == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanRequestScopedTimer.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanRequestScopedTimer.java
new file mode 100644
index 0000000..9b8a21d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanRequestScopedTimer.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * Request scoped CDI bean to be injected into {@link JCDIBeanDependentResource}.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+public class JCDIBeanRequestScopedTimer {
+
+ private long ms;
+
+ /**
+ * Provide information on actual request time.
+ *
+ * @return milliseconds when the current bean was post-constructed.
+ */
+ public long getMiliseconds() {
+ return ms;
+ }
+
+ @PostConstruct
+ public void init() {
+ this.ms = System.currentTimeMillis();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanSingletonResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanSingletonResource.java
new file mode 100644
index 0000000..27cd7c4
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanSingletonResource.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+/**
+ * Application scoped JAX-RS resource.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak
+ */
+@Path("/jcdibean/singleton/{p}")
+@ApplicationScoped
+public class JCDIBeanSingletonResource {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanSingletonResource.class.getName());
+
+ @Resource(name = "injectedResource")
+ private int counter = 0;
+
+ @Context
+ private UriInfo uiFieldinject;
+
+ @Context
+ private
+ ResourceContext resourceContext;
+
+ private UriInfo uiMethodInject;
+
+ @Inject
+ Provider<JCDIBeanExceptionMapper> mapperProvider;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ LOGGER.info(String.format("In post construct of %s", this));
+ ensureInjected();
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getMessage(@PathParam("p") String p) {
+ LOGGER.info(String.format(
+ "In getMessage in %s; uiFieldInject: %s; uiMethodInject: %s; provider: %s; provider.get(): %s", this,
+ uiFieldinject, uiMethodInject, mapperProvider, mapperProvider.get()));
+ ensureInjected();
+
+ return String.format("%s: p=%s, queryParam=%s",
+ uiFieldinject.getRequestUri().toString(), p, uiMethodInject.getQueryParameters().getFirst("x"));
+ }
+
+ @Path("exception")
+ public String getException() {
+ throw new JDCIBeanException();
+ }
+
+ @Path("counter")
+ @GET
+ public synchronized String getCounter() {
+ return Integer.toString(counter++);
+ }
+
+ @Path("counter")
+ @PUT
+ public synchronized void setCounter(String counter) {
+ this.counter = Integer.decode(counter);
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("In pre destroy of %s", this));
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldinject == null || uiMethodInject == null
+ || resourceContext == null || mapperProvider.get() == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanDependentException.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanDependentException.java
new file mode 100644
index 0000000..73e837a
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanDependentException.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Exception to be treated by {@link JCDIBeanDependentExceptionMapper}.
+ *
+ * @author Paul Sandoz
+ */
+public class JDCIBeanDependentException extends RuntimeException {
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanException.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanException.java
new file mode 100644
index 0000000..2b80a0c
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanException.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Exception to be treated by {@link JCDIBeanExceptionMapper}.
+ *
+ * @author Paul Sandoz
+ */
+public class JDCIBeanException extends RuntimeException {
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedBean.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedBean.java
new file mode 100644
index 0000000..fd7a884
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedBean.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * This is to be JAX-RS injected at runtime.
+ * The bean is fully CDI managed, contains JAX-RS injection points and is getting injected into JAX-RS
+ * resources included in two distinct JAX-RS applications running in parallel.
+ */
+@RequestScoped
+public class JaxRsInjectedBean {
+
+ @HeaderParam("x-test")
+ String testHeader;
+
+ @Context
+ UriInfo uriInfo;
+
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ public String getTestHeader() {
+ return testHeader;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java
new file mode 100644
index 0000000..aa38055
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+
+import javax.inject.Inject;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jonathan Benoit
+ * @author Patrik Dudits
+ */
+@ApplicationPath("main")
+@ApplicationScoped
+public class MainApplication extends Application {
+
+ static AtomicInteger postConstructCounter = new AtomicInteger();
+
+ @Inject BeanManager bm;
+
+ private static final Logger LOGGER = Logger.getLogger(MainApplication.class.getName());
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(JCDIBeanDependentResource.class);
+ classes.add(JDCIBeanException.class);
+ classes.add(JDCIBeanDependentException.class);
+ classes.add(JCDIBeanSingletonResource.class);
+ classes.add(JCDIBeanPerRequestResource.class);
+ classes.add(JCDIBeanExceptionMapper.class);
+ classes.add(JCDIBeanDependentSingletonResource.class);
+ classes.add(JCDIBeanDependentPerRequestResource.class);
+ classes.add(JCDIBeanDependentExceptionMapper.class);
+ classes.add(StutteringEchoResource.class);
+ classes.add(StutteringEcho.class);
+ classes.add(ReversingEchoResource.class);
+ classes.add(CounterResource.class);
+ classes.add(ConstructorInjectedResource.class);
+ classes.add(ProducerResource.class);
+ classes.add(FirstNonJaxRsBeanInjectedResource.class);
+ classes.add(ResponseFilter.class);
+ return classes;
+ }
+
+ // JERSEY-2531: make sure this type gets managed by CDI
+ @PostConstruct
+ public void postConstruct() {
+ LOGGER.info(String.format("%s: POST CONSTRUCT.", this.getClass().getName()));
+ postConstructCounter.incrementAndGet();
+ if (bm == null) {
+ throw new IllegalStateException("BeanManager should have been injected into a CDI managed bean.");
+ }
+ if (postConstructCounter.intValue() > 1) {
+ throw new IllegalStateException("postConstruct should have been invoked only once on app scoped bean.");
+ }
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("%s: PRE DESTROY.", this.getClass().getName()));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MethodProducedBean.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MethodProducedBean.java
new file mode 100644
index 0000000..1ad53e7
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MethodProducedBean.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.inject.Vetoed;
+
+/**
+ * A bean that would be produced by a CDI producer method.
+ * This is to make sure we do not mess up with CDI producers with HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@Vetoed
+public class MethodProducedBean<T> implements ValueHolder<T> {
+
+ private final T value;
+
+ /**
+ * Make an instance with given value.
+ *
+ * @param value
+ */
+ public MethodProducedBean(T value) {
+ this.value = value;
+ }
+
+ /**
+ * Value getter.
+ *
+ * @return value.
+ */
+ @Override
+ public T getValue() {
+ return value;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ProducerResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ProducerResource.java
new file mode 100644
index 0000000..9482e50
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ProducerResource.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * This one will get injected with a CDI producer.
+ * HK2 should not mess up with this.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("producer")
+public class ProducerResource {
+
+ @Inject
+ MethodProducedBean<String> m;
+
+ @Inject
+ FieldProducedBean<String> f;
+
+ /**
+ * Return field produced bean value.
+ *
+ * @return value from field produced bean.
+ */
+ @Path("f")
+ @GET
+ public String getFieldValue() {
+ return f.getValue();
+ }
+
+ /**
+ * Return method produced bean value.
+ *
+ * @return value from method produced bean.
+ */
+ @Path("m")
+ @GET
+ public String getMethodValue() {
+ return m.getValue();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ResponseFilter.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ResponseFilter.java
new file mode 100644
index 0000000..6acfd36
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ResponseFilter.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import java.io.IOException;
+import java.util.UUID;
+
+/**
+ * CDI Managed response filter that should add single HTTP header.
+ * @author Patrik Dudits
+ */
+public class ResponseFilter implements ContainerResponseFilter {
+
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
+ responseContext.getHeaders().add("Filter-Invoked", UUID.randomUUID().toString());
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReverseEcho.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReverseEcho.java
new file mode 100644
index 0000000..b8bee4b
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReverseEcho.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Echo implementation to reverse given input.
+ *
+ * @author Jakub Podlesak
+ */
+@Reversing
+public class ReverseEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return reverseString(s);
+ }
+
+ private String reverseString(final String s) {
+ final int len = s.length();
+
+ char[] chars = new char[len];
+ for (int i = 0; i < len; i++) {
+ chars[i] = s.charAt(len - i - 1);
+ }
+ return new String(chars);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Reversing.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Reversing.java
new file mode 100644
index 0000000..9ffe455
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Reversing.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for reversing echo service.
+ *
+ * @author Jakub Podlesak
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface Reversing {
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReversingEchoResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReversingEchoResource.java
new file mode 100644
index 0000000..cac4c3c
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReversingEchoResource.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+/**
+ * CDI backed JAX-RS resource to reverse input query parameter using
+ * qualified injection to get a CDI backed service provider.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("reverse")
+public class ReversingEchoResource {
+
+ @Inject @Reversing EchoService echoService;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondNonJaxRsBeanInjectedResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondNonJaxRsBeanInjectedResource.java
new file mode 100644
index 0000000..892307e
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondNonJaxRsBeanInjectedResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * JAX-RS resource that gets injected with a CDI managed bean,
+ * that includes JAX-RS injection points. The very same bean
+ * gets injected also to {@link FirstNonJaxRsBeanInjectedResource}.
+ *
+ * @author Jakub Podlesak
+ */
+@Path("non-jaxrs-bean-injected")
+@RequestScoped
+public class SecondNonJaxRsBeanInjectedResource {
+
+ @Inject
+ JaxRsInjectedBean bean;
+
+ @GET
+ @Path("path/2")
+ public String getPath() {
+ return bean.getUriInfo().getPath();
+ }
+
+ @GET
+ @Path("header/2")
+ public String getAcceptHeader() {
+ return bean.getTestHeader();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondaryApplication.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondaryApplication.java
new file mode 100644
index 0000000..5b0d909
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondaryApplication.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Secondary JAX-RS application to configure resources.
+ * This one is to make sure two Jersey apps could co-exist
+ * in CDI managed environment and JAX-RS injection keeps
+ * functioning as expected.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("secondary")
+@ApplicationScoped
+public class SecondaryApplication extends Application {
+
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(SecondNonJaxRsBeanInjectedResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Stuttering.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Stuttering.java
new file mode 100644
index 0000000..90d5b5a
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Stuttering.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for stuttering echo service.
+ *
+ * @author Jakub Podlesak
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface Stuttering {
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEcho.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEcho.java
new file mode 100644
index 0000000..448132e
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEcho.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Echo implementation to stutter given input n-times.
+ * The stutter factor could be set via JAX-RS interface.
+ *
+ * @author Jakub Podlesak
+ */
+@Stuttering
+@ApplicationScoped
+@Path("stutter-service-factor")
+public class StutteringEcho implements EchoService {
+
+ private static final int MIN_FACTOR = 2;
+ private int factor = MIN_FACTOR;
+
+ @Override
+ public String echo(String s) {
+ StringBuilder result = new StringBuilder();
+ for (int i = 0; i < factor; i++) {
+ result.append(s);
+ }
+ return result.toString();
+ }
+
+ @PUT
+ public void setFactor(String factor) {
+ this.factor = ensureValidInput(factor);
+ }
+
+ @GET
+ public String getFactor() {
+ return Integer.toString(factor);
+ }
+
+ private int ensureValidInput(String factor) throws WebApplicationException {
+ try {
+ final int newValue = Integer.parseInt(factor);
+ if (newValue < MIN_FACTOR) {
+ throw createWebAppException(String.format("New factor can not be lesser then %d!", MIN_FACTOR));
+ }
+ return newValue;
+ } catch (NumberFormatException nfe) {
+ throw createWebAppException(String.format("Error parsing %s as an integer!", factor));
+ }
+ }
+
+ private WebApplicationException createWebAppException(String message) {
+
+ return new WebApplicationException(
+
+ Response.status(Response.Status.BAD_REQUEST)
+ .type(MediaType.TEXT_PLAIN)
+ .entity(Entity.text(message)).build());
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEchoResource.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEchoResource.java
new file mode 100644
index 0000000..1a140ed
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEchoResource.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * CDI backed JAX-RS resource to stutter input query parameter.
+ * Uses qualified injection to get a CDI backed service provider.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationScoped
+@Path("stutter")
+public class StutteringEchoResource {
+
+ @Inject @Stuttering EchoService echoService;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ValueHolder.java b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ValueHolder.java
new file mode 100644
index 0000000..05cee03
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ValueHolder.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Helper type to check CDI producer mechanism is not broken
+ * by automatic HK2/CDI bindings.
+ *
+ * @author Jakub Podlesak
+ */
+public interface ValueHolder<T> {
+
+ /**
+ * Value getter.
+ *
+ * @return value.
+ */
+ T getValue();
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/resources/META-INF/beans.xml b/tests/integration/cdi-integration/cdi-test-webapp/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/tests/integration/cdi-integration/cdi-test-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..7331615
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.resources.CustomExtension
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-integration/cdi-test-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-integration/cdi-test-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff67ca5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <env-entry>
+ <env-entry-name>injectedResource</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+</web-app>
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..067e2af
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.jboss.weld.environment.se.Weld;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak
+ */
+public class CdiTest extends JerseyTest {
+
+ Weld weld;
+
+ @Override
+ public void setUp() throws Exception {
+ weld = new Weld();
+ weld.initialize();
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ weld.shutdown();
+ super.tearDown();
+ }
+
+ @Override
+ protected Application configure() {
+ return new MainApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-test-webapp/main").build();
+ }
+}
+
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectionTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectionTest.java
new file mode 100644
index 0000000..0263084
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import org.junit.Test;
+
+/**
+ * Part of JERSEY-2526 reproducer. Without the fix, the application would
+ * not deploy at all. This is just to make sure the JAX-RS parameter producer
+ * keeps working as expected without regressions.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oralc.com)
+ */
+public class ConstructorInjectionTest extends CdiTest {
+
+ @Test
+ public void testConstructorInjectedResource() {
+
+ final WebTarget target = target().path("ctor-injected");
+
+ final Response pathParamResponse = target.path("pathParam").request().get();
+ assertThat(pathParamResponse.getStatus(), is(200));
+ assertThat(pathParamResponse.readEntity(String.class), is("pathParam"));
+
+ final Response queryParamResponse = target.path("queryParam").queryParam("q", "123").request().get();
+ assertThat(queryParamResponse.getStatus(), is(200));
+ assertThat(queryParamResponse.readEntity(String.class), is("123"));
+
+ final Response matrixParamResponse = target.path("matrixParam").matrixParam("m", "456").request().get();
+ assertThat(matrixParamResponse.getStatus(), is(200));
+ assertThat(matrixParamResponse.readEntity(String.class), is("456"));
+
+ final Response headerParamResponse = target.path("headerParam").request().header("Custom-Header", "789").get();
+ assertThat(headerParamResponse.getStatus(), is(200));
+ assertThat(headerParamResponse.readEntity(String.class), is("789"));
+
+ final Response cdiParamResponse = target.path("cdiParam").request().get();
+ assertThat(cdiParamResponse.getStatus(), is(200));
+ assertThat(cdiParamResponse.readEntity(String.class), is("cdi-produced"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CounterTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CounterTest.java
new file mode 100644
index 0000000..0d7e76d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CounterTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Part of JERSEY-2641 reproducer. Accessing CDI bean that has custom CDI
+ * extension injected.
+ *
+ * @author Jakub Podlesak
+ */
+public class CounterTest extends CdiTest {
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("counter");
+
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), is(200));
+ int firstNumber = Integer.decode(firstResponse.readEntity(String.class));
+
+ final Response secondResponse = target.request().get();
+ assertThat(secondResponse.getStatus(), is(200));
+ int secondNumber = Integer.decode(secondResponse.readEntity(String.class));
+
+ assertTrue("Second request should have greater number!", secondNumber > firstNumber);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedCdiBeanTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedCdiBeanTest.java
new file mode 100644
index 0000000..64630ee
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedCdiBeanTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test that a raw CDI managed bean gets JAX-RS injected.
+ *
+ * @author Jakub Podlesak
+ */
+public class JaxRsInjectedCdiBeanTest extends CdiTest {
+
+ @Test
+ public void testPathAndHeader() {
+ _testPathAndHeader(target());
+ }
+
+ public static void _testPathAndHeader(final WebTarget webTarget) {
+ final WebTarget target = webTarget.path("non-jaxrs-bean-injected");
+
+ final Response pathResponse = target.path("path/1").request().get();
+ assertThat(pathResponse.getStatus(), is(200));
+ final String path = pathResponse.readEntity(String.class);
+
+ assertThat(path, is("non-jaxrs-bean-injected/path/1"));
+
+ final Response headerResponse = target.path("header/1").request().header("x-test", "bummer").get();
+ assertThat(headerResponse.getStatus(), is(200));
+ final String header = headerResponse.readEntity(String.class);
+
+ assertThat(header, is("bummer"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/NonJaxRsBeanJaxRsInjectionTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/NonJaxRsBeanJaxRsInjectionTest.java
new file mode 100644
index 0000000..a955785
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/NonJaxRsBeanJaxRsInjectionTest.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Properties;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainerProvider;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.TestProperties;
+
+import org.glassfish.grizzly.http.server.HttpHandler;
+import org.glassfish.grizzly.http.server.HttpServer;
+
+import org.hamcrest.CoreMatchers;
+import org.jboss.weld.environment.se.Weld;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test two Jersey apps running simultaneously within a single Grizzly HTTP server
+ * to make sure two injection managers do not interfere. The test is not executed
+ * if other than the default (Grizzly) test container has been set.
+ * For Servlet based container testing, the other two tests, {@link JaxRsInjectedCdiBeanTest}
+ * and {@link SecondJaxRsInjectedCdiBeanTest},
+ * do the same job, because the WAR application contains both Jersey apps already.
+ *
+ * @author Jakub Podlesak
+ */
+public class NonJaxRsBeanJaxRsInjectionTest {
+
+ public static final String MAIN_URI = "/main";
+ public static final String SECONDARY_URI = "/secondary";
+
+ public static final String PORT_NUMBER = getSystemProperty(TestProperties.CONTAINER_PORT,
+ Integer.toString(TestProperties.DEFAULT_CONTAINER_PORT));
+
+ private static final URI MAIN_APP_URI = URI.create("http://localhost:" + PORT_NUMBER + MAIN_URI);
+ private static final URI SECONDARY_APP_URI = URI.create("http://localhost:" + PORT_NUMBER + SECONDARY_URI);
+
+ private static final boolean isDefaultTestContainerFactorySet = isDefaultTestContainerFactorySet();
+
+ Weld weld;
+ HttpServer httpServer;
+
+ Client client;
+ WebTarget mainTarget, secondaryTarget;
+
+ @Before
+ public void before() throws IOException {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+
+ if (isDefaultTestContainerFactorySet) {
+ initializeWeld();
+ startGrizzlyContainer();
+ initializeClient();
+ }
+ }
+
+ @After
+ public void after() {
+ if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ if (isDefaultTestContainerFactorySet) {
+ httpServer.shutdownNow();
+ weld.shutdown();
+ client.close();
+ }
+ }
+ }
+
+ @Test
+ public void testPathAndHeader() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ JaxRsInjectedCdiBeanTest._testPathAndHeader(mainTarget);
+ SecondJaxRsInjectedCdiBeanTest._testPathAndHeader(secondaryTarget);
+ }
+
+ private void initializeWeld() {
+ weld = new Weld();
+ weld.initialize();
+ }
+
+ private void startGrizzlyContainer() throws IOException {
+ final ResourceConfig firstConfig = ResourceConfig.forApplicationClass(MainApplication.class);
+ final ResourceConfig secondConfig = ResourceConfig.forApplicationClass(SecondaryApplication.class);
+
+ httpServer = GrizzlyHttpServerFactory.createHttpServer(MAIN_APP_URI, firstConfig, false);
+ final HttpHandler secondHandler = createGrizzlyContainer(secondConfig);
+ httpServer.getServerConfiguration().addHttpHandler(secondHandler, SECONDARY_URI);
+ httpServer.start();
+ }
+
+ private GrizzlyHttpContainer createGrizzlyContainer(final ResourceConfig resourceConfig) {
+ return (new GrizzlyHttpContainerProvider()).createContainer(GrizzlyHttpContainer.class, resourceConfig);
+ }
+
+ private void initializeClient() {
+ client = ClientBuilder.newClient();
+ mainTarget = client.target(MAIN_APP_URI);
+ secondaryTarget = client.target(SECONDARY_APP_URI);
+ }
+
+ private static boolean isDefaultTestContainerFactorySet() {
+ final String testContainerFactory = getSystemProperty(TestProperties.CONTAINER_FACTORY, null);
+ return testContainerFactory == null || TestProperties.DEFAULT_CONTAINER_FACTORY.equals(testContainerFactory);
+ }
+
+ private static String getSystemProperty(final String propertyName, final String defaultValue) {
+ final Properties systemProperties = System.getProperties();
+ return systemProperties.getProperty(propertyName, defaultValue);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestBeanTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestBeanTest.java
new file mode 100644
index 0000000..973860b
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestBeanTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for the request scoped resource.
+ *
+ * @author Jakub Podlesak
+ * @author Patrik Dudits
+ */
+@RunWith(Parameterized.class)
+public class PerRequestBeanTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha"},
+ {"AAA"},
+ {"$%^"},
+ {"a b"}
+ });
+ }
+
+ final String x;
+
+ /**
+ * Create x new test case based on the above defined parameters.
+ *
+ * @param x query parameter value
+ */
+ public PerRequestBeanTest(String x) {
+ this.x = x;
+ }
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("jcdibean/per-request").queryParam("x", x);
+
+ String s = target.request().get(String.class);
+
+ assertThat(s, containsString(target.getUri().toString()));
+ assertThat(s, containsString(String.format("queryParam=%s", x)));
+ }
+
+ @Test
+ public void testSingleResponseFilterInvocation() {
+
+ final WebTarget target = target().path("jcdibean/per-request").queryParam("x", x);
+
+ Response response = target.request().get();
+
+ List<Object> invocationIds = response.getHeaders().get("Filter-Invoked");
+
+ assertNotNull("Filter-Invoked header should be set by ResponseFilter", invocationIds);
+ assertEquals("ResponseFilter should be invoked only once", 1, invocationIds.size());
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestDependentBeanTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestDependentBeanTest.java
new file mode 100644
index 0000000..458e548
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestDependentBeanTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for the request scoped managed bean resource.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class PerRequestDependentBeanTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha"},
+ {"AAA"},
+ {"$%^"},
+ {"a b"}
+ });
+ }
+
+ final String x;
+
+ /**
+ * Create x new test case based on the above defined parameters.
+ *
+ * @param x query parameter value
+ */
+ public PerRequestDependentBeanTest(String x) {
+ this.x = x;
+ }
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("jcdibean/dependent/per-request").queryParam("x", x);
+
+ String s = target.request().get(String.class);
+
+ assertThat(s, containsString(target.getUri().toString()));
+ assertThat(s, containsString(String.format("queryParam=%s", x)));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ProducerTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ProducerTest.java
new file mode 100644
index 0000000..418067b
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ProducerTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Check that automatic HK2 bindings do not break CDI producer mechanism.
+ *
+ * @author Jakub Podlesak
+ */
+public class ProducerTest extends CdiTest {
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("producer");
+
+ final Response fieldResponse = target.path("f").request().get();
+ assertThat(fieldResponse.getStatus(), is(200));
+ assertThat(fieldResponse.readEntity(String.class), is("field"));
+
+ final Response methodResponse = target.path("m").request().get();
+ assertThat(methodResponse.getStatus(), is(200));
+ assertThat(methodResponse.readEntity(String.class), is("method"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/QualifiedInjectionSetGetTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/QualifiedInjectionSetGetTest.java
new file mode 100644
index 0000000..a928b91
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/QualifiedInjectionSetGetTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.inject.Qualifier;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Test CDI bean injected using a {@link Qualifier}
+ * is setup via JAX-RS interface first.
+ *
+ * @author Jakub Podlesak
+ */
+public class QualifiedInjectionSetGetTest extends CdiTest {
+
+ @Test
+ public void testSetGet() {
+
+ final WebTarget factorTarget = target().path("stutter-service-factor");
+ final WebTarget stutterTarget = target().path("stutter");
+
+ factorTarget.request().put(Entity.text("3"));
+ final String shouldBeTrippled = stutterTarget.queryParam("s", "lincoln").request().get(String.class);
+
+ assertThat(shouldBeTrippled, is("lincolnlincolnlincoln"));
+
+ factorTarget.request().put(Entity.text("2"));
+ final String shouldBeDoubled = stutterTarget.queryParam("s", "lincoln").request().get(String.class);
+
+ assertThat(shouldBeDoubled, is("lincolnlincoln"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ReverseEchoTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ReverseEchoTest.java
new file mode 100644
index 0000000..d7ce046
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ReverseEchoTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for qualified injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class ReverseEchoTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha", "ahpla"},
+ {"gogol", "logog"},
+ {"elcaro", "oracle"}
+ });
+ }
+
+ final String in, out;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param in query parameter.
+ * @param out expected output.
+ */
+ public ReverseEchoTest(String in, String out) {
+ this.in = in;
+ this.out = out;
+ }
+
+ @Test
+ public void testGet() {
+ WebTarget reverseService = target().path("reverse").queryParam("s", in);
+ String s = reverseService.request().get(String.class);
+ assertThat(s, equalTo(out));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SecondJaxRsInjectedCdiBeanTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SecondJaxRsInjectedCdiBeanTest.java
new file mode 100644
index 0000000..5b86192
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SecondJaxRsInjectedCdiBeanTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.jboss.weld.environment.se.Weld;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test that a raw CDI managed bean gets JAX-RS injected.
+ *
+ * @author Jakub Podlesak
+ */
+public class SecondJaxRsInjectedCdiBeanTest extends JerseyTest {
+ Weld weld;
+
+ @Override
+ public void setUp() throws Exception {
+ weld = new Weld();
+ weld.initialize();
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ weld.shutdown();
+ super.tearDown();
+ }
+
+ @Override
+ protected Application configure() {
+ return new SecondaryApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-test-webapp/secondary").build();
+ }
+
+ @Test
+ public void testPathAndHeader() {
+ _testPathAndHeader(target());
+ }
+
+ public static void _testPathAndHeader(final WebTarget webTarget) {
+ final WebTarget target = webTarget.path("non-jaxrs-bean-injected");
+
+ final Response pathResponse = target.path("path/2").request().get();
+ assertThat(pathResponse.getStatus(), is(200));
+ final String path = pathResponse.readEntity(String.class);
+
+ assertThat(path, is("non-jaxrs-bean-injected/path/2"));
+
+ final Response headerResponse = target.path("header/2").request().header("x-test", "bummer2").get();
+ assertThat(headerResponse.getStatus(), is(200));
+ final String header = headerResponse.readEntity(String.class);
+
+ assertThat(header, is("bummer2"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonBeanTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonBeanTest.java
new file mode 100644
index 0000000..1dcf301
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonBeanTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for the application scoped resource.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class SingletonBeanTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha", "beta"},
+ {"1", "2"}
+ });
+ }
+
+ final String p, x;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param p path parameter.
+ * @param x query parameter.
+ */
+ public SingletonBeanTest(String p, String x) {
+ this.p = p;
+ this.x = x;
+ }
+
+ @Test
+ public void testGet() {
+ final WebTarget singleton = target().path("jcdibean/singleton").path(p).queryParam("x", x);
+ String s = singleton.request().get(String.class);
+ assertThat(s, containsString(singleton.getUri().toString()));
+ assertThat(s, containsString(String.format("p=%s", p)));
+ assertThat(s, containsString(String.format("queryParam=%s", x)));
+ }
+
+ @Test
+ public void testCounter() {
+
+ final WebTarget counter = target().path("jcdibean/singleton").path(p).queryParam("x", x).path("counter");
+
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ // TODO: remove this workaround once JERSEY-2744 is resolved
+ counter.request().put(Entity.text("10"));
+ }
+
+ String c10 = counter.request().get(String.class);
+ assertThat(c10, containsString("10"));
+
+ String c11 = counter.request().get(String.class);
+ assertThat(c11, containsString("11"));
+
+ counter.request().put(Entity.text("32"));
+
+ String c32 = counter.request().get(String.class);
+ assertThat(c32, containsString("32"));
+
+ counter.request().put(Entity.text("10"));
+ }
+
+ @Test
+ public void testException() {
+ final WebTarget exception = target().path("jcdibean/singleton").path(p).queryParam("x", x).path("exception");
+ assertThat(exception.request().get().readEntity(String.class), containsString("JDCIBeanException"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonDependentBeanTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonDependentBeanTest.java
new file mode 100644
index 0000000..056c3c5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonDependentBeanTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for the application scoped managed bean resource.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class SingletonDependentBeanTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha", "beta"},
+ {"1", "2"}
+ });
+ }
+
+ final String p, x;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param p path parameter.
+ * @param x query parameter.
+ */
+ public SingletonDependentBeanTest(String p, String x) {
+ this.p = p;
+ this.x = x;
+ }
+
+ @Test
+ public void testGet() {
+ final WebTarget singleton = target().path("jcdibean/dependent/singleton").path(p).queryParam("x", x);
+ String s = singleton.request().get(String.class);
+ assertThat(s, containsString(singleton.getUri().toString()));
+ assertThat(s, containsString(String.format("p=%s", p)));
+ assertThat(s, containsString(String.format("queryParam=%s", x)));
+ }
+
+ @Test
+ public void testCounter() {
+
+ final WebTarget counter = target().path("jcdibean/dependent/singleton").path(p).queryParam("x", x).path("counter");
+
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ // TODO: remove this workaround once JERSEY-2744 is resolved
+ counter.request().put(Entity.text("10"));
+ }
+
+ String c10 = counter.request().get(String.class);
+ assertThat(c10, containsString("10"));
+
+ String c11 = counter.request().get(String.class);
+ assertThat(c11, containsString("11"));
+
+ counter.request().put(Entity.text("32"));
+
+ String c32 = counter.request().get(String.class);
+ assertThat(c32, containsString("32"));
+
+ counter.request().put(Entity.text("10"));
+ }
+
+ @Test
+ public void testException() {
+ final WebTarget exception = target().path("jcdibean/dependent/singleton").path(p).queryParam("x", x).path("exception");
+ assertThat(exception.request().get().readEntity(String.class), containsString("JDCIBeanDependentException"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/StutterEchoTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/StutterEchoTest.java
new file mode 100644
index 0000000..b8655a6
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/StutterEchoTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for qualified injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class StutterEchoTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][]{
+ {"alpha", "alphaalpha"},
+ {"gogol", "gogolgogol"},
+ {"elcaro", "elcaroelcaro"}
+ });
+ };
+
+ final String in, out;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param in query parameter.
+ * @param out expected output.
+ */
+ public StutterEchoTest(String in, String out) {
+ this.in = in;
+ this.out = out;
+ }
+
+ @Test
+ public void testGet() {
+ String s = target().path("stutter").queryParam("s", in).request().get(String.class);
+ assertThat(s, equalTo(out));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TimerTest.java b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TimerTest.java
new file mode 100644
index 0000000..94eee9f
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TimerTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Reproducer for JERSEY-1747.
+ *
+ * @author Jakub Podlesak
+ */
+public class TimerTest extends CdiTest {
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("jcdibean/dependent/timer");
+
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), is(200));
+ long firstMillis = Long.decode(firstResponse.readEntity(String.class));
+ sleep(2);
+
+ final Response secondResponse = target.request().get();
+ assertThat(secondResponse.getStatus(), is(200));
+ long secondMillis = Long.decode(secondResponse.readEntity(String.class));
+
+ assertTrue("Second request should have greater millis!", secondMillis > firstMillis);
+ }
+
+ private void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(TimerTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/pom.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/pom.xml
new file mode 100644
index 0000000..8090373
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/pom.xml
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-with-jersey-injection-custom-cfg-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-with-jersey-injection-custom-cfg-webapp</name>
+
+ <description>
+ Jersey CDI test web application, this one uses Jersey (non JAX-RS) component injection and Jersey/CDI SPI to config
+ HK2 custom bindings.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-transaction</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.transaction</groupId>
+ <artifactId>jakarta.transaction-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
new file mode 100644
index 0000000..ef40213
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+
+/**
+ * Application specific echo implementation.
+ *
+ * @author Jakub Podlesak
+ */
+@AppSpecific
+@ApplicationScoped
+public class AppEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "App: " + s;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
new file mode 100644
index 0000000..62a932d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationScoped
+@Path("app-ctor-injected")
+public class AppScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ Provider<ContainerRequest> request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+ // Jersey/HK2 custom injected
+ @Inject
+ Hk2InjectedType hk2Injected;
+
+ // to make weld happy
+ public AppScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public AppScopedCtorInjectedResource(@AppSpecific final EchoService echoService,
+ final Provider<ContainerRequest> request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected,
+ final Hk2InjectedType hk2Injected) {
+ this.echoService = echoService;
+ this.request = request;
+ this.mappers = mappers;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ this.hk2Injected = hk2Injected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
new file mode 100644
index 0000000..dda6c10
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+import org.glassfish.jersey.tests.cdi.resources.MyApplication.MyInjection;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationScoped
+@Path("app-field-injected")
+public class AppScopedFieldInjectedResource {
+
+ // CDI injected
+ @Inject
+ @AppSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ Provider<ContainerRequest> request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injection
+ @Inject
+ MyInjection customInjected;
+ // Jersey/HK2 custom injection
+ @Inject
+ Hk2InjectedType hk2Injected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
new file mode 100644
index 0000000..6e156cd
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for application specific echo service.
+ *
+ * @author Jakub Podlesak
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface AppSpecific {
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
new file mode 100644
index 0000000..2ba1f04
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.inject.Qualifier;
+
+/**
+ * Simple echo service to test injections using {@link Qualifier}.
+ *
+ * @author Jakub Podlesak
+ */
+public interface EchoService {
+
+ /**
+ * Provide an echoed response.
+ *
+ * @param s String to be echoed.
+ * @return echoed input.
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Hk2InjectedType.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Hk2InjectedType.java
new file mode 100644
index 0000000..67b79dd
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Hk2InjectedType.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * CDI compliant bean. Injection will be delegated to HK2 anyway.
+ *
+ * @author Jakub Podlesak
+ */
+public class Hk2InjectedType {
+
+ private final String name;
+
+ /**
+ * No-arg constructor makes this bean suitable for CDI injection.
+ */
+ public Hk2InjectedType() {
+ name = "CDI would love this";
+ }
+
+ /**
+ * Hk2 custom binder is going to use this one.
+ *
+ * @param name
+ */
+ public Hk2InjectedType(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Simple getter to prove where this bean was initialized.
+ *
+ * @return name as defined at bean initialization.
+ */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..9329160
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.internal.monitoring.MonitoringFeature;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/*")
+public class MyApplication extends ResourceConfig {
+
+ public static class MyInjection {
+
+ private final String name;
+
+ public MyInjection(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ public MyApplication() {
+
+ // JAX-RS resource classes
+ register(AppScopedFieldInjectedResource.class);
+ register(AppScopedCtorInjectedResource.class);
+ register(RequestScopedFieldInjectedResource.class);
+ register(RequestScopedCtorInjectedResource.class);
+
+ register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(new MyInjection("1st: no way CDI would chime in")).to(MyInjection.class);
+ bind(new Hk2InjectedType("2nd: no way CDI would chime in")).to(Hk2InjectedType.class);
+ }
+ });
+
+ // Jersey monitoring
+ register(MonitoringFeature.class);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java
new file mode 100644
index 0000000..379a8d8
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider;
+
+/**
+ * Tell Jersey CDI extension what types should be bridged from HK2 to CDI.
+ *
+ * @author Jakub Podlesak
+ */
+public class MyHk2TypesProvider implements Hk2CustomBoundTypesProvider {
+
+ @Override
+ public Set<Type> getHk2Types() {
+ return new HashSet<Type>() {{
+ add(Hk2InjectedType.class);
+ add(MyApplication.MyInjection.class);
+ }};
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
new file mode 100644
index 0000000..b95c136
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Request specific echo implementation.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestSpecific
+public class RequestEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "Request: " + s;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
new file mode 100644
index 0000000..2356b4a
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("request-ctor-injected")
+public class RequestScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ ContainerRequest request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+ // Jersey/HK2 custom injected
+ Hk2InjectedType hk2Injected;
+
+ // to make weld happy
+ public RequestScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public RequestScopedCtorInjectedResource(@RequestSpecific final EchoService echoService,
+ final ContainerRequest request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected,
+ final Hk2InjectedType hk2Injected) {
+
+ this.echoService = echoService;
+ this.mappers = mappers;
+ this.request = request;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ this.hk2Injected = hk2Injected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
new file mode 100644
index 0000000..f87610f
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("request-field-injected")
+public class RequestScopedFieldInjectedResource {
+
+ // built-in CDI bean
+ @Inject
+ BeanManager beanManager;
+
+ // CDI injected
+ @Inject
+ @RequestSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ ContainerRequest request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Custom Jersey/HK2 injected
+ @Inject
+ MyApplication.MyInjection customInjected;
+ // Custom Jersey/HK2 injected
+ @Inject
+ Hk2InjectedType hk2Injected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+
+ @GET
+ @Path("bm")
+ public String getBm() {
+ return beanManager.toString();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
new file mode 100644
index 0000000..037f5a5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for request specific echo service.
+ *
+ * @author Jakub Podlesak
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface RequestSpecific {
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider
new file mode 100644
index 0000000..8ad35f8
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.resources.MyHk2TypesProvider
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff67ca5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <env-entry>
+ <env-entry-name>injectedResource</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+</web-app>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..a3763ff
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-with-jersey-injection-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak
+ */
+public class CdiTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-with-jersey-injection-custom-cfg-webapp").build();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
new file mode 100644
index 0000000..e050cff
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test custom HK2 injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class CustomInjectionTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"},
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public CustomInjectionTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance of {@link Hk2InjectedType} gets injected.
+ */
+ @Test
+ public void testCustomHk2Injection1() {
+ final WebTarget target = target().path(resource).path("custom");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("1st: no way CDI would chime in"));
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance of {@link MyApplication.MyInjection} gets injected.
+ */
+ @Test
+ public void testCustomHk2Injection2() {
+ final WebTarget target = target().path(resource).path("custom2");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("2nd: no way CDI would chime in"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
new file mode 100644
index 0000000..6319cad
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for exception mapper injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class ExceptionMappersTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"},
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public ExceptionMappersTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side, and for two
+ * the injected mappers remains the same across requests.
+ */
+ @Test
+ public void testMappersNotNull() {
+ final WebTarget target = target().path(resource).path("mappers");
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), equalTo(200));
+ final String firstValue = firstResponse.readEntity(String.class);
+ assertThat(target.request().get(String.class), equalTo(firstValue));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
new file mode 100644
index 0000000..c8de729
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for monitoring statistics injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class MonitoringTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of resource to be tested.
+ */
+ public MonitoringTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Make several requests and check the counter keeps incrementing.
+ *
+ * @throws Exception in case of unexpected test failure.
+ */
+ @Test
+ public void testRequestCount() throws Exception {
+ final WebTarget target = target().path(resource).path("requestCount");
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ final int start = Integer.decode(target.request().get(String.class));
+ for (int i = 1; i < 4; i++) {
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ final int next = Integer.decode(target.request().get(String.class));
+ assertThat(String.format("testing %s", resource), next, equalTo(start + i));
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
new file mode 100644
index 0000000..93370c5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test injection of request depending instances works as expected.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class RequestSensitiveTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected", "alpha", "App: alpha"},
+ {"app-field-injected", "gogol", "App: gogol"},
+ {"app-field-injected", "elcaro", "App: elcaro"},
+ {"app-ctor-injected", "alpha", "App: alpha"},
+ {"app-ctor-injected", "gogol", "App: gogol"},
+ {"app-ctor-injected", "elcaro", "App: elcaro"},
+ {"request-field-injected", "alpha", "Request: alpha"},
+ {"request-field-injected", "gogol", "Request: gogol"},
+ {"request-field-injected", "oracle", "Request: oracle"},
+ {"request-ctor-injected", "alpha", "Request: alpha"},
+ {"request-ctor-injected", "gogol", "Request: gogol"},
+ {"request-ctor-injected", "oracle", "Request: oracle"}
+ });
+ }
+
+ final String resource, straight, echoed;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of the resource to be tested.
+ * @param straight request specific input.
+ * @param echoed CDI injected service should produce this out of previous, straight, parameter.
+ */
+ public RequestSensitiveTest(final String resource, final String straight, final String echoed) {
+ this.resource = resource;
+ this.straight = straight;
+ this.echoed = echoed;
+ }
+
+ @Test
+ public void testCdiInjection() {
+ final String s = target().path(resource).queryParam("s", straight).request().get(String.class);
+ assertThat(s, equalTo(echoed));
+ }
+
+ @Test
+ public void testHk2Injection() {
+ final String s = target().path(resource).path("path").path(straight).request().get(String.class);
+ assertThat(s, equalTo(String.format("%s/path/%s", resource, straight)));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/pom.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/pom.xml
new file mode 100644
index 0000000..036c9ce
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/pom.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-with-jersey-injection-custom-hk2-banned-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-with-jersey-injection-custom-hk2-banned-webapp</name>
+
+ <description>
+ Jersey CDI test web application, this one uses Jersey (non JAX-RS) component injection HK2 custom binding has been banned.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-transaction</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.transaction</groupId>
+ <artifactId>jakarta.transaction-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-ban-custom-hk2-binding</artifactId>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
new file mode 100644
index 0000000..ef40213
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+
+/**
+ * Application specific echo implementation.
+ *
+ * @author Jakub Podlesak
+ */
+@AppSpecific
+@ApplicationScoped
+public class AppEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "App: " + s;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
new file mode 100644
index 0000000..1e0a529
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationScoped
+@Path("app-ctor-injected")
+public class AppScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ Provider<ContainerRequest> request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+ // Jersey/HK2 custom injected
+ @Inject
+ CdiInjectedType hk2Injected;
+
+ // to make weld happy
+ public AppScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public AppScopedCtorInjectedResource(@AppSpecific final EchoService echoService,
+ final Provider<ContainerRequest> request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected,
+ final CdiInjectedType hk2Injected) {
+ this.echoService = echoService;
+ this.request = request;
+ this.mappers = mappers;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ this.hk2Injected = hk2Injected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
new file mode 100644
index 0000000..06f5160
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+import org.glassfish.jersey.tests.cdi.resources.MyApplication.MyInjection;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationScoped
+@Path("app-field-injected")
+public class AppScopedFieldInjectedResource {
+
+ // CDI injected
+ @Inject
+ @AppSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ Provider<ContainerRequest> request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injection
+ @Inject
+ MyInjection customInjected;
+ // Jersey/HK2 custom injection
+ @Inject
+ CdiInjectedType hk2Injected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
new file mode 100644
index 0000000..6e156cd
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for application specific echo service.
+ *
+ * @author Jakub Podlesak
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface AppSpecific {
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiInjectedType.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiInjectedType.java
new file mode 100644
index 0000000..2f02cd6
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiInjectedType.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * CDI compliant bean. Injection will be done by CDI in this application.
+ *
+ * @author Jakub Podlesak
+ */
+public class CdiInjectedType {
+
+ private final String name;
+
+ /**
+ * No-arg constructor makes this bean suitable for CDI injection.
+ */
+ public CdiInjectedType() {
+ name = "CDI would love this";
+ }
+
+ /**
+ * Hk2 custom binder is going to use this one.
+ *
+ * @param name
+ */
+ public CdiInjectedType(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Simple getter to prove where this bean was initialized.
+ *
+ * @return name as defined at bean initialization.
+ */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
new file mode 100644
index 0000000..2ba1f04
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.inject.Qualifier;
+
+/**
+ * Simple echo service to test injections using {@link Qualifier}.
+ *
+ * @author Jakub Podlesak
+ */
+public interface EchoService {
+
+ /**
+ * Provide an echoed response.
+ *
+ * @param s String to be echoed.
+ * @return echoed input.
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..fafc0db
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.internal.monitoring.MonitoringFeature;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/*")
+public class MyApplication extends ResourceConfig {
+
+ public static class MyInjection {
+
+ private final String name;
+
+ public MyInjection() {
+ name = "CDI injected";
+ }
+
+ public MyInjection(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ public MyApplication() {
+
+ // JAX-RS resource classes
+ register(AppScopedFieldInjectedResource.class);
+ register(AppScopedCtorInjectedResource.class);
+ register(RequestScopedFieldInjectedResource.class);
+ register(RequestScopedCtorInjectedResource.class);
+
+ register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(new MyInjection("1st: unused HK2 binding")).to(MyInjection.class);
+ bind(new CdiInjectedType("2nd: unused HK2 binding")).to(CdiInjectedType.class);
+ }
+ });
+
+ // Jersey monitoring
+ register(MonitoringFeature.class);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
new file mode 100644
index 0000000..b95c136
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Request specific echo implementation.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestSpecific
+public class RequestEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "Request: " + s;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
new file mode 100644
index 0000000..37f1758
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("request-ctor-injected")
+public class RequestScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ ContainerRequest request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+ // Jersey/HK2 custom injected
+ CdiInjectedType hk2Injected;
+
+ // to make weld happy
+ public RequestScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public RequestScopedCtorInjectedResource(@RequestSpecific final EchoService echoService,
+ final ContainerRequest request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected,
+ final CdiInjectedType hk2Injected) {
+
+ this.echoService = echoService;
+ this.mappers = mappers;
+ this.request = request;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ this.hk2Injected = hk2Injected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
new file mode 100644
index 0000000..7363977
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("request-field-injected")
+public class RequestScopedFieldInjectedResource {
+
+ // built-in CDI bean
+ @Inject
+ BeanManager beanManager;
+
+ // CDI injected
+ @Inject
+ @RequestSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ ContainerRequest request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Custom Jersey/HK2 injected
+ @Inject
+ MyApplication.MyInjection customInjected;
+ // Custom Jersey/HK2 injected
+ @Inject
+ CdiInjectedType hk2Injected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+
+ @GET
+ @Path("bm")
+ public String getBm() {
+ return beanManager.toString();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
new file mode 100644
index 0000000..037f5a5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for request specific echo service.
+ *
+ * @author Jakub Podlesak
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface RequestSpecific {
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff67ca5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <env-entry>
+ <env-entry-name>injectedResource</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+</web-app>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..2399a21
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-with-jersey-injection-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak
+ */
+public class CdiTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-with-jersey-injection-custom-hk2-banned-webapp").build();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
new file mode 100644
index 0000000..ccdd993
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test custom HK2 injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class CustomInjectionTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"},
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public CustomInjectionTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance of {@link CdiInjectedType} gets CDI injected.
+ */
+ @Test
+ public void testCustomHk2Injection1() {
+ final WebTarget target = target().path(resource).path("custom");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("CDI injected"));
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance of {@link MyApplication.MyInjection} gets CDI injected.
+ */
+ @Test
+ public void testCustomHk2Injection2() {
+ final WebTarget target = target().path(resource).path("custom2");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("CDI would love this"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
new file mode 100644
index 0000000..00001e0
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for exception mapper injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class ExceptionMappersTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public ExceptionMappersTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side, and for two
+ * the injected mappers remains the same across requests.
+ */
+ @Test
+ public void testMappersNotNull() {
+ final WebTarget target = target().path(resource).path("mappers");
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), equalTo(200));
+ final String firstValue = firstResponse.readEntity(String.class);
+ assertThat(target.request().get(String.class), equalTo(firstValue));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
new file mode 100644
index 0000000..c8de729
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for monitoring statistics injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class MonitoringTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of resource to be tested.
+ */
+ public MonitoringTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Make several requests and check the counter keeps incrementing.
+ *
+ * @throws Exception in case of unexpected test failure.
+ */
+ @Test
+ public void testRequestCount() throws Exception {
+ final WebTarget target = target().path(resource).path("requestCount");
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ final int start = Integer.decode(target.request().get(String.class));
+ for (int i = 1; i < 4; i++) {
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ final int next = Integer.decode(target.request().get(String.class));
+ assertThat(String.format("testing %s", resource), next, equalTo(start + i));
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
new file mode 100644
index 0000000..93370c5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test injection of request depending instances works as expected.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class RequestSensitiveTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected", "alpha", "App: alpha"},
+ {"app-field-injected", "gogol", "App: gogol"},
+ {"app-field-injected", "elcaro", "App: elcaro"},
+ {"app-ctor-injected", "alpha", "App: alpha"},
+ {"app-ctor-injected", "gogol", "App: gogol"},
+ {"app-ctor-injected", "elcaro", "App: elcaro"},
+ {"request-field-injected", "alpha", "Request: alpha"},
+ {"request-field-injected", "gogol", "Request: gogol"},
+ {"request-field-injected", "oracle", "Request: oracle"},
+ {"request-ctor-injected", "alpha", "Request: alpha"},
+ {"request-ctor-injected", "gogol", "Request: gogol"},
+ {"request-ctor-injected", "oracle", "Request: oracle"}
+ });
+ }
+
+ final String resource, straight, echoed;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of the resource to be tested.
+ * @param straight request specific input.
+ * @param echoed CDI injected service should produce this out of previous, straight, parameter.
+ */
+ public RequestSensitiveTest(final String resource, final String straight, final String echoed) {
+ this.resource = resource;
+ this.straight = straight;
+ this.echoed = echoed;
+ }
+
+ @Test
+ public void testCdiInjection() {
+ final String s = target().path(resource).queryParam("s", straight).request().get(String.class);
+ assertThat(s, equalTo(echoed));
+ }
+
+ @Test
+ public void testHk2Injection() {
+ final String s = target().path(resource).path("path").path(straight).request().get(String.class);
+ assertThat(s, equalTo(String.format("%s/path/%s", resource, straight)));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/pom.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/pom.xml
new file mode 100644
index 0000000..d774b42
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/pom.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
+ <artifactId>cdi-integration-project</artifactId>
+ <version>2.30-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-with-jersey-injection-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-with-jersey-injection-webapp</name>
+
+ <description>Jersey CDI test web application, this one uses Jersey (non JAX-RS) component injection</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-transaction</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
new file mode 100644
index 0000000..ef40213
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+
+/**
+ * Application specific echo implementation.
+ *
+ * @author Jakub Podlesak
+ */
+@AppSpecific
+@ApplicationScoped
+public class AppEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "App: " + s;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
new file mode 100644
index 0000000..442ee42
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationScoped
+@Path("app-ctor-injected")
+public class AppScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ Provider<ContainerRequest> request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+
+ // to make weld happy
+ public AppScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public AppScopedCtorInjectedResource(@AppSpecific final EchoService echoService,
+ final Provider<ContainerRequest> request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected) {
+ this.echoService = echoService;
+ this.request = request;
+ this.mappers = mappers;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
new file mode 100644
index 0000000..76a49a7
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+import org.glassfish.jersey.tests.cdi.resources.MyApplication.MyInjection;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationScoped
+@Path("app-field-injected")
+public class AppScopedFieldInjectedResource {
+
+ // CDI injected
+ @Inject
+ @AppSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ Provider<ContainerRequest> request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injection
+ @Inject
+ MyInjection customInjected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
new file mode 100644
index 0000000..6e156cd
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for application specific echo service.
+ *
+ * @author Jakub Podlesak
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface AppSpecific {
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
new file mode 100644
index 0000000..2ba1f04
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.inject.Qualifier;
+
+/**
+ * Simple echo service to test injections using {@link Qualifier}.
+ *
+ * @author Jakub Podlesak
+ */
+public interface EchoService {
+
+ /**
+ * Provide an echoed response.
+ *
+ * @param s String to be echoed.
+ * @return echoed input.
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..238edb2
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.internal.monitoring.MonitoringFeature;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak
+ */
+@ApplicationPath("/*")
+public class MyApplication extends ResourceConfig {
+
+ public static class MyInjection {
+
+ private final String name;
+
+ public MyInjection(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ public MyApplication() {
+ // JAX-RS resource classes
+ register(AppScopedFieldInjectedResource.class);
+ register(AppScopedCtorInjectedResource.class);
+ register(RequestScopedFieldInjectedResource.class);
+ register(RequestScopedCtorInjectedResource.class);
+
+ register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(new MyInjection("no way CDI would chime in")).to(MyInjection.class);
+ }
+ });
+
+ // Jersey monitoring
+ register(MonitoringFeature.class);
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java
new file mode 100644
index 0000000..9131412
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider;
+
+/**
+ * Tell Jersey CDI extension what types should be bridged from HK2 to CDI.
+ *
+ * @author Jakub Podlesak
+ */
+public class MyHk2TypesProvider implements Hk2CustomBoundTypesProvider {
+
+ @Override
+ public Set<Type> getHk2Types() {
+ return new HashSet<Type>() {{
+ add(MyApplication.MyInjection.class);
+ }};
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
new file mode 100644
index 0000000..b95c136
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+/**
+ * Request specific echo implementation.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestSpecific
+public class RequestEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "Request: " + s;
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
new file mode 100644
index 0000000..76ab792
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("request-ctor-injected")
+public class RequestScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ ContainerRequest request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+
+ // to make weld happy
+ public RequestScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public RequestScopedCtorInjectedResource(@RequestSpecific EchoService echoService,
+ ContainerRequest request, ExceptionMappers mappers,
+ Provider<MonitoringStatistics> stats, MyApplication.MyInjection customInjected) {
+
+ this.echoService = echoService;
+ this.mappers = mappers;
+ this.request = request;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
new file mode 100644
index 0000000..9b20728
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak
+ */
+@RequestScoped
+@Path("request-field-injected")
+public class RequestScopedFieldInjectedResource {
+
+ // built-in CDI bean
+ @Inject
+ BeanManager beanManager;
+
+ // CDI injected
+ @Inject
+ @RequestSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ ContainerRequest request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Custom Jersey/HK2 injected
+ @Inject
+ MyApplication.MyInjection customInjected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("bm")
+ public String getBm() {
+ return beanManager.toString();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
new file mode 100644
index 0000000..037f5a5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for request specific echo service.
+ *
+ * @author Jakub Podlesak
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface RequestSpecific {
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider
new file mode 100644
index 0000000..8ad35f8
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.resources.MyHk2TypesProvider
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff67ca5
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <env-entry>
+ <env-entry-name>injectedResource</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+</web-app>
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..45bc068
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-with-jersey-injection-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak
+ */
+public class CdiTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-with-jersey-injection-webapp").build();
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
new file mode 100644
index 0000000..ffc79ad
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test custom HK2 injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class CustomInjectionTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public CustomInjectionTest(String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance gets injected.
+ */
+ @Test
+ public void testCustomHk2InjectionNull() {
+ WebTarget target = target().path(resource).path("custom");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("no way CDI would chime in"));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
new file mode 100644
index 0000000..0dc333d
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for exception mapper injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class ExceptionMappersTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public ExceptionMappersTest(String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side, and for two
+ * the injected mappers remains the same across requests.
+ */
+ @Test
+ public void testMappersNotNull() {
+ WebTarget target = target().path(resource).path("mappers");
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), equalTo(200));
+ String firstValue = firstResponse.readEntity(String.class);
+ assertThat(target.request().get(String.class), equalTo(firstValue));
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
new file mode 100644
index 0000000..ff7de39
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for monitoring statistics injection.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class MonitoringTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of resource to be tested.
+ */
+ public MonitoringTest(String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Make several requests and check the counter keeps incrementing.
+ *
+ * @throws Exception in case of unexpected test failure.
+ */
+ @Test
+ public void testRequestCount() throws Exception {
+ WebTarget target = target().path(resource).path("requestCount");
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ int start = Integer.decode(target.request().get(String.class));
+ for (int i = 1; i < 4; i++) {
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ int next = Integer.decode(target.request().get(String.class));
+ assertThat(String.format("testing %s", resource), next, equalTo(start + i));
+ }
+ }
+}
diff --git a/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
new file mode 100644
index 0000000..930eb37
--- /dev/null
+++ b/tests/integration/cdi-integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test injection of request depending instances works as expected.
+ *
+ * @author Jakub Podlesak
+ */
+@RunWith(Parameterized.class)
+public class RequestSensitiveTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected", "alpha", "App: alpha"},
+ {"app-field-injected", "gogol", "App: gogol"},
+ {"app-field-injected", "elcaro", "App: elcaro"},
+ {"app-ctor-injected", "alpha", "App: alpha"},
+ {"app-ctor-injected", "gogol", "App: gogol"},
+ {"app-ctor-injected", "elcaro", "App: elcaro"},
+ {"request-field-injected", "alpha", "Request: alpha"},
+ {"request-field-injected", "gogol", "Request: gogol"},
+ {"request-field-injected", "oracle", "Request: oracle"},
+ {"request-ctor-injected", "alpha", "Request: alpha"},
+ {"request-ctor-injected", "gogol", "Request: gogol"},
+ {"request-ctor-injected", "oracle", "Request: oracle"}
+ });
+ }
+
+ final String resource, straight, echoed;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of the resource to be tested.
+ * @param straight request specific input.
+ * @param echoed CDI injected service should produce this out of previous, straight, parameter.
+ */
+ public RequestSensitiveTest(String resource, String straight, String echoed) {
+ this.resource = resource;
+ this.straight = straight;
+ this.echoed = echoed;
+ }
+
+ @Test
+ public void testCdiInjection() {
+ String s = target().path(resource).queryParam("s", straight).request().get(String.class);
+ assertThat(s, equalTo(echoed));
+ }
+
+ @Test
+ public void testHk2Injection() {
+ String s = target().path(resource).path("path").path(straight).request().get(String.class);
+ assertThat(s, equalTo(String.format("%s/path/%s", resource, straight)));
+ }
+}
diff --git a/tests/integration/cdi-integration/pom.xml b/tests/integration/cdi-integration/pom.xml
index 03d804f..b97c5b6 100644
--- a/tests/integration/cdi-integration/pom.xml
+++ b/tests/integration/cdi-integration/pom.xml
@@ -25,13 +25,34 @@
<version>2.30-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
<groupId>org.glassfish.jersey.tests.integration.cdi</groupId>
<artifactId>cdi-integration-project</artifactId>
<name>cdi-integration-project</name>
<modules>
+ <module>cdi-beanvalidation-webapp</module>
+ <module>cdi-ejb-test-webapp</module>
+ <module>cdi-iface-with-non-jaxrs-impl-test-webapp</module>
<module>cdi-manually-bound</module>
+ <module>cdi-log-check</module>
+ <module>cdi-multimodule</module>
+ <module>cdi-multipart-webapp</module>
+ <module>cdi-test-webapp</module>
+ <module>cdi-with-jersey-injection-custom-cfg-webapp</module>
+ <module>cdi-with-jersey-injection-custom-hk2-banned-webapp</module>
+ <module>cdi-with-jersey-injection-webapp</module>
</modules>
- <packaging>pom</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file