From c6584facdb1f8fa481f73840d9935ee260be1d49 Mon Sep 17 00:00:00 2001 From: Rodion Orets Date: Mon, 19 Apr 2021 14:37:32 +0300 Subject: [PATCH] Tappx changes - Backward compatible change of version --- .../server/bidder/tappx/TappxBidder.java | 41 +++++++++++-------- .../server/bidder/tappx/TappxBidderTest.java | 25 ++++++++++- .../java/org/prebid/server/it/TappxTest.java | 2 +- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java b/src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java index 5166930985e..08d1fc9513d 100644 --- a/src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java +++ b/src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java @@ -8,6 +8,7 @@ import io.vertx.core.http.HttpMethod; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.http.client.utils.URIBuilder; import org.prebid.server.bidder.Bidder; import org.prebid.server.bidder.model.BidderBid; import org.prebid.server.bidder.model.BidderError; @@ -23,6 +24,7 @@ import org.prebid.server.util.HttpUtil; import java.math.BigDecimal; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -32,7 +34,7 @@ public class TappxBidder implements Bidder { - private static final String VERSION = "1.1"; + private static final String VERSION = "1.2"; private static final String TYPE_CNN = "prebid"; private static final TypeReference> TAPX_EXT_TYPE_REFERENCE = @@ -58,7 +60,7 @@ public Result>> makeHttpRequests(BidRequest request final String url; try { extImpTappx = parseBidRequestToExtImpTappx(request); - url = buildEndpointUrl(extImpTappx, request.getTest()); + url = resolveUrl(extImpTappx, request.getTest()); } catch (PreBidException e) { return Result.withError(BidderError.badInput(e.getMessage())); } @@ -91,7 +93,7 @@ private ExtImpTappx parseBidRequestToExtImpTappx(BidRequest request) { /** * Builds endpoint url based on adapter-specific pub settings from imp.ext. */ - private String buildEndpointUrl(ExtImpTappx extImpTappx, Integer test) { + private String resolveUrl(ExtImpTappx extImpTappx, Integer test) { final String host = extImpTappx.getHost(); if (StringUtils.isBlank(host)) { throw new PreBidException("Tappx host undefined"); @@ -107,22 +109,29 @@ private String buildEndpointUrl(ExtImpTappx extImpTappx, Integer test) { throw new PreBidException("Tappx tappxkey undefined"); } - String url = String.format("%s%s/%s?tappxkey=%s", endpointUrl, host, endpoint, tappxkey); - if (test != null && test == 0) { - int t = (int) System.nanoTime(); - url += "&ts=" + t; - } - - url += "&v=" + VERSION; - url += "&type_cnn=" + TYPE_CNN; + return buildUrl(endpointUrl, host, endpoint, tappxkey, test); + } + private static String buildUrl(String endpointUrl, String host, String endpoint, String tappxkey, Integer test) { try { - HttpUtil.validateUrl(url); - } catch (IllegalArgumentException e) { - throw new PreBidException("Not valid url: " + url, e); - } + final URIBuilder uriBuilder = new URIBuilder(endpointUrl + host); - return url; + if (!host.contains(endpoint)) { + uriBuilder.setPath(endpoint); + } + + uriBuilder.addParameter("tappxkey", tappxkey); + uriBuilder.addParameter("v", VERSION); + uriBuilder.addParameter("type_cnn", TYPE_CNN); + + if (test != null && test == 0) { + int t = (int) System.nanoTime(); + uriBuilder.addParameter("ts", String.valueOf(t)); + } + return uriBuilder.build().toString(); + } catch (URISyntaxException e) { + throw new PreBidException(String.format("Failed to build endpoint URL: %s", e.getMessage())); + } } /** diff --git a/src/test/java/org/prebid/server/bidder/tappx/TappxBidderTest.java b/src/test/java/org/prebid/server/bidder/tappx/TappxBidderTest.java index 123efcc7e02..1ff3d3ca1c2 100644 --- a/src/test/java/org/prebid/server/bidder/tappx/TappxBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/tappx/TappxBidderTest.java @@ -114,7 +114,30 @@ public void makeHttpRequestsShouldMakeRequestWithUrl() { // then assertThat(result.getErrors()).isEmpty(); - final String expectedUri = "https://host/endpoint?tappxkey=tappxkey&v=1.1&type_cnn=prebid"; + final String expectedUri = "https://host/endpoint?tappxkey=tappxkey&v=1.2&type_cnn=prebid"; + assertThat(result.getValue()).hasSize(1) + .allSatisfy(httpRequest -> { + assertThat(httpRequest.getUri()).isEqualTo(expectedUri); + assertThat(httpRequest.getMethod()).isEqualTo(HttpMethod.POST); + }); + } + + @Test + public void makeHttpRequestsShouldModifyUrl() { + // given + final BidRequest bidRequest = BidRequest.builder() + .imp(singletonList(Imp.builder() + .ext(mapper.valueToTree(ExtPrebid.of(null, + ExtImpTappx.of("endpoint.host", "tappxkey", "endpoint", BigDecimal.ONE)))) + .build())) + .build(); + + // when + final Result>> result = tappxBidder.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + final String expectedUri = "https://endpoint.host?tappxkey=tappxkey&v=1.2&type_cnn=prebid"; assertThat(result.getValue()).hasSize(1) .allSatisfy(httpRequest -> { assertThat(httpRequest.getUri()).isEqualTo(expectedUri); diff --git a/src/test/java/org/prebid/server/it/TappxTest.java b/src/test/java/org/prebid/server/it/TappxTest.java index fe12b651953..e86e6f115ae 100644 --- a/src/test/java/org/prebid/server/it/TappxTest.java +++ b/src/test/java/org/prebid/server/it/TappxTest.java @@ -28,7 +28,7 @@ public void openrtb2AuctionShouldRespondWithBidsFromTappx() throws IOException, // tappx bid response for imp 12 WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/tappx-exchange")) .withQueryParam("tappxkey", equalTo("pub-12345-android-9876")) - .withQueryParam("v", equalTo("1.1")) + .withQueryParam("v", equalTo("1.2")) .withQueryParam("type_cnn", equalTo("prebid")) .withHeader("Content-Type", equalToIgnoreCase("application/json;charset=utf-8")) .withHeader("Accept", equalTo("application/json"))