Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tappx changes - Backward compatible change of version #1222

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 25 additions & 16 deletions src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -32,7 +34,7 @@

public class TappxBidder implements Bidder<BidRequest> {

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<ExtPrebid<?, ExtImpTappx>> TAPX_EXT_TYPE_REFERENCE =
Expand All @@ -58,7 +60,7 @@ public Result<List<HttpRequest<BidRequest>>> 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()));
}
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls give reasonable names to variables.

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()));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<HttpRequest<BidRequest>>> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/prebid/server/it/TappxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down