Skip to content

Commit

Permalink
Remove version from REST uri fragment if exists (0.104) (#8250)
Browse files Browse the repository at this point in the history
Remove version from REST uri fragment if exists (#8246)

This PR fixes the issue exposed in acceptance tests

* Remove version from REST uri fragment if exists

---------

Signed-off-by: Xin Li <[email protected]>
Signed-off-by: Steven Sheehy <[email protected]>
Co-authored-by: Xin Li <[email protected]>
  • Loading branch information
steven-sheehy and xin-hedera authored May 7, 2024
1 parent 85af2a9 commit af0ea9d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hedera.mirror.test.e2e.acceptance.client;

import static com.hedera.mirror.test.e2e.acceptance.config.RestProperties.URL_PREFIX;
import static org.awaitility.Awaitility.await;

import com.google.common.base.Stopwatch;
Expand Down Expand Up @@ -372,21 +373,31 @@ public void unSubscribeFromTopic(SubscriptionHandle subscription) {
}

private <T> T callRestEndpoint(String uri, Class<T> classType, Object... uriVariables) {
return retryTemplate.execute(
x -> restClient.get().uri(uri, uriVariables).retrieve().body(classType));
String normalizedUri = normalizeUri(uri);
return retryTemplate.execute(x ->
restClient.get().uri(normalizedUri, uriVariables).retrieve().body(classType));
}

private <T> T callRestJavaEndpoint(String uri, Class<T> classType, Object... uriVariables) {
return retryTemplate.execute(
x -> restJavaClient.get().uri(uri, uriVariables).retrieve().body(classType));
String normalizedUri = normalizeUri(uri);
return retryTemplate.execute(x ->
restJavaClient.get().uri(normalizedUri, uriVariables).retrieve().body(classType));
}

private <T> T callRestEndpointNoRetry(String uri, Class<T> classType, Object... uriVariables) {
return restClient.get().uri(uri, uriVariables).retrieve().body(classType);
return restClient.get().uri(normalizeUri(uri), uriVariables).retrieve().body(classType);
}

private <T, R> T callPostRestEndpoint(String uri, Class<T> classType, R request) {
return retryTemplate.execute(
x -> web3Client.post().uri(uri).body(request).retrieve().body(classType));
}

private String normalizeUri(String uri) {
if (uri == null || !uri.startsWith(URL_PREFIX)) {
return uri;
}

return uri.substring(URL_PREFIX.length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.hedera.mirror.test.e2e.acceptance.config;

import static com.hedera.mirror.test.e2e.acceptance.config.RestProperties.URL_SUFFIX;
import static com.hedera.mirror.test.e2e.acceptance.config.RestProperties.URL_PREFIX;

import jakarta.inject.Named;
import lombok.Data;
Expand All @@ -36,8 +36,8 @@ public class RestJavaProperties {
private boolean enabled = false;

public String getBaseUrl() {
if (baseUrl != null && !baseUrl.endsWith(URL_SUFFIX)) {
return baseUrl + URL_SUFFIX;
if (baseUrl != null && !baseUrl.endsWith(URL_PREFIX)) {
return baseUrl + URL_PREFIX;
}
return baseUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@Validated
public class RestProperties {

public static final String URL_SUFFIX = "/api/v1";
public static final String URL_PREFIX = "/api/v1";

@NotBlank
private String baseUrl;
Expand All @@ -59,8 +59,8 @@ public boolean shouldRetry(Throwable t) {
}

public String getBaseUrl() {
if (baseUrl != null && !baseUrl.endsWith(URL_SUFFIX)) {
return baseUrl + URL_SUFFIX;
if (baseUrl != null && !baseUrl.endsWith(URL_PREFIX)) {
return baseUrl + URL_PREFIX;
}
return baseUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.hedera.mirror.test.e2e.acceptance.config;

import static com.hedera.mirror.test.e2e.acceptance.config.RestProperties.URL_SUFFIX;
import static com.hedera.mirror.test.e2e.acceptance.config.RestProperties.URL_PREFIX;

import jakarta.inject.Named;
import lombok.Data;
Expand All @@ -36,8 +36,8 @@ public class Web3Properties {
private boolean enabled = false;

public String getBaseUrl() {
if (baseUrl != null && !baseUrl.endsWith(URL_SUFFIX)) {
return baseUrl + URL_SUFFIX;
if (baseUrl != null && !baseUrl.endsWith(URL_PREFIX)) {
return baseUrl + URL_PREFIX;
}
return baseUrl;
}
Expand Down

0 comments on commit af0ea9d

Please sign in to comment.