diff --git a/src/main/java/org/prebid/server/bidder/bizzclick/BizzclickBidder.java b/src/main/java/org/prebid/server/bidder/bizzclick/BizzclickBidder.java index cf0278d4219..19e077624c6 100644 --- a/src/main/java/org/prebid/server/bidder/bizzclick/BizzclickBidder.java +++ b/src/main/java/org/prebid/server/bidder/bizzclick/BizzclickBidder.java @@ -9,6 +9,7 @@ import io.vertx.core.MultiMap; import io.vertx.core.http.HttpMethod; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.prebid.server.bidder.Bidder; import org.prebid.server.bidder.model.BidderBid; import org.prebid.server.bidder.model.BidderCall; @@ -33,8 +34,10 @@ public class BizzclickBidder implements Bidder { private static final TypeReference> BIZZCLICK_EXT_TYPE_REFERENCE = new TypeReference<>() { }; - private static final String URL_SOURCE_ID_MACRO = "{{.SourceId}}"; - private static final String URL_ACCOUNT_ID_MACRO = "{{.AccountID}}"; + private static final String DEFAULT_HOST = "us-e-node1"; + private static final String URL_HOST_MACRO = "{{Host}}"; + private static final String URL_SOURCE_ID_MACRO = "{{SourceId}}"; + private static final String URL_ACCOUNT_ID_MACRO = "{{AccountID}}"; private static final String DEFAULT_CURRENCY = "USD"; private final String endpointUrl; @@ -100,7 +103,11 @@ private static MultiMap headers(Device device) { } private String buildEndpointUrl(ExtImpBizzclick ext) { - return endpointUrl.replace(URL_SOURCE_ID_MACRO, HttpUtil.encodeUrl(ext.getPlacementId())) + final String host = StringUtils.isBlank(ext.getHost()) ? DEFAULT_HOST : ext.getHost(); + final String sourceId = StringUtils.isBlank(ext.getSourceId()) ? ext.getPlacementId() : ext.getSourceId(); + return endpointUrl + .replace(URL_HOST_MACRO, HttpUtil.encodeUrl(host)) + .replace(URL_SOURCE_ID_MACRO, HttpUtil.encodeUrl(sourceId)) .replace(URL_ACCOUNT_ID_MACRO, HttpUtil.encodeUrl(ext.getAccountId())); } diff --git a/src/main/java/org/prebid/server/proto/openrtb/ext/request/bizzclick/ExtImpBizzclick.java b/src/main/java/org/prebid/server/proto/openrtb/ext/request/bizzclick/ExtImpBizzclick.java index 588137321e3..dae1cd49c62 100644 --- a/src/main/java/org/prebid/server/proto/openrtb/ext/request/bizzclick/ExtImpBizzclick.java +++ b/src/main/java/org/prebid/server/proto/openrtb/ext/request/bizzclick/ExtImpBizzclick.java @@ -6,9 +6,15 @@ @Value(staticConstructor = "of") public class ExtImpBizzclick { + @JsonProperty("host") + String host; + @JsonProperty("accountId") String accountId; @JsonProperty("placementId") String placementId; + + @JsonProperty("sourceId") + String sourceId; } diff --git a/src/main/resources/bidder-config/bizzclick.yaml b/src/main/resources/bidder-config/bizzclick.yaml index afb208477ae..f5037c1014a 100644 --- a/src/main/resources/bidder-config/bizzclick.yaml +++ b/src/main/resources/bidder-config/bizzclick.yaml @@ -1,6 +1,6 @@ adapters: bizzclick: - endpoint: http://us-e-node1.bizzclick.com/bid?rtb_seat_id={{.SourceId}}&secret_key={{.AccountID}} + endpoint: http://{{Host}}.bizzclick.com/bid?rtb_seat_id={{SourceId}}&secret_key={{AccountID}} meta-info: maintainer-email: support@bizzclick.com app-media-types: diff --git a/src/test/java/org/prebid/server/bidder/bizzclick/BizzclickBidderTest.java b/src/test/java/org/prebid/server/bidder/bizzclick/BizzclickBidderTest.java index 45e0b9b968c..18d5a44a250 100644 --- a/src/test/java/org/prebid/server/bidder/bizzclick/BizzclickBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/bizzclick/BizzclickBidderTest.java @@ -36,7 +36,11 @@ public class BizzclickBidderTest extends VertxTest { - private static final String ENDPOINT = "https://test.domain.dm/uri?source={{.SourceId}}&account={{.AccountID}}"; + private static final String ENDPOINT = "https://{{Host}}/uri?source={{SourceId}}&account={{AccountID}}"; + private static final String DEFAULT_HOST = "host"; + private static final String DEFAULT_ACCOUNT_ID = "accountId"; + private static final String DEFAULT_SOURCE_ID = "sourceId"; + private static final String DEFAULT_PLACEMENT_ID = "placementId"; private final BizzclickBidder target = new BizzclickBidder(ENDPOINT, jacksonMapper); @@ -65,7 +69,7 @@ public void makeHttpRequestsShouldReturnErrorWhenImpExtCouldNotBeParsed() { public void makeHttpRequestsShouldRelyOnlyOnFirstImpExt() { // given final BidRequest bidRequest = givenBidRequest( - givenImp("accountId", "placementId"), + givenImp(), givenImp(imp -> imp.ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode()))))); // when @@ -83,8 +87,8 @@ public void makeHttpRequestsShouldRelyOnlyOnFirstImpExt() { public void makeHttpRequestsShouldRemoveExtFromEachImp() { // given final BidRequest bidRequest = givenBidRequest( - givenImp("accountId1", "placementId1"), - givenImp("accountId2", "placementId2")); + givenImp("host", "accountId1", "placementId1", "sourceId1"), + givenImp("host", "accountId2", "placementId2", "sourceId2")); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -101,7 +105,7 @@ public void makeHttpRequestsShouldRemoveExtFromEachImp() { @Test public void makeHttpRequestsShouldCreateRequestWithXOpenRtbVersionHeader() { // given - final BidRequest bidRequest = givenBidRequest(givenImp("accountId", "placementId")); + final BidRequest bidRequest = givenBidRequest(givenImp()); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -120,7 +124,7 @@ public void makeHttpRequestsShouldCreateRequestWithUserAgentHeaderIfDeviceUaPres // given final BidRequest bidRequest = givenBidRequest( device -> device.ua("ua"), - givenImp("accountId", "placementId")); + givenImp()); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -139,7 +143,7 @@ public void makeHttpRequestsShouldCreateRequestWithXForwardedForHeaderIfDeviceIp // given final BidRequest bidRequest = givenBidRequest( device -> device.ipv6("ipv6"), - givenImp("accountId", "placementId")); + givenImp()); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -158,7 +162,7 @@ public void makeHttpRequestsShouldCreateRequestWithXForwardedForHeaderIfDeviceIp // given final BidRequest bidRequest = givenBidRequest( device -> device.ip("ip"), - givenImp("accountId", "placementId")); + givenImp()); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -177,7 +181,7 @@ public void makeHttpRequestsShouldCreateRequestWithXForwardedForHeaderWithDevice // given final BidRequest bidRequest = givenBidRequest( device -> device.ip("ip").ipv6("ipv6"), - givenImp("accountId", "placementId")); + givenImp()); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -194,7 +198,7 @@ public void makeHttpRequestsShouldCreateRequestWithXForwardedForHeaderWithDevice @Test public void makeHttpRequestsShouldCreateSingleRequestWithExpectedUri() { // given - final BidRequest bidRequest = givenBidRequest(givenImp("account id", "placement id")); + final BidRequest bidRequest = givenBidRequest(givenImp()); // when final Result>> result = target.makeHttpRequests(bidRequest); @@ -202,7 +206,33 @@ public void makeHttpRequestsShouldCreateSingleRequestWithExpectedUri() { // then assertThat(result.getValue()) .extracting(HttpRequest::getUri) - .containsExactly("https://test.domain.dm/uri?source=placement+id&account=account+id"); + .containsExactly( + String.format("https://%s/uri?source=%s&account=%s", + DEFAULT_HOST, + DEFAULT_SOURCE_ID, + DEFAULT_ACCOUNT_ID)); + assertThat(result.getErrors()).isEmpty(); + } + + @Test + public void makeHttpRequestsShouldCreateSingleRequestWithExpectedAlternativeUri() { + // given + final String expectedDefaultHost = "us-e-node1"; + final BidRequest bidRequest = givenBidRequest( + givenImp(expectedDefaultHost, DEFAULT_ACCOUNT_ID, DEFAULT_PLACEMENT_ID, null) + ); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getValue()) + .extracting(HttpRequest::getUri) + .containsExactly( + String.format("https://%s/uri?source=%s&account=%s", + expectedDefaultHost, + DEFAULT_PLACEMENT_ID, + DEFAULT_ACCOUNT_ID)); assertThat(result.getErrors()).isEmpty(); } @@ -210,7 +240,7 @@ public void makeHttpRequestsShouldCreateSingleRequestWithExpectedUri() { public void makeHttpRequestsShouldCreateSingleRequest() { // given final BidRequest bidRequest = givenBidRequest( - givenImp("accountId", "placementId"), + givenImp(), givenImp(identity())); // when @@ -417,8 +447,17 @@ private Imp givenImp(UnaryOperator impCustomizer) { return impCustomizer.apply(Imp.builder()).build(); } - private Imp givenImp(String accountId, String placementId) { - final ExtPrebid ext = ExtPrebid.of(null, ExtImpBizzclick.of(accountId, placementId)); + private Imp givenImp() { + final ExtPrebid ext = ExtPrebid.of(null, ExtImpBizzclick.of( + DEFAULT_HOST, DEFAULT_ACCOUNT_ID, DEFAULT_PLACEMENT_ID, DEFAULT_SOURCE_ID + )); + return givenImp(imp -> imp.ext(mapper.valueToTree(ext))); + } + + private Imp givenImp(String host, String accountId, String placementId, String sourceId) { + final ExtPrebid ext = ExtPrebid.of( + null, ExtImpBizzclick.of(host, accountId, placementId, sourceId) + ); return givenImp(imp -> imp.ext(mapper.valueToTree(ext))); } diff --git a/src/test/java/org/prebid/server/it/BizzclickTest.java b/src/test/java/org/prebid/server/it/BizzclickTest.java index 665ddfc75df..4d98d48a52f 100644 --- a/src/test/java/org/prebid/server/it/BizzclickTest.java +++ b/src/test/java/org/prebid/server/it/BizzclickTest.java @@ -10,6 +10,7 @@ import java.io.IOException; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; @@ -22,6 +23,9 @@ public class BizzclickTest extends IntegrationTest { public void openrtb2AuctionShouldRespondWithBidsFromBizzclick() throws IOException, JSONException { // given WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/bizzclick-exchange")) + .withQueryParam("host", equalTo("host")) + .withQueryParam("source", equalTo("placementId")) + .withQueryParam("account", equalTo("accountId")) .withRequestBody(equalToJson(jsonFrom("openrtb2/bizzclick/test-bizzclick-bid-request.json"))) .willReturn(aResponse().withBody(jsonFrom("openrtb2/bizzclick/test-bizzclick-bid-response.json")))); diff --git a/src/test/resources/org/prebid/server/it/openrtb2/bizzclick/test-auction-bizzclick-request.json b/src/test/resources/org/prebid/server/it/openrtb2/bizzclick/test-auction-bizzclick-request.json index 2fae1241d83..bfbeccf737f 100644 --- a/src/test/resources/org/prebid/server/it/openrtb2/bizzclick/test-auction-bizzclick-request.json +++ b/src/test/resources/org/prebid/server/it/openrtb2/bizzclick/test-auction-bizzclick-request.json @@ -9,6 +9,7 @@ }, "ext": { "bizzclick": { + "host": "host", "accountId": "accountId", "placementId": "placementId" } diff --git a/src/test/resources/org/prebid/server/it/test-application.properties b/src/test/resources/org/prebid/server/it/test-application.properties index 2bef5e71ca2..e07188e72b1 100644 --- a/src/test/resources/org/prebid/server/it/test-application.properties +++ b/src/test/resources/org/prebid/server/it/test-application.properties @@ -112,7 +112,7 @@ adapters.bidscube.endpoint=http://localhost:8090/bidscube-exchange adapters.bidstack.enabled=true adapters.bidstack.endpoint=http://localhost:8090/bidstack-exchange adapters.bizzclick.enabled=true -adapters.bizzclick.endpoint=http://localhost:8090/bizzclick-exchange +adapters.bizzclick.endpoint=http://localhost:8090/bizzclick-exchange?host={{Host}}&source={{SourceId}}&account={{AccountID}} adapters.bliink.enabled=true adapters.bliink.endpoint=http://localhost:8090/bliink-exchange adapters.bluesea.enabled=true