1212import com .iab .openrtb .response .Bid ;
1313import com .iab .openrtb .response .BidResponse ;
1414import com .iab .openrtb .response .SeatBid ;
15+ import io .vertx .uritemplate .UriTemplate ;
16+ import io .vertx .uritemplate .Variables ;
1517import org .apache .commons .collections4 .CollectionUtils ;
1618import org .apache .commons .lang3 .StringUtils ;
1719import org .prebid .server .bidder .Bidder ;
3133import org .prebid .server .proto .openrtb .ext .response .ExtBidPrebid ;
3234import org .prebid .server .util .BidderUtil ;
3335import org .prebid .server .util .HttpUtil ;
34- import org .apache . http . client . utils . URIBuilder ;
36+ import org .prebid . server . util . UriTemplateUtil ;
3537
36- import java .net .URISyntaxException ;
3738import java .util .ArrayList ;
3839import java .util .Collection ;
3940import java .util .Collections ;
41+ import java .util .HashMap ;
4042import java .util .List ;
43+ import java .util .Map ;
4144import java .util .Objects ;
4245import java .util .Optional ;
4346
@@ -48,11 +51,12 @@ public class SparteoBidder implements Bidder<BidRequest> {
4851 private static final TypeReference <ExtPrebid <?, ExtImpSparteo >> TYPE_REFERENCE =
4952 new TypeReference <>() { };
5053
51- private final String endpointUrl ;
54+ private final UriTemplate endpointUrlTemplate ;
5255 private final JacksonMapper mapper ;
5356
5457 public SparteoBidder (String endpointUrl , JacksonMapper mapper ) {
55- this .endpointUrl = HttpUtil .validateUrl (Objects .requireNonNull (endpointUrl ));
58+ HttpUtil .validateUrl (Objects .requireNonNull (endpointUrl ));
59+ this .endpointUrlTemplate = UriTemplateUtil .createTemplate (endpointUrl , "queryParams" );
5660 this .mapper = Objects .requireNonNull (mapper );
5761 }
5862
@@ -222,24 +226,20 @@ private String resolveBundle(App app) {
222226 }
223227
224228 private String resolveEndpoint (String siteDomain , String appDomain , String networkId , String bundle ) {
225- try {
226- final URIBuilder uriBuilder = new URIBuilder (endpointUrl );
227- if (StringUtils .isNotBlank (networkId )) {
228- uriBuilder .addParameter ("network_id" , networkId );
229- }
230- if (StringUtils .isNotBlank (siteDomain )) {
231- uriBuilder .addParameter ("site_domain" , siteDomain );
232- }
233- if (StringUtils .isNotBlank (appDomain )) {
234- uriBuilder .addParameter ("app_domain" , appDomain );
235- }
236- if (StringUtils .isNotBlank (bundle )) {
237- uriBuilder .addParameter ("bundle" , bundle );
238- }
239- return uriBuilder .build ().toString ();
240- } catch (URISyntaxException e ) {
241- throw new PreBidException ("Failed to build endpoint URL" , e );
229+ final Map <String , String > queryParams = new HashMap <>();
230+ if (StringUtils .isNotBlank (networkId )) {
231+ queryParams .put ("network_id" , networkId );
232+ }
233+ if (StringUtils .isNotBlank (siteDomain )) {
234+ queryParams .put ("site_domain" , siteDomain );
235+ }
236+ if (StringUtils .isNotBlank (appDomain )) {
237+ queryParams .put ("app_domain" , appDomain );
238+ }
239+ if (StringUtils .isNotBlank (bundle )) {
240+ queryParams .put ("bundle" , bundle );
242241 }
242+ return endpointUrlTemplate .expandToString (Variables .variables ().set ("queryParams" , queryParams ));
243243 }
244244
245245 @ Override
0 commit comments