Skip to content

Commit

Permalink
Move no_content check in makeBids to higher level (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiNahornyi authored Nov 18, 2020
1 parent 2d627aa commit 63b5ecf
Show file tree
Hide file tree
Showing 66 changed files with 24 additions and 579 deletions.
21 changes: 14 additions & 7 deletions src/main/java/org/prebid/server/bidder/HttpBidderRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,25 @@ private <T> Void processHttpCall(Bidder<T> bidder,
}

private static <T> Result<List<BidderBid>> makeBids(Bidder<T> bidder, HttpCall<T> httpCall, BidRequest bidRequest) {
if (httpCall.getError() != null || !isOkOrNoContent(httpCall)) {
return null;
}
return bidder.makeBids(toHttpCallWithSafeResponseBody(httpCall), bidRequest);

return httpCall.getError() != null
? null
: makeResult(bidder, httpCall, bidRequest);
}

/**
* Returns true if response HTTP status code is equal to 200 or 204, otherwise false.
* Returns result based on response status code
*/
private static <T> boolean isOkOrNoContent(HttpCall<T> httpCall) {
private static <T> Result<List<BidderBid>> makeResult(Bidder<T> bidder, HttpCall<T> httpCall,
BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
return statusCode == HttpResponseStatus.OK.code() || statusCode == HttpResponseStatus.NO_CONTENT.code();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}
if (statusCode != HttpResponseStatus.OK.code()) {
return null;
}
return bidder.makeBids(toHttpCallWithSafeResponseBody(httpCall), bidRequest);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.iab.openrtb.request.Site;
import com.iab.openrtb.request.Source;
import com.iab.openrtb.response.Bid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -164,11 +163,6 @@ private MultiMap resolveHeaders(Device device) {

@Override
public Result<List<BidderBid>> makeBids(HttpCall<Void> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final AdgenerationResponse adgenerationResponse = decodeBodyToBidResponse(httpCall.getResponse());
if (CollectionUtils.isEmpty(adgenerationResponse.getResults())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -157,11 +156,6 @@ private static String getIfaParameter(Device device) {
public Result<List<BidderBid>> makeBids(HttpCall<Void> httpCall, BidRequest bidRequest) {
final HttpResponse httpResponse = httpCall.getResponse();

final int statusCode = httpResponse.getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

final JsonNode bodyNode;
try {
bodyNode = mapper.decodeValue(httpResponse.getBody(), JsonNode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.prebid.server.bidder.Bidder;
Expand Down Expand Up @@ -111,11 +110,6 @@ private ObjectNode makeImpExt(Map<String, JsonNode> customParams) {

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

final BidResponse bidResponse;
try {
bidResponse = decodeBodyToBidResponse(httpCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.iab.openrtb.request.Site;
import com.iab.openrtb.request.User;
import com.iab.openrtb.response.Bid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -247,11 +246,6 @@ private static MultiMap getHeaders(BidRequest request) {

@Override
public Result<List<BidderBid>> makeBids(HttpCall<Void> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

final List<NameValuePair> params;
try {
params = URLEncodedUtils.parse(new URI(httpCall.getRequest().getUri()), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -102,11 +101,6 @@ private HttpRequest<BidRequest> createSingleRequest(Imp imp, BidRequest request,

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final BidResponse bidResponse = decodeBodyToBidResponse(httpCall);
final Map<String, BidType> impTypes = getImpTypes(bidRequest);
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/prebid/server/bidder/aja/AjaBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.prebid.server.bidder.Bidder;
Expand Down Expand Up @@ -121,12 +120,6 @@ private HttpRequest<BidRequest> createSingleRequest(Imp imp, BidRequest request,

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();

if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return extractBids(httpCall.getRequest().getPayload(), bidResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -128,10 +127,6 @@ private ExtImpApplogy parseAndValidateImpExt(Imp imp) {

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
if (httpCall.getResponse().getStatusCode() == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return extractBids(httpCall.getRequest().getPayload(), bidResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.prebid.server.bidder.Bidder;
import org.prebid.server.bidder.avocet.model.AvocetBidExtension;
Expand Down Expand Up @@ -64,11 +63,6 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

final BidResponse bidResponse;
try {
bidResponse = decodeBodyToBidResponse(httpCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.iab.openrtb.request.Video;
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -385,15 +384,6 @@ private static void addDeviceHeaders(MultiMap headers, Device device) {
@Override
public Result<List<BidderBid>> makeBids(HttpCall<Void> httpCall, BidRequest bidRequest) {
final String bodyString = httpCall.getResponse().getBody();
if (StringUtils.isBlank(bodyString)) {
return Result.withError(BidderError.badServerResponse("Received a null response from beachfront"));
}

if (httpCall.getResponse().getStatusCode() == HttpResponseStatus.NO_CONTENT.code()
|| bodyString.length() <= 2) {
return Result.empty();
}

try {
return processVideoResponse(bodyString, httpCall.getRequest());
} catch (DecodeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -106,10 +105,6 @@ private HttpRequest<BidRequest> makeSingleRequest(ExtImpBetween extImpBetween, B

@Override
public final Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
if (httpCall.getResponse().getStatusCode() == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.of(extractBids(httpCall.getRequest().getPayload(), bidResponse), Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.iab.openrtb.request.Site;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -150,10 +149,6 @@ private static MultiMap resolveHeaders(Device device) {

@Override
public final Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
if (httpCall.getResponse().getStatusCode() == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.of(extractBids(bidResponse), Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.prebid.server.bidder.Bidder;
Expand Down Expand Up @@ -92,10 +91,6 @@ private Imp createImp(ExtImpCpmStar extImpCpmStar, Imp imp) {

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
if (httpCall.getResponse().getStatusCode() == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return extractBids(httpCall.getRequest().getPayload(), bidResponse);
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/prebid/server/bidder/dmx/DmxBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -218,11 +217,6 @@ private static void checkIfHasId(App app, User user) {

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

final BidResponse bidResponse;
try {
bidResponse = decodeBodyToBidResponse(httpCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -107,10 +106,6 @@ private ExtImpEngagebdr parseImpExt(Imp imp) {

@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
if (httpCall.getResponse().getStatusCode() == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.withValues(extractBids(bidResponse, bidRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.iab.openrtb.response.Bid;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.codec.binary.Hex;
Expand Down Expand Up @@ -280,13 +279,6 @@ private String makeAuthId(String requestId) {
@Override
public Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {
final HttpResponse response = httpCall.getResponse();
final int statusCode = response.getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
final String message = response.getHeaders().get("x-fb-an-errors");
return Result.withError(BidderError.badInput(
String.format("Unexpected status code %d with error message '%s'", statusCode, message)));
}

try {
final BidResponse bidResponse = mapper.decodeValue(response.getBody(), BidResponse.class);
return extractBids(bidResponse, bidRequest.getImp());
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/prebid/server/bidder/gamma/GammaBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.iab.openrtb.request.Format;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.Bid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -197,10 +196,6 @@ private MultiMap makeHeaders(Device device) {

@Override
public Result<List<BidderBid>> makeBids(HttpCall<Void> httpCall, BidRequest bidRequest) {
if (httpCall.getResponse().getStatusCode() == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

final String body = httpCall.getResponse().getBody();
if (body == null) {
return Result.withError(BidderError.badServerResponse("bad server response: body is empty"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -100,12 +99,6 @@ private Imp updateImp(Imp imp) {

@Override
public final Result<List<BidderBid>> makeBids(HttpCall<BidRequest> httpCall, BidRequest bidRequest) {

final int statusCode = httpCall.getResponse().getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.of(Collections.emptyList(), Collections.emptyList());
}

try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.of(extractBids(httpCall.getRequest().getPayload(), bidResponse), Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.iab.openrtb.request.Regs;
import com.iab.openrtb.request.Site;
import com.iab.openrtb.request.User;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpMethod;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -277,11 +276,6 @@ private static MultiMap resolveHeaders(Device device, Site site) {

@Override
public final Result<List<BidderBid>> makeBids(HttpCall<InvibesBidRequest> httpCall, BidRequest bidRequest) {
final int statusCode = httpCall.getResponse().getStatusCode();
if (statusCode == HttpResponseStatus.NO_CONTENT.code()) {
return Result.empty();
}

try {
final InvibesBidderResponse bidResponse =
mapper.decodeValue(httpCall.getResponse().getBody(), InvibesBidderResponse.class);
Expand Down
Loading

0 comments on commit 63b5ecf

Please sign in to comment.