use of org.apache.meecrowave.proxy.servlet.configuration.Routes in project meecrowave by apache.
the class ConfigurationLoader method doLoad.
protected Optional<Routes> doLoad(final String content) {
try (final Jsonb jsonb = JsonbBuilder.newBuilder().withProvider(loadJsonpProvider()).withConfig(new JsonbConfig().setProperty("org.apache.johnzon.supports-comments", true)).build()) {
routes = jsonb.fromJson(content, Routes.class);
final boolean hasRoutes = routes.routes != null && !routes.routes.isEmpty();
if (routes.defaultRoute == null && !hasRoutes) {
return Optional.empty();
}
if (hasRoutes) {
// before merging, ensure all routes have an id to not duplicate default id
routes.routes.stream().filter(it -> it.id == null).forEach(it -> it.id = newId());
}
if (routes.defaultRoute != null) {
if (routes.defaultRoute.id == null) {
routes.defaultRoute.id = "default";
}
if (routes.routes == null) {
// no route were defined, consider it is the default route, /!\ empty means no route, don't default
routes.routes = singletonList(routes.defaultRoute);
}
if (hasRoutes) {
final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(emptyMap());
final JsonObject template = jsonb.fromJson(jsonb.toJson(routes.defaultRoute), JsonObject.class);
routes.routes = routes.routes.stream().map(r -> merge(jsonb, jsonFactory, template, r)).collect(toList());
}
}
} catch (final Exception e) {
throw new IllegalArgumentException(e);
}
routes.routes.forEach(this::init);
return Optional.of(routes);
}
Aggregations