/
RootRoute.java
executable file
·616 lines (536 loc) · 29.2 KB
/
RootRoute.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.gateway.endpoints.routes;
import static akka.http.javadsl.server.Directives.complete;
import static akka.http.javadsl.server.Directives.extractRequestContext;
import static akka.http.javadsl.server.Directives.handleExceptions;
import static akka.http.javadsl.server.Directives.handleRejections;
import static akka.http.javadsl.server.Directives.parameterOptional;
import static akka.http.javadsl.server.Directives.rawPathPrefix;
import static akka.http.javadsl.server.Directives.route;
import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull;
import static org.eclipse.ditto.services.gateway.endpoints.directives.CorrelationIdEnsuringDirective.ensureCorrelationId;
import static org.eclipse.ditto.services.gateway.endpoints.directives.CustomPathMatchers.mergeDoubleSlashes;
import static org.eclipse.ditto.services.gateway.endpoints.directives.RequestResultLoggingDirective.logRequestResult;
import static org.eclipse.ditto.services.gateway.endpoints.directives.auth.AuthorizationContextVersioningDirective.mapAuthorizationContext;
import static org.eclipse.ditto.services.gateway.endpoints.utils.DirectivesLoggingUtils.enhanceLogWithCorrelationId;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import org.eclipse.ditto.json.JsonRuntimeException;
import org.eclipse.ditto.model.base.auth.AuthorizationContext;
import org.eclipse.ditto.model.base.auth.AuthorizationSubject;
import org.eclipse.ditto.model.base.exceptions.DittoJsonException;
import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException;
import org.eclipse.ditto.model.base.headers.DittoHeaders;
import org.eclipse.ditto.model.base.headers.DittoHeadersBuilder;
import org.eclipse.ditto.model.base.headers.DittoHeadersSizeChecker;
import org.eclipse.ditto.model.base.json.JsonSchemaVersion;
import org.eclipse.ditto.protocoladapter.HeaderTranslator;
import org.eclipse.ditto.protocoladapter.ProtocolAdapter;
import org.eclipse.ditto.protocoladapter.TopicPath;
import org.eclipse.ditto.services.gateway.endpoints.directives.CorsEnablingDirective;
import org.eclipse.ditto.services.gateway.endpoints.directives.EncodingEnsuringDirective;
import org.eclipse.ditto.services.gateway.endpoints.directives.HttpsEnsuringDirective;
import org.eclipse.ditto.services.gateway.endpoints.directives.RequestTimeoutHandlingDirective;
import org.eclipse.ditto.services.gateway.endpoints.directives.SecurityResponseHeadersDirective;
import org.eclipse.ditto.services.gateway.endpoints.directives.auth.GatewayAuthenticationDirective;
import org.eclipse.ditto.services.gateway.endpoints.routes.devops.DevOpsRoute;
import org.eclipse.ditto.services.gateway.endpoints.routes.health.CachingHealthRoute;
import org.eclipse.ditto.services.gateway.endpoints.routes.policies.PoliciesRoute;
import org.eclipse.ditto.services.gateway.endpoints.routes.sse.SseThingsRoute;
import org.eclipse.ditto.services.gateway.endpoints.routes.stats.StatsRoute;
import org.eclipse.ditto.services.gateway.endpoints.routes.status.OverallStatusRoute;
import org.eclipse.ditto.services.gateway.endpoints.routes.things.ThingsRoute;
import org.eclipse.ditto.services.gateway.endpoints.routes.thingsearch.ThingSearchRoute;
import org.eclipse.ditto.services.gateway.endpoints.routes.websocket.WebsocketRoute;
import org.eclipse.ditto.services.gateway.endpoints.utils.DittoRejectionHandlerFactory;
import org.eclipse.ditto.services.utils.health.routes.StatusRoute;
import org.eclipse.ditto.services.utils.protocol.ProtocolAdapterProvider;
import org.eclipse.ditto.signals.commands.base.CommandNotSupportedException;
import org.eclipse.ditto.signals.commands.base.exceptions.GatewayDuplicateHeaderException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import akka.http.javadsl.model.ContentTypes;
import akka.http.javadsl.model.HttpHeader;
import akka.http.javadsl.model.HttpMessage;
import akka.http.javadsl.model.HttpResponse;
import akka.http.javadsl.model.StatusCodes;
import akka.http.javadsl.server.Directives;
import akka.http.javadsl.server.ExceptionHandler;
import akka.http.javadsl.server.PathMatchers;
import akka.http.javadsl.server.RejectionHandler;
import akka.http.javadsl.server.RequestContext;
import akka.http.javadsl.server.Route;
import akka.util.ByteString;
/**
* Builder for creating Akka HTTP routes for {@code /}.
*/
public final class RootRoute {
static final String HTTP_PATH_API_PREFIX = "api";
static final String WS_PATH_PREFIX = "ws";
private static final Logger LOGGER = LoggerFactory.getLogger(RootRoute.class);
private final StatusRoute ownStatusRoute;
private final OverallStatusRoute overallStatusRoute;
private final CachingHealthRoute cachingHealthRoute;
private final DevOpsRoute devopsRoute;
private final PoliciesRoute policiesRoute;
private final SseThingsRoute sseThingsRoute;
private final ThingsRoute thingsRoute;
private final ThingSearchRoute thingSearchRoute;
private final WebsocketRoute websocketRoute;
private final StatsRoute statsRoute;
private final CustomApiRoutesProvider customApiRoutesProvider;
private final GatewayAuthenticationDirective apiAuthenticationDirective;
private final GatewayAuthenticationDirective wsAuthenticationDirective;
private final ExceptionHandler exceptionHandler;
private final List<Integer> supportedSchemaVersions;
private final ProtocolAdapterProvider protocolAdapterProvider;
private final HeaderTranslator headerTranslator;
private final CustomHeadersHandler customHeadersHandler;
private final RejectionHandler rejectionHandler;
private final DittoHeadersSizeChecker dittoHeadersSizeChecker;
private RootRoute(final Builder builder) {
ownStatusRoute = builder.statusRoute;
overallStatusRoute = builder.overallStatusRoute;
cachingHealthRoute = builder.cachingHealthRoute;
devopsRoute = builder.devopsRoute;
policiesRoute = builder.policiesRoute;
sseThingsRoute = builder.sseThingsRoute;
thingsRoute = builder.thingsRoute;
thingSearchRoute = builder.thingSearchRoute;
websocketRoute = builder.websocketRoute;
statsRoute = builder.statsRoute;
customApiRoutesProvider = builder.customApiRoutesProvider;
apiAuthenticationDirective = builder.httpAuthenticationDirective;
wsAuthenticationDirective = builder.wsAuthenticationDirective;
exceptionHandler = null != builder.exceptionHandler ? builder.exceptionHandler : createExceptionHandler();
supportedSchemaVersions = builder.supportedSchemaVersions;
protocolAdapterProvider = builder.protocolAdapterProvider;
headerTranslator = builder.headerTranslator;
customHeadersHandler = builder.customHeadersHandler;
rejectionHandler = builder.rejectionHandler;
dittoHeadersSizeChecker = checkNotNull(builder.dittoHeadersSizeChecker, "dittoHeadersSizeChecker");
}
public static RootRouteBuilder getBuilder() {
return new Builder()
.customApiRoutesProvider(NoopCustomApiRoutesProvider.getInstance())
.customHeadersHandler(NoopCustomHeadersHandler.getInstance())
.rejectionHandler(DittoRejectionHandlerFactory.createInstance());
}
private static Route newRouteInstance(final Builder builder) {
final RootRoute rootRoute = new RootRoute(builder);
return rootRoute.buildRoute();
}
private Route buildRoute() {
return wrapWithRootDirectives(correlationId ->
extractRequestContext(ctx ->
route(
statsRoute.buildStatsRoute(correlationId), // /stats
cachingHealthRoute.buildHealthRoute(), // /health
api(ctx, correlationId), // /api
ws(ctx, correlationId), // /ws
ownStatusRoute.buildStatusRoute(), // /status
overallStatusRoute.buildOverallStatusRoute(), // /overall
devopsRoute.buildDevopsRoute(ctx) // /devops
)
)
);
}
private Route wrapWithRootDirectives(final java.util.function.Function<String, Route> rootRoute) {
final Function<Function<String, Route>, Route> outerRouteProvider = innerRouteProvider ->
/* the outer handleExceptions is for handling exceptions in the directives wrapping the rootRoute
(which normally should not occur */
handleExceptions(exceptionHandler, () ->
ensureCorrelationId(correlationId ->
RequestTimeoutHandlingDirective.handleRequestTimeout(correlationId, () ->
logRequestResult(correlationId, () ->
innerRouteProvider.apply(correlationId)
)
)
)
);
final Function<String, Route> innerRouteProvider = correlationId ->
EncodingEnsuringDirective.ensureEncoding(correlationId, () ->
HttpsEnsuringDirective.ensureHttps(correlationId, () ->
CorsEnablingDirective.enableCors(() ->
SecurityResponseHeadersDirective.addSecurityResponseHeaders(() ->
/* handling the rejections is done by akka automatically, but if we
do it here explicitly, we are able to log the status code for the
rejection (e.g. 404 or 405) in a wrapping directive. */
handleRejections(rejectionHandler, () ->
/* the inner handleExceptions is for handling exceptions
occurring in the route route. It makes sure that the
wrapping directives such as addSecurityResponseHeaders are
even called in an error case in the route route. */
handleExceptions(exceptionHandler, () ->
rootRoute.apply(correlationId)
)
)
)
)
)
);
return outerRouteProvider.apply(innerRouteProvider);
}
private Route apiAuthentication(final CharSequence correlationId,
final Function<AuthorizationContext, Route> inner) {
return apiAuthenticationDirective.authenticate(correlationId, inner);
}
private Route wsAuthentication(final CharSequence correlationId,
final Function<AuthorizationContext, Route> inner) {
return wsAuthenticationDirective.authenticate(correlationId, inner);
}
/*
* Describes {@code /api} route.
*
* @return route for API resource.
*/
private Route api(final RequestContext ctx, final String correlationId) {
return rawPathPrefix(mergeDoubleSlashes().concat(HTTP_PATH_API_PREFIX), () -> // /api
ensureSchemaVersion(apiVersion -> // /api/<apiVersion>
customApiRoutesProvider.unauthorized(apiVersion, correlationId).orElse(
apiAuthentication(correlationId,
authContextWithPrefixedSubjects ->
mapAuthorizationContext(
correlationId,
apiVersion,
authContextWithPrefixedSubjects,
authContext ->
parameterOptional(TopicPath.Channel.LIVE.getName(),
liveParam ->
withDittoHeaders(
authContext,
apiVersion,
correlationId,
ctx,
liveParam.orElse(null),
CustomHeadersHandler.RequestType.API,
dittoHeaders ->
buildApiSubRoutes(ctx,
dittoHeaders,
authContext)
)
)
)
))
)
);
}
private Route ensureSchemaVersion(final IntFunction<Route> inner) {
return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.integerSegment()),
apiVersion -> { // /xx/<schemaVersion>
if (supportedSchemaVersions.contains(apiVersion)) {
try {
return inner.apply(apiVersion);
} catch (final RuntimeException e) {
throw e; // rethrow RuntimeExceptions
} catch (final Exception e) {
throw new IllegalStateException("Unexpected checked exception", e);
}
}
return complete(getHttpResponseFor(CommandNotSupportedException.newBuilder(apiVersion).build()));
});
}
private HttpResponse getHttpResponseFor(final DittoRuntimeException exception) {
return HttpResponse.create()
.withStatus(exception.getStatusCode().toInt())
.withHeaders(getExternalHeadersFor(exception.getDittoHeaders()))
.withEntity(ContentTypes.APPLICATION_JSON, ByteString.fromString(exception.toJsonString()));
}
private Set<HttpHeader> getExternalHeadersFor(final DittoHeaders dittoHeaders) {
final Map<String, String> externalHeaders = headerTranslator.toExternalHeaders(dittoHeaders);
return externalHeaders.entrySet()
.stream()
.map(headerEntry -> HttpHeader.parse(headerEntry.getKey(), headerEntry.getValue()))
.collect(Collectors.toSet());
}
private Route buildApiSubRoutes(final RequestContext ctx, final DittoHeaders dittoHeaders,
final AuthorizationContext authorizationContext) {
final Route customApiSubRoutes = customApiRoutesProvider.authorized(dittoHeaders);
return Directives.route(
// /api/{apiVersion}/policies
policiesRoute.buildPoliciesRoute(ctx, dittoHeaders),
// /api/{apiVersion}/things SSE support
sseThingsRoute.buildThingsSseRoute(ctx, () ->
overwriteDittoHeaders(ctx, dittoHeaders, authorizationContext)),
// /api/{apiVersion}/things
thingsRoute.buildThingsRoute(ctx, dittoHeaders),
// /api/{apiVersion}/search/things
thingSearchRoute.buildSearchRoute(ctx, dittoHeaders)
).orElse(customApiSubRoutes);
}
/*
* Describes {@code /ws} route.
*
* @return route for Websocket resource.
*/
private Route ws(final RequestContext ctx, final String correlationId) {
return rawPathPrefix(mergeDoubleSlashes().concat(WS_PATH_PREFIX), () -> // /ws
ensureSchemaVersion(wsVersion -> // /ws/<wsVersion>
wsAuthentication(correlationId, authContextWithPrefixedSubjects ->
mapAuthorizationContext(correlationId, wsVersion, authContextWithPrefixedSubjects,
authContext ->
withDittoHeaders(authContext, wsVersion, correlationId, ctx, null,
CustomHeadersHandler.RequestType.WS, dittoHeaders -> {
final String userAgent = extractUserAgent(ctx).orElse(null);
final ProtocolAdapter chosenProtocolAdapter =
protocolAdapterProvider.getProtocolAdapter(
userAgent);
return websocketRoute.buildWebsocketRoute(wsVersion,
correlationId,
authContext, dittoHeaders, chosenProtocolAdapter);
}
)
)
)
)
);
}
private static Optional<String> extractUserAgent(final RequestContext requestContext) {
final Stream<HttpHeader> headerStream =
StreamSupport.stream(requestContext.getRequest().getHeaders().spliterator(), false);
// find user-agent: HTTP header names are case-insensitive
return headerStream.filter(header -> "user-agent".equalsIgnoreCase(header.name()))
.map(HttpHeader::value)
.findAny();
}
private Route withDittoHeaders(final AuthorizationContext authorizationContext,
final Integer version,
final String correlationId,
final RequestContext ctx,
@Nullable final String liveParam,
final CustomHeadersHandler.RequestType requestType,
final Function<DittoHeaders, Route> inner) {
final DittoHeaders dittoHeaders =
buildDittoHeaders(authorizationContext, version, correlationId, ctx, liveParam, requestType);
return dittoHeadersSizeChecker.run(dittoHeaders, inner, error ->
handleExceptions(exceptionHandler, () -> {
throw error;
}));
}
private DittoHeaders overwriteDittoHeaders(final RequestContext ctx, final DittoHeaders dittoHeaders,
final AuthorizationContext authorizationContext) {
final String correlationId = dittoHeaders.getCorrelationId().orElseGet(() -> UUID.randomUUID().toString());
return handleCustomHeaders(correlationId, ctx, CustomHeadersHandler.RequestType.SSE, authorizationContext,
dittoHeaders);
}
private DittoHeaders buildDittoHeaders(final AuthorizationContext authorizationContext,
final Integer version,
final String correlationId,
final RequestContext ctx,
@Nullable final String liveParam,
final CustomHeadersHandler.RequestType requestType) {
final DittoHeadersBuilder builder = DittoHeaders.newBuilder();
final Map<String, String> externalHeadersMap = getFilteredExternalHeaders(ctx.getRequest(), correlationId);
builder.putHeaders(externalHeadersMap);
final JsonSchemaVersion jsonSchemaVersion = JsonSchemaVersion.forInt(version)
.orElseThrow(() -> CommandNotSupportedException.newBuilder(version).build());
builder.authorizationContext(authorizationContext)
.schemaVersion(jsonSchemaVersion)
.correlationId(correlationId);
authorizationContext.getFirstAuthorizationSubject().map(AuthorizationSubject::getId).ifPresent(builder::source);
// if the "live" query param was set - no matter what the value was - use live channel
if (liveParam != null) {
builder.channel(TopicPath.Channel.LIVE.getName());
}
final DittoHeaders dittoDefaultHeaders = builder.build();
return handleCustomHeaders(correlationId, ctx, requestType, authorizationContext, dittoDefaultHeaders);
}
private DittoHeaders handleCustomHeaders(final String correlationId, final RequestContext ctx,
final CustomHeadersHandler.RequestType requestType,
final AuthorizationContext authorizationContext,
final DittoHeaders dittoDefaultHeaders) {
return customHeadersHandler.handleCustomHeaders(correlationId, ctx, requestType,
authorizationContext, dittoDefaultHeaders);
}
private Map<String, String> getFilteredExternalHeaders(final HttpMessage httpRequest, final String correlationId) {
Map<String, String> externalHeaders =
StreamSupport.stream(httpRequest.getHeaders().spliterator(), false)
.collect(Collectors.toMap(HttpHeader::name, HttpHeader::value, (dv1, dv2) -> {
throw GatewayDuplicateHeaderException
.newBuilder()
.dittoHeaders(DittoHeaders.newBuilder().correlationId(correlationId).build())
.build();
}));
return headerTranslator.fromExternalHeaders(externalHeaders);
}
private ExceptionHandler createExceptionHandler() {
return ExceptionHandler.newBuilder()
.match(DittoRuntimeException.class, dittoRuntimeException -> {
logException(dittoRuntimeException);
return complete(getHttpResponseFor(dittoRuntimeException));
})
.match(JsonRuntimeException.class, jsonRuntimeException -> {
final DittoRuntimeException dittoRuntimeException = new DittoJsonException(jsonRuntimeException);
logException(dittoRuntimeException);
return complete(getHttpResponseFor(dittoRuntimeException));
})
.matchAny(throwable -> {
LOGGER.error("Unexpected RuntimeException in gateway root route: <{}>!", throwable.getMessage(),
throwable);
return complete(StatusCodes.INTERNAL_SERVER_ERROR);
})
.build();
}
private static void logException(final DittoRuntimeException exception) {
final DittoHeaders dittoHeaders = exception.getDittoHeaders();
final Optional<String> correlationIdOptional = dittoHeaders.getCorrelationId();
final String simpleExceptionName = exception.getClass().getSimpleName();
final String exceptionMessage = exception.getMessage();
if (!correlationIdOptional.isPresent()) {
LOGGER.warn("Correlation ID was missing in headers of <{}>: <{}>!", simpleExceptionName, exceptionMessage);
}
enhanceLogWithCorrelationId(correlationIdOptional,
() -> LOGGER.info("<{}> occurred in gateway root route: <{}>!", simpleExceptionName, exceptionMessage));
}
@NotThreadSafe
private static final class Builder implements RootRouteBuilder {
private StatusRoute statusRoute;
private OverallStatusRoute overallStatusRoute;
private CachingHealthRoute cachingHealthRoute;
private DevOpsRoute devopsRoute;
private PoliciesRoute policiesRoute;
private SseThingsRoute sseThingsRoute;
private ThingsRoute thingsRoute;
private ThingSearchRoute thingSearchRoute;
private WebsocketRoute websocketRoute;
private StatsRoute statsRoute;
private CustomApiRoutesProvider customApiRoutesProvider;
private GatewayAuthenticationDirective httpAuthenticationDirective;
private GatewayAuthenticationDirective wsAuthenticationDirective;
private ExceptionHandler exceptionHandler;
private List<Integer> supportedSchemaVersions;
private ProtocolAdapterProvider protocolAdapterProvider;
private HeaderTranslator headerTranslator;
private CustomHeadersHandler customHeadersHandler;
private RejectionHandler rejectionHandler;
private DittoHeadersSizeChecker dittoHeadersSizeChecker;
private Builder() {
super();
}
@Override
public RootRouteBuilder statusRoute(final StatusRoute route) {
statusRoute = route;
return this;
}
@Override
public RootRouteBuilder overallStatusRoute(final OverallStatusRoute route) {
overallStatusRoute = route;
return this;
}
@Override
public RootRouteBuilder cachingHealthRoute(final CachingHealthRoute route) {
cachingHealthRoute = route;
return this;
}
@Override
public RootRouteBuilder devopsRoute(final DevOpsRoute route) {
devopsRoute = route;
return this;
}
@Override
public RootRouteBuilder policiesRoute(final PoliciesRoute route) {
policiesRoute = route;
return this;
}
@Override
public RootRouteBuilder sseThingsRoute(final SseThingsRoute route) {
sseThingsRoute = route;
return this;
}
@Override
public RootRouteBuilder thingsRoute(final ThingsRoute route) {
thingsRoute = route;
return this;
}
@Override
public RootRouteBuilder thingSearchRoute(final ThingSearchRoute route) {
thingSearchRoute = route;
return this;
}
@Override
public RootRouteBuilder websocketRoute(final WebsocketRoute route) {
websocketRoute = route;
return this;
}
@Override
public RootRouteBuilder statsRoute(final StatsRoute route) {
statsRoute = route;
return this;
}
@Override
public RootRouteBuilder customApiRoutesProvider(final CustomApiRoutesProvider provider) {
customApiRoutesProvider = provider;
return this;
}
@Override
public RootRouteBuilder httpAuthenticationDirective(final GatewayAuthenticationDirective directive) {
httpAuthenticationDirective = directive;
return this;
}
@Override
public RootRouteBuilder wsAuthenticationDirective(final GatewayAuthenticationDirective directive) {
wsAuthenticationDirective = directive;
return this;
}
@Override
public RootRouteBuilder exceptionHandler(final ExceptionHandler handler) {
exceptionHandler = handler;
return this;
}
@Override
public RootRouteBuilder supportedSchemaVersions(final List<Integer> versions) {
supportedSchemaVersions = versions;
return this;
}
@Override
public RootRouteBuilder protocolAdapterProvider(final ProtocolAdapterProvider provider) {
protocolAdapterProvider = provider;
return this;
}
@Override
public RootRouteBuilder headerTranslator(final HeaderTranslator translator) {
headerTranslator = translator;
return this;
}
@Override
public RootRouteBuilder customHeadersHandler(final CustomHeadersHandler handler) {
customHeadersHandler = handler;
return this;
}
@Override
public RootRouteBuilder rejectionHandler(final RejectionHandler handler) {
rejectionHandler = handler;
return this;
}
@Override
public RootRouteBuilder dittoHeadersSizeChecker(final DittoHeadersSizeChecker checker) {
dittoHeadersSizeChecker = checker;
return this;
}
@Override
public Route build() {
return newRouteInstance(this);
}
}
}