diff --git a/ext/microprofile/mp-rest-client/pom.xml b/ext/microprofile/mp-rest-client/pom.xml index 02c29396f3..bf65b5ab26 100644 --- a/ext/microprofile/mp-rest-client/pom.xml +++ b/ext/microprofile/mp-rest-client/pom.xml @@ -22,7 +22,7 @@ project org.glassfish.jersey.ext.microprofile - 3.0.0-SNAPSHOT + 3.1.0-SNAPSHOT 4.0.0 @@ -32,7 +32,7 @@ org.eclipse.microprofile.rest.client microprofile-rest-client-api - 2.0 + 3.0-RC3 org.eclipse.microprofile.config 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 8a5fe0de92..48bc397b18 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 @@ -58,6 +58,7 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.glassfish.jersey.internal.util.ReflectionHelper; +import org.glassfish.jersey.microprofile.restclient.internal.LocalizationMessages; /** * Handles proper rest client injection. @@ -138,11 +139,11 @@ public Object create(CreationalContext creationalContext) { getConfigOption(Long.class, CONFIG_READ_TIMEOUT) .ifPresent(aLong -> restClientBuilder.readTimeout(aLong, TimeUnit.MILLISECONDS)); getConfigOption(Boolean.class, CONFIG_FOLLOW_REDIRECTS) - .ifPresent(follow -> VersionSupport.followRedirects(restClientBuilder, follow)); + .ifPresent(follow -> _followRedirects(restClientBuilder, follow)); getConfigOption(String.class, CONFIG_QUERY_PARAM_STYLE) - .ifPresent(value -> VersionSupport.queryParamStyle(restClientBuilder, value)); + .ifPresent(value -> _queryParamStyle(restClientBuilder, value)); getConfigOption(String.class, CONFIG_PROXY_ADDRESS) - .ifPresent(proxy -> VersionSupport.proxyAddress(restClientBuilder, proxy)); + .ifPresent(proxy -> _proxyAddress(restClientBuilder, proxy)); // Providers from configuration addConfiguredProviders(restClientBuilder); @@ -417,4 +418,31 @@ private KeyStoreConfig(KeyStore keyStore, String password) { this.password = password; } } + + private RestClientBuilder _followRedirects(RestClientBuilder restClientBuilder, boolean follow) { + return restClientBuilder.followRedirects(follow); + } + + private 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); + } + + private RestClientBuilder _queryParamStyle(RestClientBuilder restClientBuilder, String style) { + 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/java/org/glassfish/jersey/microprofile/restclient/VersionSupport.java b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/VersionSupport.java deleted file mode 100644 index c3d8da0388..0000000000 --- a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/VersionSupport.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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 currentVersion = Values.lazy((Value) () -> { - 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 index 71f05e0220..3afc639ad8 100644 --- 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 @@ -16,7 +16,3 @@ 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/ext/microprofile/pom.xml b/ext/microprofile/pom.xml index 6bc3d24fe5..9d278bff24 100644 --- a/ext/microprofile/pom.xml +++ b/ext/microprofile/pom.xml @@ -32,8 +32,8 @@ pom - - mp-config + mp-rest-client + mp-config diff --git a/tests/integration/microprofile/pom.xml b/tests/integration/microprofile/pom.xml index e41fdaecfb..c9aec44dea 100644 --- a/tests/integration/microprofile/pom.xml +++ b/tests/integration/microprofile/pom.xml @@ -32,8 +32,7 @@ microprofile-integration-project config - - + rest-client diff --git a/tests/integration/microprofile/rest-client/pom.xml b/tests/integration/microprofile/rest-client/pom.xml index 6d3b5e80ec..87c29a8c69 100644 --- a/tests/integration/microprofile/rest-client/pom.xml +++ b/tests/integration/microprofile/rest-client/pom.xml @@ -23,7 +23,7 @@ microprofile-integration-project org.glassfish.jersey.tests.integration.microprofile - 3.0-SNAPSHOT + 3.1.0-SNAPSHOT 4.0.0 @@ -41,6 +41,10 @@ jakarta.enterprise jakarta.enterprise.cdi-api + + jakarta.ejb + jakarta.ejb-api + org.jboss.weld.se weld-se-core @@ -61,7 +65,7 @@ org.eclipse.microprofile.rest.client microprofile-rest-client-tck - 2.0 + 3.0-RC3 test @@ -77,25 +81,25 @@ com.github.tomakehurst wiremock - 2.21.0 + 2.27.2 test org.jboss.arquillian.testng arquillian-testng-container - 1.4.1.Final + 1.7.0.Alpha10 test org.jboss.arquillian.container arquillian-container-test-spi - 1.4.1.Final + 1.7.0.Alpha10 test org.jboss.arquillian.container arquillian-weld-embedded - 2.1.0.Final + 3.0.0.Final test diff --git a/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/restclient/InboundHeadersProviderTest.java b/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/restclient/InboundHeadersProviderTest.java index fe043bae21..5828d01001 100644 --- a/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/restclient/InboundHeadersProviderTest.java +++ b/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/restclient/InboundHeadersProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -24,8 +24,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; -import javax.json.Json; -import javax.json.JsonObject; +import jakarta.json.Json; +import jakarta.json.JsonObject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.container.AsyncResponse; diff --git a/tests/integration/microprofile/rest-client/tck-suite.xml b/tests/integration/microprofile/rest-client/tck-suite.xml index a317e79ede..66f52cad31 100644 --- a/tests/integration/microprofile/rest-client/tck-suite.xml +++ b/tests/integration/microprofile/rest-client/tck-suite.xml @@ -20,18 +20,20 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/tests/integration/microprofile/rest-client14-compatibility/pom.xml b/tests/integration/microprofile/rest-client14-compatibility/pom.xml deleted file mode 100644 index 567c6f4252..0000000000 --- a/tests/integration/microprofile/rest-client14-compatibility/pom.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - microprofile-integration-project - org.glassfish.jersey.tests.integration.microprofile - 3.1.0-SNAPSHOT - - 4.0.0 - - jersey-rest-client14-compatibility - - - - org.glassfish.jersey.ext.microprofile - jersey-mp-rest-client - ${project.version} - test - - - jakarta.enterprise - jakarta.enterprise.cdi-api - - - javax.enterprise - cdi-api - - - org.eclipse.microprofile.rest.client - microprofile-rest-client-api - - - - - - jakarta.enterprise - jakarta.enterprise.cdi-api - test - - - org.eclipse.microprofile.rest.client - microprofile-rest-client-api - - 1.4.1 - test - - - org.glassfish.jersey.ext.cdi - jersey-weld2-se - test - - - org.jboss.weld.se - weld-se-core - test - - - org.glassfish.jersey.ext.cdi - jersey-cdi1x - test - - - io.smallrye.config - smallrye-config - 1.8.4 - test - - - javax.enterprise - cdi-api - - - - - junit - junit - test - - - org.glassfish.jersey.test-framework - jersey-test-framework-core - test - - - org.glassfish.jersey.test-framework.providers - jersey-test-framework-provider-bundle - pom - test - - - org.glassfish.jersey.ext.cdi - jersey-weld2-se - test - - - 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 deleted file mode 100644 index 16476e8a50..0000000000 --- a/tests/integration/microprofile/rest-client14-compatibility/src/test/java/org/glassfish/jersey/tests/restclient/compatibility/Compatibility14Test.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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 jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.core.Application; -import jakarta.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 deleted file mode 100644 index 70897bddc7..0000000000 --- a/tests/integration/microprofile/rest-client14-compatibility/src/test/resources/META-INF/beans.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - 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 deleted file mode 100644 index 616d54535b..0000000000 --- a/tests/integration/microprofile/rest-client14-compatibility/src/test/resources/META-INF/microprofile-config.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# 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