-
Notifications
You must be signed in to change notification settings - Fork 250
Port Floxis: New Adapter #4529
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
base: master
Are you sure you want to change the base?
Port Floxis: New Adapter #4529
Changes from 6 commits
07efcf6
f6797a3
41c57c2
86a34b6
ee616ff
0db0e0c
21d1900
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,213 @@ | ||
| package org.prebid.server.bidder.floxis; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| 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 io.vertx.core.http.HttpMethod; | ||
| 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.ExtPrebid; | ||
| import org.prebid.server.proto.openrtb.ext.request.floxis.ExtImpFloxis; | ||
| 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.List; | ||
| import java.util.Objects; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class FloxisBidder implements Bidder<BidRequest> { | ||
|
|
||
| private static final TypeReference<ExtPrebid<?, ExtImpFloxis>> FLOXIS_EXT_TYPE_REFERENCE = | ||
| new TypeReference<>() { | ||
| }; | ||
|
|
||
| private static final String HOST_MACRO = "{{Host}}"; | ||
| private static final String SEAT_MACRO = "{{SeatId}}"; | ||
|
|
||
| private static final String DEFAULT_REGION = "us-e"; | ||
| private static final String DEFAULT_PARTNER = "floxis"; | ||
|
|
||
| // region/partner are interpolated into the request host, so each must be a valid DNS label β | ||
| // otherwise a value carrying URL delimiters could rewrite the request origin. | ||
| private static final Pattern HOST_LABEL = Pattern.compile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$"); | ||
|
|
||
| private final String endpointUrl; | ||
| private final JacksonMapper mapper; | ||
|
|
||
| public FloxisBidder(String endpointUrl, JacksonMapper mapper) { | ||
| this.endpointUrl = HttpUtil.validateUrl(Objects.requireNonNull(endpointUrl)); | ||
| this.mapper = Objects.requireNonNull(mapper); | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) { | ||
| if (CollectionUtils.isEmpty(request.getImp())) { | ||
| return Result.withError(BidderError.badInput("no impressions in the bid request")); | ||
| } | ||
|
floxis-admin marked this conversation as resolved.
Outdated
|
||
|
|
||
| final String uri; | ||
| try { | ||
| uri = resolveUrl(endpointUrl, resolveCommonImpExt(request.getImp())); | ||
| } catch (PreBidException e) { | ||
| return Result.withError(BidderError.badInput(e.getMessage())); | ||
| } | ||
|
|
||
| // The request body is forwarded unchanged; no caller-owned struct is mutated. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove comment
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed this one too. |
||
| return Result.withValue(HttpRequest.<BidRequest>builder() | ||
| .method(HttpMethod.POST) | ||
| .uri(uri) | ||
| .headers(HttpUtil.headers()) | ||
| .impIds(BidderUtil.impIds(request)) | ||
| .payload(request) | ||
| .body(mapper.encodeToBytes(request)) | ||
| .build()); | ||
| } | ||
|
|
||
| // A single request routes to one Floxis host/seat (the seat is the URL query key, partner+region | ||
| // the host). All imps must therefore share the same seat, region and partner; a mismatch is a | ||
| // misconfigured request rather than something to silently route on imp[0]'s key. | ||
|
floxis-admin marked this conversation as resolved.
Outdated
|
||
| private ExtImpFloxis resolveCommonImpExt(List<Imp> imps) { | ||
| final ExtImpFloxis first = parseImpExt(imps.getFirst()); | ||
| for (Imp imp : imps.subList(1, imps.size())) { | ||
| final ExtImpFloxis current = parseImpExt(imp); | ||
| if (!Objects.equals(current.getSeat(), first.getSeat()) | ||
| || !Objects.equals(current.getRegion(), first.getRegion()) | ||
| || !Objects.equals(current.getPartner(), first.getPartner())) { | ||
| throw new PreBidException( | ||
| "all impressions must target the same Floxis seat, region and partner; " | ||
| + "imp %s differs from imp %s" | ||
| .formatted(imp.getId(), imps.getFirst().getId())); | ||
| } | ||
| } | ||
| return first; | ||
| } | ||
|
floxis-admin marked this conversation as resolved.
Outdated
|
||
|
|
||
| private ExtImpFloxis parseImpExt(Imp imp) { | ||
| try { | ||
| return mapper.mapper().convertValue(imp.getExt(), FLOXIS_EXT_TYPE_REFERENCE).getBidder(); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new PreBidException("invalid imp.ext.bidder for imp %s: %s".formatted(imp.getId(), e.getMessage())); | ||
| } | ||
| } | ||
|
|
||
| // {{Host}} subdomain label for the endpoint template (which pins the fixed .floxis.tech | ||
| // domain): the region, or partner-region for a named supply partner (floxis has no prefix). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove comment
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gone. |
||
| private static String resolveBidHost(String region, String partner) { | ||
| final String resolvedRegion = isBlank(region) ? DEFAULT_REGION : region; | ||
| final String resolvedPartner = isBlank(partner) ? DEFAULT_PARTNER : partner; | ||
| if (!HOST_LABEL.matcher(resolvedRegion).matches() || !HOST_LABEL.matcher(resolvedPartner).matches()) { | ||
| throw new PreBidException( | ||
| "invalid Floxis region or partner; both must be DNS labels: region=%s partner=%s" | ||
| .formatted(resolvedRegion, resolvedPartner)); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for regex. It will be already validated using regex in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed β dropped it. floxis.json already enforces the same pattern, so the in-code regex was redundant. |
||
| return resolvedPartner.equals(DEFAULT_PARTNER) | ||
| ? resolvedRegion | ||
| : resolvedPartner + "-" + resolvedRegion; | ||
|
floxis-admin marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| private static boolean isBlank(String value) { | ||
| return value == null || value.isEmpty(); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched to StringUtils.isBlank and removed the custom helper. |
||
|
|
||
| private static String resolveUrl(String endpoint, ExtImpFloxis extImp) { | ||
| return endpoint | ||
| .replace(HOST_MACRO, resolveBidHost(extImp.getRegion(), extImp.getPartner())) | ||
| .replace(SEAT_MACRO, HttpUtil.encodeUrl(extImp.getSeat())); | ||
| } | ||
|
|
||
| @Override | ||
| public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
| final BidResponse bidResponse; | ||
| try { | ||
| bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
| } catch (DecodeException e) { | ||
| return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
|
|
||
| if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) { | ||
| return Result.empty(); | ||
| } | ||
|
|
||
| final List<BidderError> errors = new ArrayList<>(); | ||
| final List<BidderBid> bids = new ArrayList<>(); | ||
| for (SeatBid seatBid : bidResponse.getSeatbid()) { | ||
| if (seatBid == null || CollectionUtils.isEmpty(seatBid.getBid())) { | ||
| continue; | ||
| } | ||
| for (Bid bid : seatBid.getBid()) { | ||
| try { | ||
| bids.add(BidderBid.of(bid, getMediaTypeForBid(bidRequest.getImp(), bid), bidResponse.getCur())); | ||
| } catch (PreBidException e) { | ||
| errors.add(BidderError.badServerResponse(e.getMessage())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return Result.of(bids, errors); | ||
|
floxis-admin marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // Resolves the bid's media type. When bid.mtype (OpenRTB 2.6) is set it is treated as | ||
| // authoritative. When unset, a single-format imp's media type is used; multi-format imps | ||
| // without mtype cannot be disambiguated and surface an error. | ||
|
floxis-admin marked this conversation as resolved.
Outdated
|
||
| private static BidType getMediaTypeForBid(List<Imp> imps, Bid bid) { | ||
| final Integer mtype = bid.getMtype(); | ||
| if (mtype != null && mtype != 0) { | ||
| return switch (mtype) { | ||
| case 1 -> BidType.banner; | ||
| case 2 -> BidType.video; | ||
| case 3 -> BidType.audio; | ||
| case 4 -> BidType.xNative; | ||
| default -> throw new PreBidException( | ||
| "unsupported bid.mtype %d for impression %s".formatted(mtype, bid.getImpid())); | ||
| }; | ||
| } | ||
|
|
||
| for (Imp imp : imps) { | ||
| if (!Objects.equals(imp.getId(), bid.getImpid())) { | ||
| continue; | ||
| } | ||
| int formats = 0; | ||
| BidType resolved = null; | ||
| if (imp.getBanner() != null) { | ||
| formats++; | ||
| resolved = BidType.banner; | ||
| } | ||
| if (imp.getVideo() != null) { | ||
| formats++; | ||
| resolved = BidType.video; | ||
| } | ||
| if (imp.getAudio() != null) { | ||
| formats++; | ||
| resolved = BidType.audio; | ||
| } | ||
| if (imp.getXNative() != null) { | ||
| formats++; | ||
| resolved = BidType.xNative; | ||
| } | ||
| if (formats == 1) { | ||
| return resolved; | ||
| } else if (formats > 1) { | ||
| throw new PreBidException( | ||
| "bid for multi-format imp %s requires bid.mtype to disambiguate".formatted(bid.getImpid())); | ||
| } else { | ||
| throw new PreBidException( | ||
| "unable to resolve media type for impression %s".formatted(bid.getImpid())); | ||
| } | ||
|
floxis-admin marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| throw new PreBidException("unable to find impression %s for bid".formatted(bid.getImpid())); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.prebid.server.proto.openrtb.ext.request.floxis; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import lombok.Value; | ||
|
|
||
| @Value(staticConstructor = "of") | ||
| public class ExtImpFloxis { | ||
|
|
||
| @JsonProperty("seat") | ||
| String seat; | ||
|
|
||
| @JsonProperty("region") | ||
| String region; | ||
|
|
||
| @JsonProperty("partner") | ||
| String partner; | ||
|
floxis-admin marked this conversation as resolved.
Outdated
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.prebid.server.spring.config.bidder; | ||
|
|
||
| import org.prebid.server.bidder.BidderDeps; | ||
| import org.prebid.server.bidder.floxis.FloxisBidder; | ||
| 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/floxis.yaml", | ||
| factory = YamlPropertySourceFactory.class) | ||
|
floxis-admin marked this conversation as resolved.
Outdated
|
||
| public class FloxisConfiguration { | ||
|
|
||
| private static final String BIDDER_NAME = "floxis"; | ||
|
|
||
| @Bean("floxisConfigurationProperties") | ||
| @ConfigurationProperties("adapters.floxis") | ||
| BidderConfigurationProperties configurationProperties() { | ||
| return new BidderConfigurationProperties(); | ||
| } | ||
|
|
||
| @Bean | ||
| BidderDeps floxisBidderDeps(BidderConfigurationProperties floxisConfigurationProperties, | ||
| @NotBlank @Value("${external-url}") String externalUrl, | ||
| JacksonMapper mapper) { | ||
|
|
||
| return BidderDepsAssembler.forBidder(BIDDER_NAME) | ||
| .withConfig(floxisConfigurationProperties) | ||
| .usersyncerCreator(UsersyncerCreator.create(externalUrl)) | ||
| .bidderCreator(config -> new FloxisBidder(config.getEndpoint(), mapper)) | ||
| .assemble(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| adapters: | ||
| floxis: | ||
| endpoint: https://{{Host}}.floxis.tech/pbs?seat={{SeatId}} | ||
| ortb-version: "2.6" | ||
| modifying-vast-xml-allowed: false | ||
| meta-info: | ||
| maintainer-email: prebid@floxis.tech | ||
| app-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| - audio | ||
| site-media-types: | ||
| - banner | ||
| - video | ||
| - native | ||
| - audio | ||
| supported-vendors: | ||
| vendor-id: 1609 | ||
| usersync: | ||
| cookie-family-name: floxis | ||
| redirect: | ||
| url: "https://px-us-e.floxis.tech/sync?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&gpp={{gpp}}&gpp_sid={{gpp_sid}}&us_privacy={{us_privacy}}&dest={{redirect_url}}" | ||
| support-cors: false | ||
| uid-macro: "${USER_ID}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Floxis Adapter Params", | ||
| "description": "A schema which validates params accepted by the Floxis adapter", | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "properties": { | ||
| "seat": { | ||
| "type": "string", | ||
| "minLength": 1, | ||
| "description": "The Floxis seat ID this publisher buys through" | ||
| }, | ||
| "region": { | ||
| "type": "string", | ||
| "pattern": "^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$", | ||
| "description": "The Floxis region (DNS label, interpolated into the bidding host); defaults to us-e when omitted" | ||
| }, | ||
| "partner": { | ||
| "type": "string", | ||
| "pattern": "^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$", | ||
| "description": "The white-label partner (DNS label, interpolated into the bidding host); defaults to floxis when omitted" | ||
| } | ||
| }, | ||
| "required": ["seat"] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.