From 02ce2d422bdd37cac6ea842a39c8967b9a4e1217 Mon Sep 17 00:00:00 2001 From: Daniel Gheorghian Date: Wed, 3 Jun 2026 14:44:41 +0300 Subject: [PATCH] New Adapter: Sevio --- .../server/bidder/sevio/SevioBidder.java | 96 +++++++ .../config/bidder/SevioConfiguration.java | 41 +++ src/main/resources/bidder-config/sevio.yaml | 13 + .../resources/static/bidder-params/sevio.json | 16 ++ .../server/bidder/sevio/SevioBidderTest.java | 235 ++++++++++++++++++ .../java/org/prebid/server/it/SevioTest.java | 38 +++ .../sevio/test-auction-sevio-request.json | 23 ++ .../sevio/test-auction-sevio-response.json | 39 +++ .../sevio/test-sevio-bid-request.json | 56 +++++ .../sevio/test-sevio-bid-response.json | 18 ++ .../server/it/test-application.properties | 2 + 11 files changed, 577 insertions(+) create mode 100644 src/main/java/org/prebid/server/bidder/sevio/SevioBidder.java create mode 100644 src/main/java/org/prebid/server/spring/config/bidder/SevioConfiguration.java create mode 100644 src/main/resources/bidder-config/sevio.yaml create mode 100644 src/main/resources/static/bidder-params/sevio.json create mode 100644 src/test/java/org/prebid/server/bidder/sevio/SevioBidderTest.java create mode 100644 src/test/java/org/prebid/server/it/SevioTest.java create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/sevio/test-auction-sevio-request.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/sevio/test-auction-sevio-response.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/sevio/test-sevio-bid-request.json create mode 100644 src/test/resources/org/prebid/server/it/openrtb2/sevio/test-sevio-bid-response.json diff --git a/src/main/java/org/prebid/server/bidder/sevio/SevioBidder.java b/src/main/java/org/prebid/server/bidder/sevio/SevioBidder.java new file mode 100644 index 00000000000..013b5e05f41 --- /dev/null +++ b/src/main/java/org/prebid/server/bidder/sevio/SevioBidder.java @@ -0,0 +1,96 @@ +package org.prebid.server.bidder.sevio; + +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.response.Bid; +import com.iab.openrtb.response.BidResponse; +import com.iab.openrtb.response.SeatBid; +import io.vertx.core.MultiMap; +import org.apache.commons.collections4.CollectionUtils; +import org.prebid.server.bidder.Bidder; +import org.prebid.server.bidder.model.BidderBid; +import org.prebid.server.bidder.model.BidderCall; +import org.prebid.server.bidder.model.BidderError; +import org.prebid.server.bidder.model.HttpRequest; +import org.prebid.server.bidder.model.Result; +import org.prebid.server.exception.PreBidException; +import org.prebid.server.json.DecodeException; +import org.prebid.server.json.JacksonMapper; +import org.prebid.server.proto.openrtb.ext.response.BidType; +import org.prebid.server.util.BidderUtil; +import org.prebid.server.util.HttpUtil; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +public class SevioBidder implements Bidder { + + private final String endpointUrl; + private final JacksonMapper mapper; + + public SevioBidder(String endpointUrl, JacksonMapper mapper) { + this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); + this.mapper = Objects.requireNonNull(mapper); + } + + @Override + public Result>> makeHttpRequests(BidRequest bidRequest) { + final MultiMap headers = HttpUtil.headers().add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.6"); + return Result.withValue(BidderUtil.defaultRequest(bidRequest, headers, endpointUrl, mapper)); + } + + @Override + public final Result> makeBids(BidderCall httpCall, BidRequest bidRequest) { + try { + final var bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); + final var errors = new ArrayList(); + return Result.of(extractBids(bidResponse, errors), errors); + } catch (DecodeException e) { + return Result.withError(BidderError.badServerResponse(e.getMessage())); + } + } + + private static List extractBids(BidResponse bidResponse, List errors) { + if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { + return Collections.emptyList(); + } + return bidsFromResponse(bidResponse, errors); + } + + private static List bidsFromResponse(BidResponse bidResponse, List errors) { + return bidResponse.getSeatbid().stream() + .filter(Objects::nonNull) + .map(SeatBid::getBid) + .filter(Objects::nonNull) + .flatMap(Collection::stream) + .map(bid -> makeBid(bid, bidResponse.getCur(), errors)) + .filter(Objects::nonNull) + .toList(); + } + + private static BidderBid makeBid(Bid bid, String currency, List errors) { + try { + return BidderBid.of(bid, getBidType(bid), currency); + } catch (PreBidException e) { + errors.add(BidderError.badServerResponse(e.getMessage())); + return null; + } + } + + private static BidType getBidType(Bid bid) { + final var mtype = bid.getMtype(); + if (mtype == null) { + throw new PreBidException("Missing MType for bid: " + bid.getId()); + } + + return switch (mtype) { + case 1 -> BidType.banner; + case 4 -> BidType.xNative; + case 2 -> BidType.video; + default -> throw new PreBidException( + "failed to parse bid mtype (%d) for impression id \"%s\"".formatted(mtype, bid.getImpid())); + }; + } +} diff --git a/src/main/java/org/prebid/server/spring/config/bidder/SevioConfiguration.java b/src/main/java/org/prebid/server/spring/config/bidder/SevioConfiguration.java new file mode 100644 index 00000000000..06e840eb769 --- /dev/null +++ b/src/main/java/org/prebid/server/spring/config/bidder/SevioConfiguration.java @@ -0,0 +1,41 @@ +package org.prebid.server.spring.config.bidder; + +import org.prebid.server.bidder.BidderDeps; +import org.prebid.server.bidder.sevio.SevioBidder; +import org.prebid.server.json.JacksonMapper; +import org.prebid.server.spring.config.bidder.model.BidderConfigurationProperties; +import org.prebid.server.spring.config.bidder.util.BidderDepsAssembler; +import org.prebid.server.spring.config.bidder.util.UsersyncerCreator; +import org.prebid.server.spring.env.YamlPropertySourceFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +import jakarta.validation.constraints.NotBlank; + +@Configuration +@PropertySource(value = "classpath:/bidder-config/sevio.yaml", factory = YamlPropertySourceFactory.class) +public class SevioConfiguration { + + private static final String BIDDER_NAME = "sevio"; + + @Bean("sevioConfigurationProperties") + @ConfigurationProperties("adapters.sevio") + BidderConfigurationProperties configurationProperties() { + return new BidderConfigurationProperties(); + } + + @Bean + BidderDeps sevioBidderDeps(BidderConfigurationProperties sevioConfigurationProperties, + @NotBlank @Value("${external-url}") String externalUrl, + JacksonMapper mapper) { + + return BidderDepsAssembler.forBidder(BIDDER_NAME) + .withConfig(sevioConfigurationProperties) + .usersyncerCreator(UsersyncerCreator.create(externalUrl)) + .bidderCreator(config -> new SevioBidder(config.getEndpoint(), mapper)) + .assemble(); + } +} diff --git a/src/main/resources/bidder-config/sevio.yaml b/src/main/resources/bidder-config/sevio.yaml new file mode 100644 index 00000000000..0e910b81e42 --- /dev/null +++ b/src/main/resources/bidder-config/sevio.yaml @@ -0,0 +1,13 @@ +adapters: + sevio: + endpoint: https://req.adx.ws/rtb + meta-info: + maintainer-email: technical@sevio.com + app-media-types: + - banner + - native + site-media-types: + - banner + - native + supported-vendors: + vendor-id: 0 diff --git a/src/main/resources/static/bidder-params/sevio.json b/src/main/resources/static/bidder-params/sevio.json new file mode 100644 index 00000000000..2be8bcc4eaa --- /dev/null +++ b/src/main/resources/static/bidder-params/sevio.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Sevio Adapter Params", + "description": "A schema which validates params accepted by the Sevio adapter", + "type": "object", + "properties": { + "placementId": { + "type": "string", + "minLength": 1, + "description": "Ad placement identifier" + } + }, + "required": [ + "placementId" + ] +} diff --git a/src/test/java/org/prebid/server/bidder/sevio/SevioBidderTest.java b/src/test/java/org/prebid/server/bidder/sevio/SevioBidderTest.java new file mode 100644 index 00000000000..aa0271afd93 --- /dev/null +++ b/src/test/java/org/prebid/server/bidder/sevio/SevioBidderTest.java @@ -0,0 +1,235 @@ +package org.prebid.server.bidder.sevio; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.iab.openrtb.request.BidRequest; +import com.iab.openrtb.request.Imp; +import com.iab.openrtb.response.Bid; +import com.iab.openrtb.response.BidResponse; +import com.iab.openrtb.response.SeatBid; +import org.junit.jupiter.api.Test; +import org.prebid.server.VertxTest; +import org.prebid.server.bidder.model.BidderBid; +import org.prebid.server.bidder.model.BidderCall; +import org.prebid.server.bidder.model.BidderError; +import org.prebid.server.bidder.model.HttpRequest; +import org.prebid.server.bidder.model.HttpResponse; +import org.prebid.server.bidder.model.Result; + +import java.util.Arrays; +import java.util.List; +import java.util.function.UnaryOperator; + +import static java.util.Collections.singletonList; +import static java.util.function.UnaryOperator.identity; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.prebid.server.proto.openrtb.ext.response.BidType.banner; +import static org.prebid.server.proto.openrtb.ext.response.BidType.video; +import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative; +import static org.prebid.server.util.HttpUtil.ACCEPT_HEADER; +import static org.prebid.server.util.HttpUtil.APPLICATION_JSON_CONTENT_TYPE; +import static org.prebid.server.util.HttpUtil.CONTENT_TYPE_HEADER; +import static org.prebid.server.util.HttpUtil.X_OPENRTB_VERSION_HEADER; +import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE; + +public class SevioBidderTest extends VertxTest { + + private static final String ENDPOINT_URL = "https://req.adx.ws/rtb"; + + private final SevioBidder target = new SevioBidder(ENDPOINT_URL, jacksonMapper); + + @Test + public void creationShouldFailOnInvalidEndpointUrl() { + assertThatIllegalArgumentException().isThrownBy(() -> new SevioBidder("invalid_url", jacksonMapper)); + } + + @Test + public void makeHttpRequestsShouldReturnExpectedRequestWithAllImps() { + // given + final BidRequest bidRequest = givenBidRequest( + imp -> imp.id("impId1"), + imp -> imp.id("impId2")); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1).first() + .satisfies(request -> assertThat(request.getBody()) + .isEqualTo(jacksonMapper.encodeToBytes(bidRequest))) + .satisfies(request -> assertThat(request.getPayload()) + .isEqualTo(bidRequest)) + .satisfies(request -> assertThat(request.getImpIds()) + .containsExactlyInAnyOrder("impId1", "impId2")); + } + + @Test + public void makeHttpRequestsShouldReturnExpectedHeaders() { + // given + final BidRequest bidRequest = givenBidRequest( + imp -> imp.id("impId1"), + imp -> imp.id("impId2")); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1).first() + .extracting(HttpRequest::getHeaders) + .satisfies(headers -> assertThat(headers.get(CONTENT_TYPE_HEADER)) + .isEqualTo(APPLICATION_JSON_CONTENT_TYPE)) + .satisfies(headers -> assertThat(headers.get(ACCEPT_HEADER)) + .isEqualTo(APPLICATION_JSON_VALUE)) + .satisfies(headers -> assertThat(headers.get(X_OPENRTB_VERSION_HEADER)) + .isEqualTo("2.6")); + } + + @Test + public void makeHttpRequestsShouldUseCorrectUri() { + // given + final BidRequest bidRequest = givenBidRequest(identity()); + + // when + final Result>> result = target.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1).first() + .extracting(HttpRequest::getUri) + .isEqualTo(ENDPOINT_URL); + } + + @Test + public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() { + // given + final BidderCall httpCall = givenHttpCall("invalid"); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getValue()).isEmpty(); + assertThat(result.getErrors()).hasSize(1) + .allSatisfy(error -> { + assertThat(error.getType()).isEqualTo(BidderError.Type.bad_server_response); + assertThat(error.getMessage()).startsWith("Failed to decode: Unrecognized token"); + }); + } + + @Test + public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws JsonProcessingException { + // given + final BidderCall httpCall = givenHttpCall(mapper.writeValueAsString(BidResponse.builder().build())); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).isEmpty(); + } + + @Test + public void makeBidsShouldReturnBannerBidWhenMtypeIsBanner() throws JsonProcessingException { + // given + final Bid bannerBid = Bid.builder().impid("1").mtype(1).build(); + + final BidderCall httpCall = givenHttpCall(givenBidResponse(bannerBid)); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).containsOnly(BidderBid.of(bannerBid, banner, "USD")); + } + + @Test + public void makeBidsShouldReturnVideoBidWhenMtypeIsVideo() throws JsonProcessingException { + // given + final Bid videoBid = Bid.builder().impid("2").mtype(2).build(); + + final BidderCall httpCall = givenHttpCall(givenBidResponse(videoBid)); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).containsOnly(BidderBid.of(videoBid, video, "USD")); + } + + @Test + public void makeBidsShouldReturnNativeBidWhenMtypeIsNative() throws JsonProcessingException { + // given + final Bid nativeBid = Bid.builder().impid("4").mtype(4).build(); + + final BidderCall httpCall = givenHttpCall(givenBidResponse(nativeBid)); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).containsOnly(BidderBid.of(nativeBid, xNative, "USD")); + } + + @Test + public void makeBidsShouldReturnErrorWhenMtypeIsNotSupported() throws JsonProcessingException { + // given + final Bid bannerBid = Bid.builder().impid("id").mtype(1).build(); + final Bid audioBid = Bid.builder().impid("id").mtype(3).build(); + + final BidderCall httpCall = givenHttpCall(givenBidResponse(bannerBid, audioBid)); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getErrors()).containsExactly( + BidderError.badServerResponse("failed to parse bid mtype (3) for impression id \"id\"")); + assertThat(result.getValue()).containsOnly(BidderBid.of(bannerBid, banner, "USD")); + } + + @Test + public void makeBidsShouldReturnErrorWhenMtypeIsMissing() throws JsonProcessingException { + // given + final Bid bid = Bid.builder().id("bidId").impid("1").build(); + + final BidderCall httpCall = givenHttpCall(givenBidResponse(bid)); + + // when + final Result> result = target.makeBids(httpCall, null); + + // then + assertThat(result.getValue()).isEmpty(); + assertThat(result.getErrors()).containsExactly( + BidderError.badServerResponse("Missing MType for bid: bidId")); + } + + private static BidRequest givenBidRequest(UnaryOperator... impCustomizers) { + return BidRequest.builder() + .imp(Arrays.stream(impCustomizers).map(SevioBidderTest::givenImp).toList()) + .build(); + } + + private static Imp givenImp(UnaryOperator impCustomizer) { + return impCustomizer.apply(Imp.builder().id("impId")).build(); + } + + private static String givenBidResponse(Bid... bids) throws JsonProcessingException { + return mapper.writeValueAsString(BidResponse.builder() + .cur("USD") + .seatbid(singletonList(SeatBid.builder().bid(List.of(bids)).build())) + .build()); + } + + private static BidderCall givenHttpCall(String body) { + return BidderCall.succeededHttp( + HttpRequest.builder().build(), + HttpResponse.of(200, null, body), + null); + } +} diff --git a/src/test/java/org/prebid/server/it/SevioTest.java b/src/test/java/org/prebid/server/it/SevioTest.java new file mode 100644 index 00000000000..041a111bffe --- /dev/null +++ b/src/test/java/org/prebid/server/it/SevioTest.java @@ -0,0 +1,38 @@ +package org.prebid.server.it; + +import io.restassured.response.Response; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.prebid.server.model.Endpoint; + +import java.io.IOException; +import java.util.List; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +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; + +public class SevioTest extends IntegrationTest { + + @Test + public void openrtb2AuctionShouldRespondWithBidsFromSevio() throws IOException, JSONException { + // given + WIRE_MOCK_RULE.stubFor(post(urlPathEqualTo("/sevio-exchange")) + .withRequestBody(equalToJson(jsonFrom("openrtb2/sevio/test-sevio-bid-request.json"))) + .willReturn(aResponse().withBody(jsonFrom("openrtb2/sevio/test-sevio-bid-response.json")))); + + // when + final Response response = responseFor( + "openrtb2/sevio/test-auction-sevio-request.json", + Endpoint.openrtb2_auction + ); + + // then + assertJsonEquals( + "openrtb2/sevio/test-auction-sevio-response.json", + response, + List.of("sevio")); + } + +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-auction-sevio-request.json b/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-auction-sevio-request.json new file mode 100644 index 00000000000..c42a183e75e --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-auction-sevio-request.json @@ -0,0 +1,23 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "banner": { + "w": 320, + "h": 250 + }, + "ext": { + "sevio": { + "placementId": "testPlacementId" + } + } + } + ], + "tmax": 5000, + "regs": { + "ext": { + "gdpr": 0 + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-auction-sevio-response.json b/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-auction-sevio-response.json new file mode 100644 index 00000000000..32c3ee19b64 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-auction-sevio-response.json @@ -0,0 +1,39 @@ +{ + "id": "request_id", + "seatbid": [ + { + "bid": [ + { + "id": "bid_id", + "impid": "imp_id", + "exp": 300, + "price": 0.01, + "crid": "crid1", + "mtype": 1, + "ext": { + "prebid": { + "type": "banner", + "meta": { + "adaptercode": "sevio" + } + }, + "origbidcpm": 0.01, + "origbidcur": "USD" + } + } + ], + "seat": "sevio", + "group": 0 + } + ], + "cur": "USD", + "ext": { + "responsetimemillis": { + "sevio": "{{ sevio.response_time_ms }}" + }, + "prebid": { + "auctiontimestamp": 0 + }, + "tmaxrequest": 5000 + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-sevio-bid-request.json b/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-sevio-bid-request.json new file mode 100644 index 00000000000..ba39e95105a --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-sevio-bid-request.json @@ -0,0 +1,56 @@ +{ + "id": "request_id", + "imp": [ + { + "id": "imp_id", + "secure": 1, + "banner": { + "w": 320, + "h": 250 + }, + "ext": { + "tid": "${json-unit.any-string}", + "bidder": { + "placementId": "testPlacementId" + } + } + } + ], + "source": { + "tid": "${json-unit.any-string}" + }, + "site": { + "domain": "www.example.com", + "page": "http://www.example.com", + "publisher": { + "domain": "example.com" + }, + "ext": { + "amp": 0 + } + }, + "device": { + "ua": "userAgent", + "ip": "193.168.244.1" + }, + "at": 1, + "tmax": "${json-unit.any-number}", + "cur": [ + "USD" + ], + "regs": { + "ext": { + "gdpr": 0 + } + }, + "ext": { + "prebid": { + "server": { + "externalurl": "http://localhost:8080", + "gvlid": 1, + "datacenter": "local", + "endpoint": "/openrtb2/auction" + } + } + } +} diff --git a/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-sevio-bid-response.json b/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-sevio-bid-response.json new file mode 100644 index 00000000000..53d65871871 --- /dev/null +++ b/src/test/resources/org/prebid/server/it/openrtb2/sevio/test-sevio-bid-response.json @@ -0,0 +1,18 @@ +{ + "id": "tid", + "seatbid": [ + { + "bid": [ + { + "crid": "crid1", + "price": 0.01, + "id": "bid_id", + "impid": "imp_id", + "mtype": 1 + } + ], + "type": "banner" + } + ], + "cur": "USD" +} 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 1569de649f5..53d5f5656da 100644 --- a/src/test/resources/org/prebid/server/it/test-application.properties +++ b/src/test/resources/org/prebid/server/it/test-application.properties @@ -509,6 +509,8 @@ adapters.seedingAlliance.aliases.finative.enabled=true adapters.seedingAlliance.aliases.finative.endpoint=http://localhost:8090/finative-exchange?ssp={{AccountId}} adapters.seedtag.enabled=true adapters.seedtag.endpoint=http://localhost:8090/seedtag-exchange +adapters.sevio.enabled=true +adapters.sevio.endpoint=http://localhost:8090/sevio-exchange adapters.smaato.enabled=true adapters.smaato.endpoint=http://localhost:8090/smaato-exchange adapters.smartadserver.enabled=true