55import com .iab .openrtb .response .BidResponse ;
66import com .iab .openrtb .response .SeatBid ;
77import io .vertx .core .Future ;
8+ import io .vertx .uritemplate .UriTemplate ;
9+ import io .vertx .uritemplate .Variables ;
810import org .apache .commons .collections4 .CollectionUtils ;
9- import org .apache .http . client . utils . URIBuilder ;
11+ import org .apache .commons . lang3 . StringUtils ;
1012import org .prebid .server .analytics .AnalyticsReporter ;
1113import org .prebid .server .analytics .model .AuctionEvent ;
1214import org .prebid .server .analytics .model .NotificationEvent ;
2729import org .prebid .server .log .LoggerFactory ;
2830import org .prebid .server .proto .openrtb .ext .request .ExtRequest ;
2931import org .prebid .server .proto .openrtb .ext .request .ExtRequestPrebid ;
32+ import org .prebid .server .util .HttpUtil ;
33+ import org .prebid .server .util .UriTemplateUtil ;
3034import org .prebid .server .vertx .httpclient .HttpClient ;
3135
32- import java .net .URISyntaxException ;
36+ import java .net .MalformedURLException ;
37+ import java .net .URL ;
3338import java .util .Collection ;
3439import java .util .List ;
3540import java .util .Objects ;
@@ -44,6 +49,7 @@ public class LiveIntentAnalyticsReporter implements AnalyticsReporter {
4449 private final HttpClient httpClient ;
4550 private final LiveIntentAnalyticsProperties properties ;
4651 private final JacksonMapper jacksonMapper ;
52+ private final UriTemplate uriTemplate ;
4753
4854 public LiveIntentAnalyticsReporter (
4955 LiveIntentAnalyticsProperties properties ,
@@ -53,6 +59,21 @@ public LiveIntentAnalyticsReporter(
5359 this .httpClient = Objects .requireNonNull (httpClient );
5460 this .properties = Objects .requireNonNull (properties );
5561 this .jacksonMapper = Objects .requireNonNull (jacksonMapper );
62+
63+ final URL url ;
64+ try {
65+ url = HttpUtil .parseUrl (properties .getAnalyticsEndpoint ());
66+ } catch (MalformedURLException e ) {
67+ throw new IllegalArgumentException (e );
68+ }
69+
70+ final String query = url .getQuery () != null ? "?" + url .getQuery () : StringUtils .EMPTY ;
71+ this .uriTemplate = UriTemplateUtil .createTemplate (
72+ url .getProtocol () + "://" + url .getAuthority () + "/analytic-events{/path}" + query ,
73+ query .contains ("?" ),
74+ "b" ,
75+ "bidId" );
76+
5677 }
5778
5879 @ Override
@@ -96,10 +117,7 @@ private Future<Void> processAuctionEvent(AuctionContext auctionContext) {
96117
97118 try {
98119 return httpClient .post (
99- new URIBuilder (properties .getAnalyticsEndpoint ())
100- .setPath ("/analytic-events/pbsj-bids" )
101- .build ()
102- .toString (),
120+ uriTemplate .expandToString (Variables .variables ().set ("path" , "pbsj-bids" )),
103121 jacksonMapper .encodeToString (pbsjBids ),
104122 properties .getTimeoutMs ())
105123 .mapEmpty ();
@@ -169,18 +187,11 @@ private Optional<PbsjBid> buildPbsjBid(
169187 }
170188
171189 private Future <Void > processNotificationEvent (NotificationEvent notificationEvent ) {
172- try {
173- final String url = new URIBuilder (properties .getAnalyticsEndpoint ())
174- .setPath ("/analytic-events/pbsj-winning-bid" )
175- .setParameter ("b" , notificationEvent .getBidder ())
176- .setParameter ("bidId" , notificationEvent .getBidId ())
177- .build ()
178- .toString ();
179- return httpClient .get (url , properties .getTimeoutMs ()).mapEmpty ();
180- } catch (URISyntaxException e ) {
181- logger .error ("Error composing url for notification event: {}" , e .getMessage ());
182- return Future .failedFuture (e );
183- }
190+ final String url = uriTemplate .expandToString (Variables .variables ()
191+ .set ("path" , "pbsj-winning-bid" )
192+ .set ("b" , notificationEvent .getBidder ())
193+ .set ("bidId" , notificationEvent .getBidId ()));
194+ return httpClient .get (url , properties .getTimeoutMs ()).mapEmpty ();
184195 }
185196
186197 @ Override
0 commit comments