Skip to content

Commit 1fa7072

Browse files
committed
Updated deprecated code
1 parent 627266a commit 1fa7072

File tree

2 files changed

+79
-80
lines changed

2 files changed

+79
-80
lines changed

src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java

Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -108,31 +108,30 @@ public void start(Promise<Void> startPromise) throws Exception {
108108
this.healthComponent.setHealthStatus(false, "still starting");
109109

110110
this.idService = new UIDOperatorService(
111-
this.config,
112-
this.optOutStore,
113-
this.saltProvider,
114-
this.encoder,
115-
this.clock,
116-
this.identityScope
111+
this.config,
112+
this.optOutStore,
113+
this.saltProvider,
114+
this.encoder,
115+
this.clock,
116+
this.identityScope
117117
);
118118

119119
final Router router = createRoutesSetup();
120120
final int port = Const.Port.ServicePortForOperator + Utils.getPortOffset();
121121
LOGGER.info("starting service on http.port: " + port);
122-
vertx
123-
.createHttpServer()
124-
.requestHandler(router::handle)
125-
.listen(port, result -> {
126-
if (result.succeeded()) {
127-
this.healthComponent.setHealthStatus(true);
128-
startPromise.complete();
129-
} else {
130-
this.healthComponent.setHealthStatus(false, result.cause().getMessage());
131-
startPromise.fail(result.cause());
132-
}
122+
vertx.createHttpServer()
123+
.requestHandler(router)
124+
.listen(port, result -> {
125+
if (result.succeeded()) {
126+
this.healthComponent.setHealthStatus(true);
127+
startPromise.complete();
128+
} else {
129+
this.healthComponent.setHealthStatus(false, result.cause().getMessage());
130+
startPromise.fail(result.cause());
131+
}
133132

134-
LOGGER.info("UIDOperatorVerticle instance started");
135-
});
133+
LOGGER.info("UIDOperatorVerticle instance started");
134+
});
136135

137136
}
138137

@@ -149,16 +148,17 @@ private Router createRoutesSetup() throws IOException {
149148

150149
router.route().handler(new RequestCapturingHandler());
151150
router.route().handler(new ClientVersionCapturingHandler("static/js", "*.js"));
152-
router.route().handler(CorsHandler.create(".*.")
153-
.allowedMethod(io.vertx.core.http.HttpMethod.GET)
154-
.allowedMethod(io.vertx.core.http.HttpMethod.POST)
155-
.allowedMethod(io.vertx.core.http.HttpMethod.OPTIONS)
156-
.allowedHeader(com.uid2.shared.Const.Http.ClientVersionHeader)
157-
.allowedHeader("Access-Control-Request-Method")
158-
.allowedHeader("Access-Control-Allow-Credentials")
159-
.allowedHeader("Access-Control-Allow-Origin")
160-
.allowedHeader("Access-Control-Allow-Headers")
161-
.allowedHeader("Content-Type"));
151+
router.route().handler(CorsHandler.create()
152+
.addRelativeOrigin(".*.")
153+
.allowedMethod(io.vertx.core.http.HttpMethod.GET)
154+
.allowedMethod(io.vertx.core.http.HttpMethod.POST)
155+
.allowedMethod(io.vertx.core.http.HttpMethod.OPTIONS)
156+
.allowedHeader(com.uid2.shared.Const.Http.ClientVersionHeader)
157+
.allowedHeader("Access-Control-Request-Method")
158+
.allowedHeader("Access-Control-Allow-Credentials")
159+
.allowedHeader("Access-Control-Allow-Origin")
160+
.allowedHeader("Access-Control-Allow-Headers")
161+
.allowedHeader("Content-Type"));
162162
final BodyHandler bodyHandler = BodyHandler.create().setHandleFileUploads(false).setBodyLimit(MAX_REQUEST_BODY_SIZE);
163163

164164
router.route().handler(new StatsCollectorHandler(_statsCollectorQueue, vertx));
@@ -201,23 +201,23 @@ private void setupV2Routes(Router mainRouter, BodyHandler bodyHandler) {
201201
final Router v2Router = Router.router(vertx);
202202

203203
v2Router.post("/token/generate").handler(bodyHandler).handler(auth.handleV1(
204-
rc -> v2PayloadHandler.handleTokenGenerate(rc, this::handleTokenGenerateV2), Role.GENERATOR));
204+
rc -> v2PayloadHandler.handleTokenGenerate(rc, this::handleTokenGenerateV2), Role.GENERATOR));
205205
v2Router.post("/token/refresh").handler(bodyHandler).handler(auth.handleWithOptionalAuth(
206-
rc -> v2PayloadHandler.handleTokenRefresh(rc, this::handleTokenRefreshV2)));
206+
rc -> v2PayloadHandler.handleTokenRefresh(rc, this::handleTokenRefreshV2)));
207207
v2Router.post("/token/validate").handler(bodyHandler).handler(auth.handleV1(
208-
rc -> v2PayloadHandler.handle(rc, this::handleTokenValidateV2), Role.GENERATOR));
208+
rc -> v2PayloadHandler.handle(rc, this::handleTokenValidateV2), Role.GENERATOR));
209209
v2Router.post("/identity/buckets").handler(bodyHandler).handler(auth.handleV1(
210-
rc -> v2PayloadHandler.handle(rc, this::handleBucketsV2), Role.MAPPER));
210+
rc -> v2PayloadHandler.handle(rc, this::handleBucketsV2), Role.MAPPER));
211211
v2Router.post("/identity/map").handler(bodyHandler).handler(auth.handleV1(
212-
rc -> v2PayloadHandler.handle(rc, this::handleIdentityMapV2), Role.MAPPER));
212+
rc -> v2PayloadHandler.handle(rc, this::handleIdentityMapV2), Role.MAPPER));
213213
v2Router.post("/key/latest").handler(bodyHandler).handler(auth.handleV1(
214-
rc -> v2PayloadHandler.handle(rc, this::handleKeysRequestV2), Role.ID_READER));
214+
rc -> v2PayloadHandler.handle(rc, this::handleKeysRequestV2), Role.ID_READER));
215215
v2Router.post("/key/sharing").handler(bodyHandler).handler(auth.handleV1(
216216
rc -> v2PayloadHandler.handle(rc, this::handleKeysSharing), Role.SHARER));
217217
v2Router.post("/token/logout").handler(bodyHandler).handler(auth.handleV1(
218-
rc -> v2PayloadHandler.handleAsync(rc, this::handleLogoutAsyncV2), Role.OPTOUT));
218+
rc -> v2PayloadHandler.handleAsync(rc, this::handleLogoutAsyncV2), Role.OPTOUT));
219219

220-
mainRouter.mountSubRouter("/v2", v2Router);
220+
mainRouter.route("/v2/*").subRouter(v2Router);
221221
}
222222

223223
private void handleKeysRequestCommon(RoutingContext rc, Handler<JsonArray> onSuccess) {
@@ -460,10 +460,10 @@ private void handleTokenGenerateV1(RoutingContext rc) {
460460
} else {
461461
final ClientKey clientKey = (ClientKey) AuthMiddleware.getAuthClient(rc);
462462
final IdentityTokens t = this.idService.generateIdentity(
463-
new IdentityRequest(
464-
new PublisherIdentity(clientKey.getSiteId(), 0, 0),
465-
input.toUserIdentity(this.identityScope, 1, Instant.now()),
466-
TokenGeneratePolicy.defaultPolicy()));
463+
new IdentityRequest(
464+
new PublisherIdentity(clientKey.getSiteId(), 0, 0),
465+
input.toUserIdentity(this.identityScope, 1, Instant.now()),
466+
TokenGeneratePolicy.defaultPolicy()));
467467

468468
//Integer.parseInt(rc.queryParam("privacy_bits").get(0))));
469469

@@ -504,10 +504,10 @@ private void handleTokenGenerateV2(RoutingContext rc) {
504504
}
505505

506506
final IdentityTokens t = this.idService.generateIdentity(
507-
new IdentityRequest(
508-
new PublisherIdentity(clientKey.getSiteId(), 0, 0),
509-
input.toUserIdentity(this.identityScope, 1, Instant.now()),
510-
readTokenGeneratePolicy(req)));
507+
new IdentityRequest(
508+
new PublisherIdentity(clientKey.getSiteId(), 0, 0),
509+
input.toUserIdentity(this.identityScope, 1, Instant.now()),
510+
readTokenGeneratePolicy(req)));
511511

512512
if (t.isEmptyToken()) {
513513
ResponseUtil.OptOutV2(rc, toJsonV1(t));
@@ -637,9 +637,8 @@ private void handleOptOutGet(RoutingContext rc) {
637637
final Instant result = this.idService.getLatestOptoutEntry(userIdentity, now);
638638
long timestamp = result == null ? -1 : result.getEpochSecond();
639639
rc.response().setStatusCode(200)
640-
.setChunked(true)
641-
.write(String.valueOf(timestamp))
642-
.end();
640+
.setChunked(true)
641+
.write(String.valueOf(timestamp));
643642
} catch (Exception ex) {
644643
LOGGER.error("Unexpected error while handling optout get", ex);
645644
rc.fail(500);
@@ -799,7 +798,7 @@ private InputUtil.InputVal getTokenInputV2(JsonObject req) {
799798

800799
return getInput != null ? getInput.get() : null;
801800
}
802-
801+
803802
private InputUtil.InputVal getTokenInputV1(RoutingContext rc) {
804803
final List<String> emailInput = rc.queryParam("email");
805804
final List<String> emailHashInput = rc.queryParam("email_hash");
@@ -861,7 +860,7 @@ private boolean checkTokenInputV1(InputUtil.InputVal input, RoutingContext rc) {
861860
}
862861

863862
private InputUtil.InputVal[] getIdentityBulkInput(RoutingContext rc) {
864-
final JsonObject obj = rc.getBodyAsJson();
863+
final JsonObject obj = rc.body().asJsonObject();
865864
final JsonArray emails = obj.getJsonArray("email");
866865
final JsonArray emailHashes = obj.getJsonArray("email_hash");
867866
// FIXME TODO. Avoid Double Iteration. Turn to a decorator pattern
@@ -881,7 +880,7 @@ private InputUtil.InputVal[] getIdentityBulkInput(RoutingContext rc) {
881880

882881

883882
private InputUtil.InputVal[] getIdentityBulkInputV1(RoutingContext rc) {
884-
final JsonObject obj = rc.getBodyAsJson();
883+
final JsonObject obj = rc.body().asJsonObject();
885884
final JsonArray emails = obj.getJsonArray("email");
886885
final JsonArray emailHashes = obj.getJsonArray("email_hash");
887886
final JsonArray phones = obj.getJsonArray("phone");
@@ -1032,13 +1031,13 @@ private InputUtil.InputVal[] getIdentityMapV2Input(RoutingContext rc) {
10321031
}
10331032

10341033
return getInputList == null ?
1035-
createInputListV1(null, IdentityType.Email, InputUtil.IdentityInputType.Raw) : // handle empty array
1036-
getInputList.get();
1034+
createInputListV1(null, IdentityType.Email, InputUtil.IdentityInputType.Raw) : // handle empty array
1035+
getInputList.get();
10371036
}
10381037

10391038
private void handleIdentityMapBatch(RoutingContext rc) {
10401039
try {
1041-
final JsonObject obj = rc.getBodyAsJson();
1040+
final JsonObject obj = rc.body().asJsonObject();
10421041
final InputUtil.InputVal[] inputList;
10431042
final JsonArray emails = obj.getJsonArray("email");
10441043
final JsonArray emailHashes = obj.getJsonArray("email_hash");
@@ -1096,10 +1095,10 @@ private void recordIdentityMapStats(RoutingContext rc, int inputCount) {
10961095
String apiContact = getApiContact(rc);
10971096

10981097
DistributionSummary ds = _identityMapMetricSummaries.computeIfAbsent(apiContact, k -> DistributionSummary
1099-
.builder("uid2.operator.identity.map.inputs")
1100-
.description("number of emails or email hashes passed to identity map batch endpoint")
1101-
.tags("api_contact", apiContact)
1102-
.register(Metrics.globalRegistry));
1098+
.builder("uid2.operator.identity.map.inputs")
1099+
.description("number of emails or email hashes passed to identity map batch endpoint")
1100+
.tags("api_contact", apiContact)
1101+
.register(Metrics.globalRegistry));
11031102
ds.record(inputCount);
11041103
}
11051104

@@ -1122,12 +1121,12 @@ private void recordRefreshDurationStats(RoutingContext rc, Duration durationSinc
11221121
Integer siteId = rc.get(Const.RoutingContextData.SiteId);
11231122

11241123
DistributionSummary ds = _refreshDurationMetricSummaries.computeIfAbsent(apiContact, k ->
1125-
DistributionSummary
1126-
.builder("uid2.token_refresh_duration_seconds")
1127-
.description("duration between token refreshes")
1128-
.tag("site_id", String.valueOf(siteId))
1129-
.tag("api_contact", apiContact)
1130-
.register(Metrics.globalRegistry)
1124+
DistributionSummary
1125+
.builder("uid2.token_refresh_duration_seconds")
1126+
.description("duration between token refreshes")
1127+
.tag("site_id", String.valueOf(siteId))
1128+
.tag("api_contact", apiContact)
1129+
.register(Metrics.globalRegistry)
11311130
);
11321131
ds.record(durationSinceLastRefresh.getSeconds());
11331132
}
@@ -1195,13 +1194,13 @@ private UserConsentStatus validateUserConsent(JsonObject req) {
11951194
return UserConsentStatus.INVALID;
11961195
}
11971196
final boolean userConsent = tcResult.getTCString().hasConsent(tcfVendorId,
1198-
TransparentConsentPurpose.STORE_INFO_ON_DEVICE, // 1
1199-
TransparentConsentPurpose.CREATE_PERSONALIZED_ADS_PROFILE, // 3
1200-
TransparentConsentPurpose.SELECT_PERSONALIZED_ADS, // 4
1201-
TransparentConsentPurpose.SELECT_BASIC_ADS, // 2
1202-
TransparentConsentPurpose.MEASURE_AD_PERFORMANCE, // 7
1203-
TransparentConsentPurpose.DEVELOP_AND_IMPROVE_PRODUCTS // 10
1204-
);
1197+
TransparentConsentPurpose.STORE_INFO_ON_DEVICE, // 1
1198+
TransparentConsentPurpose.CREATE_PERSONALIZED_ADS_PROFILE, // 3
1199+
TransparentConsentPurpose.SELECT_PERSONALIZED_ADS, // 4
1200+
TransparentConsentPurpose.SELECT_BASIC_ADS, // 2
1201+
TransparentConsentPurpose.MEASURE_AD_PERFORMANCE, // 7
1202+
TransparentConsentPurpose.DEVELOP_AND_IMPROVE_PRODUCTS // 10
1203+
);
12051204
final boolean allowPreciseGeo = tcResult.getTCString().hasSpecialFeature(TransparentConsentSpecialFeature.PreciseGeolocationData);
12061205

12071206
if (!userConsent || !allowPreciseGeo) {
@@ -1215,7 +1214,7 @@ private UserConsentStatus validateUserConsent(JsonObject req) {
12151214
private static final String TOKEN_GENERATE_POLICY_PARAM = "policy";
12161215
private TokenGeneratePolicy readTokenGeneratePolicy(JsonObject req) {
12171216
return req.containsKey(TOKEN_GENERATE_POLICY_PARAM) ?
1218-
TokenGeneratePolicy.fromValue(req.getInteger(TOKEN_GENERATE_POLICY_PARAM)) :
1217+
TokenGeneratePolicy.fromValue(req.getInteger(TOKEN_GENERATE_POLICY_PARAM)) :
12191218
TokenGeneratePolicy.defaultPolicy();
12201219
}
12211220

@@ -1276,12 +1275,12 @@ private JsonObject toJson(IdentityTokens t) {
12761275

12771276
private void sendJsonResponse(RoutingContext rc, JsonObject json) {
12781277
rc.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json")
1279-
.end(json.encode());
1278+
.end(json.encode());
12801279
}
12811280

12821281
private void sendJsonResponse(RoutingContext rc, JsonArray json) {
12831282
rc.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json")
1284-
.end(json.encode());
1283+
.end(json.encode());
12851284
}
12861285

12871286
public static class ResponseStatus {
@@ -1299,7 +1298,7 @@ public static class ResponseStatus {
12991298
public static enum UserConsentStatus {
13001299
SUFFICIENT,
13011300
INSUFFICIENT,
1302-
INVALID,
1301+
INVALID,
13031302
}
13041303
}
13051304

src/main/java/com/uid2/operator/vertx/V2PayloadHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void handle(RoutingContext rc, Handler<RoutingContext> apiHandler) {
4141
return;
4242
}
4343

44-
V2RequestUtil.V2Request request = V2RequestUtil.parseRequest(rc.getBodyAsString(), AuthMiddleware.getAuthClient(ClientKey.class, rc));
44+
V2RequestUtil.V2Request request = V2RequestUtil.parseRequest(rc.body().asString(), AuthMiddleware.getAuthClient(ClientKey.class, rc));
4545
if (!request.isValid()) {
4646
ResponseUtil.ClientError(rc, request.errorMessage);
4747
return;
@@ -59,7 +59,7 @@ public void handleAsync(RoutingContext rc, Function<RoutingContext, Future> apiH
5959
return;
6060
}
6161

62-
V2RequestUtil.V2Request request = V2RequestUtil.parseRequest(rc.getBodyAsString(), AuthMiddleware.getAuthClient(ClientKey.class, rc));
62+
V2RequestUtil.V2Request request = V2RequestUtil.parseRequest(rc.body().asString(), AuthMiddleware.getAuthClient(ClientKey.class, rc));
6363
if (!request.isValid()) {
6464
ResponseUtil.ClientError(rc, request.errorMessage);
6565
return;
@@ -77,7 +77,7 @@ public void handleTokenGenerate(RoutingContext rc, Handler<RoutingContext> apiHa
7777
return;
7878
}
7979

80-
V2RequestUtil.V2Request request = V2RequestUtil.parseRequest(rc.getBodyAsString(), AuthMiddleware.getAuthClient(ClientKey.class, rc));
80+
V2RequestUtil.V2Request request = V2RequestUtil.parseRequest(rc.body().asString(), AuthMiddleware.getAuthClient(ClientKey.class, rc));
8181
if (!request.isValid()) {
8282
ResponseUtil.ClientError(rc, request.errorMessage);
8383
return;
@@ -112,7 +112,7 @@ public void handleTokenRefresh(RoutingContext rc, Handler<RoutingContext> apiHan
112112
return;
113113
}
114114

115-
String bodyString = rc.getBodyAsString();
115+
String bodyString = rc.body().asString();
116116

117117
V2RequestUtil.V2Request request = null;
118118
if (bodyString.length() == V2RequestUtil.V2_REFRESH_PAYLOAD_LENGTH) {
@@ -160,7 +160,7 @@ public void handleTokenRefresh(RoutingContext rc, Handler<RoutingContext> apiHan
160160
}
161161

162162
private void passThrough(RoutingContext rc, Handler<RoutingContext> apiHandler) {
163-
rc.data().put("request", rc.getBodyAsJson());
163+
rc.data().put("request", rc.body().asJsonObject());
164164
apiHandler.handle(rc);
165165
if (rc.response().getStatusCode() != 200) {
166166
return;

0 commit comments

Comments
 (0)