Skip to content

Commit

Permalink
Enable MP RestClient
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed Oct 11, 2021
1 parent f29b874 commit 6b117d1
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 421 deletions.
4 changes: 2 additions & 2 deletions ext/microprofile/mp-rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>project</artifactId>
<groupId>org.glassfish.jersey.ext.microprofile</groupId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -32,7 +32,7 @@
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-api</artifactId>
<version>2.0</version>
<version>3.0-RC3</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -138,11 +139,11 @@ public Object create(CreationalContext<Object> 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);
Expand Down Expand Up @@ -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);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.

4 changes: 2 additions & 2 deletions ext/microprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<packaging>pom</packaging>

<modules>
<!-- <module>mp-rest-client</module>-->
<module>mp-config</module>
<module>mp-rest-client</module>
<module>mp-config</module>
</modules>


Expand Down
3 changes: 1 addition & 2 deletions tests/integration/microprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
<name>microprofile-integration-project</name>
<modules>
<module>config</module>
<!-- <module>rest-client</module>-->
<!-- <module>rest-client14-compatibility</module>-->
<module>rest-client</module>
</modules>

<build>
Expand Down
16 changes: 10 additions & 6 deletions tests/integration/microprofile/rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>microprofile-integration-project</artifactId>
<groupId>org.glassfish.jersey.tests.integration.microprofile</groupId>
<version>3.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -41,6 +41,10 @@
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ejb</groupId>
<artifactId>jakarta.ejb-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
Expand All @@ -61,7 +65,7 @@
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-tck</artifactId>
<version>2.0</version>
<version>3.0-RC3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -77,25 +81,25 @@
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.21.0</version>
<version>2.27.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<version>1.4.1.Final</version>
<version>1.7.0.Alpha10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
<version>1.4.1.Final</version>
<version>1.7.0.Alpha10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-embedded</artifactId>
<version>2.1.0.Final</version>
<version>3.0.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down
26 changes: 14 additions & 12 deletions tests/integration/microprofile/rest-client/tck-suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
<suite name="microprofile-rest-client-TCK" verbose="2" configfailurepolicy="continue">

<test name="microprofile-rest-client TCK">
<packages>
<package name="org.eclipse.microprofile.rest.client.tck.*">
</package>
</packages>
<classes>
<class name="org.eclipse.microprofile.rest.client.tck.ProxyServerTest">
<methods>
<!--https://github.com/eclipse/microprofile-rest-client/pull/298-->
<exclude name="testProxy"></exclude>
</methods>
</class>
</classes>
<!-- Exclude the TCK tests till the TCK bundle contains references to javax.servlet -->

<!-- <packages>-->
<!-- <package name="org.eclipse.microprofile.rest.client.tck.*">-->
<!-- </package>-->
<!-- </packages>-->
<!-- <classes>-->
<!-- <class name="org.eclipse.microprofile.rest.client.tck.ProxyServerTest">-->
<!-- <methods>-->
<!-- &lt;!&ndash;https://github.com/eclipse/microprofile-rest-client/pull/298&ndash;&gt;-->
<!-- <exclude name="testProxy"></exclude>-->
<!-- </methods>-->
<!-- </class>-->
<!-- </classes>-->
</test>

</suite>
Loading

0 comments on commit 6b117d1

Please sign in to comment.