jersey-3992 CDI Bean created (but fails) when interface has @Path annotation

Signed-off-by: Gaurav Gupta <gaurav.gupta.jc@gmail.com>
diff --git a/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java b/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java
index 7dd258d..7a98004 100644
--- a/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java
+++ b/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018 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
@@ -292,6 +293,11 @@
 
         final boolean isJaxRsResource = jaxRsResourceCache.apply(clazz);
 
+        if (isJaxRsResource && !Resource.isAcceptable(clazz)) {
+            LOGGER.warning(LocalizationMessages.CDI_NON_INSTANTIABLE_COMPONENT(clazz));
+            return false;
+        }
+
         final Class<? extends Annotation> beanScopeAnnotation = CdiUtil.getBeanScope(clazz, beanManager);
         final boolean isRequestScoped = beanScopeAnnotation == RequestScoped.class
                                         || (beanScopeAnnotation == Dependent.class && isJaxRsResource);
diff --git a/ext/cdi/jersey-cdi1x/src/main/resources/org/glassfish/jersey/ext/cdi1x/internal/localization.properties b/ext/cdi/jersey-cdi1x/src/main/resources/org/glassfish/jersey/ext/cdi1x/internal/localization.properties
index 82ac7de..ee1f8e7 100644
--- a/ext/cdi/jersey-cdi1x/src/main/resources/org/glassfish/jersey/ext/cdi1x/internal/localization.properties
+++ b/ext/cdi/jersey-cdi1x/src/main/resources/org/glassfish/jersey/ext/cdi1x/internal/localization.properties
@@ -1,5 +1,6 @@
 #
 # Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2018 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
@@ -24,3 +25,4 @@
 cdi.provider.initialized=Jersey CDI component provider initialized.
 cdi.request.scoped.components.recognized=The following CDI types were recognized as request scoped components in Jersey: {0}.
 cdi.type.vetoed=The following types have been vetoed by Jersey as per {0} configuration: {1}
+cdi.non.instantiable.component=Component of class {0} cannot be instantiated and will be ignored.
\ No newline at end of file
diff --git a/tests/integration/jersey-3992/pom.xml b/tests/integration/jersey-3992/pom.xml
new file mode 100644
index 0000000..8b85467
--- /dev/null
+++ b/tests/integration/jersey-3992/pom.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+    Copyright (c) 2018 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
+
+-->
+
+<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</groupId>
+        <artifactId>project</artifactId>
+        <version>2.28-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>jersey-3992</artifactId>
+    <packaging>war</packaging>
+    <name>jersey-3992</name>
+
+    <description>Jersey CDI Inheritance test web application</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>javax.ws.rs-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.annotation</groupId>
+            <artifactId>javax.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/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java b/tests/integration/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java
new file mode 100644
index 0000000..49d6329
--- /dev/null
+++ b/tests/integration/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2010, 2017 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018 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 (jonathan.benoit at oracle.com)
+ */
+@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(UserResource.class);
+        classes.add(UserResourceImpl.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/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/UserResource.java b/tests/integration/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/UserResource.java
new file mode 100644
index 0000000..91edf6a
--- /dev/null
+++ b/tests/integration/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/UserResource.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018 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.GET;
+import javax.ws.rs.Path;
+
+/**
+ *
+ * @author Gaurav Gupta (gaurav.gupta@payara.fish)
+ */
+public interface UserResource {
+
+    /**
+     * Gets the user count
+     *
+     * @return user count.
+     */
+    @GET
+    @Path("/count")
+    public int getCount();
+
+}
\ No newline at end of file
diff --git a/tests/integration/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/UserResourceImpl.java b/tests/integration/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/UserResourceImpl.java
new file mode 100644
index 0000000..218d60c
--- /dev/null
+++ b/tests/integration/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/UserResourceImpl.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2018 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.GET;
+import javax.ws.rs.Path;
+
+/**
+ *
+ * @author Gaurav Gupta (gaurav.gupta@payara.fish)
+ */
+@Path("user")
+public class UserResourceImpl implements UserResource {
+
+    /**
+     * Gets the user count
+     *
+     * @return user count.
+     */
+    @GET
+    @Path("/count")
+    @Override
+    public int getCount() {
+        return 0;
+    }
+}
diff --git a/tests/integration/jersey-3992/src/main/resources/META-INF/beans.xml b/tests/integration/jersey-3992/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..b30e66e
--- /dev/null
+++ b/tests/integration/jersey-3992/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2018 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
+
+-->
+
+<beans
+        xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
+                      http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
+        bean-discovery-mode="annotated">
+</beans>
diff --git a/tests/integration/jersey-3992/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/jersey-3992/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..091b8ad
--- /dev/null
+++ b/tests/integration/jersey-3992/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013, 2017 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018 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.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 (jakub.podlesak at oracle.com)
+ */
+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/jersey-3992/src/test/java/org/glassfish/jersey/tests/cdi/resources/InheritanceTest.java b/tests/integration/jersey-3992/src/test/java/org/glassfish/jersey/tests/cdi/resources/InheritanceTest.java
new file mode 100644
index 0000000..24479fb
--- /dev/null
+++ b/tests/integration/jersey-3992/src/test/java/org/glassfish/jersey/tests/cdi/resources/InheritanceTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2018 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.client.WebTarget;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ *
+ * @author Gaurav Gupta (gaurav.gupta@payara.fish)
+ */
+public class InheritanceTest extends CdiTest {
+
+    @Test
+    public void testGet() {
+
+        final WebTarget target = target().path("user/count");
+
+        final Response response = target.request().get();
+        assertThat(response.getStatus(), is(200));
+
+    }
+}
diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml
index e7cec86..77d9154 100644
--- a/tests/integration/pom.xml
+++ b/tests/integration/pom.xml
@@ -2,6 +2,7 @@
 <!--
 
     Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
+    Copyright (c) 2018 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
@@ -85,6 +86,7 @@
         <module>jersey-2878</module>
         <module>jersey-2892</module>
         <module>jersey-780</module>
+        <module>jersey-3992</module>
         <module>portability-jersey-1</module>
         <module>portability-jersey-2</module>
         <module>property-check</module>