Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@v5
with:
file: ./**/target/site/jacoco/jacoco.xml
name: codecov
fail_ci_if_error: true
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>gooddata-rest-common</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>GoodData REST Common Library</description>
<url>https://github.com/gooddata/gooddata-rest-common</url>
Expand Down Expand Up @@ -74,7 +74,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<version>0.7.0</version>
<executions>
<execution>
<id>jacoco-prepare-agent</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.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;


// AsyncClientHttpRequestFactory and createAsyncRequest was removed in Spring 5.0/6.0
// so this class is no longer used in the SDK. It is kept here for backward compatibility

/**
* now for calling use RestTemplate with UriPrefixingClientHttpRequestFactory
*
* import org.springframework.web.client.RestTemplate;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class AsyncRestTemplateExample {

private final RestTemplate restTemplate;
private final ExecutorService executor = Executors.newFixedThreadPool(8);

public AsyncRestTemplateExample(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}

public CompletableFuture<String> getAsync(String url) {
return CompletableFuture.supplyAsync(() ->
restTemplate.getForObject(url, String.class), executor);
}
}


and used:

// Create a RestTemplate with a URI prefixing factory
RestTemplate restTemplate = new RestTemplate(
new UriPrefixingClientHttpRequestFactory(
* e.g., HttpComponentsClientHttpRequestFactory *,
"https://my-api.example.com"
)
);

// Create an instance of the asynchronous RestTemplate wrapper
AsyncRestTemplateExample asyncExample = new AsyncRestTemplateExample(restTemplate);

// Perform an asynchronous GET request and print the response when ready
asyncExample.getAsync("/my/resource")
.thenAccept(response -> System.out.println("Response: " + response));

*
*
*
*/



public class UriPrefixingClientHttpRequestFactory implements ClientHttpRequestFactory {

private final ClientHttpRequestFactory wrapped;
private final UriPrefixer prefixer;

public UriPrefixingClientHttpRequestFactory(final ClientHttpRequestFactory factory, final URI uriPrefix) {
this(factory, new UriPrefixer(uriPrefix));
}

public UriPrefixingClientHttpRequestFactory(final ClientHttpRequestFactory factory, final String uri) {
this(factory, URI.create(uri));
}

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);
}
}
63 changes: 0 additions & 63 deletions src/main/java/com/gooddata/sdk/common/UriPrefixingWebClient.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,26 @@
package com.gooddata.sdk.common

import org.springframework.http.HttpMethod
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.http.client.SimpleClientHttpRequestFactory
import spock.lang.Shared
import spock.lang.Specification

class UriPrefixingWebClientTest extends Specification {
class UriPrefixingClientHttpRequestFactoryTest extends Specification {

@Shared
def webClientBuilder = WebClient.builder()
def WRAPPED = new SimpleClientHttpRequestFactory()

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'))
def request = requestFactory.createRequest(URI.create('/gdc/resource'), HttpMethod.GET)

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)
request.URI.toString() == 'http://localhost:1234/gdc/resource'

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()
where:
requestFactory << [
new UriPrefixingClientHttpRequestFactory(WRAPPED, 'http', 'localhost', 1234),
new UriPrefixingClientHttpRequestFactory(WRAPPED, 'http://localhost:1234')
]
}
}
Loading