Skip to content

Commit 44ad9ce

Browse files
committed
Fix compile errors
1 parent f12410e commit 44ad9ce

1 file changed

Lines changed: 29 additions & 18 deletions

File tree

src/main/java/org/prebid/server/analytics/reporter/liveintent/LiveIntentAnalyticsReporter.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import com.iab.openrtb.response.BidResponse;
66
import com.iab.openrtb.response.SeatBid;
77
import io.vertx.core.Future;
8+
import io.vertx.uritemplate.UriTemplate;
9+
import io.vertx.uritemplate.Variables;
810
import org.apache.commons.collections4.CollectionUtils;
9-
import org.apache.http.client.utils.URIBuilder;
11+
import org.apache.commons.lang3.StringUtils;
1012
import org.prebid.server.analytics.AnalyticsReporter;
1113
import org.prebid.server.analytics.model.AuctionEvent;
1214
import org.prebid.server.analytics.model.NotificationEvent;
@@ -27,9 +29,12 @@
2729
import org.prebid.server.log.LoggerFactory;
2830
import org.prebid.server.proto.openrtb.ext.request.ExtRequest;
2931
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid;
32+
import org.prebid.server.util.HttpUtil;
33+
import org.prebid.server.util.UriTemplateUtil;
3034
import org.prebid.server.vertx.httpclient.HttpClient;
3135

32-
import java.net.URISyntaxException;
36+
import java.net.MalformedURLException;
37+
import java.net.URL;
3338
import java.util.Collection;
3439
import java.util.List;
3540
import 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

Comments
 (0)