Prevent NoSuchMethodError when used MP Rest Client 1.4 API & CDI (#4835)

Signed-off-by: jansupol <jan.supol@oracle.com>
diff --git a/ext/microprofile/mp-rest-client/pom.xml b/ext/microprofile/mp-rest-client/pom.xml
index 15b94be..4e1d2e2 100644
--- a/ext/microprofile/mp-rest-client/pom.xml
+++ b/ext/microprofile/mp-rest-client/pom.xml
@@ -99,6 +99,11 @@
     <build>
         <plugins>
             <plugin>
+                <groupId>com.sun.istack</groupId>
+                <artifactId>istack-commons-maven-plugin</artifactId>
+                <inherited>true</inherited>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <inherited>true</inherited>
diff --git a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/InterfaceModel.java b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/InterfaceModel.java
index 09dd904..076eb66 100644
--- a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/InterfaceModel.java
+++ b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/InterfaceModel.java
@@ -35,18 +35,13 @@
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.ParamConverterProvider;
 
 import org.eclipse.microprofile.rest.client.RestClientDefinitionException;
 import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam;
 import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
-import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptor;
-import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory;
 import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory;
-import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;
 import org.glassfish.jersey.client.inject.ParameterUpdater;
 import org.glassfish.jersey.client.inject.ParameterUpdaterProvider;
-import org.glassfish.jersey.internal.inject.InjectionManager;
 import org.glassfish.jersey.internal.inject.Providers;
 import org.glassfish.jersey.model.Parameter;
 
diff --git a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientExtension.java b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientExtension.java
index 58fca82..ab69937 100644
--- a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientExtension.java
+++ b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientExtension.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2021 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
@@ -16,8 +16,6 @@
 
 package org.glassfish.jersey.microprofile.restclient;
 
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -26,20 +24,12 @@
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.DeploymentException;
 import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
-import javax.enterprise.inject.spi.ProcessInjectionPoint;
 import javax.enterprise.inject.spi.WithAnnotations;
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Qualifier;
 
 import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
 import org.eclipse.microprofile.rest.client.inject.RestClient;
 
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
 /**
  * Filters out all interfaces annotated with {@link RegisterRestClient}
  * and creates new Producer from each of these selected interfaces.
diff --git a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientModel.java b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientModel.java
index 59edbc1..81e5d87 100644
--- a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientModel.java
+++ b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientModel.java
@@ -20,17 +20,9 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
-import javax.enterprise.inject.spi.BeanManager;
 import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.ext.ParamConverterProvider;
-
-import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory;
-import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;
-import org.glassfish.jersey.internal.inject.InjectionManager;
 
 /**
  * Model of the rest client interface.
diff --git a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientProducer.java b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientProducer.java
index 57fedd8..eb3181b 100644
--- a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientProducer.java
+++ b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/RestClientProducer.java
@@ -55,7 +55,6 @@
 import org.eclipse.microprofile.config.Config;
 import org.eclipse.microprofile.config.ConfigProvider;
 import org.eclipse.microprofile.rest.client.RestClientBuilder;
-import org.eclipse.microprofile.rest.client.ext.QueryParamStyle;
 import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
 import org.eclipse.microprofile.rest.client.inject.RestClient;
 import org.glassfish.jersey.internal.util.ReflectionHelper;
@@ -139,26 +138,11 @@
         getConfigOption(Long.class, CONFIG_READ_TIMEOUT)
                 .ifPresent(aLong -> restClientBuilder.readTimeout(aLong, TimeUnit.MILLISECONDS));
         getConfigOption(Boolean.class, CONFIG_FOLLOW_REDIRECTS)
-                .ifPresent(restClientBuilder::followRedirects);
+                .ifPresent(follow -> VersionSupport.followRedirects(restClientBuilder, follow));
         getConfigOption(String.class, CONFIG_QUERY_PARAM_STYLE)
-                .ifPresent(value -> restClientBuilder.queryParamStyle(QueryParamStyle.valueOf(value)));
+                .ifPresent(value -> VersionSupport.queryParamStyle(restClientBuilder, value));
         getConfigOption(String.class, CONFIG_PROXY_ADDRESS)
-                .ifPresent(proxy -> {
-                    int index = proxy.lastIndexOf(':');
-                    //If : was not found at all or it is the last character of the proxy string
-                    if (index < 0 || proxy.length() - 1 == index) {
-                        throw new IllegalArgumentException("Invalid proxy URI: " + proxy);
-                    }
-                    String proxyHost = proxy.substring(0, index);
-                    int proxyPort;
-                    String proxyPortStr = proxy.substring(index + 1);
-                    try {
-                        proxyPort = Integer.parseInt(proxyPortStr);
-                    } catch (NumberFormatException nfe) {
-                        throw new IllegalArgumentException("Invalid proxy port: " + proxyPortStr, nfe);
-                    }
-                    restClientBuilder.proxyAddress(proxyHost, proxyPort);
-                });
+                .ifPresent(proxy -> VersionSupport.proxyAddress(restClientBuilder, proxy));
 
         // Providers from configuration
         addConfiguredProviders(restClientBuilder);
diff --git a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/VersionSupport.java b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/VersionSupport.java
new file mode 100644
index 0000000..c3d8da0
--- /dev/null
+++ b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/VersionSupport.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2021 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.microprofile.restclient;
+
+import org.eclipse.microprofile.rest.client.RestClientBuilder;
+import org.glassfish.jersey.microprofile.restclient.internal.LocalizationMessages;
+import org.glassfish.jersey.internal.util.collection.LazyValue;
+import org.glassfish.jersey.internal.util.collection.Value;
+import org.glassfish.jersey.internal.util.collection.Values;
+
+import java.util.logging.Logger;
+
+/**
+ * Backward compatibility support not to throw an exception when an old API is used.
+ */
+abstract class VersionSupport {
+
+    protected abstract RestClientBuilder _followRedirects(RestClientBuilder restClientBuilder, boolean follow);
+    protected abstract RestClientBuilder _proxyAddress(RestClientBuilder restClientBuilder, String proxy);
+    protected abstract RestClientBuilder _queryParamStyle(RestClientBuilder restClientBuilder, String style);
+
+    private static final Logger logger = Logger.getLogger(VersionSupport.class.getName());
+
+    // determine the version only once per jvm
+    private static LazyValue<VersionSupport> currentVersion = Values.lazy((Value<VersionSupport>) () -> {
+        final Class<?> restClientBuilderClass = RestClientBuilder.class;
+        try {
+            if (null != restClientBuilderClass.getMethod("followRedirects", boolean.class)) {
+                return new Version20Support();
+            }
+        } catch (NoSuchMethodException e) {
+            // VERSION 1.4
+        }
+        return new Version14Support();
+    });
+
+    static RestClientBuilder followRedirects(RestClientBuilder restClientBuilder, boolean follow) {
+        return currentVersion.get()._followRedirects(restClientBuilder, follow);
+    }
+
+    static RestClientBuilder proxyAddress(RestClientBuilder restClientBuilder, String proxy) {
+        return currentVersion.get()._proxyAddress(restClientBuilder, proxy);
+    }
+
+    static RestClientBuilder queryParamStyle(RestClientBuilder restClientBuilder, String style) {
+        return currentVersion.get()._queryParamStyle(restClientBuilder, style);
+    }
+
+    private static class Version14Support extends VersionSupport {
+        protected RestClientBuilder _followRedirects(RestClientBuilder restClientBuilder, boolean follow) {
+            logger.warning(LocalizationMessages.WARN_VERSION_14_FOLLOWREDIRECT());
+            return restClientBuilder;
+        }
+
+        protected RestClientBuilder _proxyAddress(RestClientBuilder restClientBuilder, String proxy) {
+            logger.warning(LocalizationMessages.WARN_VERSION_14_PROXY());
+            return restClientBuilder;
+        }
+
+        protected RestClientBuilder _queryParamStyle(RestClientBuilder restClientBuilder, String style) {
+            logger.warning(LocalizationMessages.WARN_VERSION_14_QUERYPARAMSTYLE());
+            return restClientBuilder;
+        }
+    }
+
+    private static class Version20Support extends VersionSupport {
+        protected RestClientBuilder _followRedirects(RestClientBuilder restClientBuilder, boolean follow) {
+            return restClientBuilder.followRedirects(follow);
+        }
+
+        protected RestClientBuilder _proxyAddress(RestClientBuilder restClientBuilder, String proxy) {
+            int index = proxy.lastIndexOf(':');
+            //If : was not found at all or it is the last character of the proxy string
+            if (index < 0 || proxy.length() - 1 == index) {
+                throw new IllegalArgumentException(LocalizationMessages.ERR_INVALID_PROXY_URI(proxy));
+            }
+            String proxyHost = proxy.substring(0, index);
+            int proxyPort;
+            String proxyPortStr = proxy.substring(index + 1);
+            try {
+                proxyPort = Integer.parseInt(proxyPortStr);
+            } catch (NumberFormatException nfe) {
+                throw new IllegalArgumentException(LocalizationMessages.ERR_INVALID_PROXY_PORT(proxyPortStr), nfe);
+            }
+            return restClientBuilder.proxyAddress(proxyHost, proxyPort);
+        }
+
+        protected RestClientBuilder _queryParamStyle(RestClientBuilder restClientBuilder, String style) {
+            // do not import for compatibility with 1.4
+            org.eclipse.microprofile.rest.client.ext.QueryParamStyle queryParamStyle =
+                    org.eclipse.microprofile.rest.client.ext.QueryParamStyle.valueOf(style);
+            return restClientBuilder.queryParamStyle(queryParamStyle);
+        }
+    }
+}
diff --git a/ext/microprofile/mp-rest-client/src/main/resources/org/glassfish/jersey/microprofile/restclient/internal/localization.properties b/ext/microprofile/mp-rest-client/src/main/resources/org/glassfish/jersey/microprofile/restclient/internal/localization.properties
new file mode 100644
index 0000000..71f05e0
--- /dev/null
+++ b/ext/microprofile/mp-rest-client/src/main/resources/org/glassfish/jersey/microprofile/restclient/internal/localization.properties
@@ -0,0 +1,22 @@
+#
+# Copyright (c) 2021 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
+#
+
+err.invalid.proxy.uri=Invalid proxy URI: {0}.
+err.invalid.proxy.port=Invalid proxy port: {0}.
+warn.version14.followredirect=MP Rest Client Version 1.4 does not support RestClientBuilder#followRedirect and it is ignored.
+warn.version14.proxy=MP Rest Client Version 1.4 does not support RestClientBuilder#proxy and it is ignored.
+warn.version14.queryparamstyle=MP Rest Client Version 1.4 does not support RestClientBuilder#queryParamStyle and it is ignored.
+
diff --git a/tests/integration/cdi-integration/pom.xml b/tests/integration/cdi-integration/pom.xml
index 9f7719d..6c0bfec 100644
--- a/tests/integration/cdi-integration/pom.xml
+++ b/tests/integration/cdi-integration/pom.xml
@@ -42,6 +42,7 @@
         <module>cdi-multimodule</module>
         <module>cdi-multipart-webapp</module>
         <module>cdi-resource-with-at-context</module>
+        <module>cdi-singleton</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>
diff --git a/tests/integration/microprofile/pom.xml b/tests/integration/microprofile/pom.xml
index e4e329f..882eab2 100644
--- a/tests/integration/microprofile/pom.xml
+++ b/tests/integration/microprofile/pom.xml
@@ -33,6 +33,7 @@
     <modules>
         <module>config</module>
         <module>rest-client</module>
+        <module>rest-client14-compatibility</module>
     </modules>
 
     <build>
diff --git a/tests/integration/microprofile/rest-client14-compatibility/pom.xml b/tests/integration/microprofile/rest-client14-compatibility/pom.xml
new file mode 100644
index 0000000..d831d9b
--- /dev/null
+++ b/tests/integration/microprofile/rest-client14-compatibility/pom.xml
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2021 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">
+    <parent>
+        <artifactId>microprofile-integration-project</artifactId>
+        <groupId>org.glassfish.jersey.tests.integration.microprofile</groupId>
+        <version>2.35-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>jersey-rest-client14-compatibility</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.glassfish.jersey.ext.microprofile</groupId>
+            <artifactId>jersey-mp-rest-client</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>jakarta.enterprise</groupId>
+                    <artifactId>jakarta.enterprise.cdi-api</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>javax.enterprise</groupId>
+                    <artifactId>cdi-api</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.eclipse.microprofile.rest.client</groupId>
+                    <artifactId>microprofile-rest-client-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <!-- Overrides CDI from parent pom -->
+        <dependency>
+            <groupId>jakarta.enterprise</groupId>
+            <artifactId>jakarta.enterprise.cdi-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.microprofile.rest.client</groupId>
+            <artifactId>microprofile-rest-client-api</artifactId>
+            <!-- specifically this version we check with the backward compatibility -->
+            <version>1.4.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.ext.cdi</groupId>
+            <artifactId>jersey-weld2-se</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.weld.se</groupId>
+            <artifactId>weld-se-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.ext.cdi</groupId>
+            <artifactId>jersey-cdi1x</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.smallrye.config</groupId>
+            <artifactId>smallrye-config</artifactId>
+            <version>1.8.4</version> <!-- Workswith CQ 22471 -->
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>javax.enterprise</groupId>
+                    <artifactId>cdi-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.test-framework</groupId>
+            <artifactId>jersey-test-framework-core</artifactId>
+            <scope>test</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>
+</project>
diff --git a/tests/integration/microprofile/rest-client14-compatibility/src/test/java/org/glassfish/jersey/tests/restclient/compatibility/Compatibility14Test.java b/tests/integration/microprofile/rest-client14-compatibility/src/test/java/org/glassfish/jersey/tests/restclient/compatibility/Compatibility14Test.java
new file mode 100644
index 0000000..8507722
--- /dev/null
+++ b/tests/integration/microprofile/rest-client14-compatibility/src/test/java/org/glassfish/jersey/tests/restclient/compatibility/Compatibility14Test.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2021 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.restclient.compatibility;
+
+import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
+import org.eclipse.microprofile.rest.client.inject.RestClient;
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.ServerProperties;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+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.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+public class Compatibility14Test extends JerseyTest {
+    private Weld weld;
+
+    @Before
+    public void setup() {
+        Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+            weld = new Weld();
+            weld.initialize();
+            super.setUp();
+        }
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+            weld.shutdown();
+            super.tearDown();
+        }
+    }
+
+    @RegisterRestClient
+    public static interface CompatibilityClient {
+        @GET
+        public String get();
+    }
+
+    @Path("/resource")
+    @RequestScoped
+    public static class CompatibilityResource {
+
+        @Inject
+        @RestClient
+        CompatibilityClient client;
+
+        @GET
+        public String get() {
+            return client.get();
+        }
+    }
+
+    @Path("/inner")
+    public static class InnerResource implements CompatibilityClient {
+
+        public String get() {
+            return "INNER";
+        }
+    }
+
+    @Override
+    protected Application configure() {
+        set(TestProperties.RECORD_LOG_LEVEL, Level.WARNING.intValue());
+        return new ResourceConfig(InnerResource.class, CompatibilityResource.class)
+                .property(ServerProperties.WADL_FEATURE_DISABLE, true);
+    }
+
+    @Test
+    public void testCompatibility() {
+        final String loggerName = "org.glassfish.jersey.microprofile.restclient.VersionSupport";
+
+        try (Response r = target("/resource").request().get()) {
+            String entity = r.readEntity(String.class);
+            Assert.assertEquals(new InnerResource().get(), entity);
+        }
+
+        int warningCounts = 0;
+        for (final LogRecord logRecord : getLoggedRecords()) {
+            if (loggerName.equals(logRecord.getLoggerName()) && logRecord.getLevel() == Level.WARNING) {
+                warningCounts++;
+            }
+        }
+
+        Assert.assertEquals(3, warningCounts);
+    }
+}
diff --git a/tests/integration/microprofile/rest-client14-compatibility/src/test/resources/META-INF/beans.xml b/tests/integration/microprofile/rest-client14-compatibility/src/test/resources/META-INF/beans.xml
new file mode 100644
index 0000000..70897bd
--- /dev/null
+++ b/tests/integration/microprofile/rest-client14-compatibility/src/test/resources/META-INF/beans.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2021 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://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/microprofile/rest-client14-compatibility/src/test/resources/META-INF/microprofile-config.properties b/tests/integration/microprofile/rest-client14-compatibility/src/test/resources/META-INF/microprofile-config.properties
new file mode 100644
index 0000000..616d545
--- /dev/null
+++ b/tests/integration/microprofile/rest-client14-compatibility/src/test/resources/META-INF/microprofile-config.properties
@@ -0,0 +1,19 @@
+#
+# Copyright (c) 2021 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
+
+org.glassfish.jersey.tests.restclient.compatibility.Compatibility14Test$CompatibilityClient/mp-rest/uri=http://localhost:9998/inner
+org.glassfish.jersey.tests.restclient.compatibility.Compatibility14Test$CompatibilityClient/mp-rest/followRedirects=true
+org.glassfish.jersey.tests.restclient.compatibility.Compatibility14Test$CompatibilityClient/mp-rest/queryParamStyle=COMMA_SEPARATED
+org.glassfish.jersey.tests.restclient.compatibility.Compatibility14Test$CompatibilityClient/mp-rest/proxyAddress=http://localhost:1010/nowehere
\ No newline at end of file