From 7976a0c5dd79dcc972725277fd28f7f35a34a306 Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Fri, 15 Oct 2021 13:59:38 +0300 Subject: [PATCH 1/5] Refactor HttpRequest to support body as array of bytes --- .../analytics/LogAnalyticsReporter.java | 2 +- .../pubstack/PubstackEventHandler.java | 2 +- .../server/auction/BidResponseCreator.java | 2 +- .../prebid/server/bidder/GenericBidder.java | 2 +- .../server/bidder/HttpBidderRequester.java | 22 ++- .../prebid/server/bidder/OpenrtbBidder.java | 3 +- .../server/bidder/aceex/AceexBidder.java | 2 +- .../bidder/acuityads/AcuityadsBidder.java | 2 +- .../server/bidder/adagio/AdagioBidder.java | 2 +- .../bidder/adform/AdformRequestUtil.java | 2 +- .../server/bidder/adhese/AdheseBidder.java | 2 +- .../bidder/adkernel/AdkernelBidder.java | 3 +- .../bidder/adkerneladn/AdkernelAdnBidder.java | 3 +- .../server/bidder/admixer/AdmixerBidder.java | 3 +- .../bidder/adoppler/AdopplerBidder.java | 3 +- .../prebid/server/bidder/adot/AdotBidder.java | 2 +- .../server/bidder/adpone/AdponeBidder.java | 2 +- .../bidder/adtarget/AdtargetBidder.java | 2 +- .../bidder/adtelligent/AdtelligentBidder.java | 4 +- .../advangelists/AdvangelistsBidder.java | 2 +- .../server/bidder/adview/AdviewBidder.java | 2 +- .../server/bidder/adxcg/AdxcgBidder.java | 2 +- .../bidder/adyoulike/AdyoulikeBidder.java | 2 +- .../prebid/server/bidder/aja/AjaBidder.java | 4 +- .../server/bidder/algorix/AlgorixBidder.java | 2 +- .../prebid/server/bidder/amx/AmxBidder.java | 2 +- .../server/bidder/applogy/ApplogyBidder.java | 2 +- .../bidder/appnexus/AppnexusBidder.java | 2 +- .../server/bidder/avocet/AvocetBidder.java | 4 +- .../server/bidder/axonix/AxonixBidder.java | 2 +- .../bidder/beachfront/BeachfrontBidder.java | 4 +- .../server/bidder/beintoo/BeintooBidder.java | 3 +- .../server/bidder/between/BetweenBidder.java | 2 +- .../bidder/bidmachine/BidmachineBidder.java | 3 +- .../bidder/bidmyadz/BidmyadzBidder.java | 2 +- .../bidder/bidscube/BidscubeBidder.java | 2 +- .../prebid/server/bidder/bmtm/BmtmBidder.java | 3 +- .../bidder/brightroll/BrightrollBidder.java | 4 +- .../bidder/connectad/ConnectadBidder.java | 2 +- .../bidder/consumable/ConsumableBidder.java | 4 +- .../bidder/conversant/ConversantBidder.java | 2 +- .../server/bidder/cpmstar/CpmStarBidder.java | 2 +- .../server/bidder/criteo/CriteoBidder.java | 2 +- .../bidder/datablocks/DatablocksBidder.java | 3 +- .../bidder/decenterads/DecenteradsBidder.java | 2 +- .../bidder/deepintent/DeepintentBidder.java | 2 +- .../prebid/server/bidder/dmx/DmxBidder.java | 2 +- .../bidder/emxdigital/EmxDigitalBidder.java | 10 +- .../bidder/engagebdr/EngagebdrBidder.java | 3 +- .../prebid/server/bidder/epom/EpomBidder.java | 2 +- .../bidder/evolution/EvolutionBidder.java | 2 +- .../bidder/facebook/FacebookBidder.java | 4 +- .../server/bidder/gamoshi/GamoshiBidder.java | 3 +- .../prebid/server/bidder/grid/GridBidder.java | 2 +- .../server/bidder/gumgum/GumgumBidder.java | 2 +- .../improvedigital/ImprovedigitalBidder.java | 2 +- .../server/bidder/inmobi/InmobiBidder.java | 2 +- .../InteractiveOffersBidder.java | 2 +- .../server/bidder/invibes/InvibesBidder.java | 6 +- .../server/bidder/iqzone/IqzoneBidder.java | 2 +- .../org/prebid/server/bidder/ix/IxBidder.java | 4 +- .../server/bidder/jixie/JixieBidder.java | 2 +- .../server/bidder/kayzen/KayzenBidder.java | 2 +- .../server/bidder/kidoz/KidozBidder.java | 4 +- .../bidder/krushmedia/KrushmediaBidder.java | 2 +- .../server/bidder/kubient/KubientBidder.java | 4 +- .../bidder/lockerdome/LockerdomeBidder.java | 4 +- .../server/bidder/logicad/LogicadBidder.java | 3 +- .../server/bidder/loopme/LoopmeBidder.java | 2 +- .../bidder/lunamedia/LunamediaBidder.java | 2 +- .../bidder/madvertise/MadvertiseBidder.java | 2 +- .../bidder/marsmedia/MarsmediaBidder.java | 4 +- .../prebid/server/bidder/mgid/MgidBidder.java | 2 +- .../bidder/mobfoxpb/MobfoxpbBidder.java | 2 +- .../bidder/mobilefuse/MobilefuseBidder.java | 3 +- .../server/bidder/model/HttpRequest.java | 2 +- .../NanointeractiveBidder.java | 3 +- .../ninthdecimal/NinthdecimalBidder.java | 3 +- .../server/bidder/nobid/NobidBidder.java | 2 +- .../server/bidder/onetag/OnetagBidder.java | 2 +- .../server/bidder/openweb/OpenWebBidder.java | 2 +- .../server/bidder/openx/OpenxBidder.java | 8 +- .../bidder/operaads/OperaadsBidder.java | 4 +- .../bidder/orbidder/OrbidderBidder.java | 3 +- .../bidder/outbrain/OutbrainBidder.java | 6 +- .../server/bidder/pangle/PangleBidder.java | 2 +- .../bidder/pubmatic/PubmaticBidder.java | 3 +- .../bidder/pubnative/PubnativeBidder.java | 2 +- .../bidder/rhythmone/RhythmoneBidder.java | 3 +- .../server/bidder/rubicon/RubiconBidder.java | 2 +- .../bidder/salunamedia/SaLunamediaBidder.java | 2 +- .../sharethrough/SharethroughBidder.java | 2 +- .../bidder/silvermob/SilvermobBidder.java | 2 +- .../server/bidder/smaato/SmaatoBidder.java | 2 +- .../smartadserver/SmartadserverBidder.java | 2 +- .../bidder/smarthub/SmarthubBidder.java | 2 +- .../bidder/smartrtb/SmartrtbBidder.java | 3 +- .../bidder/smartyads/SmartyAdsBidder.java | 2 +- .../bidder/smilewanted/SmileWantedBidder.java | 2 +- .../somoaudience/SomoaudienceBidder.java | 2 +- .../server/bidder/sovrn/SovrnBidder.java | 3 +- .../synacormedia/SynacormediaBidder.java | 2 +- .../server/bidder/tappx/TappxBidder.java | 2 +- .../server/bidder/telaria/TelariaBidder.java | 3 +- .../bidder/triplelift/TripleliftBidder.java | 2 +- .../TripleliftNativeBidder.java | 2 +- .../prebid/server/bidder/ttx/TtxBidder.java | 2 +- .../bidder/ucfunnel/UcfunnelBidder.java | 3 +- .../server/bidder/unicorn/UnicornBidder.java | 2 +- .../server/bidder/unruly/UnrulyBidder.java | 4 +- .../ValueImpressionBidder.java | 2 +- .../prebid/server/bidder/visx/VisxBidder.java | 2 +- .../bidder/yahoossp/YahooSSPBidder.java | 2 +- .../bidder/yeahmobi/YeahmobiBidder.java | 4 +- .../bidder/yieldone/YieldoneBidder.java | 2 +- .../zeroclickfraud/ZeroclickfraudBidder.java | 3 +- .../org/prebid/server/cache/CacheService.java | 4 +- .../org/prebid/server/cookie/UidsCookie.java | 2 +- .../prebid/server/deals/AlertHttpService.java | 2 +- .../server/deals/DeliveryStatsService.java | 2 +- .../prebid/server/deals/RegisterService.java | 2 +- .../org/prebid/server/deals/UserService.java | 4 +- .../SimulationAwareHttpBidderRequester.java | 6 +- .../handler/CollectedMetricsHandler.java | 2 +- .../server/handler/CookieSyncHandler.java | 2 +- .../server/handler/DealsStatusHandler.java | 2 +- .../prebid/server/handler/GetuidsHandler.java | 2 +- .../server/handler/LineItemStatusHandler.java | 2 +- .../prebid/server/handler/StatusHandler.java | 2 +- .../prebid/server/handler/VtrackHandler.java | 2 +- .../handler/info/BidderDetailsHandler.java | 2 +- .../server/handler/info/BiddersHandler.java | 2 +- .../server/handler/openrtb2/AmpHandler.java | 2 +- .../handler/openrtb2/AuctionHandler.java | 2 +- .../server/handler/openrtb2/VideoHandler.java | 2 +- .../org/prebid/server/json/JacksonMapper.java | 18 ++- .../prebid/server/log/CriteriaLogManager.java | 4 +- .../server/log/HttpInteractionLogger.java | 4 +- .../spring/config/ServiceConfiguration.java | 6 +- .../validation/BidderParamValidator.java | 2 +- .../VideoStoredRequestProcessorTest.java | 6 +- .../bidder/BidderErrorNotifierTest.java | 23 +-- .../bidder/HttpBidderRequesterTest.java | 151 +++++++++++------- .../bidder/adhese/AdheseBidderTest.java | 8 +- .../bidder/adocean/AdoceanBidderTest.java | 7 +- .../adtelligent/AdtelligentBidderTest.java | 2 +- .../beachfront/BeachfrontBidderTest.java | 16 +- .../brightroll/BrightrollBidderTest.java | 6 +- .../bidder/facebook/FacebookBidderTest.java | 31 ++-- .../server/bidder/mgid/MgidBidderTest.java | 6 +- .../bidder/outbrain/OutbrainBidderTest.java | 4 +- .../sharethrough/SharethroughBidderTest.java | 4 +- .../prebid/server/deals/UserServiceTest.java | 10 +- .../execution/HookStageExecutorTest.java | 2 +- 154 files changed, 361 insertions(+), 322 deletions(-) diff --git a/src/main/java/org/prebid/server/analytics/LogAnalyticsReporter.java b/src/main/java/org/prebid/server/analytics/LogAnalyticsReporter.java index f947e226178..14e472c1226 100644 --- a/src/main/java/org/prebid/server/analytics/LogAnalyticsReporter.java +++ b/src/main/java/org/prebid/server/analytics/LogAnalyticsReporter.java @@ -49,7 +49,7 @@ public Future processEvent(T event) { logEvent = new LogEvent<>("unknown", null); } - logger.debug(mapper.encode(logEvent)); + logger.debug(mapper.encodeToString(logEvent)); return Future.succeededFuture(); } diff --git a/src/main/java/org/prebid/server/analytics/pubstack/PubstackEventHandler.java b/src/main/java/org/prebid/server/analytics/pubstack/PubstackEventHandler.java index 35491f22046..9dda0492e62 100644 --- a/src/main/java/org/prebid/server/analytics/pubstack/PubstackEventHandler.java +++ b/src/main/java/org/prebid/server/analytics/pubstack/PubstackEventHandler.java @@ -103,7 +103,7 @@ public void updateConfig(boolean enabled, String endpoint, String scopeId) { private void buffer(T event) { final ObjectNode eventNode = jacksonMapper.mapper().valueToTree(event); eventNode.put(SCOPE_FIELD_NAME, scopeId); - final String jsonEvent = jacksonMapper.encode(eventNode); + final String jsonEvent = jacksonMapper.encodeToString(eventNode); events.get().add(jsonEvent); byteSize.getAndAdd(jsonEvent.getBytes().length); } diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 9bdfade0a81..dedd70c0bc9 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -1259,7 +1259,7 @@ private String createNativeMarkup(String bidAdm, Imp correspondingImp) { } responseAssets.forEach(asset -> setAssetTypes(asset, nativeRequest.getAssets())); - return mapper.encode(nativeMarkup); + return mapper.encodeToString(nativeMarkup); } return bidAdm; diff --git a/src/main/java/org/prebid/server/bidder/GenericBidder.java b/src/main/java/org/prebid/server/bidder/GenericBidder.java index d653e86eff5..88da5f28826 100644 --- a/src/main/java/org/prebid/server/bidder/GenericBidder.java +++ b/src/main/java/org/prebid/server/bidder/GenericBidder.java @@ -40,7 +40,7 @@ public final Result>> makeHttpRequests(BidRequest b .method(HttpMethod.POST) .uri(endpointUrl) .headers(HttpUtil.headers()) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .payload(bidRequest) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java b/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java index e46f4cc5cf1..1cd5fe665ec 100644 --- a/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java +++ b/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java @@ -19,6 +19,7 @@ import org.prebid.server.bidder.model.HttpResponse; import org.prebid.server.bidder.model.Result; import org.prebid.server.execution.Timeout; +import org.prebid.server.json.JacksonMapper; import org.prebid.server.model.CaseInsensitiveMultiMap; import org.prebid.server.proto.openrtb.ext.response.ExtHttpCall; import org.prebid.server.util.HttpUtil; @@ -52,16 +53,19 @@ public class HttpBidderRequester { private final BidderRequestCompletionTrackerFactory completionTrackerFactory; private final BidderErrorNotifier bidderErrorNotifier; private final HttpBidderRequestEnricher requestEnricher; + private final JacksonMapper mapper; public HttpBidderRequester(HttpClient httpClient, BidderRequestCompletionTrackerFactory completionTrackerFactory, BidderErrorNotifier bidderErrorNotifier, - HttpBidderRequestEnricher requestEnricher) { + HttpBidderRequestEnricher requestEnricher, + JacksonMapper mapper) { this.httpClient = Objects.requireNonNull(httpClient); this.completionTrackerFactory = completionTrackerFactoryOrFallback(completionTrackerFactory); this.bidderErrorNotifier = Objects.requireNonNull(bidderErrorNotifier); this.requestEnricher = Objects.requireNonNull(requestEnricher); + this.mapper = Objects.requireNonNull(mapper); } /** @@ -93,7 +97,8 @@ public Future requestBids(Bidder bidder, : httpRequests.stream().map(httpRequest -> doRequest(httpRequest, timeout)); final BidderRequestCompletionTracker completionTracker = completionTrackerFactory.create(bidRequest); - final ResultBuilder resultBuilder = new ResultBuilder<>(httpRequests, bidderErrors, completionTracker); + final ResultBuilder resultBuilder = + new ResultBuilder<>(httpRequests, bidderErrors, completionTracker, mapper); final List> httpRequestFutures = httpCalls .map(httpCallFuture -> httpCallFuture @@ -266,13 +271,16 @@ private static class ResultBuilder { final Map, HttpCall> httpCallsRecorded = new HashMap<>(); final List bidsRecorded = new ArrayList<>(); final List errorsRecorded = new ArrayList<>(); + private final JacksonMapper mapper; ResultBuilder(List> httpRequests, List previousErrors, - BidderRequestCompletionTracker completionTracker) { + BidderRequestCompletionTracker completionTracker, + JacksonMapper mapper) { this.httpRequests = httpRequests; this.previousErrors = previousErrors; this.completionTracker = completionTracker; + this.mapper = mapper; } void addHttpCall(HttpCall httpCall, Result> bidsResult) { @@ -299,7 +307,9 @@ BidderSeatBid toBidderSeatBid(boolean debugEnabled) { // Capture debugging info from the requests final List extHttpCalls = debugEnabled - ? httpCalls.stream().map(ResultBuilder::toExt).collect(Collectors.toList()) + ? httpCalls.stream() + .map(httpCall -> toExt(httpCall, mapper)) + .collect(Collectors.toList()) : Collections.emptyList(); final List errors = errors(previousErrors, httpCalls, errorsRecorded); @@ -310,11 +320,11 @@ BidderSeatBid toBidderSeatBid(boolean debugEnabled) { /** * Constructs {@link ExtHttpCall} filled with HTTP call information. */ - private static ExtHttpCall toExt(HttpCall httpCall) { + private static ExtHttpCall toExt(HttpCall httpCall, JacksonMapper mapper) { final HttpRequest request = httpCall.getRequest(); final ExtHttpCall.ExtHttpCallBuilder builder = ExtHttpCall.builder() .uri(request.getUri()) - .requestbody(request.getBody()) + .requestbody(mapper.encodeToString(request.getPayload())) .requestheaders(HttpUtil.toDebugHeaders(request.getHeaders())); final HttpResponse response = httpCall.getResponse(); diff --git a/src/main/java/org/prebid/server/bidder/OpenrtbBidder.java b/src/main/java/org/prebid/server/bidder/OpenrtbBidder.java index 72998feb6f7..1cea93ef1cf 100644 --- a/src/main/java/org/prebid/server/bidder/OpenrtbBidder.java +++ b/src/main/java/org/prebid/server/bidder/OpenrtbBidder.java @@ -161,12 +161,11 @@ private HttpRequest makeRequest(BidRequest bidRequest, Listbuilder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(headers()) .payload(outgoingRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/aceex/AceexBidder.java b/src/main/java/org/prebid/server/bidder/aceex/AceexBidder.java index 9d35c0e54a4..eec5e76d4b1 100644 --- a/src/main/java/org/prebid/server/bidder/aceex/AceexBidder.java +++ b/src/main/java/org/prebid/server/bidder/aceex/AceexBidder.java @@ -59,7 +59,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .uri(resolveEndpoint(extImpAceex.getAccountId())) .headers(constructHeaders(request)) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .payload(request) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/acuityads/AcuityadsBidder.java b/src/main/java/org/prebid/server/bidder/acuityads/AcuityadsBidder.java index c8bba89783b..d8af07580d9 100644 --- a/src/main/java/org/prebid/server/bidder/acuityads/AcuityadsBidder.java +++ b/src/main/java/org/prebid/server/bidder/acuityads/AcuityadsBidder.java @@ -70,7 +70,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(url) .headers(resolveHeaders(request.getDevice())) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), Collections.emptyList()); } diff --git a/src/main/java/org/prebid/server/bidder/adagio/AdagioBidder.java b/src/main/java/org/prebid/server/bidder/adagio/AdagioBidder.java index 1e02b7e49d4..7f11c4aa7a0 100644 --- a/src/main/java/org/prebid/server/bidder/adagio/AdagioBidder.java +++ b/src/main/java/org/prebid/server/bidder/adagio/AdagioBidder.java @@ -46,7 +46,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(resolveHeaders(request.getDevice())) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/adform/AdformRequestUtil.java b/src/main/java/org/prebid/server/bidder/adform/AdformRequestUtil.java index 9cc2260fff0..700dcec2161 100644 --- a/src/main/java/org/prebid/server/bidder/adform/AdformRequestUtil.java +++ b/src/main/java/org/prebid/server/bidder/adform/AdformRequestUtil.java @@ -55,7 +55,7 @@ String getEids(ExtUser extUser, JacksonMapper mapper) { } } - final String encodedEids = mapper.encode(eidsMap); + final String encodedEids = mapper.encodeToString(eidsMap); return ObjectUtils .defaultIfNull(Base64.getUrlEncoder().withoutPadding().encodeToString(encodedEids.getBytes()), diff --git a/src/main/java/org/prebid/server/bidder/adhese/AdheseBidder.java b/src/main/java/org/prebid/server/bidder/adhese/AdheseBidder.java index ad39c142947..4b5ff672c06 100644 --- a/src/main/java/org/prebid/server/bidder/adhese/AdheseBidder.java +++ b/src/main/java/org/prebid/server/bidder/adhese/AdheseBidder.java @@ -84,7 +84,7 @@ public Result>> makeHttpRequests(BidRequest request) { HttpRequest.builder() .method(HttpMethod.POST) .uri(uri) - .body(mapper.encode(buildBody(request, extImpAdhese))) + .body(mapper.encodeToBytes(buildBody(request, extImpAdhese))) .headers(replaceHeaders(request.getDevice())) .build()), Collections.emptyList()); diff --git a/src/main/java/org/prebid/server/bidder/adkernel/AdkernelBidder.java b/src/main/java/org/prebid/server/bidder/adkernel/AdkernelBidder.java index 769e7c4e6d0..caa85e76a4e 100644 --- a/src/main/java/org/prebid/server/bidder/adkernel/AdkernelBidder.java +++ b/src/main/java/org/prebid/server/bidder/adkernel/AdkernelBidder.java @@ -132,13 +132,12 @@ private HttpRequest createHttpRequest(Map.Entrybuilder() .method(HttpMethod.POST) .uri(uri) .headers(headers) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/adkerneladn/AdkernelAdnBidder.java b/src/main/java/org/prebid/server/bidder/adkerneladn/AdkernelAdnBidder.java index 3e9688fed43..a7c4a91576a 100644 --- a/src/main/java/org/prebid/server/bidder/adkerneladn/AdkernelAdnBidder.java +++ b/src/main/java/org/prebid/server/bidder/adkerneladn/AdkernelAdnBidder.java @@ -175,11 +175,10 @@ private List> buildAdapterRequests(BidRequest preBidRequ private HttpRequest createRequest(ExtImpAdkernelAdn extImp, List imps, BidRequest preBidRequest) { final BidRequest outgoingRequest = createBidRequest(preBidRequest, imps); - final String body = mapper.encode(outgoingRequest); return HttpRequest.builder() .method(HttpMethod.POST) .uri(buildEndpoint(extImp)) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(headers()) .payload(outgoingRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/admixer/AdmixerBidder.java b/src/main/java/org/prebid/server/bidder/admixer/AdmixerBidder.java index b7b41cfc804..3315dd98170 100644 --- a/src/main/java/org/prebid/server/bidder/admixer/AdmixerBidder.java +++ b/src/main/java/org/prebid/server/bidder/admixer/AdmixerBidder.java @@ -63,7 +63,6 @@ public Result>> makeHttpRequests(BidRequest request } } final BidRequest outgoingRequest = request.toBuilder().imp(validImps).build(); - final String body = mapper.encode(outgoingRequest); return Result.of(Collections.singletonList( HttpRequest.builder() @@ -71,7 +70,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/adoppler/AdopplerBidder.java b/src/main/java/org/prebid/server/bidder/adoppler/AdopplerBidder.java index 3b05ec3f98c..8e761fb4049 100644 --- a/src/main/java/org/prebid/server/bidder/adoppler/AdopplerBidder.java +++ b/src/main/java/org/prebid/server/bidder/adoppler/AdopplerBidder.java @@ -103,13 +103,12 @@ private String resolveUrl(ExtImpAdoppler extImp) { private HttpRequest createSingleRequest(Imp imp, BidRequest request, String url) { final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(imp)).build(); - final String body = mapper.encode(outgoingRequest); final MultiMap headers = HttpUtil.headers().add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5"); return HttpRequest.builder() .method(HttpMethod.POST) .uri(url) .headers(headers) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/adot/AdotBidder.java b/src/main/java/org/prebid/server/bidder/adot/AdotBidder.java index 543ab275c13..ac409d92ad1 100644 --- a/src/main/java/org/prebid/server/bidder/adot/AdotBidder.java +++ b/src/main/java/org/prebid/server/bidder/adot/AdotBidder.java @@ -52,7 +52,7 @@ public Result>> makeHttpRequests(BidRequest bidRequ .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(bidRequest) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/adpone/AdponeBidder.java b/src/main/java/org/prebid/server/bidder/adpone/AdponeBidder.java index 13647763e6c..7ac14552680 100644 --- a/src/main/java/org/prebid/server/bidder/adpone/AdponeBidder.java +++ b/src/main/java/org/prebid/server/bidder/adpone/AdponeBidder.java @@ -49,7 +49,7 @@ public Result>> makeHttpRequests(BidRequest bidRequ .uri(endpointUrl) .headers(HttpUtil.headers() .add(HttpUtil.X_OPENRTB_VERSION_HEADER, OPENRTB_VERSION)) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .payload(bidRequest) .build()), Collections.emptyList()); diff --git a/src/main/java/org/prebid/server/bidder/adtarget/AdtargetBidder.java b/src/main/java/org/prebid/server/bidder/adtarget/AdtargetBidder.java index 46180d24045..67f798debaa 100644 --- a/src/main/java/org/prebid/server/bidder/adtarget/AdtargetBidder.java +++ b/src/main/java/org/prebid/server/bidder/adtarget/AdtargetBidder.java @@ -62,7 +62,7 @@ public Result>> makeHttpRequests(BidRequest request httpRequests.add(HttpRequest.builder() .method(HttpMethod.POST) .uri(url) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .headers(HttpUtil.headers()) .payload(bidRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/adtelligent/AdtelligentBidder.java b/src/main/java/org/prebid/server/bidder/adtelligent/AdtelligentBidder.java index f1816d19400..7c2c6b18839 100644 --- a/src/main/java/org/prebid/server/bidder/adtelligent/AdtelligentBidder.java +++ b/src/main/java/org/prebid/server/bidder/adtelligent/AdtelligentBidder.java @@ -115,9 +115,9 @@ private Result>> createHttpRequests(Map> sourceIdToImps : sourceToImps.entrySet()) { final String url = String.format("%s?aid=%d", endpointUrl, sourceIdToImps.getKey()); final BidRequest bidRequest = request.toBuilder().imp(sourceIdToImps.getValue()).build(); - final String bidRequestBody; + final byte[] bidRequestBody; try { - bidRequestBody = mapper.encode(bidRequest); + bidRequestBody = mapper.encodeToBytes(bidRequest); } catch (EncodeException e) { errors.add(BidderError.badInput( String.format("error while encoding bidRequest, err: %s", e.getMessage()))); diff --git a/src/main/java/org/prebid/server/bidder/advangelists/AdvangelistsBidder.java b/src/main/java/org/prebid/server/bidder/advangelists/AdvangelistsBidder.java index 410de427315..5afa4104357 100644 --- a/src/main/java/org/prebid/server/bidder/advangelists/AdvangelistsBidder.java +++ b/src/main/java/org/prebid/server/bidder/advangelists/AdvangelistsBidder.java @@ -158,7 +158,7 @@ private List> buildAdapterRequests(BidRequest bidRequest final HttpRequest createdBidRequest = HttpRequest.builder() .method(HttpMethod.POST) .uri(createdEndpoint) - .body(mapper.encode(updatedBidRequest)) + .body(mapper.encodeToBytes(updatedBidRequest)) .headers(headers) .payload(bidRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/adview/AdviewBidder.java b/src/main/java/org/prebid/server/bidder/adview/AdviewBidder.java index 6cf0d745574..5de8002241e 100644 --- a/src/main/java/org/prebid/server/bidder/adview/AdviewBidder.java +++ b/src/main/java/org/prebid/server/bidder/adview/AdviewBidder.java @@ -61,7 +61,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .uri(resolveEndpoint(extImpAdview.getAccountId())) .headers(HttpUtil.headers()) - .body(mapper.encode(modifiedRequest)) + .body(mapper.encodeToBytes(modifiedRequest)) .payload(modifiedRequest) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/adxcg/AdxcgBidder.java b/src/main/java/org/prebid/server/bidder/adxcg/AdxcgBidder.java index 4a02e60add4..e7f2e5480d6 100644 --- a/src/main/java/org/prebid/server/bidder/adxcg/AdxcgBidder.java +++ b/src/main/java/org/prebid/server/bidder/adxcg/AdxcgBidder.java @@ -43,7 +43,7 @@ public Result>> makeHttpRequests(BidRequest bidRequ .method(HttpMethod.POST) .uri(endpointUrl) .headers(HttpUtil.headers()) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .payload(bidRequest) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/adyoulike/AdyoulikeBidder.java b/src/main/java/org/prebid/server/bidder/adyoulike/AdyoulikeBidder.java index 76659033446..e7d0405523c 100644 --- a/src/main/java/org/prebid/server/bidder/adyoulike/AdyoulikeBidder.java +++ b/src/main/java/org/prebid/server/bidder/adyoulike/AdyoulikeBidder.java @@ -71,7 +71,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(resolveHeaders()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/aja/AjaBidder.java b/src/main/java/org/prebid/server/bidder/aja/AjaBidder.java index 4796727a4cc..dbf5bb473ee 100644 --- a/src/main/java/org/prebid/server/bidder/aja/AjaBidder.java +++ b/src/main/java/org/prebid/server/bidder/aja/AjaBidder.java @@ -100,9 +100,9 @@ private HttpRequest createSingleRequest(Imp imp, BidRequest request, .imp(Collections.singletonList(imp)) .build(); - final String body; + final byte[] body; try { - body = mapper.encode(outgoingRequest); + body = mapper.encodeToBytes(outgoingRequest); } catch (EncodeException e) { errors.add(BidderError.badInput( String.format("Failed to unmarshal bidrequest ID: %s err: %s", request.getId(), e.getMessage()))); diff --git a/src/main/java/org/prebid/server/bidder/algorix/AlgorixBidder.java b/src/main/java/org/prebid/server/bidder/algorix/AlgorixBidder.java index ce4cf3b8eec..e4b42c4f482 100644 --- a/src/main/java/org/prebid/server/bidder/algorix/AlgorixBidder.java +++ b/src/main/java/org/prebid/server/bidder/algorix/AlgorixBidder.java @@ -74,7 +74,7 @@ public Result>> makeHttpRequests(BidRequest request } final BidRequest outgoingRequest = request.toBuilder().imp(updatedImps).build(); - final String body = mapper.encode(outgoingRequest); + final byte[] body = mapper.encodeToBytes(outgoingRequest); return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) diff --git a/src/main/java/org/prebid/server/bidder/amx/AmxBidder.java b/src/main/java/org/prebid/server/bidder/amx/AmxBidder.java index 729e255b75c..5fe1d1303f2 100644 --- a/src/main/java/org/prebid/server/bidder/amx/AmxBidder.java +++ b/src/main/java/org/prebid/server/bidder/amx/AmxBidder.java @@ -97,7 +97,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/applogy/ApplogyBidder.java b/src/main/java/org/prebid/server/bidder/applogy/ApplogyBidder.java index 491075288dd..d310840b0e7 100644 --- a/src/main/java/org/prebid/server/bidder/applogy/ApplogyBidder.java +++ b/src/main/java/org/prebid/server/bidder/applogy/ApplogyBidder.java @@ -68,7 +68,7 @@ public Result>> makeHttpRequests(BidRequest request private HttpRequest createSingleRequest(Imp imp, BidRequest request, String url) { final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(imp)).build(); - final String body = mapper.encode(outgoingRequest); + final byte[] body = mapper.encodeToBytes(outgoingRequest); return HttpRequest.builder() .method(HttpMethod.POST) diff --git a/src/main/java/org/prebid/server/bidder/appnexus/AppnexusBidder.java b/src/main/java/org/prebid/server/bidder/appnexus/AppnexusBidder.java index 4063b9840c4..25f63ba778e 100644 --- a/src/main/java/org/prebid/server/bidder/appnexus/AppnexusBidder.java +++ b/src/main/java/org/prebid/server/bidder/appnexus/AppnexusBidder.java @@ -336,7 +336,7 @@ private HttpRequest createHttpRequest(BidRequest bidRequest, return HttpRequest.builder() .method(HttpMethod.POST) .uri(url) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(HttpUtil.headers()) .payload(outgoingRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java b/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java index 04c5e6543cc..26f85925a3a 100644 --- a/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java +++ b/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java @@ -42,9 +42,9 @@ public AvocetBidder(String endpointUrl, JacksonMapper mapper) { @Override public Result>> makeHttpRequests(BidRequest request) { - final String body; + final byte[] body; try { - body = mapper.encode(request); + body = mapper.encodeToBytes(request); } catch (EncodeException e) { return Result.withError( BidderError.badInput(String.format("Failed to encode request body, error: %s", e.getMessage()))); diff --git a/src/main/java/org/prebid/server/bidder/axonix/AxonixBidder.java b/src/main/java/org/prebid/server/bidder/axonix/AxonixBidder.java index 943202547d0..6c942fde1c3 100644 --- a/src/main/java/org/prebid/server/bidder/axonix/AxonixBidder.java +++ b/src/main/java/org/prebid/server/bidder/axonix/AxonixBidder.java @@ -56,7 +56,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(resolveEndpoint(extImpAxonix.getSupplyId())) .headers(HttpUtil.headers()) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/beachfront/BeachfrontBidder.java b/src/main/java/org/prebid/server/bidder/beachfront/BeachfrontBidder.java index 74b23de4d55..c4be60074b4 100644 --- a/src/main/java/org/prebid/server/bidder/beachfront/BeachfrontBidder.java +++ b/src/main/java/org/prebid/server/bidder/beachfront/BeachfrontBidder.java @@ -108,7 +108,7 @@ public Result>> makeHttpRequests(BidRequest bidRequest) { requests.add(HttpRequest.builder() .method(HttpMethod.POST) .uri(bannerEndpointUrl) - .body(mapper.encode(bannerRequest)) + .body(mapper.encodeToBytes(bannerRequest)) .headers(headers) .build()); } @@ -125,7 +125,7 @@ public Result>> makeHttpRequests(BidRequest bidRequest) { .map(videoRequest -> HttpRequest.builder() .method(HttpMethod.POST) .uri(resolveVideoUri(videoRequest.getAppId(), videoRequest.getIsPrebid())) - .body(mapper.encode(videoRequest)) + .body(mapper.encodeToBytes(videoRequest)) .headers(videoHeaders) .build()) .forEach(requests::add); diff --git a/src/main/java/org/prebid/server/bidder/beintoo/BeintooBidder.java b/src/main/java/org/prebid/server/bidder/beintoo/BeintooBidder.java index e77a85ee47b..87116667f1a 100644 --- a/src/main/java/org/prebid/server/bidder/beintoo/BeintooBidder.java +++ b/src/main/java/org/prebid/server/bidder/beintoo/BeintooBidder.java @@ -59,14 +59,13 @@ public Result>> makeHttpRequests(BidRequest request return Result.withError(BidderError.badInput(e.getMessage())); } - final String body = mapper.encode(updatedBidRequest); final MultiMap headers = makeHeaders(request); return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(updatedBidRequest)) .headers(headers) .payload(request) .build()), Collections.emptyList()); diff --git a/src/main/java/org/prebid/server/bidder/between/BetweenBidder.java b/src/main/java/org/prebid/server/bidder/between/BetweenBidder.java index dd0c37652b4..f3ee7859942 100644 --- a/src/main/java/org/prebid/server/bidder/between/BetweenBidder.java +++ b/src/main/java/org/prebid/server/bidder/between/BetweenBidder.java @@ -138,7 +138,7 @@ private HttpRequest createRequest(ExtImpBetween extImpBetween, BidRe .uri(url) .headers(resolveHeaders(request.getDevice(), request.getSite())) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/bidmachine/BidmachineBidder.java b/src/main/java/org/prebid/server/bidder/bidmachine/BidmachineBidder.java index 15f1742d82e..f06d0b996b4 100644 --- a/src/main/java/org/prebid/server/bidder/bidmachine/BidmachineBidder.java +++ b/src/main/java/org/prebid/server/bidder/bidmachine/BidmachineBidder.java @@ -58,12 +58,11 @@ public Result>> makeHttpRequests(BidRequest request validateImp(imp); final ExtPrebid mappedExt = parseImpExt(imp); final BidRequest outgoingRequest = createRequest(imp, mappedExt.getPrebid(), request); - final String body = mapper.encode(outgoingRequest); httpRequests.add(HttpRequest.builder() .method(HttpMethod.POST) .uri(buildEndpointUrl(mappedExt.getBidder())) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(resolveHeaders()) .payload(outgoingRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/bidmyadz/BidmyadzBidder.java b/src/main/java/org/prebid/server/bidder/bidmyadz/BidmyadzBidder.java index d301f5490ee..df8318718ea 100644 --- a/src/main/java/org/prebid/server/bidder/bidmyadz/BidmyadzBidder.java +++ b/src/main/java/org/prebid/server/bidder/bidmyadz/BidmyadzBidder.java @@ -47,7 +47,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(createHeaders()) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/bidscube/BidscubeBidder.java b/src/main/java/org/prebid/server/bidder/bidscube/BidscubeBidder.java index 3f038b7d0ca..cb58371c7e2 100644 --- a/src/main/java/org/prebid/server/bidder/bidscube/BidscubeBidder.java +++ b/src/main/java/org/prebid/server/bidder/bidscube/BidscubeBidder.java @@ -77,7 +77,7 @@ private HttpRequest createRequest(BidRequest request, Imp imp, Objec .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(internalRequest) - .body(mapper.encode(internalRequest)) + .body(mapper.encodeToBytes(internalRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/bmtm/BmtmBidder.java b/src/main/java/org/prebid/server/bidder/bmtm/BmtmBidder.java index f8c5a2381e2..ac488674ae9 100644 --- a/src/main/java/org/prebid/server/bidder/bmtm/BmtmBidder.java +++ b/src/main/java/org/prebid/server/bidder/bmtm/BmtmBidder.java @@ -57,12 +57,11 @@ public Result>> makeHttpRequests(BidRequest request validateImp(imp); final ExtImpBmtm impExt = parseImpExt(imp); final BidRequest outgoingRequest = createRequest(request, modifyImp(imp, impExt)); - final String body = mapper.encode(outgoingRequest); httpRequests.add(HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(createHeaders(request)) .payload(outgoingRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java b/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java index 575143dae9f..dc93aa5e11b 100644 --- a/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java +++ b/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java @@ -78,9 +78,9 @@ public Result>> makeHttpRequests(BidRequest request return Result.withErrors(errors); } - final String bidRequestBody; + final byte[] bidRequestBody; try { - bidRequestBody = mapper.encode(updateBidRequest); + bidRequestBody = mapper.encodeToBytes(updateBidRequest); } catch (EncodeException e) { errors.add(BidderError.badInput(String.format("error while encoding bidRequest, err: %s", e.getMessage()))); return Result.withErrors(errors); diff --git a/src/main/java/org/prebid/server/bidder/connectad/ConnectadBidder.java b/src/main/java/org/prebid/server/bidder/connectad/ConnectadBidder.java index 80530eb4f79..77637ab34b5 100644 --- a/src/main/java/org/prebid/server/bidder/connectad/ConnectadBidder.java +++ b/src/main/java/org/prebid/server/bidder/connectad/ConnectadBidder.java @@ -72,7 +72,7 @@ public Result>> makeHttpRequests(BidRequest request } final BidRequest outgoingRequest = request.toBuilder().imp(processedImps).build(); - final String body = mapper.encode(outgoingRequest); + final byte[] body = mapper.encodeToBytes(outgoingRequest); return Result.of(Collections.singletonList( HttpRequest.builder() diff --git a/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java b/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java index 45af03baa47..ec5454b3f20 100644 --- a/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java +++ b/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java @@ -95,9 +95,9 @@ public Result>> makeHttpRequests(BidReque } final ConsumableBidRequest outgoingRequest = requestBuilder.build(); - final String body; + final byte[] body; try { - body = mapper.encode(outgoingRequest); + body = mapper.encodeToBytes(outgoingRequest); } catch (EncodeException e) { return Result.withError(BidderError.badInput( String.format("Failed to encode request body, error: %s", e.getMessage()))); diff --git a/src/main/java/org/prebid/server/bidder/conversant/ConversantBidder.java b/src/main/java/org/prebid/server/bidder/conversant/ConversantBidder.java index 0bc98fd60ab..ef50a0a9010 100644 --- a/src/main/java/org/prebid/server/bidder/conversant/ConversantBidder.java +++ b/src/main/java/org/prebid/server/bidder/conversant/ConversantBidder.java @@ -80,7 +80,7 @@ public Result>> makeHttpRequests(BidRequest bidRequ .method(HttpMethod.POST) .uri(endpointUrl) .headers(HttpUtil.headers()) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build()), Collections.emptyList()); diff --git a/src/main/java/org/prebid/server/bidder/cpmstar/CpmStarBidder.java b/src/main/java/org/prebid/server/bidder/cpmstar/CpmStarBidder.java index a82137c18b2..c59bf2d80dc 100644 --- a/src/main/java/org/prebid/server/bidder/cpmstar/CpmStarBidder.java +++ b/src/main/java/org/prebid/server/bidder/cpmstar/CpmStarBidder.java @@ -53,7 +53,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .uri(endpointUrl) .headers(HttpUtil.headers()) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .payload(request) .build()), Collections.emptyList()); diff --git a/src/main/java/org/prebid/server/bidder/criteo/CriteoBidder.java b/src/main/java/org/prebid/server/bidder/criteo/CriteoBidder.java index 1842a9ba623..3748aeffb07 100644 --- a/src/main/java/org/prebid/server/bidder/criteo/CriteoBidder.java +++ b/src/main/java/org/prebid/server/bidder/criteo/CriteoBidder.java @@ -83,7 +83,7 @@ public Result>> makeHttpRequests(BidRequest bidR return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(jsonMapper.encode(outgoingRequest)) + .body(jsonMapper.encodeToBytes(outgoingRequest)) .headers(resolveHeaders(outgoingRequest)) .payload(outgoingRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/datablocks/DatablocksBidder.java b/src/main/java/org/prebid/server/bidder/datablocks/DatablocksBidder.java index 7d16c383bbe..0488d545280 100644 --- a/src/main/java/org/prebid/server/bidder/datablocks/DatablocksBidder.java +++ b/src/main/java/org/prebid/server/bidder/datablocks/DatablocksBidder.java @@ -93,13 +93,12 @@ private HttpRequest makeHttpRequest(Map.Entrybuilder() .method(HttpMethod.POST) .headers(HttpUtil.headers()) .uri(uri) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/decenterads/DecenteradsBidder.java b/src/main/java/org/prebid/server/bidder/decenterads/DecenteradsBidder.java index 3f10c4fb1a9..96b3d934be3 100644 --- a/src/main/java/org/prebid/server/bidder/decenterads/DecenteradsBidder.java +++ b/src/main/java/org/prebid/server/bidder/decenterads/DecenteradsBidder.java @@ -76,7 +76,7 @@ private HttpRequest createRequest(BidRequest request, Imp requestImp .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/deepintent/DeepintentBidder.java b/src/main/java/org/prebid/server/bidder/deepintent/DeepintentBidder.java index fb7d106b9da..23016d5af23 100644 --- a/src/main/java/org/prebid/server/bidder/deepintent/DeepintentBidder.java +++ b/src/main/java/org/prebid/server/bidder/deepintent/DeepintentBidder.java @@ -114,7 +114,7 @@ private HttpRequest createRequest(BidRequest request, Imp imp) { .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/dmx/DmxBidder.java b/src/main/java/org/prebid/server/bidder/dmx/DmxBidder.java index 273c116d3f2..b4f2136144b 100644 --- a/src/main/java/org/prebid/server/bidder/dmx/DmxBidder.java +++ b/src/main/java/org/prebid/server/bidder/dmx/DmxBidder.java @@ -118,7 +118,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .uri(uri) .headers(HttpUtil.headers()) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build()), errors); diff --git a/src/main/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidder.java b/src/main/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidder.java index bf07d29ecf9..457181efe8a 100644 --- a/src/main/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidder.java +++ b/src/main/java/org/prebid/server/bidder/emxdigital/EmxDigitalBidder.java @@ -65,15 +65,11 @@ public Result>> makeHttpRequests(BidRequest request return Result.withError(BidderError.badInput(e.getMessage())); } - final String body = mapper.encode(bidRequest); - final MultiMap headers = makeHeaders(request); - final String url = makeUrl(request); - return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) - .uri(url) - .body(body) - .headers(headers) + .uri(makeUrl(request)) + .body(mapper.encodeToBytes(bidRequest)) + .headers(makeHeaders(request)) .payload(request) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/engagebdr/EngagebdrBidder.java b/src/main/java/org/prebid/server/bidder/engagebdr/EngagebdrBidder.java index e6fc64e68f0..194a4eb021d 100644 --- a/src/main/java/org/prebid/server/bidder/engagebdr/EngagebdrBidder.java +++ b/src/main/java/org/prebid/server/bidder/engagebdr/EngagebdrBidder.java @@ -53,12 +53,11 @@ public Result>> makeHttpRequests(BidRequest bidRequ final List> httpRequests = new ArrayList<>(); for (Map.Entry> sspidToImpsEntry : dispatchedRequest.entrySet()) { final BidRequest updatedBidRequest = bidRequest.toBuilder().imp(sspidToImpsEntry.getValue()).build(); - final String body = mapper.encode(updatedBidRequest); httpRequests.add(HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl + "?zoneid=" + sspidToImpsEntry.getKey()) - .body(body) + .body(mapper.encodeToBytes(updatedBidRequest)) .headers(HttpUtil.headers()) .payload(updatedBidRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/epom/EpomBidder.java b/src/main/java/org/prebid/server/bidder/epom/EpomBidder.java index 2d4fa6a831d..87638fb5b1d 100644 --- a/src/main/java/org/prebid/server/bidder/epom/EpomBidder.java +++ b/src/main/java/org/prebid/server/bidder/epom/EpomBidder.java @@ -49,7 +49,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/evolution/EvolutionBidder.java b/src/main/java/org/prebid/server/bidder/evolution/EvolutionBidder.java index 8eaf26efb4e..ba59bfdcacd 100644 --- a/src/main/java/org/prebid/server/bidder/evolution/EvolutionBidder.java +++ b/src/main/java/org/prebid/server/bidder/evolution/EvolutionBidder.java @@ -41,7 +41,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build(); return Result.withValue(internalRequest); } diff --git a/src/main/java/org/prebid/server/bidder/facebook/FacebookBidder.java b/src/main/java/org/prebid/server/bidder/facebook/FacebookBidder.java index a5d13d7c79d..5f2fd02c90f 100644 --- a/src/main/java/org/prebid/server/bidder/facebook/FacebookBidder.java +++ b/src/main/java/org/prebid/server/bidder/facebook/FacebookBidder.java @@ -122,12 +122,10 @@ private HttpRequest makeHttpRequest(Imp imp, BidRequest bidRequest, ExtRequest.empty(), FacebookExt.of(platformId, makeAuthId(bidRequest.getId())))) .build(); - final String body = mapper.encode(outgoingRequest); - return HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(headers) .payload(outgoingRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/gamoshi/GamoshiBidder.java b/src/main/java/org/prebid/server/bidder/gamoshi/GamoshiBidder.java index 2f9b45f1bed..8bb126dc13d 100644 --- a/src/main/java/org/prebid/server/bidder/gamoshi/GamoshiBidder.java +++ b/src/main/java/org/prebid/server/bidder/gamoshi/GamoshiBidder.java @@ -69,7 +69,6 @@ public Result>> makeHttpRequests(BidRequest request } final BidRequest outgoingRequest = request.toBuilder().imp(validImps).build(); - final String body = mapper.encode(outgoingRequest); final String requestUrl = endpointUrl + "/r/" + firstImpExt.getSupplyPartnerId() + "/bidr?bidder=prebid-server"; final MultiMap headers = resolveHeaders(request.getDevice()); @@ -80,7 +79,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(requestUrl) .headers(headers) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/grid/GridBidder.java b/src/main/java/org/prebid/server/bidder/grid/GridBidder.java index cd3a82663ae..6828701fbd1 100644 --- a/src/main/java/org/prebid/server/bidder/grid/GridBidder.java +++ b/src/main/java/org/prebid/server/bidder/grid/GridBidder.java @@ -77,7 +77,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .headers(HttpUtil.headers()) .payload(modifiedRequest) - .body(mapper.encode(modifiedRequest)) + .body(mapper.encodeToBytes(modifiedRequest)) .build(); return Result.of(Collections.singletonList(httpRequest), errors); diff --git a/src/main/java/org/prebid/server/bidder/gumgum/GumgumBidder.java b/src/main/java/org/prebid/server/bidder/gumgum/GumgumBidder.java index f38a107a803..cb377c74049 100644 --- a/src/main/java/org/prebid/server/bidder/gumgum/GumgumBidder.java +++ b/src/main/java/org/prebid/server/bidder/gumgum/GumgumBidder.java @@ -74,7 +74,7 @@ public Result>> makeHttpRequests(BidRequest bidRequ HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(HttpUtil.headers()) .payload(outgoingRequest) .build()), diff --git a/src/main/java/org/prebid/server/bidder/improvedigital/ImprovedigitalBidder.java b/src/main/java/org/prebid/server/bidder/improvedigital/ImprovedigitalBidder.java index 15166a6f09e..4912b22cf80 100644 --- a/src/main/java/org/prebid/server/bidder/improvedigital/ImprovedigitalBidder.java +++ b/src/main/java/org/prebid/server/bidder/improvedigital/ImprovedigitalBidder.java @@ -91,7 +91,7 @@ private HttpRequest resolveRequest(BidRequest bidRequest, Imp imp) { .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(modifiedRequest) - .body(mapper.encode(modifiedRequest)) + .body(mapper.encodeToBytes(modifiedRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/inmobi/InmobiBidder.java b/src/main/java/org/prebid/server/bidder/inmobi/InmobiBidder.java index 7800981aa6f..8ca2e97a9a2 100644 --- a/src/main/java/org/prebid/server/bidder/inmobi/InmobiBidder.java +++ b/src/main/java/org/prebid/server/bidder/inmobi/InmobiBidder.java @@ -74,7 +74,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/interactiveoffers/InteractiveOffersBidder.java b/src/main/java/org/prebid/server/bidder/interactiveoffers/InteractiveOffersBidder.java index cf3ee803982..1bb5b9fdafa 100644 --- a/src/main/java/org/prebid/server/bidder/interactiveoffers/InteractiveOffersBidder.java +++ b/src/main/java/org/prebid/server/bidder/interactiveoffers/InteractiveOffersBidder.java @@ -46,7 +46,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(resolvedEndpointUrl) .headers(HttpUtil.headers()) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/invibes/InvibesBidder.java b/src/main/java/org/prebid/server/bidder/invibes/InvibesBidder.java index be96544da4d..87187fa576d 100644 --- a/src/main/java/org/prebid/server/bidder/invibes/InvibesBidder.java +++ b/src/main/java/org/prebid/server/bidder/invibes/InvibesBidder.java @@ -194,14 +194,12 @@ private HttpRequest makeRequest(InvibesInternalParams invibes final Site site = request.getSite(); final MultiMap headers = resolveHeaders(device, site); - final String body = mapper.encode(parameter); - return HttpRequest.builder() .method(HttpMethod.POST) .uri(url) .headers(headers) .payload(parameter) - .body(body) + .body(mapper.encodeToBytes(parameter)) .build(); } @@ -220,7 +218,7 @@ private InvibesBidRequest createRequest(InvibesInternalParams invibesParams, Str return InvibesBidRequest.builder() .isTestBid(StringUtils.isNotBlank(testBvid)) - .bidParamsJson(mapper.encode(invibesParams.getBidParams())) + .bidParamsJson(mapper.encodeToString(invibesParams.getBidParams())) .location(site.getPage()) .lid(lid) .kw(site.getKeywords()) diff --git a/src/main/java/org/prebid/server/bidder/iqzone/IqzoneBidder.java b/src/main/java/org/prebid/server/bidder/iqzone/IqzoneBidder.java index 1429a993a75..ed5ce7e77e9 100644 --- a/src/main/java/org/prebid/server/bidder/iqzone/IqzoneBidder.java +++ b/src/main/java/org/prebid/server/bidder/iqzone/IqzoneBidder.java @@ -92,7 +92,7 @@ private HttpRequest makeHttpRequest(BidRequest request, Imp imp) { .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/ix/IxBidder.java b/src/main/java/org/prebid/server/bidder/ix/IxBidder.java index 07212ea12f9..479afc1c0f0 100644 --- a/src/main/java/org/prebid/server/bidder/ix/IxBidder.java +++ b/src/main/java/org/prebid/server/bidder/ix/IxBidder.java @@ -99,7 +99,7 @@ public Result>> makeHttpRequests(BidRequest bidRequ .map(request -> HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .headers(HttpUtil.headers()) .payload(request) .build()) @@ -259,7 +259,7 @@ private String updateBidAdmWithNativeAttributes(String adm) { final boolean isV11 = responseV11 != null; final Response response = isV11 ? responseV11 : parseBidAdm(adm, Response.class); final List trackers = ObjectUtil.getIfNotNull(response, Response::getEventtrackers); - final String updatedAdm = CollectionUtils.isNotEmpty(trackers) ? mapper.encode(isV11 + final String updatedAdm = CollectionUtils.isNotEmpty(trackers) ? mapper.encodeToString(isV11 ? NativeV11Wrapper.of(mergeNativeImpTrackers(response, trackers)) : mergeNativeImpTrackers(response, trackers)) : null; diff --git a/src/main/java/org/prebid/server/bidder/jixie/JixieBidder.java b/src/main/java/org/prebid/server/bidder/jixie/JixieBidder.java index e6d7a1216c9..4b53f6c5347 100644 --- a/src/main/java/org/prebid/server/bidder/jixie/JixieBidder.java +++ b/src/main/java/org/prebid/server/bidder/jixie/JixieBidder.java @@ -45,7 +45,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(resolveHeaders(request.getDevice(), request.getSite())) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/kayzen/KayzenBidder.java b/src/main/java/org/prebid/server/bidder/kayzen/KayzenBidder.java index 55fe0c9fc46..7c2eccabb72 100644 --- a/src/main/java/org/prebid/server/bidder/kayzen/KayzenBidder.java +++ b/src/main/java/org/prebid/server/bidder/kayzen/KayzenBidder.java @@ -81,7 +81,7 @@ private HttpRequest createRequest(ExtImpKayzen extImpKayzen, BidRequ .uri(url) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/kidoz/KidozBidder.java b/src/main/java/org/prebid/server/bidder/kidoz/KidozBidder.java index 526b3c131ff..c3e50a35bb6 100644 --- a/src/main/java/org/prebid/server/bidder/kidoz/KidozBidder.java +++ b/src/main/java/org/prebid/server/bidder/kidoz/KidozBidder.java @@ -67,15 +67,13 @@ public Result>> makeHttpRequests(BidRequest request private HttpRequest createSingleRequest(Imp imp, BidRequest request, String url) { final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(imp)).build(); - final String body = mapper.encode(outgoingRequest); - final MultiMap headers = HttpUtil.headers().add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5"); return HttpRequest.builder() .method(HttpMethod.POST) .uri(url) .headers(headers) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/krushmedia/KrushmediaBidder.java b/src/main/java/org/prebid/server/bidder/krushmedia/KrushmediaBidder.java index 20c03202f33..30ccd93d0fb 100644 --- a/src/main/java/org/prebid/server/bidder/krushmedia/KrushmediaBidder.java +++ b/src/main/java/org/prebid/server/bidder/krushmedia/KrushmediaBidder.java @@ -70,7 +70,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(url) .headers(resolveHeaders(request.getDevice())) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java b/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java index 52861196438..9d5de7d3e6d 100644 --- a/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java +++ b/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java @@ -55,9 +55,9 @@ public Result>> makeHttpRequests(BidRequest request } } - String body; + final byte[] body; try { - body = mapper.encode(request); + body = mapper.encodeToBytes(request); } catch (EncodeException e) { return Result.withError( BidderError.badInput(String.format("Failed to encode request body, error: %s", e.getMessage()))); diff --git a/src/main/java/org/prebid/server/bidder/lockerdome/LockerdomeBidder.java b/src/main/java/org/prebid/server/bidder/lockerdome/LockerdomeBidder.java index 50a313b1733..25465ad7e82 100644 --- a/src/main/java/org/prebid/server/bidder/lockerdome/LockerdomeBidder.java +++ b/src/main/java/org/prebid/server/bidder/lockerdome/LockerdomeBidder.java @@ -70,14 +70,12 @@ public Result>> makeHttpRequests(BidRequest bidRequ ? bidRequest.toBuilder().imp(validImps).build() : bidRequest; - final String body = mapper.encode(outgoingRequest); - return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) .headers(headers) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build()), errors); diff --git a/src/main/java/org/prebid/server/bidder/logicad/LogicadBidder.java b/src/main/java/org/prebid/server/bidder/logicad/LogicadBidder.java index a435ae299e3..2e4bfd94f15 100644 --- a/src/main/java/org/prebid/server/bidder/logicad/LogicadBidder.java +++ b/src/main/java/org/prebid/server/bidder/logicad/LogicadBidder.java @@ -105,12 +105,11 @@ private List> buildAdapterRequests(BidRequest bidRequest for (Map.Entry> entry : extImpToImps.entrySet()) { final BidRequest updatedBidRequest = bidRequest.toBuilder().imp(entry.getValue()).build(); - final String body = mapper.encode(updatedBidRequest); final HttpRequest createdBidRequest = HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(updatedBidRequest)) .headers(HttpUtil.headers()) .payload(bidRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/loopme/LoopmeBidder.java b/src/main/java/org/prebid/server/bidder/loopme/LoopmeBidder.java index 99f3f1a2eff..4873842d535 100644 --- a/src/main/java/org/prebid/server/bidder/loopme/LoopmeBidder.java +++ b/src/main/java/org/prebid/server/bidder/loopme/LoopmeBidder.java @@ -42,7 +42,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/lunamedia/LunamediaBidder.java b/src/main/java/org/prebid/server/bidder/lunamedia/LunamediaBidder.java index e324e5c7fd3..cb4c0ee2001 100644 --- a/src/main/java/org/prebid/server/bidder/lunamedia/LunamediaBidder.java +++ b/src/main/java/org/prebid/server/bidder/lunamedia/LunamediaBidder.java @@ -155,7 +155,7 @@ private List> buildBidderRequests(BidRequest bidRequest, final HttpRequest createdBidRequest = HttpRequest.builder() .method(HttpMethod.POST) .uri(url) - .body(mapper.encode(updatedBidRequest)) + .body(mapper.encodeToBytes(updatedBidRequest)) .headers(headers()) .payload(updatedBidRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/madvertise/MadvertiseBidder.java b/src/main/java/org/prebid/server/bidder/madvertise/MadvertiseBidder.java index 9c5563789cc..97ead4e0dbd 100644 --- a/src/main/java/org/prebid/server/bidder/madvertise/MadvertiseBidder.java +++ b/src/main/java/org/prebid/server/bidder/madvertise/MadvertiseBidder.java @@ -100,7 +100,7 @@ private HttpRequest createRequest(BidRequest request, String zoneID) .uri(url) .headers(resolveHeaders(request.getDevice())) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/marsmedia/MarsmediaBidder.java b/src/main/java/org/prebid/server/bidder/marsmedia/MarsmediaBidder.java index 68821a4a9a9..70f835fd458 100644 --- a/src/main/java/org/prebid/server/bidder/marsmedia/MarsmediaBidder.java +++ b/src/main/java/org/prebid/server/bidder/marsmedia/MarsmediaBidder.java @@ -61,13 +61,11 @@ public Result>> makeHttpRequests(BidRequest bidRequ final String uri = String.format("%s%s%s", endpointUrl, "&zone=", firstImpZone); final MultiMap headers = resolveHeaders(bidRequest.getDevice()); - final String body = mapper.encode(outgoingRequest); - return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) .uri(uri) .headers(headers) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/mgid/MgidBidder.java b/src/main/java/org/prebid/server/bidder/mgid/MgidBidder.java index 60be72f155e..da11945247e 100644 --- a/src/main/java/org/prebid/server/bidder/mgid/MgidBidder.java +++ b/src/main/java/org/prebid/server/bidder/mgid/MgidBidder.java @@ -74,7 +74,7 @@ public final Result>> makeHttpRequests(BidRequest b return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl + accountId) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(HttpUtil.headers()) .payload(outgoingRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/mobfoxpb/MobfoxpbBidder.java b/src/main/java/org/prebid/server/bidder/mobfoxpb/MobfoxpbBidder.java index 372ec643451..0d353037bd4 100644 --- a/src/main/java/org/prebid/server/bidder/mobfoxpb/MobfoxpbBidder.java +++ b/src/main/java/org/prebid/server/bidder/mobfoxpb/MobfoxpbBidder.java @@ -70,7 +70,7 @@ public final Result>> makeHttpRequests(BidRequest b return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) .uri(uri) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(HttpUtil.headers()) .payload(outgoingRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/mobilefuse/MobilefuseBidder.java b/src/main/java/org/prebid/server/bidder/mobilefuse/MobilefuseBidder.java index f025bcec2d1..79fc0d910fc 100644 --- a/src/main/java/org/prebid/server/bidder/mobilefuse/MobilefuseBidder.java +++ b/src/main/java/org/prebid/server/bidder/mobilefuse/MobilefuseBidder.java @@ -70,14 +70,13 @@ public Result>> makeHttpRequests(BidRequest request } final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(requestImp)).build(); - final String body = mapper.encode(outgoingRequest); return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) .uri(makeUrl(firstExtImpMobilefuse)) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/model/HttpRequest.java b/src/main/java/org/prebid/server/bidder/model/HttpRequest.java index 069f187467f..3c445d60a82 100644 --- a/src/main/java/org/prebid/server/bidder/model/HttpRequest.java +++ b/src/main/java/org/prebid/server/bidder/model/HttpRequest.java @@ -16,7 +16,7 @@ public class HttpRequest { String uri; - String body; + byte[] body; MultiMap headers; diff --git a/src/main/java/org/prebid/server/bidder/nanointeractive/NanointeractiveBidder.java b/src/main/java/org/prebid/server/bidder/nanointeractive/NanointeractiveBidder.java index c9d68ed97c9..bc9490f62b9 100644 --- a/src/main/java/org/prebid/server/bidder/nanointeractive/NanointeractiveBidder.java +++ b/src/main/java/org/prebid/server/bidder/nanointeractive/NanointeractiveBidder.java @@ -72,7 +72,6 @@ public Result>> makeHttpRequests(BidRequest request .imp(validImps) .site(modified(reference, request.getSite())) .build(); - final String body = mapper.encode(outgoingRequest); return Result.of(Collections.singletonList( HttpRequest.builder() @@ -80,7 +79,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(headers(request)) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/ninthdecimal/NinthdecimalBidder.java b/src/main/java/org/prebid/server/bidder/ninthdecimal/NinthdecimalBidder.java index 067867b9dc0..f7d6489a21c 100644 --- a/src/main/java/org/prebid/server/bidder/ninthdecimal/NinthdecimalBidder.java +++ b/src/main/java/org/prebid/server/bidder/ninthdecimal/NinthdecimalBidder.java @@ -152,7 +152,6 @@ private List> buildBidderRequests(BidRequest bidRequest, final List imps = impExtAndListOfImp.getValue(); final BidRequest updatedBidRequest = makeBidRequest(bidRequest, extImpNinthdecimal, imps); - final String body = mapper.encode(updatedBidRequest); final MultiMap headers = HttpUtil.headers() .add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5"); final String createdEndpoint = endpointUrl + extImpNinthdecimal.getPubid(); @@ -160,7 +159,7 @@ private List> buildBidderRequests(BidRequest bidRequest, final HttpRequest createdBidRequest = HttpRequest.builder() .method(HttpMethod.POST) .uri(createdEndpoint) - .body(body) + .body(mapper.encodeToBytes(updatedBidRequest)) .headers(headers) .payload(bidRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/nobid/NobidBidder.java b/src/main/java/org/prebid/server/bidder/nobid/NobidBidder.java index 58bf6ab7352..7252ea85ca4 100644 --- a/src/main/java/org/prebid/server/bidder/nobid/NobidBidder.java +++ b/src/main/java/org/prebid/server/bidder/nobid/NobidBidder.java @@ -45,7 +45,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()), Collections.emptyList()); } diff --git a/src/main/java/org/prebid/server/bidder/onetag/OnetagBidder.java b/src/main/java/org/prebid/server/bidder/onetag/OnetagBidder.java index 1de1d622c10..8c6cb35720f 100644 --- a/src/main/java/org/prebid/server/bidder/onetag/OnetagBidder.java +++ b/src/main/java/org/prebid/server/bidder/onetag/OnetagBidder.java @@ -89,7 +89,7 @@ private HttpRequest createRequest(BidRequest request, List imps .uri(url) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/openweb/OpenWebBidder.java b/src/main/java/org/prebid/server/bidder/openweb/OpenWebBidder.java index 56f731dc852..f737bf95d57 100644 --- a/src/main/java/org/prebid/server/bidder/openweb/OpenWebBidder.java +++ b/src/main/java/org/prebid/server/bidder/openweb/OpenWebBidder.java @@ -115,7 +115,7 @@ private HttpRequest makeGroupRequest(BidRequest request, List i .method(HttpMethod.POST) .uri(resolveEndpoint(sourceId)) .headers(HttpUtil.headers()) - .body(mapper.encode(modifiedRequest)) + .body(mapper.encodeToBytes(modifiedRequest)) .payload(modifiedRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/openx/OpenxBidder.java b/src/main/java/org/prebid/server/bidder/openx/OpenxBidder.java index b98ca7daf94..7697bf4cba2 100644 --- a/src/main/java/org/prebid/server/bidder/openx/OpenxBidder.java +++ b/src/main/java/org/prebid/server/bidder/openx/OpenxBidder.java @@ -126,8 +126,12 @@ private List errors(List notSupportedImps, List p private List> createHttpRequests(List bidRequests) { return bidRequests.stream() .filter(Objects::nonNull) - .map(singleBidRequest -> HttpRequest.builder().method(HttpMethod.POST).uri(endpointUrl) - .body(mapper.encode(singleBidRequest)).headers(HttpUtil.headers()).payload(singleBidRequest) + .map(singleBidRequest -> HttpRequest.builder() + .method(HttpMethod.POST) + .uri(endpointUrl) + .body(mapper.encodeToBytes(singleBidRequest)) + .headers(HttpUtil.headers()) + .payload(singleBidRequest) .build()) .collect(Collectors.toList()); } diff --git a/src/main/java/org/prebid/server/bidder/operaads/OperaadsBidder.java b/src/main/java/org/prebid/server/bidder/operaads/OperaadsBidder.java index 0571d3c4768..97f869ed600 100644 --- a/src/main/java/org/prebid/server/bidder/operaads/OperaadsBidder.java +++ b/src/main/java/org/prebid/server/bidder/operaads/OperaadsBidder.java @@ -110,7 +110,7 @@ private Native resolveNative(Native xNative) { if (nativeNode != null && nativeNode.isObject()) { final JsonNode requestNode = mapper.mapper().createObjectNode().set("native", nativeNode); return xNative.toBuilder() - .request(mapper.encode(requestNode)) + .request(mapper.encodeToString(requestNode)) .build(); } } catch (JsonProcessingException e) { @@ -151,7 +151,7 @@ private HttpRequest createRequest(BidRequest bidRequest, Imp imp, Ex .uri(resolvedUrl) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java b/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java index 20eca5a6c3f..28d6e463d2f 100644 --- a/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java +++ b/src/main/java/org/prebid/server/bidder/orbidder/OrbidderBidder.java @@ -55,7 +55,6 @@ public Result>> makeHttpRequests(BidRequest request } } final BidRequest outgoingRequest = request.toBuilder().imp(validImps).build(); - final String body = mapper.encode(outgoingRequest); return Result.of(Collections.singletonList( HttpRequest.builder() @@ -63,7 +62,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/outbrain/OutbrainBidder.java b/src/main/java/org/prebid/server/bidder/outbrain/OutbrainBidder.java index e706778033b..0b548a5f9e4 100644 --- a/src/main/java/org/prebid/server/bidder/outbrain/OutbrainBidder.java +++ b/src/main/java/org/prebid/server/bidder/outbrain/OutbrainBidder.java @@ -80,7 +80,7 @@ public Result>> makeHttpRequests(BidRequest request HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(mapper.encode(updatedRequest)) + .body(mapper.encodeToBytes(updatedRequest)) .headers(HttpUtil.headers()) .payload(updatedRequest) .build()), errors); @@ -198,7 +198,7 @@ private String resolveBidAdm(String adm, List errors) { return null; } - final List imptrackers = ListUtils.defaultIfNull(response.getImptrackers(), new ArrayList<>()); + final List imptrackers = ListUtils.defaultIfNull(response.getImptrackers(), new ArrayList<>()); String jstracker = response.getJstracker(); for (EventTracker eventTracker : eventtrackers) { @@ -214,7 +214,7 @@ private String resolveBidAdm(String adm, List errors) { } } - return mapper.encode(response.toBuilder() + return mapper.encodeToString(response.toBuilder() .eventtrackers(null) .jstracker(jstracker) .imptrackers(imptrackers) diff --git a/src/main/java/org/prebid/server/bidder/pangle/PangleBidder.java b/src/main/java/org/prebid/server/bidder/pangle/PangleBidder.java index c77627a3a03..1075d63e1f5 100644 --- a/src/main/java/org/prebid/server/bidder/pangle/PangleBidder.java +++ b/src/main/java/org/prebid/server/bidder/pangle/PangleBidder.java @@ -138,7 +138,7 @@ private HttpRequest createRequest(BidRequest request, Imp imp, Strin .uri(endpointUrl) .headers(makeHeaders(token)) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/pubmatic/PubmaticBidder.java b/src/main/java/org/prebid/server/bidder/pubmatic/PubmaticBidder.java index 2000a3e43ef..f8f01efc9c7 100644 --- a/src/main/java/org/prebid/server/bidder/pubmatic/PubmaticBidder.java +++ b/src/main/java/org/prebid/server/bidder/pubmatic/PubmaticBidder.java @@ -263,12 +263,11 @@ private HttpRequest createRequest(BidRequest request, } final BidRequest modifiedRequest = requestBuilder.build(); - final String body = mapper.encode(modifiedRequest); return HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(modifiedRequest)) .headers(HttpUtil.headers()) .payload(modifiedRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/pubnative/PubnativeBidder.java b/src/main/java/org/prebid/server/bidder/pubnative/PubnativeBidder.java index 164578c42cd..82a983b57af 100644 --- a/src/main/java/org/prebid/server/bidder/pubnative/PubnativeBidder.java +++ b/src/main/java/org/prebid/server/bidder/pubnative/PubnativeBidder.java @@ -161,7 +161,7 @@ private HttpRequest createHttpRequest(BidRequest outgoingRequest, Ex .method(HttpMethod.POST) .uri(requestUri) .headers(HttpUtil.headers()) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/rhythmone/RhythmoneBidder.java b/src/main/java/org/prebid/server/bidder/rhythmone/RhythmoneBidder.java index bb63291792e..e977d34d324 100644 --- a/src/main/java/org/prebid/server/bidder/rhythmone/RhythmoneBidder.java +++ b/src/main/java/org/prebid/server/bidder/rhythmone/RhythmoneBidder.java @@ -71,13 +71,12 @@ public Result>> makeHttpRequests(BidRequest bidRequ } final BidRequest outgoingRequest = bidRequest.toBuilder().imp(modifiedImps).build(); - final String body = mapper.encode(outgoingRequest); return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(composedUrl) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(HttpUtil.headers()) .payload(outgoingRequest) .build()), diff --git a/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java b/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java index f20c3ae0954..b01f16b8d16 100644 --- a/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java +++ b/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java @@ -1257,7 +1257,7 @@ private HttpRequest createHttpRequest(BidRequest bidRequest, String return HttpRequest.builder() .method(HttpMethod.POST) .uri(uri) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .headers(headers) .payload(bidRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/salunamedia/SaLunamediaBidder.java b/src/main/java/org/prebid/server/bidder/salunamedia/SaLunamediaBidder.java index 9cd2735c751..21638028e33 100644 --- a/src/main/java/org/prebid/server/bidder/salunamedia/SaLunamediaBidder.java +++ b/src/main/java/org/prebid/server/bidder/salunamedia/SaLunamediaBidder.java @@ -40,7 +40,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .headers(HttpUtil.headers()) .payload(request) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/sharethrough/SharethroughBidder.java b/src/main/java/org/prebid/server/bidder/sharethrough/SharethroughBidder.java index af8f15fc95d..fad020f771a 100644 --- a/src/main/java/org/prebid/server/bidder/sharethrough/SharethroughBidder.java +++ b/src/main/java/org/prebid/server/bidder/sharethrough/SharethroughBidder.java @@ -190,7 +190,7 @@ private HttpRequest makeHttpRequest( .method(HttpMethod.POST) .uri(uri) .headers(headers) - .body(mapper.encode(body)) + .body(mapper.encodeToBytes(body)) .payload(body) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/silvermob/SilvermobBidder.java b/src/main/java/org/prebid/server/bidder/silvermob/SilvermobBidder.java index 88f451fd32f..1820e95b66e 100644 --- a/src/main/java/org/prebid/server/bidder/silvermob/SilvermobBidder.java +++ b/src/main/java/org/prebid/server/bidder/silvermob/SilvermobBidder.java @@ -75,7 +75,7 @@ private HttpRequest createRequestForImp(Imp imp, BidRequest request) .uri(resolveEndpoint(extImp)) .headers(resolveHeaders(request.getDevice())) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java b/src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java index 7321e257b80..8a2c4c833bd 100644 --- a/src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java +++ b/src/main/java/org/prebid/server/bidder/smaato/SmaatoBidder.java @@ -315,7 +315,7 @@ private HttpRequest constructHttpRequest(BidRequest bidRequest) { .uri(endpointUrl) .method(HttpMethod.POST) .headers(HttpUtil.headers()) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .payload(bidRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/smartadserver/SmartadserverBidder.java b/src/main/java/org/prebid/server/bidder/smartadserver/SmartadserverBidder.java index df8a4b77a2d..f5108e14b0d 100644 --- a/src/main/java/org/prebid/server/bidder/smartadserver/SmartadserverBidder.java +++ b/src/main/java/org/prebid/server/bidder/smartadserver/SmartadserverBidder.java @@ -82,7 +82,7 @@ private HttpRequest createSingleRequest(BidRequest request) { .method(HttpMethod.POST) .uri(getUri()) .headers(HttpUtil.headers()) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .payload(request) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/smarthub/SmarthubBidder.java b/src/main/java/org/prebid/server/bidder/smarthub/SmarthubBidder.java index db7a4795399..c81c4a1e8a8 100644 --- a/src/main/java/org/prebid/server/bidder/smarthub/SmarthubBidder.java +++ b/src/main/java/org/prebid/server/bidder/smarthub/SmarthubBidder.java @@ -55,7 +55,7 @@ public Result>> makeHttpRequests(BidRequest request return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) - .body(mapper.encode(request)) + .body(mapper.encodeToBytes(request)) .uri(buildEndpointUrl(extImpSmarthub)) .payload(request) .headers(resolveHeaders()) diff --git a/src/main/java/org/prebid/server/bidder/smartrtb/SmartrtbBidder.java b/src/main/java/org/prebid/server/bidder/smartrtb/SmartrtbBidder.java index 3b10561081f..4f8ef7bac66 100644 --- a/src/main/java/org/prebid/server/bidder/smartrtb/SmartrtbBidder.java +++ b/src/main/java/org/prebid/server/bidder/smartrtb/SmartrtbBidder.java @@ -82,7 +82,6 @@ public Result>> makeHttpRequests(BidRequest request } final BidRequest outgoingRequest = request.toBuilder().imp(validImps).build(); - final String body = mapper.encode(outgoingRequest); final String requestUrl = endpointUrl + pubId; final MultiMap headers = HttpUtil.headers().add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5"); @@ -92,7 +91,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(requestUrl) .headers(headers) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/smartyads/SmartyAdsBidder.java b/src/main/java/org/prebid/server/bidder/smartyads/SmartyAdsBidder.java index 7873e540dec..de6d143b6ad 100644 --- a/src/main/java/org/prebid/server/bidder/smartyads/SmartyAdsBidder.java +++ b/src/main/java/org/prebid/server/bidder/smartyads/SmartyAdsBidder.java @@ -70,7 +70,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(resolveUrl(extImpSmartyAds)) .headers(resolveHeaders(request.getDevice())) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build())); } diff --git a/src/main/java/org/prebid/server/bidder/smilewanted/SmileWantedBidder.java b/src/main/java/org/prebid/server/bidder/smilewanted/SmileWantedBidder.java index 32e93da0158..4bb677f9c41 100644 --- a/src/main/java/org/prebid/server/bidder/smilewanted/SmileWantedBidder.java +++ b/src/main/java/org/prebid/server/bidder/smilewanted/SmileWantedBidder.java @@ -46,7 +46,7 @@ public Result>> makeHttpRequests(BidRequest request .uri(endpointUrl) .headers(createHeaders()) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/somoaudience/SomoaudienceBidder.java b/src/main/java/org/prebid/server/bidder/somoaudience/SomoaudienceBidder.java index 79ff97ebdce..bd47413f173 100644 --- a/src/main/java/org/prebid/server/bidder/somoaudience/SomoaudienceBidder.java +++ b/src/main/java/org/prebid/server/bidder/somoaudience/SomoaudienceBidder.java @@ -120,7 +120,7 @@ private HttpRequest makeRequest(BidRequest bidRequest, List imp return HttpRequest.builder() .method(HttpMethod.POST) .uri(url) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(headers(outgoingRequest.getDevice())) .payload(outgoingRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/sovrn/SovrnBidder.java b/src/main/java/org/prebid/server/bidder/sovrn/SovrnBidder.java index bb62fdbca7a..a97020183b8 100644 --- a/src/main/java/org/prebid/server/bidder/sovrn/SovrnBidder.java +++ b/src/main/java/org/prebid/server/bidder/sovrn/SovrnBidder.java @@ -70,13 +70,12 @@ public Result>> makeHttpRequests(BidRequest bidRequ } final BidRequest outgoingRequest = bidRequest.toBuilder().imp(processedImps).build(); - final String body = mapper.encode(outgoingRequest); return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(headers(bidRequest)) .payload(outgoingRequest) .build()), diff --git a/src/main/java/org/prebid/server/bidder/synacormedia/SynacormediaBidder.java b/src/main/java/org/prebid/server/bidder/synacormedia/SynacormediaBidder.java index 301d67d9e70..2aa3de3db31 100644 --- a/src/main/java/org/prebid/server/bidder/synacormedia/SynacormediaBidder.java +++ b/src/main/java/org/prebid/server/bidder/synacormedia/SynacormediaBidder.java @@ -84,7 +84,7 @@ public Result>> makeHttpRequests(BidRequest bidRequ .method(HttpMethod.POST) .headers(HttpUtil.headers()) .uri(endpointUrl.replaceAll("\\{\\{Host}}", firstExtImp.getSeatId())) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build()), errors); diff --git a/src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java b/src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java index b18861e21e4..eaebf4bb802 100644 --- a/src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java +++ b/src/main/java/org/prebid/server/bidder/tappx/TappxBidder.java @@ -67,7 +67,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .headers(HttpUtil.headers()) .uri(url) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/telaria/TelariaBidder.java b/src/main/java/org/prebid/server/bidder/telaria/TelariaBidder.java index 89886ce810c..937a24aebf6 100644 --- a/src/main/java/org/prebid/server/bidder/telaria/TelariaBidder.java +++ b/src/main/java/org/prebid/server/bidder/telaria/TelariaBidder.java @@ -85,14 +85,13 @@ public Result>> makeHttpRequests(BidRequest bidRequ } final BidRequest outgoingRequest = requestBuilder.imp(validImps).build(); - final String body = mapper.encode(outgoingRequest); return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) .headers(headers(bidRequest)) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()); } diff --git a/src/main/java/org/prebid/server/bidder/triplelift/TripleliftBidder.java b/src/main/java/org/prebid/server/bidder/triplelift/TripleliftBidder.java index b83189b6e11..db0238d6133 100644 --- a/src/main/java/org/prebid/server/bidder/triplelift/TripleliftBidder.java +++ b/src/main/java/org/prebid/server/bidder/triplelift/TripleliftBidder.java @@ -71,7 +71,7 @@ public final Result>> makeHttpRequests(BidRequest b HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(mapper.encode(updatedRequest)) + .body(mapper.encodeToBytes(updatedRequest)) .headers(HttpUtil.headers()) .payload(updatedRequest) .build()), diff --git a/src/main/java/org/prebid/server/bidder/tripleliftnative/TripleliftNativeBidder.java b/src/main/java/org/prebid/server/bidder/tripleliftnative/TripleliftNativeBidder.java index 9b72802a300..fbcd4dc384c 100644 --- a/src/main/java/org/prebid/server/bidder/tripleliftnative/TripleliftNativeBidder.java +++ b/src/main/java/org/prebid/server/bidder/tripleliftnative/TripleliftNativeBidder.java @@ -103,7 +103,7 @@ public Result>> makeHttpRequests(BidRequest bidRequ HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(mapper.encode(updatedRequest)) + .body(mapper.encodeToBytes(updatedRequest)) .headers(HttpUtil.headers()) .payload(updatedRequest) .build()), diff --git a/src/main/java/org/prebid/server/bidder/ttx/TtxBidder.java b/src/main/java/org/prebid/server/bidder/ttx/TtxBidder.java index 2d319c0d206..ec295e5f517 100644 --- a/src/main/java/org/prebid/server/bidder/ttx/TtxBidder.java +++ b/src/main/java/org/prebid/server/bidder/ttx/TtxBidder.java @@ -145,7 +145,7 @@ private HttpRequest createRequest(BidRequest request, Imp requestImp .uri(endpointUrl) .headers(HttpUtil.headers()) .payload(modifiedRequest) - .body(mapper.encode(modifiedRequest)) + .body(mapper.encodeToBytes(modifiedRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/ucfunnel/UcfunnelBidder.java b/src/main/java/org/prebid/server/bidder/ucfunnel/UcfunnelBidder.java index c009e355c4b..a848ea714c8 100644 --- a/src/main/java/org/prebid/server/bidder/ucfunnel/UcfunnelBidder.java +++ b/src/main/java/org/prebid/server/bidder/ucfunnel/UcfunnelBidder.java @@ -63,14 +63,13 @@ public Result>> makeHttpRequests(BidRequest request errors.add(BidderError.badInput(e.getMessage())); } - final String body = mapper.encode(request); final String requestUrl = String.format("%s/%s/request", endpointUrl, HttpUtil.encodeUrl(partnerId)); return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(requestUrl) - .body(body) + .body(mapper.encodeToBytes(request)) .headers(HttpUtil.headers()) .payload(request) .build()), diff --git a/src/main/java/org/prebid/server/bidder/unicorn/UnicornBidder.java b/src/main/java/org/prebid/server/bidder/unicorn/UnicornBidder.java index 01347549211..fc6b8a0da5b 100644 --- a/src/main/java/org/prebid/server/bidder/unicorn/UnicornBidder.java +++ b/src/main/java/org/prebid/server/bidder/unicorn/UnicornBidder.java @@ -189,7 +189,7 @@ private HttpRequest createRequest(BidRequest request, .uri(endpointUrl) .headers(resolveHeaders(request.getDevice())) .payload(outgoingRequest) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/unruly/UnrulyBidder.java b/src/main/java/org/prebid/server/bidder/unruly/UnrulyBidder.java index d7a2a1de86a..f1793ce62d6 100644 --- a/src/main/java/org/prebid/server/bidder/unruly/UnrulyBidder.java +++ b/src/main/java/org/prebid/server/bidder/unruly/UnrulyBidder.java @@ -89,13 +89,11 @@ private HttpRequest createSingleRequest(Imp modifiedImp, BidRequest String endpointUrl) { final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(modifiedImp)).build(); - final String body = mapper.encode(outgoingRequest); - return HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) .headers(getHeaders()) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/valueimpression/ValueImpressionBidder.java b/src/main/java/org/prebid/server/bidder/valueimpression/ValueImpressionBidder.java index 3982c5c7d82..b92b3b8788a 100644 --- a/src/main/java/org/prebid/server/bidder/valueimpression/ValueImpressionBidder.java +++ b/src/main/java/org/prebid/server/bidder/valueimpression/ValueImpressionBidder.java @@ -53,7 +53,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .uri(endpointUrl) .headers(HttpUtil.headers()) - .body(mapper.encode(bidRequest)) + .body(mapper.encodeToBytes(bidRequest)) .payload(request) .build()), Collections.emptyList()); diff --git a/src/main/java/org/prebid/server/bidder/visx/VisxBidder.java b/src/main/java/org/prebid/server/bidder/visx/VisxBidder.java index 091a0f85e27..a88018c81e3 100644 --- a/src/main/java/org/prebid/server/bidder/visx/VisxBidder.java +++ b/src/main/java/org/prebid/server/bidder/visx/VisxBidder.java @@ -48,7 +48,7 @@ private HttpRequest makeRequest(BidRequest bidRequest) { return HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(HttpUtil.headers()) .payload(outgoingRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/yahoossp/YahooSSPBidder.java b/src/main/java/org/prebid/server/bidder/yahoossp/YahooSSPBidder.java index 75d086b731a..89a06782e76 100644 --- a/src/main/java/org/prebid/server/bidder/yahoossp/YahooSSPBidder.java +++ b/src/main/java/org/prebid/server/bidder/yahoossp/YahooSSPBidder.java @@ -143,7 +143,7 @@ private HttpRequest makeHttpRequest(BidRequest outgoingRequest) { return HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(makeHeaders(outgoingRequest.getDevice())) .payload(outgoingRequest) .build(); diff --git a/src/main/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidder.java b/src/main/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidder.java index 22bb7c5627e..0d6762f8a2a 100644 --- a/src/main/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidder.java +++ b/src/main/java/org/prebid/server/bidder/yeahmobi/YeahmobiBidder.java @@ -70,15 +70,13 @@ public Result>> makeHttpRequests(BidRequest request final BidRequest outgoingRequest = request.toBuilder().imp(validImps).build(); - final String body = mapper.encode(outgoingRequest); - return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(url) .headers(HttpUtil.headers()) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/yieldone/YieldoneBidder.java b/src/main/java/org/prebid/server/bidder/yieldone/YieldoneBidder.java index e241c44fcbc..1bacb87c015 100644 --- a/src/main/java/org/prebid/server/bidder/yieldone/YieldoneBidder.java +++ b/src/main/java/org/prebid/server/bidder/yieldone/YieldoneBidder.java @@ -67,7 +67,7 @@ public Result>> makeHttpRequests(BidRequest request .method(HttpMethod.POST) .uri(endpointUrl) .headers(HttpUtil.headers()) - .body(mapper.encode(outgoingRequest)) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build()), errors); diff --git a/src/main/java/org/prebid/server/bidder/zeroclickfraud/ZeroclickfraudBidder.java b/src/main/java/org/prebid/server/bidder/zeroclickfraud/ZeroclickfraudBidder.java index 5d7be111962..18c3251a5fe 100644 --- a/src/main/java/org/prebid/server/bidder/zeroclickfraud/ZeroclickfraudBidder.java +++ b/src/main/java/org/prebid/server/bidder/zeroclickfraud/ZeroclickfraudBidder.java @@ -95,13 +95,12 @@ private HttpRequest makeHttpRequest(ExtImpZeroclickfraud extImpZeroc .replace(SOURCE_ID, extImpZeroclickfraud.getSourceId().toString()); final BidRequest outgoingRequest = bidRequest.toBuilder().imp(imps).build(); - final String body = mapper.encode(outgoingRequest); return HttpRequest.builder() .method(HttpMethod.POST) .headers(HttpUtil.headers()) .uri(uri) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); } diff --git a/src/main/java/org/prebid/server/cache/CacheService.java b/src/main/java/org/prebid/server/cache/CacheService.java index 026e9efaf4d..09232382340 100644 --- a/src/main/java/org/prebid/server/cache/CacheService.java +++ b/src/main/java/org/prebid/server/cache/CacheService.java @@ -129,7 +129,7 @@ private Future makeRequest( } final long startTime = clock.millis(); - return httpClient.post(endpointUrl.toString(), CACHE_HEADERS, mapper.encode(bidCacheRequest), + return httpClient.post(endpointUrl.toString(), CACHE_HEADERS, mapper.encodeToString(bidCacheRequest), remainingTimeout) .map(response -> toBidCacheResponse( response.getStatusCode(), response.getBody(), bidCount, accountId, startTime)) @@ -312,7 +312,7 @@ private Future doCacheOpenrtb(List bids, updateCreativeMetrics(accountId, cachedCreatives); final String url = endpointUrl.toString(); - final String body = mapper.encode(bidCacheRequest); + final String body = mapper.encodeToString(bidCacheRequest); final CacheHttpRequest httpRequest = CacheHttpRequest.of(url, body); final long startTime = clock.millis(); diff --git a/src/main/java/org/prebid/server/cookie/UidsCookie.java b/src/main/java/org/prebid/server/cookie/UidsCookie.java index 91915580707..274e1ad12c0 100644 --- a/src/main/java/org/prebid/server/cookie/UidsCookie.java +++ b/src/main/java/org/prebid/server/cookie/UidsCookie.java @@ -103,7 +103,7 @@ public UidsCookie updateOptout(boolean optout) { * Converts {@link Uids} to JSON string. */ String toJson() { - return mapper.encode(uids); + return mapper.encodeToString(uids); } /** diff --git a/src/main/java/org/prebid/server/deals/AlertHttpService.java b/src/main/java/org/prebid/server/deals/AlertHttpService.java index 10e8fcbd7b2..1abfb3d21d7 100644 --- a/src/main/java/org/prebid/server/deals/AlertHttpService.java +++ b/src/main/java/org/prebid/server/deals/AlertHttpService.java @@ -108,7 +108,7 @@ public void alert(String name, AlertPriority alertPriority, String message) { try { httpClient.post(alertProxyProperties.getUrl(), headers(), - mapper.encode(Collections.singletonList(alertEvent)), timeoutMillis) + mapper.encodeToString(Collections.singletonList(alertEvent)), timeoutMillis) .setHandler(this::handleResponse); } catch (EncodeException e) { logger.warn("Can't parse alert proxy payload: {0}", e.getMessage()); diff --git a/src/main/java/org/prebid/server/deals/DeliveryStatsService.java b/src/main/java/org/prebid/server/deals/DeliveryStatsService.java index 5763e73095b..17f4dbb7f18 100644 --- a/src/main/java/org/prebid/server/deals/DeliveryStatsService.java +++ b/src/main/java/org/prebid/server/deals/DeliveryStatsService.java @@ -150,7 +150,7 @@ protected Future sendReport(DeliveryProgressReport deliveryProgressReport, return promise.future(); } - final String body = mapper.encode(deliveryProgressReportFactory + final String body = mapper.encodeToString(deliveryProgressReportFactory .updateReportTimeStamp(deliveryProgressReport, now)); logger.info("Sending delivery progress report to Delivery Stats, {0} is {1}", PG_TRX_ID, diff --git a/src/main/java/org/prebid/server/deals/RegisterService.java b/src/main/java/org/prebid/server/deals/RegisterService.java index 70b6243477b..915d59f82ed 100644 --- a/src/main/java/org/prebid/server/deals/RegisterService.java +++ b/src/main/java/org/prebid/server/deals/RegisterService.java @@ -129,7 +129,7 @@ protected void register(MultiMap headers) { deploymentProperties.getPbsHostId(), deploymentProperties.getPbsRegion(), deploymentProperties.getPbsVendor()); - final String body = mapper.encode(request); + final String body = mapper.encodeToString(request); logger.info("Sending register request to Planner, {0} is {1}", PG_TRX_ID, headers.get(PG_TRX_ID)); logger.debug("Register request payload: {0}", body); diff --git a/src/main/java/org/prebid/server/deals/UserService.java b/src/main/java/org/prebid/server/deals/UserService.java index deda5564547..3a445d4159c 100644 --- a/src/main/java/org/prebid/server/deals/UserService.java +++ b/src/main/java/org/prebid/server/deals/UserService.java @@ -105,7 +105,7 @@ public Future getUserDetails(AuctionContext context, Timeout timeou final UserDetailsRequest userDetailsRequest = UserDetailsRequest.of( UTC_MILLIS_FORMATTER.format(ZonedDateTime.now(clock)), userIds); - final String body = mapper.encode(userDetailsRequest); + final String body = mapper.encodeToString(userDetailsRequest); final long requestTimeout = Math.min(this.timeout, timeout.remaining()); @@ -233,7 +233,7 @@ public void processWinEvent(String lineItemId, String bidId, UidsCookie uids) { return; } - final String body = mapper.encode(WinEventNotification.builder() + final String body = mapper.encodeToString(WinEventNotification.builder() .bidderCode(lineItem.getSource()) .bidId(bidId) .lineItemId(lineItemId) diff --git a/src/main/java/org/prebid/server/deals/simulation/SimulationAwareHttpBidderRequester.java b/src/main/java/org/prebid/server/deals/simulation/SimulationAwareHttpBidderRequester.java index 3875f406fe1..c98082f89a5 100644 --- a/src/main/java/org/prebid/server/deals/simulation/SimulationAwareHttpBidderRequester.java +++ b/src/main/java/org/prebid/server/deals/simulation/SimulationAwareHttpBidderRequester.java @@ -49,8 +49,8 @@ public class SimulationAwareHttpBidderRequester extends HttpBidderRequester { private static final String DEFAULT_CURRENCY = "USD"; private static final String BID_ID_FORMAT = "%s-%s"; - private Map bidRates; - private LineItemService lineItemService; + private final Map bidRates; + private final LineItemService lineItemService; private final JacksonMapper mapper; public SimulationAwareHttpBidderRequester( @@ -61,7 +61,7 @@ public SimulationAwareHttpBidderRequester( LineItemService lineItemService, JacksonMapper mapper) { - super(httpClient, bidderRequestCompletionTrackerFactory, bidderErrorNotifier, requestEnricher); + super(httpClient, bidderRequestCompletionTrackerFactory, bidderErrorNotifier, requestEnricher, mapper); this.lineItemService = Objects.requireNonNull(lineItemService); this.mapper = Objects.requireNonNull(mapper); diff --git a/src/main/java/org/prebid/server/handler/CollectedMetricsHandler.java b/src/main/java/org/prebid/server/handler/CollectedMetricsHandler.java index 9ce6c772111..0a789d87d92 100644 --- a/src/main/java/org/prebid/server/handler/CollectedMetricsHandler.java +++ b/src/main/java/org/prebid/server/handler/CollectedMetricsHandler.java @@ -35,7 +35,7 @@ public CollectedMetricsHandler(MetricRegistry metricRegistry, @Override public void handle(RoutingContext routingContext) { - final String responseString = mapper.encode(getAllMetrics()); + final String responseString = mapper.encodeToString(getAllMetrics()); HttpUtil.executeSafely(routingContext, endpoint, response -> response diff --git a/src/main/java/org/prebid/server/handler/CookieSyncHandler.java b/src/main/java/org/prebid/server/handler/CookieSyncHandler.java index 09d20461b39..6471bc3426f 100644 --- a/src/main/java/org/prebid/server/handler/CookieSyncHandler.java +++ b/src/main/java/org/prebid/server/handler/CookieSyncHandler.java @@ -450,7 +450,7 @@ private void respondWithRejectedBidders(CookieSyncContext cookieSyncContext, final HttpResponseStatus status = HttpResponseStatus.OK; final CookieSyncResponse cookieSyncResponse = CookieSyncResponse.of(cookieSyncStatus, updatedBidderStatuses); - final String body = mapper.encode(cookieSyncResponse); + final String body = mapper.encodeToString(cookieSyncResponse); HttpUtil.executeSafely(cookieSyncContext.getRoutingContext(), Endpoint.cookie_sync, response -> response diff --git a/src/main/java/org/prebid/server/handler/DealsStatusHandler.java b/src/main/java/org/prebid/server/handler/DealsStatusHandler.java index 965197e0088..15a9dc066dd 100644 --- a/src/main/java/org/prebid/server/handler/DealsStatusHandler.java +++ b/src/main/java/org/prebid/server/handler/DealsStatusHandler.java @@ -28,7 +28,7 @@ public DealsStatusHandler(DeliveryProgressService deliveryProgressService, Jacks public void handle(RoutingContext routingContext) { final DeliveryProgressReport deliveryProgressReport = deliveryProgressService .getOverallDeliveryProgressReport(); - final String body = mapper.encode(deliveryProgressReport); + final String body = mapper.encodeToString(deliveryProgressReport); // don't send the response if client has gone if (routingContext.response().closed()) { diff --git a/src/main/java/org/prebid/server/handler/GetuidsHandler.java b/src/main/java/org/prebid/server/handler/GetuidsHandler.java index 4c26e36b507..deb3822e4a9 100644 --- a/src/main/java/org/prebid/server/handler/GetuidsHandler.java +++ b/src/main/java/org/prebid/server/handler/GetuidsHandler.java @@ -28,7 +28,7 @@ public GetuidsHandler(UidsCookieService uidsCookieService, JacksonMapper mapper) @Override public void handle(RoutingContext routingContext) { final Map uids = uidsFrom(routingContext); - final String body = mapper.encode(BuyerUids.of(uids)); + final String body = mapper.encodeToString(BuyerUids.of(uids)); HttpUtil.executeSafely(routingContext, Endpoint.getuids, response -> response .putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpUtil.APPLICATION_JSON_CONTENT_TYPE) diff --git a/src/main/java/org/prebid/server/handler/LineItemStatusHandler.java b/src/main/java/org/prebid/server/handler/LineItemStatusHandler.java index b32ae8b9cc2..3a376b3d2a3 100644 --- a/src/main/java/org/prebid/server/handler/LineItemStatusHandler.java +++ b/src/main/java/org/prebid/server/handler/LineItemStatusHandler.java @@ -55,7 +55,7 @@ public void handle(RoutingContext routingContext) { HttpUtil.executeSafely(routingContext, endpoint, response -> response .setStatusCode(HttpResponseStatus.OK.code()) - .end(mapper.encode(report))); + .end(mapper.encodeToString(report))); } catch (PreBidException e) { HttpUtil.executeSafely(routingContext, endpoint, response -> response diff --git a/src/main/java/org/prebid/server/handler/StatusHandler.java b/src/main/java/org/prebid/server/handler/StatusHandler.java index 1c6acab5ea7..f356971d598 100644 --- a/src/main/java/org/prebid/server/handler/StatusHandler.java +++ b/src/main/java/org/prebid/server/handler/StatusHandler.java @@ -40,7 +40,7 @@ public void handle(RoutingContext routingContext) { HttpUtil.executeSafely(routingContext, Endpoint.status, response -> response .putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON) - .end(mapper.encode(nameToStatus))); + .end(mapper.encodeToString(nameToStatus))); } } } diff --git a/src/main/java/org/prebid/server/handler/VtrackHandler.java b/src/main/java/org/prebid/server/handler/VtrackHandler.java index ca657c4bd37..b0aa382f482 100644 --- a/src/main/java/org/prebid/server/handler/VtrackHandler.java +++ b/src/main/java/org/prebid/server/handler/VtrackHandler.java @@ -211,7 +211,7 @@ private void handleCacheResult(AsyncResult async, RoutingConte respondWithServerError(routingContext, "Error occurred while sending request to cache", async.cause()); } else { try { - respondWith(routingContext, HttpResponseStatus.OK, mapper.encode(async.result())); + respondWith(routingContext, HttpResponseStatus.OK, mapper.encodeToString(async.result())); } catch (EncodeException e) { respondWithServerError(routingContext, "Error occurred while encoding response", e); } diff --git a/src/main/java/org/prebid/server/handler/info/BidderDetailsHandler.java b/src/main/java/org/prebid/server/handler/info/BidderDetailsHandler.java index 2f7df84162e..caa24790820 100644 --- a/src/main/java/org/prebid/server/handler/info/BidderDetailsHandler.java +++ b/src/main/java/org/prebid/server/handler/info/BidderDetailsHandler.java @@ -54,7 +54,7 @@ private Map createBidderInfos(BidderCatalog bidderCatalog) { return Stream.of(nameToInfo, allToInfos) .flatMap(map -> map.entrySet().stream()) - .collect(Collectors.toMap(Map.Entry::getKey, map -> mapper.encode(map.getValue()))); + .collect(Collectors.toMap(Map.Entry::getKey, map -> mapper.encodeToString(map.getValue()))); } private ObjectNode bidderNode(BidderCatalog bidderCatalog, String name) { diff --git a/src/main/java/org/prebid/server/handler/info/BiddersHandler.java b/src/main/java/org/prebid/server/handler/info/BiddersHandler.java index 4039050b697..fa5581fda46 100644 --- a/src/main/java/org/prebid/server/handler/info/BiddersHandler.java +++ b/src/main/java/org/prebid/server/handler/info/BiddersHandler.java @@ -45,7 +45,7 @@ private String resolveBodyFromContext(RoutingContext routingContext) { .collect(Collectors.toSet()) : bidderCatalog.names(); - return mapper.encode(new TreeSet<>(bidderNamesAndAliases)); + return mapper.encodeToString(new TreeSet<>(bidderNamesAndAliases)); } private static boolean enabledOnlyFromQueryStringParams(RoutingContext routingContext) { diff --git a/src/main/java/org/prebid/server/handler/openrtb2/AmpHandler.java b/src/main/java/org/prebid/server/handler/openrtb2/AmpHandler.java index c6cc7c30cdc..c924880e820 100644 --- a/src/main/java/org/prebid/server/handler/openrtb2/AmpHandler.java +++ b/src/main/java/org/prebid/server/handler/openrtb2/AmpHandler.java @@ -277,7 +277,7 @@ private void handleResult(AsyncResult> respo status = HttpResponseStatus.OK; routingContext.response().headers().add(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON); - body = mapper.encode(responseResult.result().getLeft()); + body = mapper.encodeToString(responseResult.result().getLeft()); } else { final Throwable exception = responseResult.cause(); if (exception instanceof InvalidRequestException) { diff --git a/src/main/java/org/prebid/server/handler/openrtb2/VideoHandler.java b/src/main/java/org/prebid/server/handler/openrtb2/VideoHandler.java index 8e029d32cf8..07eb40cd2a1 100644 --- a/src/main/java/org/prebid/server/handler/openrtb2/VideoHandler.java +++ b/src/main/java/org/prebid/server/handler/openrtb2/VideoHandler.java @@ -104,7 +104,7 @@ private void handleResult(AsyncResult responseResult, VideoEvent. status = HttpResponseStatus.OK; routingContext.response().headers().add(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON); - body = mapper.encode(responseResult.result()); + body = mapper.encodeToString(responseResult.result()); } else { final Throwable exception = responseResult.cause(); if (exception instanceof InvalidRequestException) { diff --git a/src/main/java/org/prebid/server/json/JacksonMapper.java b/src/main/java/org/prebid/server/json/JacksonMapper.java index e2d77bf4767..6673f6c1879 100644 --- a/src/main/java/org/prebid/server/json/JacksonMapper.java +++ b/src/main/java/org/prebid/server/json/JacksonMapper.java @@ -24,7 +24,7 @@ public ObjectMapper mapper() { return mapper; } - public String encode(T obj) throws EncodeException { + public String encodeToString(T obj) throws EncodeException { try { return mapper.writeValueAsString(obj); } catch (JsonProcessingException e) { @@ -32,6 +32,14 @@ public String encode(T obj) throws EncodeException { } } + public byte[] encodeToBytes(T obj) throws EncodeException { + try { + return mapper.writeValueAsBytes(obj); + } catch (JsonProcessingException e) { + throw new EncodeException("Failed to encode as byte array: " + e.getMessage()); + } + } + public T decodeValue(String str, Class clazz) throws DecodeException { try { return mapper.readValue(str, clazz); @@ -40,6 +48,14 @@ public T decodeValue(String str, Class clazz) throws DecodeException { } } + public T decodeValue(byte[] bytes, Class clazz) throws DecodeException { + try { + return mapper.readValue(bytes, clazz); + } catch (IOException e) { + throw new DecodeException(String.format(FAILED_TO_DECODE, e.getMessage())); + } + } + public T decodeValue(String str, TypeReference type) throws DecodeException { try { return mapper.readValue(str, type); diff --git a/src/main/java/org/prebid/server/log/CriteriaLogManager.java b/src/main/java/org/prebid/server/log/CriteriaLogManager.java index 53dd6f21973..b8e5801d436 100644 --- a/src/main/java/org/prebid/server/log/CriteriaLogManager.java +++ b/src/main/java/org/prebid/server/log/CriteriaLogManager.java @@ -50,8 +50,8 @@ public BidResponse traceResponse(Logger logger, BidResponse bidResponse, BidRequ final String jsonBidResponse; final String jsonBidRequest; try { - jsonBidResponse = mapper.encode(bidResponse); - jsonBidRequest = debugEnabled ? null : mapper.encode(bidRequest); + jsonBidResponse = mapper.encodeToString(bidResponse); + jsonBidRequest = debugEnabled ? null : mapper.encodeToString(bidRequest); } catch (EncodeException e) { CriteriaLogManager.logger.warn("Failed to parse bidResponse or bidRequest to json string: {0}", e); return bidResponse; diff --git a/src/main/java/org/prebid/server/log/HttpInteractionLogger.java b/src/main/java/org/prebid/server/log/HttpInteractionLogger.java index 5afb0f01a73..77da9396f54 100644 --- a/src/main/java/org/prebid/server/log/HttpInteractionLogger.java +++ b/src/main/java/org/prebid/server/log/HttpInteractionLogger.java @@ -60,7 +60,7 @@ public void maybeLogOpenrtb2Auction(AuctionContext auctionContext, private String toOneLineString(String value) { try { - return mapper.encode(mapper.mapper().readTree(value)); + return mapper.encodeToString(mapper.mapper().readTree(value)); } catch (JsonProcessingException e) { return String.format("Not parseable JSON passed: %s", value.replaceAll("[\r\n]+", " ")); } @@ -87,7 +87,7 @@ public void maybeLogBidderRequest(AuctionContext context, BidderRequest bidderRe if (interactionSatisfiesSpec(context, bidder)) { final BidRequest bidRequest = bidderRequest.getBidRequest(); final BidRequest updatedBidRequest = bidRequestWithBidderName(bidder, bidRequest); - final String jsonBidRequest = mapper.encode(updatedBidRequest); + final String jsonBidRequest = mapper.encodeToString(updatedBidRequest); logger.info("Request body to {0}: \"{1}\"", bidder, jsonBidRequest); incLoggedInteractions(); diff --git a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java index 2436163ec57..b433a2439a7 100644 --- a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java @@ -479,12 +479,14 @@ HttpBidderRequester httpBidderRequester( HttpClient httpClient, @Autowired(required = false) BidderRequestCompletionTrackerFactory bidderRequestCompletionTrackerFactory, BidderErrorNotifier bidderErrorNotifier, - HttpBidderRequestEnricher requestEnricher) { + HttpBidderRequestEnricher requestEnricher, + JacksonMapper mapper) { return new HttpBidderRequester(httpClient, bidderRequestCompletionTrackerFactory, bidderErrorNotifier, - requestEnricher); + requestEnricher, + mapper); } @Bean diff --git a/src/main/java/org/prebid/server/validation/BidderParamValidator.java b/src/main/java/org/prebid/server/validation/BidderParamValidator.java index 13a405bd2db..856201f6252 100644 --- a/src/main/java/org/prebid/server/validation/BidderParamValidator.java +++ b/src/main/java/org/prebid/server/validation/BidderParamValidator.java @@ -97,7 +97,7 @@ private static Map toBidderSchemas(Map bid private static String toSchemas(Map bidderRawSchemas, JacksonMapper mapper) { try { - return mapper.encode(bidderRawSchemas); + return mapper.encodeToString(bidderRawSchemas); } catch (EncodeException e) { throw new IllegalArgumentException("Couldn't combine json schemas into single json string"); } diff --git a/src/test/java/org/prebid/server/auction/VideoStoredRequestProcessorTest.java b/src/test/java/org/prebid/server/auction/VideoStoredRequestProcessorTest.java index 00177809761..8dd052c74c6 100644 --- a/src/test/java/org/prebid/server/auction/VideoStoredRequestProcessorTest.java +++ b/src/test/java/org/prebid/server/auction/VideoStoredRequestProcessorTest.java @@ -145,7 +145,7 @@ public void shouldReturnFutureWithMergedStoredAndDefaultRequest() { builder -> builder.pods(singletonList(Pod.of(123, 20, STORED_POD_ID)))); final StoredDataResult storedDataResult = StoredDataResult.of( - singletonMap(STORED_REQUEST_ID, jacksonMapper.encode(storedVideo)), + singletonMap(STORED_REQUEST_ID, jacksonMapper.encodeToString(storedVideo)), singletonMap(STORED_POD_ID, "{}"), emptyList()); @@ -266,7 +266,7 @@ public void shouldReturnFutureWithCorrectAdPodDurationIfRequireExactDurationIsTr .pods(singletonList(Pod.of(123, 30, STORED_POD_ID)))); final StoredDataResult storedDataResult = StoredDataResult.of( - singletonMap(STORED_REQUEST_ID, jacksonMapper.encode(storedVideo)), + singletonMap(STORED_REQUEST_ID, jacksonMapper.encodeToString(storedVideo)), singletonMap(STORED_POD_ID, "{}"), emptyList()); @@ -339,7 +339,7 @@ public void shouldReturnFutureWithCorrectPriceGranularityInRequest() { builder -> builder.pods(singletonList(Pod.of(123, 20, STORED_POD_ID)))); final StoredDataResult storedDataResult = StoredDataResult.of( - singletonMap(STORED_REQUEST_ID, jacksonMapper.encode(storedVideo)), + singletonMap(STORED_REQUEST_ID, jacksonMapper.encodeToString(storedVideo)), singletonMap(STORED_POD_ID, "{}"), emptyList()); diff --git a/src/test/java/org/prebid/server/bidder/BidderErrorNotifierTest.java b/src/test/java/org/prebid/server/bidder/BidderErrorNotifierTest.java index d71f2b608b4..228807fddda 100644 --- a/src/test/java/org/prebid/server/bidder/BidderErrorNotifierTest.java +++ b/src/test/java/org/prebid/server/bidder/BidderErrorNotifierTest.java @@ -10,6 +10,7 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; +import org.prebid.server.VertxTest; import org.prebid.server.bidder.model.BidderError; import org.prebid.server.bidder.model.HttpCall; import org.prebid.server.bidder.model.HttpRequest; @@ -28,7 +29,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; -public class BidderErrorNotifierTest { +public class BidderErrorNotifierTest extends VertxTest { + + private static final byte[] EMPTY_BODY = "{}".getBytes(); @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -72,10 +75,10 @@ public void shouldSendTimeoutNotificationAndUpdateSuccessMetric() { given(bidder.makeTimeoutNotification(any())).willReturn(HttpRequest.builder() .uri("url") .method(HttpMethod.POST) - .body("{}") + .body(EMPTY_BODY) .build()); - given(httpClient.request(any(), anyString(), any(), anyString(), anyLong())) + given(httpClient.request(any(), anyString(), any(), any(byte[].class), anyLong())) .willReturn(Future.succeededFuture(HttpClientResponse.of(200, null, null))); // when @@ -85,7 +88,7 @@ public void shouldSendTimeoutNotificationAndUpdateSuccessMetric() { Assertions.assertThat(result).isSameAs(bidderCall); verify(bidder).makeTimeoutNotification(eq(bidderRequest)); - verify(httpClient).request(eq(HttpMethod.POST), eq("url"), isNull(), eq("{}"), eq(200L)); + verify(httpClient).request(eq(HttpMethod.POST), eq("url"), isNull(), eq(EMPTY_BODY), eq(200L)); verify(metrics).updateTimeoutNotificationMetric(eq(true)); } @@ -97,10 +100,10 @@ public void shouldSendTimeoutNotificationAndUpdateFailedMetricWhenResponseCodeNo given(bidder.makeTimeoutNotification(any())).willReturn(HttpRequest.builder() .uri("url") .method(HttpMethod.POST) - .body("{}") + .body(EMPTY_BODY) .build()); - given(httpClient.request(any(), anyString(), any(), anyString(), anyLong())) + given(httpClient.request(any(), anyString(), any(), any(byte[].class), anyLong())) .willReturn(Future.succeededFuture(HttpClientResponse.of(404, null, null))); // when @@ -108,7 +111,7 @@ public void shouldSendTimeoutNotificationAndUpdateFailedMetricWhenResponseCodeNo // then verify(bidder).makeTimeoutNotification(eq(bidderRequest)); - verify(httpClient).request(eq(HttpMethod.POST), eq("url"), isNull(), eq("{}"), eq(200L)); + verify(httpClient).request(eq(HttpMethod.POST), eq("url"), isNull(), eq(EMPTY_BODY), eq(200L)); verify(metrics).updateTimeoutNotificationMetric(eq(false)); } @@ -120,10 +123,10 @@ public void shouldSendTimeoutNotificationAndUpdateFailedMetricWhenResponseTimedO given(bidder.makeTimeoutNotification(any())).willReturn(HttpRequest.builder() .uri("url") .method(HttpMethod.POST) - .body("{}") + .body(EMPTY_BODY) .build()); - given(httpClient.request(any(), anyString(), any(), anyString(), anyLong())) + given(httpClient.request(any(), anyString(), any(), any(byte[].class), anyLong())) .willReturn(Future.failedFuture(new TimeoutException("Timeout exception"))); // when @@ -131,7 +134,7 @@ public void shouldSendTimeoutNotificationAndUpdateFailedMetricWhenResponseTimedO // then verify(bidder).makeTimeoutNotification(eq(bidderRequest)); - verify(httpClient).request(eq(HttpMethod.POST), eq("url"), isNull(), eq("{}"), eq(200L)); + verify(httpClient).request(eq(HttpMethod.POST), eq("url"), isNull(), eq(EMPTY_BODY), eq(200L)); verify(metrics).updateTimeoutNotificationMetric(eq(false)); } } diff --git a/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java b/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java index 3570a9f6b6f..2ce9c8a7b0f 100644 --- a/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java +++ b/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java @@ -1,5 +1,6 @@ package org.prebid.server.bidder; +import com.fasterxml.jackson.core.JsonProcessingException; import com.iab.openrtb.request.BidRequest; import com.iab.openrtb.request.Deal; import com.iab.openrtb.request.Imp; @@ -45,12 +46,14 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeoutException; +import java.util.function.UnaryOperator; import java.util.stream.Collectors; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; +import static java.util.function.UnaryOperator.identity; import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -68,6 +71,7 @@ public class HttpBidderRequesterTest extends VertxTest { + private static final byte[] EMPTY_BYTE_BODY = "{}".getBytes(); @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -101,7 +105,8 @@ public void setUp() { timeout = timeoutFactory.create(500L); expiredTimeout = timeoutFactory.create(clock.instant().minusMillis(1500L).toEpochMilli(), 1000L); - httpBidderRequester = new HttpBidderRequester(httpClient, null, bidderErrorNotifier, requestEnricher); + httpBidderRequester = new HttpBidderRequester( + httpClient, null, bidderErrorNotifier, requestEnricher, jacksonMapper); } @Test @@ -154,7 +159,7 @@ public void shouldPassStoredResponseToBidderMakeBidsMethodAndReturnSeatBids() { HttpRequest.builder() .method(HttpMethod.POST) .uri("uri") - .body("requestBody") + .body(EMPTY_BYTE_BODY) .headers(headers) .build()), emptyList())); @@ -190,13 +195,13 @@ public void shouldMakeRequestToBidderWhenStoredResponseDefinedButBidderCreatesMo HttpRequest.builder() .method(HttpMethod.POST) .uri("uri") - .body("requestBody") + .body(EMPTY_BYTE_BODY) .headers(headers) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri("uri") - .body("requestBody2") + .body(EMPTY_BYTE_BODY) .headers(headers) .build()), emptyList())); @@ -207,7 +212,7 @@ public void shouldMakeRequestToBidderWhenStoredResponseDefinedButBidderCreatesMo httpBidderRequester.requestBids(bidder, bidderRequest, timeout, CaseInsensitiveMultiMap.empty(), false); // then - verify(httpClient, times(2)).request(any(), anyString(), any(), anyString(), anyLong()); + verify(httpClient, times(2)).request(any(), anyString(), any(), any(byte[].class), anyLong()); } @Test @@ -228,25 +233,26 @@ public void shouldSendPopulatedGetRequestWithoutBody() { httpBidderRequester.requestBids(bidder, bidderRequest, timeout, CaseInsensitiveMultiMap.empty(), false); // then - verify(httpClient).request(any(), anyString(), any(), (String) isNull(), anyLong()); + verify(httpClient).request(any(), anyString(), any(), (byte[]) isNull(), anyLong()); } @Test - public void shouldSendMultipleRequests() { + public void shouldSendMultipleRequests() throws JsonProcessingException { // given givenHttpClientReturnsResponse(200, null); + final BidRequest bidRequest = givenBidRequest(identity()); given(bidder.makeHttpRequests(any())).willReturn(Result.of(asList( HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(mapper.writeValueAsBytes(bidRequest)) .headers(new CaseInsensitiveHeaders()) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(mapper.writeValueAsBytes(bidRequest)) .headers(new CaseInsensitiveHeaders()) .build()), emptyList())); @@ -257,7 +263,7 @@ public void shouldSendMultipleRequests() { httpBidderRequester.requestBids(bidder, bidderRequest, timeout, CaseInsensitiveMultiMap.empty(), false); // then - verify(httpClient, times(2)).request(any(), anyString(), any(), anyString(), anyLong()); + verify(httpClient, times(2)).request(any(), anyString(), any(), any(byte[].class), anyLong()); } @Test @@ -267,7 +273,7 @@ public void shouldReturnBidsCreatedByBidder() { HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build()), emptyList())); @@ -289,40 +295,48 @@ public void shouldReturnBidsCreatedByBidder() { } @Test - public void shouldNotWaitForResponsesWhenAllDealsIsGathered() { + public void shouldNotWaitForResponsesWhenAllDealsIsGathered() throws JsonProcessingException { // given httpBidderRequester = new HttpBidderRequester(httpClient, new DealsBidderRequestCompletionTrackerFactory(), - bidderErrorNotifier, requestEnricher); + bidderErrorNotifier, requestEnricher, jacksonMapper); final BidRequest bidRequest = bidRequestWithDeals("deal1", "deal2"); final BidderRequest bidderRequest = BidderRequest.of("bidder", null, bidRequest); + final BidRequest firstRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder.id("r1")); + final byte[] firstRequestBody = mapper.writeValueAsBytes(firstRequest); + final BidRequest secondRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder.id("r2")); + final byte[] secondRequestBody = mapper.writeValueAsBytes(secondRequest); + final BidRequest thirdRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder.id("r3")); + final byte[] thirdRequestBody = mapper.writeValueAsBytes(thirdRequest); + final BidRequest forthRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder.id("r4")); + final byte[] forthRequestBody = mapper.writeValueAsBytes(forthRequest); given(bidder.makeHttpRequests(any())).willReturn(Result.of(Arrays.asList( HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body("r1") + .body(firstRequestBody) .headers(new CaseInsensitiveHeaders()) .payload(bidRequestWithDeals("deal1")) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body("r2") + .body(secondRequestBody) .headers(new CaseInsensitiveHeaders()) .payload(bidRequestWithDeals("deal1")) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body("r3") + .body(thirdRequestBody) .headers(new CaseInsensitiveHeaders()) .payload(bidRequestWithDeals("deal2")) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body("r4") + .body(forthRequestBody) .headers(new CaseInsensitiveHeaders()) .payload(bidRequestWithDeals("deal1")) .build()), @@ -333,13 +347,13 @@ public void shouldNotWaitForResponsesWhenAllDealsIsGathered() { final HttpClientResponse respWithDeal2 = HttpClientResponse.of(200, null, "{\"seatbid\":[{\"bid\":[{\"dealid\":\"deal2\"}]}]}"); - given(httpClient.request(any(), anyString(), any(), eq("r1"), anyLong())) + given(httpClient.request(any(), anyString(), any(), eq(firstRequestBody), anyLong())) .willReturn(Future.succeededFuture(respWithDeal1)); - given(httpClient.request(any(), anyString(), any(), eq("r2"), anyLong())) + given(httpClient.request(any(), anyString(), any(), eq(secondRequestBody), anyLong())) .willReturn(Promise.promise().future()); - given(httpClient.request(any(), anyString(), any(), eq("r3"), anyLong())) + given(httpClient.request(any(), anyString(), any(), eq(thirdRequestBody), anyLong())) .willReturn(Future.succeededFuture(respWithDeal2)); - given(httpClient.request(any(), anyString(), any(), eq("r4"), anyLong())) + given(httpClient.request(any(), anyString(), any(), eq(forthRequestBody), anyLong())) .willReturn(Promise.promise().future()); final BidderBid bidderBidDeal1 = BidderBid.of(Bid.builder().impid("deal1").dealid("deal1").build(), null, null); @@ -356,7 +370,7 @@ public void shouldNotWaitForResponsesWhenAllDealsIsGathered() { // then verify(bidder, times(1)).makeHttpRequests(any()); - verify(httpClient, times(4)).request(any(), any(), any(), anyString(), anyLong()); + verify(httpClient, times(4)).request(any(), any(), any(), any(byte[].class), anyLong()); verify(bidder, times(2)).makeBids(any(), any()); assertThat(bidderSeatBid.getBids()).containsOnly(bidderBidDeal1, bidderBidDeal2); @@ -372,28 +386,28 @@ public void shouldFinishWhenAllDealRequestsAreFinishedAndNoDealsProvided() { HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body("r1") + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .payload(bidRequestWithDeals("deal1")) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body("r2") + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .payload(bidRequestWithDeals("deal2")) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body("r3") + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .payload(bidRequestWithDeals("deal2")) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body("r4") + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .payload(bidRequestWithDeals("deal2")) .build()), @@ -412,27 +426,31 @@ public void shouldFinishWhenAllDealRequestsAreFinishedAndNoDealsProvided() { // then verify(bidder, times(1)).makeHttpRequests(any()); - verify(httpClient, times(4)).request(any(), any(), any(), anyString(), anyLong()); + verify(httpClient, times(4)).request(any(), any(), any(), any(byte[].class), anyLong()); verify(bidder, times(4)).makeBids(any(), any()); assertThat(bidderSeatBid.getBids()).contains(bidderBid, bidderBid, bidderBid, bidderBid); } @Test - public void shouldReturnFullDebugInfoIfDebugEnabled() { + public void shouldReturnFullDebugInfoIfDebugEnabled() throws JsonProcessingException { // given final MultiMap headers = new CaseInsensitiveHeaders().add("headerKey", "headerValue"); + final BidRequest firstBidRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder.id("firstId")); + final BidRequest secondBidRequest = givenBidRequest(bidRequestBuilder -> bidRequestBuilder.id("secondId")); given(bidder.makeHttpRequests(any())).willReturn(Result.of(asList( HttpRequest.builder() .method(HttpMethod.POST) .uri("uri1") - .body("requestBody1") + .body(mapper.writeValueAsBytes(firstBidRequest)) + .payload(firstBidRequest) .headers(headers) .build(), HttpRequest.builder() .method(HttpMethod.POST) .uri("uri2") - .body("requestBody2") + .body(mapper.writeValueAsBytes(secondBidRequest)) + .payload(secondBidRequest) .headers(headers) .build()), emptyList())); @@ -454,10 +472,12 @@ public void shouldReturnFullDebugInfoIfDebugEnabled() { // then assertThat(bidderSeatBid.getHttpCalls()).hasSize(2).containsOnly( - ExtHttpCall.builder().uri("uri1").requestbody("requestBody1").responsebody("responseBody1") + ExtHttpCall.builder().uri("uri1").requestbody(mapper.writeValueAsString(firstBidRequest)) + .responsebody("responseBody1") .requestheaders(singletonMap("headerKey", singletonList("headerValue"))) .status(200).build(), - ExtHttpCall.builder().uri("uri2").requestbody("requestBody2").responsebody("responseBody2") + ExtHttpCall.builder().uri("uri2").requestbody(mapper.writeValueAsString(secondBidRequest)) + .responsebody("responseBody2") .requestheaders(singletonMap("headerKey", singletonList("headerValue"))) .status(200).build()); } @@ -472,7 +492,7 @@ public void shouldNotReturnSensitiveHeadersInFullDebugInfo() { HttpRequest.builder() .method(HttpMethod.POST) .uri("uri1") - .body("requestBody1") + .body(EMPTY_BYTE_BODY) .headers(headers) .build()), emptyList())); @@ -496,15 +516,18 @@ public void shouldNotReturnSensitiveHeadersInFullDebugInfo() { } @Test - public void shouldReturnPartialDebugInfoIfDebugEnabledAndGlobalTimeoutAlreadyExpired() { + public void shouldReturnPartialDebugInfoIfDebugEnabledAndGlobalTimeoutAlreadyExpired() + throws JsonProcessingException { // given final MultiMap headers = new CaseInsensitiveHeaders().add("headerKey", "headerValue"); + final BidRequest givenBidRequest = givenBidRequest(identity()); given(bidder.makeHttpRequests(any())).willReturn(Result.of(singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri("uri1") .headers(headers) - .body("requestBody1") + .payload(givenBidRequest) + .body(mapper.writeValueAsBytes(givenBidRequest)) .build()), emptyList())); @@ -519,20 +542,22 @@ public void shouldReturnPartialDebugInfoIfDebugEnabledAndGlobalTimeoutAlreadyExp // then assertThat(bidderSeatBid.getHttpCalls()).hasSize(1).containsOnly( - ExtHttpCall.builder().uri("uri1").requestbody("requestBody1") + ExtHttpCall.builder().uri("uri1").requestbody(mapper.writeValueAsString(givenBidRequest)) .requestheaders(singletonMap("headerKey", singletonList("headerValue"))) .build()); } @Test - public void shouldReturnPartialDebugInfoIfDebugEnabledAndHttpErrorOccurs() { + public void shouldReturnPartialDebugInfoIfDebugEnabledAndHttpErrorOccurs() throws JsonProcessingException { // given final MultiMap headers = new CaseInsensitiveHeaders().add("headerKey", "headerValue"); + final BidRequest givenBidRequest = givenBidRequest(identity()); given(bidder.makeHttpRequests(any())).willReturn(Result.of(singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri("uri1") - .body("requestBody1") + .body(mapper.writeValueAsBytes(givenBidRequest)) + .payload(givenBidRequest) .headers(headers) .build()), emptyList())); @@ -550,20 +575,23 @@ public void shouldReturnPartialDebugInfoIfDebugEnabledAndHttpErrorOccurs() { // then assertThat(bidderSeatBid.getHttpCalls()).hasSize(1).containsOnly( - ExtHttpCall.builder().uri("uri1").requestbody("requestBody1") + ExtHttpCall.builder().uri("uri1") + .requestbody(mapper.writeValueAsString(givenBidRequest)) .requestheaders(singletonMap("headerKey", singletonList("headerValue"))) .build()); } @Test - public void shouldReturnFullDebugInfoIfDebugEnabledAndErrorStatus() { + public void shouldReturnFullDebugInfoIfDebugEnabledAndErrorStatus() throws JsonProcessingException { // given final MultiMap headers = new CaseInsensitiveHeaders().add("headerKey", "headerValue"); + final BidRequest givenBidRequest = givenBidRequest(identity()); given(bidder.makeHttpRequests(any())).willReturn(Result.of(singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri("uri1") - .body("requestBody1") + .body(mapper.writeValueAsBytes(givenBidRequest)) + .payload(givenBidRequest) .headers(headers) .build()), emptyList())); @@ -581,7 +609,8 @@ public void shouldReturnFullDebugInfoIfDebugEnabledAndErrorStatus() { // then assertThat(bidderSeatBid.getHttpCalls()).hasSize(1).containsOnly( - ExtHttpCall.builder().uri("uri1").requestbody("requestBody1").responsebody("responseBody1") + ExtHttpCall.builder().uri("uri1").requestbody(mapper.writeValueAsString(givenBidRequest)) + .responsebody("responseBody1") .requestheaders(singletonMap("headerKey", singletonList("headerValue"))) .status(500).build()); assertThat(bidderSeatBid.getErrors()).hasSize(1) @@ -596,7 +625,7 @@ public void shouldTolerateAlreadyExpiredGlobalTimeout() { HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build()), emptyList())); @@ -621,12 +650,12 @@ public void shouldNotifyBidderOfTimeout() { final HttpRequest httpRequest = HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .build(); given(bidder.makeHttpRequests(any())).willReturn(Result.of(singletonList(httpRequest), null)); - given(httpClient.request(any(), anyString(), any(), anyString(), anyLong())) + given(httpClient.request(any(), anyString(), any(), any(byte[].class), anyLong())) // bidder request .willReturn(Future.failedFuture(new TimeoutException("Timeout exception"))); @@ -647,47 +676,47 @@ public void shouldTolerateMultipleErrors() { HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build(), // this request will fail with timeout HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build(), // this request will fail with 500 status HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build(), // this request will fail with 400 status HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build(), // this request will get 204 status HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build(), // finally this request will succeed HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build()), singletonList(BidderError.badInput("makeHttpRequestsError")))); when(requestEnricher.enrichHeaders(any(), any(), any())).thenAnswer(invocation -> new CaseInsensitiveHeaders()); - given(httpClient.request(any(), anyString(), any(), anyString(), anyLong())) + given(httpClient.request(any(), anyString(), any(), any(byte[].class), anyLong())) // simulate response error for the first request .willReturn(Future.failedFuture(new RuntimeException("Response exception"))) // simulate timeout for the second request @@ -732,7 +761,7 @@ public void shouldNotMakeBidsIfResponseStatusIs204() { HttpRequest.builder() .method(HttpMethod.POST) .uri(EMPTY) - .body(EMPTY) + .body(EMPTY_BYTE_BODY) .headers(new CaseInsensitiveHeaders()) .build()), emptyList())); @@ -748,6 +777,16 @@ public void shouldNotMakeBidsIfResponseStatusIs204() { verify(bidder, never()).makeBids(any(), any()); } + private static BidRequest givenBidRequest(UnaryOperator bidRequestCustomizer) { + + return bidRequestCustomizer.apply(BidRequest.builder() + .id("requestId") + .imp(singletonList(Imp.builder() + .id("impId") + .build()))) + .build(); + } + private static BidRequest bidRequestWithDeals(String... ids) { final List impsWithDeals = Arrays.stream(ids) .map(HttpBidderRequesterTest::impWithDeal) @@ -765,18 +804,18 @@ private static Imp impWithDeal(String dealId) { } private void givenHttpClientReturnsResponse(int statusCode, String response) { - given(httpClient.request(any(), anyString(), any(), (String) any(), anyLong())) + given(httpClient.request(any(), anyString(), any(), (byte[]) any(), anyLong())) .willReturn(Future.succeededFuture(HttpClientResponse.of(statusCode, null, response))); } private void givenHttpClientProducesException(Throwable throwable) { - given(httpClient.request(any(), anyString(), any(), anyString(), anyLong())) + given(httpClient.request(any(), anyString(), any(), any(byte[].class), anyLong())) .willReturn(Future.failedFuture(throwable)); } private void givenHttpClientReturnsResponses(HttpClientResponse... httpClientResponses) { BDDMockito.BDDMyOngoingStubbing> stubbing = - given(httpClient.request(any(), anyString(), any(), anyString(), anyLong())); + given(httpClient.request(any(), anyString(), any(), any(byte[].class), anyLong())); // setup multiple answers for (HttpClientResponse httpClientResponse : httpClientResponses) { diff --git a/src/test/java/org/prebid/server/bidder/adhese/AdheseBidderTest.java b/src/test/java/org/prebid/server/bidder/adhese/AdheseBidderTest.java index 7cb67c1739b..469ab530d2d 100644 --- a/src/test/java/org/prebid/server/bidder/adhese/AdheseBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/adhese/AdheseBidderTest.java @@ -128,7 +128,7 @@ public void makeHttpRequestsShouldModifyIncomingRequestAndSetExpectedHttpRequest .containsOnly("https://ads-demo.adhese.com/json"); assertThat(result.getValue()) .extracting(HttpRequest::getBody) - .containsOnly(jacksonMapper.mapper().writeValueAsString( + .containsOnly(jacksonMapper.mapper().writeValueAsBytes( AdheseRequestBody .builder() .slots(Collections.singletonList( @@ -165,7 +165,7 @@ public void makeHttpRequestsShouldModifyIncomingRequestWithIfaParameter() throws .containsOnly("https://ads-demo.adhese.com/json"); assertThat(result.getValue()) .extracting(HttpRequest::getBody) - .containsOnly(jacksonMapper.mapper().writeValueAsString( + .containsOnly(jacksonMapper.mapper().writeValueAsBytes( AdheseRequestBody .builder() .slots(Collections.singletonList( @@ -198,7 +198,7 @@ public void makeHttpRequestsShouldModifyIncomingRequestWithRefererParameter() th .containsOnly("https://ads-demo.adhese.com/json"); assertThat(result.getValue()) .extracting(HttpRequest::getBody) - .containsOnly(jacksonMapper.mapper().writeValueAsString( + .containsOnly(jacksonMapper.mapper().writeValueAsBytes( AdheseRequestBody .builder() .slots(Collections.singletonList( @@ -235,7 +235,7 @@ public void makeHttpRequestsShouldNotModifyIncomingRequestIfTargetsNotPresent() .containsOnly("https://ads-demo.adhese.com/json"); assertThat(result.getValue()) .extracting(HttpRequest::getBody) - .containsOnly(jacksonMapper.mapper().writeValueAsString( + .containsOnly(jacksonMapper.mapper().writeValueAsBytes( AdheseRequestBody .builder() .slots(Collections.singletonList( diff --git a/src/test/java/org/prebid/server/bidder/adocean/AdoceanBidderTest.java b/src/test/java/org/prebid/server/bidder/adocean/AdoceanBidderTest.java index 9704b6f8bb8..5af69d9a5f1 100644 --- a/src/test/java/org/prebid/server/bidder/adocean/AdoceanBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/adocean/AdoceanBidderTest.java @@ -310,7 +310,7 @@ public void makeHttpRequestsShouldSetExpectedHeadersIfDeviceIpv6IsPresent() { } @Test - public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() { + public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() throws JsonProcessingException { // given final HttpCall httpCall = givenHttpCall(null, ""); @@ -519,10 +519,11 @@ private static Imp givenImp(Function impCustomiz .build(); } - private static HttpCall givenHttpCall(String requestBody, String responseBody) { + private static HttpCall givenHttpCall(String requestBody, String responseBody) + throws JsonProcessingException { return HttpCall.success( HttpRequest.builder() - .body(requestBody) + .body(mapper.writeValueAsBytes(requestBody)) .uri("https://myao.adocean.pl/_10000000/ad.json?aid=ad%3Aao-test&gdpr=1&gdpr_consent=consent" + "&nc=1&nosecure=1&pbsrv_v=1.0.0") .build(), diff --git a/src/test/java/org/prebid/server/bidder/adtelligent/AdtelligentBidderTest.java b/src/test/java/org/prebid/server/bidder/adtelligent/AdtelligentBidderTest.java index c9f48ff2b78..ca2a8dbff39 100644 --- a/src/test/java/org/prebid/server/bidder/adtelligent/AdtelligentBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/adtelligent/AdtelligentBidderTest.java @@ -76,7 +76,7 @@ public void makeHttpRequestsShouldReturnHttpRequestWithCorrectBodyHeadersAndMeth .containsOnly( tuple(HttpUtil.CONTENT_TYPE_HEADER.toString(), HttpUtil.APPLICATION_JSON_CONTENT_TYPE), tuple(HttpUtil.ACCEPT_HEADER.toString(), HttpHeaderValues.APPLICATION_JSON.toString())); - assertThat(result.getValue()).extracting(HttpRequest::getBody).containsExactly(mapper.writeValueAsString( + assertThat(result.getValue()).extracting(HttpRequest::getBody).containsExactly(mapper.writeValueAsBytes( BidRequest.builder() .imp(singletonList( Imp.builder() diff --git a/src/test/java/org/prebid/server/bidder/beachfront/BeachfrontBidderTest.java b/src/test/java/org/prebid/server/bidder/beachfront/BeachfrontBidderTest.java index 80412cdb315..0150e6aae64 100644 --- a/src/test/java/org/prebid/server/bidder/beachfront/BeachfrontBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/beachfront/BeachfrontBidderTest.java @@ -454,7 +454,7 @@ public void makeHttpRequestsShouldUseImpBidFloor() { } @Test - public void makeBidsShouldReturnEmptyResultWhenResponseBodyHasEmptyArray() { + public void makeBidsShouldReturnEmptyResultWhenResponseBodyHasEmptyArray() throws JsonProcessingException { // given final HttpCall httpCall = givenHttpCall(null, "[]"); @@ -467,7 +467,7 @@ public void makeBidsShouldReturnEmptyResultWhenResponseBodyHasEmptyArray() { } @Test - public void makeBidsShouldReturnErrorWhenResponseBodyIsInvalid() { + public void makeBidsShouldReturnErrorWhenResponseBodyIsInvalid() throws JsonProcessingException { // given final HttpCall httpCall = givenHttpCall(null, "invalid"); @@ -517,7 +517,10 @@ public void makeBidsShouldReturnExpectedBannerBid() throws JsonProcessingExcepti @Test public void makeBidsShouldReturnEmptyResultWhenResponseHasEmptySeatBids() throws JsonProcessingException { // given - final HttpCall httpCall = givenHttpCall("{}", + final byte[] byteArray = mapper.writeValueAsBytes(BeachfrontVideoRequest.builder().build()); + final BeachfrontVideoRequest videoRequest = jacksonMapper.decodeValue(byteArray, BeachfrontVideoRequest.class); + final HttpCall httpCall = givenHttpCall( + mapper.writeValueAsBytes(BeachfrontVideoRequest.builder().build()), mapper.writeValueAsString(BidResponse.builder().id("some_id").build())); // when @@ -543,7 +546,7 @@ public void makeBidsShouldReturnExpectedNurlVideoBid() throws JsonProcessingExce final HttpCall httpCall = HttpCall.success( HttpRequest.builder() - .body(mapper.writeValueAsString(videoRequest)) + .body(mapper.writeValueAsBytes(videoRequest)) .uri("url&prebidserver").build(), HttpResponse.of(200, null, mapper.writeValueAsString(bidResponse)), null); @@ -576,7 +579,7 @@ public void makeBidsShouldReturnExpectedAdmVideoBid() throws JsonProcessingExcep final HttpCall httpCall = HttpCall.success( HttpRequest.builder() - .body(mapper.writeValueAsString(videoRequest)) + .body(mapper.writeValueAsBytes(videoRequest)) .uri("url").build(), HttpResponse.of(200, null, mapper.writeValueAsString(bidResponse)), null); @@ -627,7 +630,8 @@ private static BidResponse givenBidResponse(Function givenHttpCall(String requestBody, String responseBody) { + private static HttpCall givenHttpCall(byte[] requestBody, String responseBody) + throws JsonProcessingException { return HttpCall.success( HttpRequest.builder().body(requestBody).build(), HttpResponse.of(200, null, responseBody), null); diff --git a/src/test/java/org/prebid/server/bidder/brightroll/BrightrollBidderTest.java b/src/test/java/org/prebid/server/bidder/brightroll/BrightrollBidderTest.java index 50d83af29fb..6a02f13b569 100644 --- a/src/test/java/org/prebid/server/bidder/brightroll/BrightrollBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/brightroll/BrightrollBidderTest.java @@ -97,7 +97,7 @@ public void makeHttpRequestsShouldReturnHttpRequestWithCorrectBodyHeadersAndMeth tuple(HttpUtil.X_FORWARDED_FOR_HEADER.toString(), "192.168.0.1"), tuple(HttpUtil.DNT_HEADER.toString(), "1"), tuple(HttpUtil.X_OPENRTB_VERSION_HEADER.toString(), "2.5")); - assertThat(result.getValue()).extracting(HttpRequest::getBody).containsExactly(mapper.writeValueAsString( + assertThat(result.getValue()).extracting(HttpRequest::getBody).containsExactly(mapper.writeValueAsBytes( BidRequest.builder() .imp(singletonList(Imp.builder() .bidfloor(BID_FLOOR) @@ -199,7 +199,7 @@ public void makeHttpRequestShouldUpdateBannerWhenWAndHMissedAndFormatIsPresent() // then assertThat(result.getValue()).hasSize(1).extracting(HttpRequest::getMethod).containsExactly(HttpMethod.POST); - assertThat(result.getValue()).extracting(HttpRequest::getBody).containsExactly(mapper.writeValueAsString( + assertThat(result.getValue()).extracting(HttpRequest::getBody).containsExactly(mapper.writeValueAsBytes( BidRequest.builder() .imp(singletonList(Imp.builder().banner(Banner.builder().w(200).h(100) .format(singletonList(Format.builder().w(200).h(100).build())).build()) @@ -277,7 +277,7 @@ public void makeHttpRequestShouldDropNotValidImpsFromRequest() throws JsonProces // then assertThat(result.getValue()).hasSize(1).extracting(HttpRequest::getMethod).containsExactly(HttpMethod.POST); - assertThat(result.getValue()).extracting(HttpRequest::getBody).containsExactly(mapper.writeValueAsString( + assertThat(result.getValue()).extracting(HttpRequest::getBody).containsExactly(mapper.writeValueAsBytes( BidRequest.builder() .imp(singletonList(Imp.builder().banner(Banner.builder().build()) .ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpBrightroll.of("publisher")))) diff --git a/src/test/java/org/prebid/server/bidder/facebook/FacebookBidderTest.java b/src/test/java/org/prebid/server/bidder/facebook/FacebookBidderTest.java index dcd1de2803c..7a7831a7710 100644 --- a/src/test/java/org/prebid/server/bidder/facebook/FacebookBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/facebook/FacebookBidderTest.java @@ -60,12 +60,10 @@ public void setUp() { @Test public void creationShouldFailOnBlankArguments() { - assertThatIllegalArgumentException().isThrownBy( - () -> new FacebookBidder( + assertThatIllegalArgumentException().isThrownBy(() -> new FacebookBidder( ENDPOINT_URL, " ", APP_SECRET, TIMEOUT_NOTIFICATION_URL_TEMPLATE, jacksonMapper)) .withMessageStartingWith("No facebook platform-id specified."); - assertThatIllegalArgumentException().isThrownBy( - () -> new FacebookBidder( + assertThatIllegalArgumentException().isThrownBy(() -> new FacebookBidder( ENDPOINT_URL, PLATFORM_ID, " ", TIMEOUT_NOTIFICATION_URL_TEMPLATE, jacksonMapper)) .withMessageStartingWith("No facebook app-secret specified."); } @@ -411,7 +409,8 @@ public void makeHttpRequestsShouldModifyImpVideoAsExpected() { } @Test - public void makeHttpRequestsShouldModifyImpNativeByAddingWidthAndHeightAndRemovingRequestAndVerFields() { + public void makeHttpRequestsShouldModifyImpNativeByAddingWidthAndHeightAndRemovingRequestAndVerFields() + throws JsonProcessingException { // given final BidRequest bidRequest = givenBidRequest( impBuilder -> impBuilder @@ -433,8 +432,10 @@ public void makeHttpRequestsShouldModifyImpNativeByAddingWidthAndHeightAndRemovi .containsOnly(FacebookNative.builder().w(-1).h(-1).api(singletonList(1)).build()); // extra check to assure that data in body is displayed correctly - assertThat(result.getValue().get(0).getBody()) - .contains("\"native\":{\"api\":[1],\"w\":-1,\"h\":-1},\"tagid\":\"pubId_placementId\"}"); + assertThat(result.getValue()) + .extracting(value -> new String(value.getBody())) + .allSatisfy(s -> assertThat(s) + .contains("\"native\":{\"api\":[1],\"w\":-1,\"h\":-1},\"tagid\":\"pubId_placementId\"}")); } @Test @@ -699,7 +700,7 @@ public void makeTimeoutNotificationShouldGenerateRequest() throws JsonProcessing .app(App.builder().publisher(Publisher.builder().id("test").build()).build()) .build(); final HttpRequest httpRequest = HttpRequest.builder() - .body(mapper.writeValueAsString(bidRequest)) + .body(mapper.writeValueAsBytes(bidRequest)) .payload(bidRequest) .build(); @@ -715,9 +716,9 @@ private static BidRequest givenBidRequest( Function impExtCustomizer, Function requestCustomizer) { return requestCustomizer.apply(BidRequest.builder() - .id("req1") - .user(User.builder().buyeruid("bUid").build()) - .imp(singletonList(givenImp(impCustomizer, impExtCustomizer)))) + .id("req1") + .user(User.builder().buyeruid("bUid").build()) + .imp(singletonList(givenImp(impCustomizer, impExtCustomizer)))) .build(); } @@ -729,10 +730,10 @@ private static BidRequest givenBidRequest(Function impCustomizer, Function impExtCustomizer) { return impCustomizer.apply(Imp.builder() - .id("imp1") - .banner(Banner.builder().h(50).format(singletonList(Format.builder().build())).build()) - .ext(mapper.valueToTree(ExtPrebid.of( - null, impExtCustomizer.apply(ExtImpFacebook.of("placementId", "pubId")))))) + .id("imp1") + .banner(Banner.builder().h(50).format(singletonList(Format.builder().build())).build()) + .ext(mapper.valueToTree(ExtPrebid.of( + null, impExtCustomizer.apply(ExtImpFacebook.of("placementId", "pubId")))))) .build(); } diff --git a/src/test/java/org/prebid/server/bidder/mgid/MgidBidderTest.java b/src/test/java/org/prebid/server/bidder/mgid/MgidBidderTest.java index 8da915a3cca..882820654e8 100644 --- a/src/test/java/org/prebid/server/bidder/mgid/MgidBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/mgid/MgidBidderTest.java @@ -180,7 +180,7 @@ public void makeHttpRequestsShouldSetBidFloorCurAndBidFloorToIncomingRequestWhen assertThat(result.getValue()).hasSize(1) .extracting(HttpRequest::getBody) - .containsExactly(mapper.writeValueAsString(expected)); + .containsExactly(mapper.writeValueAsBytes(expected)); } @Test @@ -219,7 +219,7 @@ public void makeHttpRequestsShouldSetBidFloorCurAndBidFloorToRequestWhenImpExtHa assertThat(result.getValue()).hasSize(1) .extracting(HttpRequest::getBody) - .containsExactly(mapper.writeValueAsString(expected)); + .containsExactly(mapper.writeValueAsBytes(expected)); } @Test @@ -257,7 +257,7 @@ public void makeHttpRequestsShouldNotModifyIncomingRequestWhenImpExtNotContainsP assertThat(result.getValue()).hasSize(1) .extracting(HttpRequest::getBody) - .containsExactly(mapper.writeValueAsString(expected)); + .containsExactly(mapper.writeValueAsBytes(expected)); } @Test diff --git a/src/test/java/org/prebid/server/bidder/outbrain/OutbrainBidderTest.java b/src/test/java/org/prebid/server/bidder/outbrain/OutbrainBidderTest.java index c6ef4f1fed9..e68e73c8b52 100644 --- a/src/test/java/org/prebid/server/bidder/outbrain/OutbrainBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/outbrain/OutbrainBidderTest.java @@ -286,13 +286,13 @@ public void makeBidsShouldReturnNativeBidWithModifiedImpIfNativeIsPresent() thro .imp(singletonList(Imp.builder().xNative(Native.builder().build()).id("123").build())).build(), mapper.writeValueAsString( givenBidResponse(bidBuilder -> bidBuilder.impid("123") - .adm(jacksonMapper.encode(nativeResponse))))); + .adm(jacksonMapper.encodeToString(nativeResponse))))); // when final Result> result = outbrainBidder.makeBids(httpCall, null); // then - final String expectedAdm = jacksonMapper.encode(Response.builder() + final String expectedAdm = jacksonMapper.encodeToString(Response.builder() .eventtrackers(null) .jstracker(String.format("", jsUrl)) .imptrackers(singletonList(impUrl)) diff --git a/src/test/java/org/prebid/server/bidder/sharethrough/SharethroughBidderTest.java b/src/test/java/org/prebid/server/bidder/sharethrough/SharethroughBidderTest.java index 9ba342050f3..d768649f029 100644 --- a/src/test/java/org/prebid/server/bidder/sharethrough/SharethroughBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/sharethrough/SharethroughBidderTest.java @@ -156,7 +156,7 @@ public void makeHttpRequestsShouldReturnRequestWithCorrectUriAndHeaders() throws assertThat(result.getValue()).doesNotContainNull() .hasSize(1).element(0) .returns(HttpMethod.POST, HttpRequest::getMethod) - .returns(mapper.writeValueAsString(expectedPayload), HttpRequest::getBody) + .returns(mapper.writeValueAsBytes(expectedPayload), HttpRequest::getBody) .returns(expectedPayload, HttpRequest::getPayload) .returns(ENDPOINT_URL + expectedParameters, HttpRequest::getUri); assertThat(result.getValue().get(0).getHeaders()).isNotNull() @@ -210,7 +210,7 @@ public void makeHttpRequestsShouldReturnRequestWithCorrectUriAndHeadersDefaultPa assertThat(result.getValue()).doesNotContainNull() .hasSize(1).element(0) .returns(HttpMethod.POST, HttpRequest::getMethod) - .returns(mapper.writeValueAsString(expectedPayload), HttpRequest::getBody) + .returns(mapper.writeValueAsBytes(expectedPayload), HttpRequest::getBody) .returns(expectedPayload, HttpRequest::getPayload) .returns(ENDPOINT_URL + expectedParameters, HttpRequest::getUri); } diff --git a/src/test/java/org/prebid/server/deals/UserServiceTest.java b/src/test/java/org/prebid/server/deals/UserServiceTest.java index 9484314d101..7d8ebfbacd8 100644 --- a/src/test/java/org/prebid/server/deals/UserServiceTest.java +++ b/src/test/java/org/prebid/server/deals/UserServiceTest.java @@ -276,7 +276,7 @@ public void getUserDetailsShouldReturnExpectedResult() { ExtUser.of(asList("L-1111", "O-2222")))); given(httpClient.post(anyString(), anyString(), anyLong())).willReturn( - Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encode(response)))); + Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encodeToString(response)))); // when final UserDetails result = userService.getUserDetails(auctionContext, timeout).result(); @@ -300,7 +300,7 @@ public void getUserDetailsShouldReturnFailedFutureWhenUserInResponseIsNull() { final UserDetailsResponse response = UserDetailsResponse.of(null); given(httpClient.post(anyString(), anyString(), anyLong())).willReturn( - Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encode(response)))); + Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encodeToString(response)))); // when final Future result = userService.getUserDetails(auctionContext, timeout); @@ -319,7 +319,7 @@ public void getUserDetailsShouldReturnFailedFutureWhenUserDataInResponseIsNull() null, ExtUser.of(asList("L-1111", "O-2222")))); given(httpClient.post(anyString(), anyString(), anyLong())).willReturn( - Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encode(response)))); + Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encodeToString(response)))); // when final Future result = userService.getUserDetails(auctionContext, timeout); @@ -339,7 +339,7 @@ public void getUserDetailsShouldReturnFailedFutureWhenExtUserInResponseIsNull() singletonList(UserData.of("2", "bluekai", singletonList(Segment.of("6666")))), null)); given(httpClient.post(anyString(), anyString(), anyLong())).willReturn( - Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encode(response)))); + Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encodeToString(response)))); // when final Future result = userService.getUserDetails(auctionContext, timeout); @@ -421,7 +421,7 @@ public void getUserDetailsShouldAddCachedHttpCallWhenCallCompletesSuccessful() t ExtUser.of(asList("L-1111", "O-2222")))); given(httpClient.post(anyString(), anyString(), anyLong())).willReturn( - Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encode(response)))); + Future.succeededFuture(HttpClientResponse.of(200, null, jacksonMapper.encodeToString(response)))); // when userService.getUserDetails(auctionContext, timeout).result(); diff --git a/src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java b/src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java index 79542d97dd2..323a140cbac 100644 --- a/src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java +++ b/src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java @@ -2561,7 +2561,7 @@ public void shouldExecuteAuctionResponseHooksAndIgnoreRejection(TestContext cont } private String executionPlan(Map endpoints) { - return jacksonMapper.encode(ExecutionPlan.of(endpoints)); + return jacksonMapper.encodeToString(ExecutionPlan.of(endpoints)); } private static StageExecutionPlan execPlanTwoGroupsTwoHooksEach() { From ff720ff773c3d243b8793c3ab2bf1406cceead5a Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Tue, 19 Oct 2021 01:18:15 +0300 Subject: [PATCH 2/5] Satisfy LGTM --- .../java/org/prebid/server/bidder/BidderErrorNotifier.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/BidderErrorNotifier.java b/src/main/java/org/prebid/server/bidder/BidderErrorNotifier.java index b7cbdefed46..08991658e15 100644 --- a/src/main/java/org/prebid/server/bidder/BidderErrorNotifier.java +++ b/src/main/java/org/prebid/server/bidder/BidderErrorNotifier.java @@ -69,7 +69,7 @@ private Void handleTimeoutNotificationSuccess(HttpClientResponse response, HttpR String.format( "Notified bidder about timeout. Status code: %s. Request body: %s", response.getStatusCode(), - timeoutNotification.getBody()), + new String(timeoutNotification.getBody())), logTimeoutNotificationSamplingRate); } @@ -84,7 +84,7 @@ private Void handleTimeoutNotificationFailure(Throwable exception, HttpRequest Date: Tue, 9 Nov 2021 11:13:58 +0200 Subject: [PATCH 3/5] Fixes after review --- .../prebid/server/bidder/algorix/AlgorixBidder.java | 3 +-- .../prebid/server/bidder/applogy/ApplogyBidder.java | 4 +--- .../org/prebid/server/bidder/avocet/AvocetBidder.java | 9 +-------- .../server/bidder/brightroll/BrightrollBidder.java | 10 +--------- .../server/bidder/connectad/ConnectadBidder.java | 4 +--- .../server/bidder/consumable/ConsumableBidder.java | 9 +-------- .../prebid/server/bidder/kubient/KubientBidder.java | 10 +--------- .../org/prebid/server/bidder/model/HttpRequest.java | 4 ++-- 8 files changed, 9 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/algorix/AlgorixBidder.java b/src/main/java/org/prebid/server/bidder/algorix/AlgorixBidder.java index e4b42c4f482..095f0d95aa3 100644 --- a/src/main/java/org/prebid/server/bidder/algorix/AlgorixBidder.java +++ b/src/main/java/org/prebid/server/bidder/algorix/AlgorixBidder.java @@ -74,14 +74,13 @@ public Result>> makeHttpRequests(BidRequest request } final BidRequest outgoingRequest = request.toBuilder().imp(updatedImps).build(); - final byte[] body = mapper.encodeToBytes(outgoingRequest); return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(resolveUrl(endpointUrl, extImpAlgorix)) .headers(resolveHeaders()) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/applogy/ApplogyBidder.java b/src/main/java/org/prebid/server/bidder/applogy/ApplogyBidder.java index d310840b0e7..1157618b9bf 100644 --- a/src/main/java/org/prebid/server/bidder/applogy/ApplogyBidder.java +++ b/src/main/java/org/prebid/server/bidder/applogy/ApplogyBidder.java @@ -68,13 +68,11 @@ public Result>> makeHttpRequests(BidRequest request private HttpRequest createSingleRequest(Imp imp, BidRequest request, String url) { final BidRequest outgoingRequest = request.toBuilder().imp(Collections.singletonList(imp)).build(); - final byte[] body = mapper.encodeToBytes(outgoingRequest); - return HttpRequest.builder() .method(HttpMethod.POST) .uri(url) .headers(HttpUtil.headers()) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); } diff --git a/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java b/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java index 26f85925a3a..d02f6eedf73 100644 --- a/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java +++ b/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java @@ -42,19 +42,12 @@ public AvocetBidder(String endpointUrl, JacksonMapper mapper) { @Override public Result>> makeHttpRequests(BidRequest request) { - final byte[] body; - try { - body = mapper.encodeToBytes(request); - } catch (EncodeException e) { - return Result.withError( - BidderError.badInput(String.format("Failed to encode request body, error: %s", e.getMessage()))); - } return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(request)) .headers(HttpUtil.headers()) .payload(request) .build()), diff --git a/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java b/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java index 328a5b0dfe2..936148996b7 100644 --- a/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java +++ b/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java @@ -77,18 +77,10 @@ public Result>> makeHttpRequests(BidRequest request return Result.withErrors(errors); } - final byte[] bidRequestBody; - try { - bidRequestBody = mapper.encodeToBytes(updateBidRequest); - } catch (EncodeException e) { - errors.add(BidderError.badInput(String.format("error while encoding bidRequest, err: %s", e.getMessage()))); - return Result.withErrors(errors); - } - return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) .uri(String.format("%s?publisher=%s", endpointUrl, firstImpExtPublisher)) - .body(bidRequestBody) + .body(mapper.encodeToBytes(updateBidRequest)) .headers(createHeaders(updateBidRequest.getDevice())) .payload(updateBidRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/connectad/ConnectadBidder.java b/src/main/java/org/prebid/server/bidder/connectad/ConnectadBidder.java index 77637ab34b5..43d9a90779b 100644 --- a/src/main/java/org/prebid/server/bidder/connectad/ConnectadBidder.java +++ b/src/main/java/org/prebid/server/bidder/connectad/ConnectadBidder.java @@ -72,15 +72,13 @@ public Result>> makeHttpRequests(BidRequest request } final BidRequest outgoingRequest = request.toBuilder().imp(processedImps).build(); - final byte[] body = mapper.encodeToBytes(outgoingRequest); - return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) .headers(resolveHeaders(request.getDevice())) .payload(outgoingRequest) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .build()), errors); } diff --git a/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java b/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java index ec5454b3f20..0b6711f77fa 100644 --- a/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java +++ b/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java @@ -95,18 +95,11 @@ public Result>> makeHttpRequests(BidReque } final ConsumableBidRequest outgoingRequest = requestBuilder.build(); - final byte[] body; - try { - body = mapper.encodeToBytes(outgoingRequest); - } catch (EncodeException e) { - return Result.withError(BidderError.badInput( - String.format("Failed to encode request body, error: %s", e.getMessage()))); - } return Result.withValue(HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .headers(resolveHeaders(request)) .payload(outgoingRequest) .build()); diff --git a/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java b/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java index 9d5de7d3e6d..f141524a25d 100644 --- a/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java +++ b/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java @@ -55,19 +55,11 @@ public Result>> makeHttpRequests(BidRequest request } } - final byte[] body; - try { - body = mapper.encodeToBytes(request); - } catch (EncodeException e) { - return Result.withError( - BidderError.badInput(String.format("Failed to encode request body, error: %s", e.getMessage()))); - } - return Result.of(Collections.singletonList( HttpRequest.builder() .method(HttpMethod.POST) .uri(endpointUrl) - .body(body) + .body(mapper.encodeToBytes(request)) .headers(HttpUtil.headers()) .payload(request) .build()), diff --git a/src/main/java/org/prebid/server/bidder/model/HttpRequest.java b/src/main/java/org/prebid/server/bidder/model/HttpRequest.java index 3c445d60a82..d636477a6ac 100644 --- a/src/main/java/org/prebid/server/bidder/model/HttpRequest.java +++ b/src/main/java/org/prebid/server/bidder/model/HttpRequest.java @@ -16,9 +16,9 @@ public class HttpRequest { String uri; - byte[] body; - MultiMap headers; + byte[] body; + T payload; } From 81347d6fffe14919a830bc038d0c4811510e8818 Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Tue, 9 Nov 2021 11:19:22 +0200 Subject: [PATCH 4/5] Import fix --- src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java | 1 - .../org/prebid/server/bidder/brightroll/BrightrollBidder.java | 1 - .../org/prebid/server/bidder/consumable/ConsumableBidder.java | 1 - .../java/org/prebid/server/bidder/kubient/KubientBidder.java | 1 - 4 files changed, 4 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java b/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java index d02f6eedf73..7bb74ce199d 100644 --- a/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java +++ b/src/main/java/org/prebid/server/bidder/avocet/AvocetBidder.java @@ -17,7 +17,6 @@ import org.prebid.server.bidder.model.Result; import org.prebid.server.exception.PreBidException; import org.prebid.server.json.DecodeException; -import org.prebid.server.json.EncodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.proto.openrtb.ext.response.BidType; import org.prebid.server.util.HttpUtil; diff --git a/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java b/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java index 936148996b7..d43deadb8bb 100644 --- a/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java +++ b/src/main/java/org/prebid/server/bidder/brightroll/BrightrollBidder.java @@ -23,7 +23,6 @@ import org.prebid.server.bidder.model.Result; import org.prebid.server.exception.PreBidException; import org.prebid.server.json.DecodeException; -import org.prebid.server.json.EncodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.proto.openrtb.ext.ExtPrebid; import org.prebid.server.proto.openrtb.ext.request.brightroll.ExtImpBrightroll; diff --git a/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java b/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java index 0b6711f77fa..fd1d35af550 100644 --- a/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java +++ b/src/main/java/org/prebid/server/bidder/consumable/ConsumableBidder.java @@ -26,7 +26,6 @@ import org.prebid.server.bidder.model.Result; import org.prebid.server.exception.PreBidException; import org.prebid.server.json.DecodeException; -import org.prebid.server.json.EncodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.proto.openrtb.ext.request.ExtRegs; import org.prebid.server.proto.openrtb.ext.request.ExtUser; diff --git a/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java b/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java index f141524a25d..e57aee88d2a 100644 --- a/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java +++ b/src/main/java/org/prebid/server/bidder/kubient/KubientBidder.java @@ -17,7 +17,6 @@ import org.prebid.server.bidder.model.Result; import org.prebid.server.exception.PreBidException; import org.prebid.server.json.DecodeException; -import org.prebid.server.json.EncodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.proto.openrtb.ext.ExtPrebid; import org.prebid.server.proto.openrtb.ext.request.kubient.ExtImpKubient; From 47b9becccb9b4a6ce90d73e9543127d8c5de4127 Mon Sep 17 00:00:00 2001 From: Serhii Nahornyi Date: Tue, 9 Nov 2021 12:18:54 +0200 Subject: [PATCH 5/5] Aja bidder fix --- .../java/org/prebid/server/bidder/aja/AjaBidder.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/aja/AjaBidder.java b/src/main/java/org/prebid/server/bidder/aja/AjaBidder.java index dbf5bb473ee..47a656a1d88 100644 --- a/src/main/java/org/prebid/server/bidder/aja/AjaBidder.java +++ b/src/main/java/org/prebid/server/bidder/aja/AjaBidder.java @@ -17,7 +17,6 @@ import org.prebid.server.bidder.model.Result; import org.prebid.server.exception.PreBidException; import org.prebid.server.json.DecodeException; -import org.prebid.server.json.EncodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.proto.openrtb.ext.ExtPrebid; import org.prebid.server.proto.openrtb.ext.response.BidType; @@ -100,20 +99,11 @@ private HttpRequest createSingleRequest(Imp imp, BidRequest request, .imp(Collections.singletonList(imp)) .build(); - final byte[] body; - try { - body = mapper.encodeToBytes(outgoingRequest); - } catch (EncodeException e) { - errors.add(BidderError.badInput( - String.format("Failed to unmarshal bidrequest ID: %s err: %s", request.getId(), e.getMessage()))); - return null; - } - return HttpRequest.builder() .method(HttpMethod.POST) .uri(url) .headers(HttpUtil.headers()) - .body(body) + .body(mapper.encodeToBytes(outgoingRequest)) .payload(outgoingRequest) .build(); }