Skip to content

Commit 7e4e016

Browse files
committed
Fix conflicts
1 parent fcf61e7 commit 7e4e016

2 files changed

Lines changed: 23 additions & 30 deletions

File tree

src/main/java/org/prebid/server/cache/CoreCacheService.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import com.iab.openrtb.response.Bid;
77
import io.vertx.core.Future;
88
import io.vertx.core.MultiMap;
9+
import io.vertx.uritemplate.UriTemplate;
10+
import io.vertx.uritemplate.Variables;
911
import org.apache.commons.collections4.CollectionUtils;
1012
import org.apache.commons.lang3.ObjectUtils;
1113
import org.apache.commons.lang3.StringUtils;
12-
import org.apache.http.client.utils.URIBuilder;
1314
import org.prebid.server.auction.model.AuctionContext;
1415
import org.prebid.server.auction.model.BidInfo;
1516
import org.prebid.server.auction.model.CachedDebugLog;
@@ -47,7 +48,6 @@
4748
import org.prebid.server.vertx.httpclient.HttpClient;
4849
import org.prebid.server.vertx.httpclient.model.HttpClientResponse;
4950

50-
import java.net.URISyntaxException;
5151
import java.net.URL;
5252
import java.time.Clock;
5353
import java.util.ArrayList;
@@ -70,8 +70,6 @@ public class CoreCacheService {
7070
private static final String BID_WURL_ATTRIBUTE = "wurl";
7171
private static final String TRACE_INFO_SEPARATOR = "-";
7272
private static final int MAX_DATACENTER_REGION_LENGTH = 4;
73-
private static final String UUID_QUERY_PARAMETER = "uuid";
74-
private static final String CH_QUERY_PARAMETER = "ch";
7573

7674
private final HttpClient httpClient;
7775
private final URL externalEndpointUrl;
@@ -648,18 +646,16 @@ public Future<HttpClientResponse> getCachedObject(String key, String ch, Timeout
648646
return Future.failedFuture(new TimeoutException("Timeout has been exceeded"));
649647
}
650648

651-
final URL endpointUrl = ObjectUtils.firstNonNull(internalEndpointUrl, externalEndpointUrl);
652-
final String url;
653-
try {
654-
final URIBuilder uriBuilder = new URIBuilder(endpointUrl.toString());
655-
uriBuilder.addParameter(UUID_QUERY_PARAMETER, key);
656-
if (StringUtils.isNotBlank(ch)) {
657-
uriBuilder.addParameter(CH_QUERY_PARAMETER, ch);
658-
}
659-
url = uriBuilder.build().toString();
660-
} catch (URISyntaxException e) {
661-
return Future.failedFuture(new IllegalArgumentException("Configured cache url is malformed", e));
649+
final String endpointUrl = ObjectUtils.firstNonNull(internalEndpointUrl, externalEndpointUrl).toString();
650+
final StringBuilder stringBuilder = new StringBuilder();
651+
stringBuilder.append(endpointUrl);
652+
stringBuilder.append(endpointUrl.contains("?") ? "{&uuid}" : "{?uuid}");
653+
if (StringUtils.isNotBlank(ch)) {
654+
stringBuilder.append("{&ch}");
662655
}
656+
final String url = UriTemplate.of(stringBuilder.toString()).expandToString(Variables.variables()
657+
.set("uuid", key)
658+
.set("ch", ch));
663659

664660
final long startTime = clock.millis();
665661
return httpClient.get(url, cacheHeaders, remainingTimeout)

src/test/java/org/prebid/server/cache/CoreCacheServiceTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,15 +1455,19 @@ public void getCachedObjectShouldAddUuidAndChQueryParamsBeforeSendingWhenChIsPre
14551455
MultiMap.caseInsensitiveMultiMap().add("Header", "Value"),
14561456
"body");
14571457

1458-
given(httpClient.get(eq("http://cache-service/cache?uuid=key&ch=ch"), any(), anyLong()))
1459-
.willReturn(Future.succeededFuture(response));
1458+
given(httpClient.get(any(), any(), anyLong())).willReturn(Future.succeededFuture(response));
14601459

14611460
// when
14621461
final Future<HttpClientResponse> result = target.getCachedObject("key", "ch", timeout);
14631462

14641463
// then
14651464
assertThat(result.result()).isEqualTo(response);
14661465
verify(metrics).updateVtrackCacheReadRequestTime(anyLong(), eq(MetricName.ok));
1466+
final ArgumentCaptor<String> urlCaptor = ArgumentCaptor.forClass(String.class);
1467+
verify(httpClient).get(urlCaptor.capture(), any(), anyLong());
1468+
assertThat(urlCaptor.getValue())
1469+
.startsWith("http://cache-service/cache?")
1470+
.contains("uuid=key", "ch=ch");
14671471
}
14681472

14691473
@Test
@@ -1487,13 +1491,13 @@ public void getCachedObjectShouldAddUuidQueryParamsBeforeSendingWhenChIsAbsent()
14871491

14881492
@Test
14891493
public void getCachedObjectShouldAddUuidQueryParamsToInternalBeforeSendingWhenChIsAbsent()
1490-
throws MalformedURLException {
1494+
throws MalformedURLException, URISyntaxException {
14911495

14921496
// given
14931497
target = new CoreCacheService(
14941498
httpClient,
1495-
new URL("http://cache-service/cache"),
1496-
new URL("http://internal-cache-service/cache"),
1499+
new URI("http://cache-service/cache").toURL(),
1500+
new URI("http://internal-cache-service/cache").toURL(),
14971501
"http://cache-service-host/cache?uuid=",
14981502
100L,
14991503
"ApiKey",
@@ -1525,12 +1529,7 @@ public void getCachedObjectShouldAddUuidQueryParamsToInternalBeforeSendingWhenCh
15251529
@Test
15261530
public void getCachedObjectShouldNotLogErrorMetricsWhenCacheIsNotReached() {
15271531
// given
1528-
final HttpClientResponse response = HttpClientResponse.of(
1529-
200,
1530-
MultiMap.caseInsensitiveMultiMap().add("Header", "Value"),
1531-
"body");
1532-
1533-
given(httpClient.get(eq("http://cache-service/cache?uuid=key&ch=ch"), any(), anyLong()))
1532+
given(httpClient.get(any(), any(), anyLong()))
15341533
.willReturn(Future.failedFuture(new TimeoutException("Timeout")));
15351534

15361535
// when
@@ -1549,8 +1548,7 @@ public void getCachedObjectShouldHandleErrorResponse() {
15491548
null,
15501549
jacksonMapper.encodeToString(CacheErrorResponse.builder().message("Resource not found").build()));
15511550

1552-
given(httpClient.get(eq("http://cache-service/cache?uuid=key&ch=ch"), any(), anyLong()))
1553-
.willReturn(Future.succeededFuture(response));
1551+
given(httpClient.get(any(), any(), anyLong())).willReturn(Future.succeededFuture(response));
15541552

15551553
// when
15561554
final Future<HttpClientResponse> result = target.getCachedObject("key", "ch", timeout);
@@ -1565,8 +1563,7 @@ public void getCachedObjectShouldFailWhenErrorResponseCanNotBeParsed() {
15651563
// given
15661564
final HttpClientResponse response = HttpClientResponse.of(404, null, "Resource not found");
15671565

1568-
given(httpClient.get(eq("http://cache-service/cache?uuid=key&ch=ch"), any(), anyLong()))
1569-
.willReturn(Future.succeededFuture(response));
1566+
given(httpClient.get(any(), any(), anyLong())).willReturn(Future.succeededFuture(response));
15701567

15711568
// when
15721569
final Future<HttpClientResponse> result = target.getCachedObject("key", "ch", timeout);

0 commit comments

Comments
 (0)