From f9b98158ef035b89075348816eb9b4cef60af6c9 Mon Sep 17 00:00:00 2001 From: alexole01 Date: Mon, 13 Jan 2025 15:32:16 +0100 Subject: [PATCH] JIRA:GRIF-99 upgrade to jdk17 --- .github/workflows/build.yml | 20 ++-- .sonar.settings | 2 +- pom.xml | 41 +++++--- .../com/gooddata/sdk/common/UriPrefixer.java | 13 ++- .../UriPrefixingClientHttpRequestFactory.java | 95 ------------------- .../sdk/common/UriPrefixingWebClient.java | 63 ++++++++++++ .../gdc/ErrorStructureDeserializer.java | 3 +- ...efixingClientHttpRequestFactoryTest.groovy | 50 ---------- .../common/UriPrefixingWebClientTest.groovy | 50 ++++++++++ 9 files changed, 166 insertions(+), 171 deletions(-) delete mode 100644 src/main/java/com/gooddata/sdk/common/UriPrefixingClientHttpRequestFactory.java create mode 100644 src/main/java/com/gooddata/sdk/common/UriPrefixingWebClient.java delete mode 100644 src/test/groovy/com/gooddata/sdk/common/UriPrefixingClientHttpRequestFactoryTest.groovy create mode 100644 src/test/groovy/com/gooddata/sdk/common/UriPrefixingWebClientTest.groovy diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7aa6c23..01c7c39 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,11 +15,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v2 + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 with: - java-version: '11' + java-version: '17' distribution: 'adopt' - uses: actions/cache@v2 with: @@ -29,9 +29,9 @@ jobs: - name: Run build steps and generate coverage report with Maven run: | mvn verify javadoc:javadoc jacoco:report -Pcoverage -B -V - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v1 - with: - file: ./**/target/site/jacoco/jacoco.xml - name: codecov - fail_ci_if_error: true +# - name: Upload coverage report to Codecov +# uses: codecov/codecov-action@v1 +# with: +# file: ./**/target/site/jacoco/jacoco.xml +# name: codecov +# fail_ci_if_error: true diff --git a/.sonar.settings b/.sonar.settings index 7aeeae8..1611fb1 100644 --- a/.sonar.settings +++ b/.sonar.settings @@ -1,2 +1,2 @@ # Settings for sonar scan -gdc.java_version=openjdk-11 +gdc.java_version=openjdk-17 diff --git a/pom.xml b/pom.xml index 81a0fb9..45fbb39 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 gooddata-rest-common - 2.0.1-SNAPSHOT + 3.0.0-SNAPSHOT ${project.artifactId} GoodData REST Common Library https://github.com/gooddata/gooddata-rest-common @@ -11,7 +11,7 @@ com.gooddata gooddata-parent - 3.1.0 + 4.0.0 @@ -39,10 +39,10 @@ - 2.13.3 - 2.13.3 - 5.3.21 - 2.35.0 + 2.15.3 + 2.15.3 + 6.0.23 + 2.38.0 @@ -53,7 +53,7 @@ org.codehaus.gmavenplus gmavenplus-plugin - 1.13.1 + 3.0.2 @@ -74,7 +74,7 @@ org.jacoco jacoco-maven-plugin - 0.8.8 + 0.8.11 jacoco-prepare-agent @@ -117,13 +117,28 @@ org.apache.commons commons-lang3 - 3.12.0 + 3.13.0 org.springframework spring-core ${spring.version} + + org.springframework.boot + spring-boot-starter-web + 3.0.13 + + + org.springframework.boot + spring-boot-starter-webflux + 3.0.13 + + + org.springframework + spring-webflux + ${spring.version} + org.springframework spring-web @@ -165,7 +180,7 @@ commons-io commons-io - 2.7 + 2.15.0 @@ -177,7 +192,7 @@ org.spockframework spock-core - 1.3-groovy-2.5 + 2.4-M1-groovy-4.0 test @@ -187,9 +202,9 @@ test - org.codehaus.groovy + org.apache.groovy groovy - 2.5.14 + 4.0.17 test diff --git a/src/main/java/com/gooddata/sdk/common/UriPrefixer.java b/src/main/java/com/gooddata/sdk/common/UriPrefixer.java index f27e960..8c5f251 100644 --- a/src/main/java/com/gooddata/sdk/common/UriPrefixer.java +++ b/src/main/java/com/gooddata/sdk/common/UriPrefixer.java @@ -91,4 +91,15 @@ public URI mergeUris(String uri) { notEmpty(uri, "uri"); return mergeUris(URI.create(uri)); } -} \ No newline at end of file + + /** + * Prefix the given URI with the URI prefix. + * + * @param uri the URI to prefix + * @return the prefixed URI + */ + public URI prefixUri(URI uri) { + return mergeUris(uri); // Use existing merging logic + } + +} diff --git a/src/main/java/com/gooddata/sdk/common/UriPrefixingClientHttpRequestFactory.java b/src/main/java/com/gooddata/sdk/common/UriPrefixingClientHttpRequestFactory.java deleted file mode 100644 index fefd5ea..0000000 --- a/src/main/java/com/gooddata/sdk/common/UriPrefixingClientHttpRequestFactory.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE.txt file in the root directory of this source tree. - */ -package com.gooddata.sdk.common; - -import org.springframework.http.HttpMethod; -import org.springframework.http.client.AsyncClientHttpRequest; -import org.springframework.http.client.AsyncClientHttpRequestFactory; -import org.springframework.http.client.ClientHttpRequest; -import org.springframework.http.client.ClientHttpRequestFactory; -import org.springframework.web.util.UriComponentsBuilder; - -import java.io.IOException; -import java.net.URI; - -import static com.gooddata.sdk.common.util.Validate.notNull; - -/** - * Factory for ClientHttpRequest and AsyncClientHttpRequest objects. - * The factory allows you to specify hostname and port for Spring REST client which by default requires absolute URI. - */ -@SuppressWarnings("deprecation") -public class UriPrefixingClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory { - - private final ClientHttpRequestFactory wrapped; - private final UriPrefixer prefixer; - - /** - * Create an instance that will wrap the given {@link org.springframework.http.client.ClientHttpRequestFactory} - * and use the given URI for setting hostname and port of all HTTP requests - * - * @param factory the factory to be wrapped - * @param uriPrefix the URI for setting hostname and port of all HTTP requests - */ - public UriPrefixingClientHttpRequestFactory(final ClientHttpRequestFactory factory, final URI uriPrefix) { - this(factory, new UriPrefixer(uriPrefix)); - } - - /** - * Create an instance that will wrap the given {@link org.springframework.http.client.ClientHttpRequestFactory} - * and use the given hostname, port, and protocol for all HTTP requests - * - * @param factory the factory to be wrapped - * @param uri the URI for setting hostname and port of all HTTP requests - */ - public UriPrefixingClientHttpRequestFactory(final ClientHttpRequestFactory factory, final String uri) { - this(factory, URI.create(uri)); - } - - /** - * Create an instance that will wrap the given {@link org.springframework.http.client.ClientHttpRequestFactory} - * and use the given protocol, hostname and port for all HTTP requests - * - * @param factory the factory to be wrapped - * @param protocol the protocol for all HTTP requests - * @param hostname the hostname for all HTTP requests - * @param port the port for all HTTP requests - */ - public UriPrefixingClientHttpRequestFactory(final ClientHttpRequestFactory factory, - final String protocol, - final String hostname, - final int port) { - this(factory, UriComponentsBuilder.newInstance().scheme(protocol).host(hostname).port(port).build().toUri()); - } - - private UriPrefixingClientHttpRequestFactory(final ClientHttpRequestFactory factory, final UriPrefixer prefixer) { - this.wrapped = notNull(factory, "factory"); - this.prefixer = notNull(prefixer, "prefixer"); - } - - @Override - public ClientHttpRequest createRequest(final URI uri, final HttpMethod httpMethod) throws IOException { - final URI merged = prefixer.mergeUris(uri); - return wrapped.createRequest(merged, httpMethod); - } - - /** - * If wrapped ClientHttpRequestFactory is not instance of AsyncClientHttpRequestFactory createAsyncRequest - * fails with UnsupportedOperationException. - * - * @throws UnsupportedOperationException if wrapped is not AsyncClientHttpRequestFactory - */ - @Override - public AsyncClientHttpRequest createAsyncRequest(final URI uri, final HttpMethod httpMethod) throws IOException { - if (wrapped instanceof AsyncClientHttpRequestFactory) { - final URI merged = prefixer.mergeUris(uri); - return ((AsyncClientHttpRequestFactory) wrapped).createAsyncRequest(merged, httpMethod); - } else { - throw new UnsupportedOperationException("Wrapped factory has to be instance of AsyncClientHttpRequestFactory to support this method"); - } - } - -} \ No newline at end of file diff --git a/src/main/java/com/gooddata/sdk/common/UriPrefixingWebClient.java b/src/main/java/com/gooddata/sdk/common/UriPrefixingWebClient.java new file mode 100644 index 0000000..0e0461b --- /dev/null +++ b/src/main/java/com/gooddata/sdk/common/UriPrefixingWebClient.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE.txt file in the root directory of this source tree. + */ +package com.gooddata.sdk.common; + +import org.springframework.http.HttpMethod; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.util.UriComponentsBuilder; + +import java.net.URI; + +import static com.gooddata.sdk.common.util.Validate.notNull; + +/** + * Factory for creating HTTP requests using WebClient. + * The factory allows you to specify hostname and port for Spring REST client which by default requires absolute URI. + */ +public class UriPrefixingWebClient { + + private final WebClient webClient; + private final UriPrefixer prefixer; + + /** + * Create an instance that uses the given {@link WebClient.Builder} + * and URI prefix for all HTTP requests. + * + * @param webClientBuilder the WebClient builder + * @param uriPrefix the URI for setting hostname and port of all HTTP requests + */ + public UriPrefixingWebClient(final WebClient.Builder webClientBuilder, final URI uriPrefix) { + this(webClientBuilder, new UriPrefixer(uriPrefix)); + } + + /** + * Create an instance that uses the given {@link WebClient.Builder} + * and URI prefix for all HTTP requests. + * + * @param webClientBuilder the WebClient builder + * @param uri the URI for setting hostname and port of all HTTP requests + */ + public UriPrefixingWebClient(final WebClient.Builder webClientBuilder, final String uri) { + this(webClientBuilder, URI.create(uri)); + } + + private UriPrefixingWebClient(final WebClient.Builder webClientBuilder, final UriPrefixer prefixer) { + this.webClient = notNull(webClientBuilder, "webClientBuilder").build(); + this.prefixer = notNull(prefixer, "prefixer"); + } + + /** + * Create a request with the given path and HTTP method. + * + * @param path the path for the HTTP request + * @param httpMethod the HTTP method (e.g., GET, POST) + * @return the WebClient.RequestHeadersSpec to customize and execute the request + */ + public WebClient.RequestHeadersSpec createRequest(final String path, final HttpMethod httpMethod) { + final URI prefixedUri = prefixer.prefixUri(URI.create(path)); + return webClient.method(httpMethod).uri(prefixedUri); + } +} diff --git a/src/main/java/com/gooddata/sdk/common/gdc/ErrorStructureDeserializer.java b/src/main/java/com/gooddata/sdk/common/gdc/ErrorStructureDeserializer.java index 162a3aa..3e33dae 100644 --- a/src/main/java/com/gooddata/sdk/common/gdc/ErrorStructureDeserializer.java +++ b/src/main/java/com/gooddata/sdk/common/gdc/ErrorStructureDeserializer.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.core.TreeNode; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; @@ -38,7 +39,7 @@ public ErrorStructure deserialize(JsonParser jp, DeserializationContext ctxt) th clazz = DefaultDeserializerErrorStructure.class; } } else { - throw ctxt.mappingException("Unknown type of ErrorStructure"); + throw JsonMappingException.from(ctxt, "Unknown type of ErrorStructure"); } final JsonParser nextParser = tokenBuffer.asParser(); diff --git a/src/test/groovy/com/gooddata/sdk/common/UriPrefixingClientHttpRequestFactoryTest.groovy b/src/test/groovy/com/gooddata/sdk/common/UriPrefixingClientHttpRequestFactoryTest.groovy deleted file mode 100644 index e9e35f3..0000000 --- a/src/test/groovy/com/gooddata/sdk/common/UriPrefixingClientHttpRequestFactoryTest.groovy +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE.txt file in the root directory of this source tree. - */ -package com.gooddata.sdk.common - -import org.springframework.core.task.SimpleAsyncTaskExecutor -import org.springframework.http.HttpMethod -import org.springframework.http.client.ClientHttpRequestFactory -import org.springframework.http.client.SimpleClientHttpRequestFactory -import spock.lang.Shared -import spock.lang.Specification - -class UriPrefixingClientHttpRequestFactoryTest extends Specification { - - @Shared WRAPPED = new SimpleClientHttpRequestFactory() - - void setupSpec() { - WRAPPED.setTaskExecutor(new SimpleAsyncTaskExecutor()) - } - - def "should create prefixed request"() { - when: - def request = requestFactory."$method" URI.create('/gdc/resource'), HttpMethod.GET - - then: - request.URI.toString() == 'http://localhost:1234/gdc/resource' - - where: - [requestFactory, method] << [ - [new UriPrefixingClientHttpRequestFactory(WRAPPED, 'http', 'localhost', 1234), - new UriPrefixingClientHttpRequestFactory(WRAPPED, 'http://localhost:1234')], - ['createRequest', 'createAsyncRequest'] - ].combinations() - } - - def "should not createAsyncRequest without async factory"() { - given: - ClientHttpRequestFactory wrapped = { uri, httpMethod -> null } - UriPrefixingClientHttpRequestFactory requestFactory = new UriPrefixingClientHttpRequestFactory(wrapped, "http", "localhost", 1234) - - when: - requestFactory.createAsyncRequest(URI.create("/gdc/resource"), HttpMethod.GET) - - then: - thrown(UnsupportedOperationException) - } - -} diff --git a/src/test/groovy/com/gooddata/sdk/common/UriPrefixingWebClientTest.groovy b/src/test/groovy/com/gooddata/sdk/common/UriPrefixingWebClientTest.groovy new file mode 100644 index 0000000..cfc5e03 --- /dev/null +++ b/src/test/groovy/com/gooddata/sdk/common/UriPrefixingWebClientTest.groovy @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved. + * This source code is licensed under the BSD-style license found in the + * LICENSE.txt file in the root directory of this source tree. + */ +package com.gooddata.sdk.common + +import org.springframework.http.HttpMethod +import org.springframework.web.reactive.function.client.WebClient +import spock.lang.Shared +import spock.lang.Specification + +class UriPrefixingWebClientTest extends Specification { + + @Shared + def webClientBuilder = WebClient.builder() + + def "should create prefixed request"() { + given: + def prefixer = new UriPrefixer('http://localhost:1234') + def requestFactory = new UriPrefixingWebClient(webClientBuilder, prefixer) + + when: + def uri = prefixer.prefixUri(URI.create('/gdc/resource')) + + then: + uri.toString() == 'http://localhost:1234/gdc/resource' + } + + def "should handle invalid URI gracefully"() { + given: + def prefixer = new UriPrefixer('http://localhost:1234') + def requestFactory = new UriPrefixingWebClient(webClientBuilder, prefixer) + + when: + requestFactory.createRequest('/invalid uri', HttpMethod.GET) + + then: + thrown(IllegalArgumentException) + } + + def "should handle multiple constructors of UriPrefixer"() { + when: + def prefixer1 = new UriPrefixer('http://localhost:1234') + def prefixer2 = new UriPrefixer(URI.create('http://localhost:1234')) + + then: + prefixer1.getUriPrefix() == prefixer2.getUriPrefix() + } +}